Skip to content

fix(taskfile): Isolate log-viewer dependency tasks to fix race condition in webui build (fixes #2167).#2168

Open
junhaoliao wants to merge 21 commits intoy-scope:mainfrom
junhaoliao:fix-log-viewer-race
Open

fix(taskfile): Isolate log-viewer dependency tasks to fix race condition in webui build (fixes #2167).#2168
junhaoliao wants to merge 21 commits intoy-scope:mainfrom
junhaoliao:fix-log-viewer-race

Conversation

@junhaoliao
Copy link
Copy Markdown
Member

@junhaoliao junhaoliao commented Apr 2, 2026

Description

Isolate the log-viewer's source download, node_modules installation, and production build into a
self-contained deps:yscope-log-viewer taskfile (taskfiles/deps/log-viewer.yaml). This fixes a
race condition where download-and-extract-tar (which does rm -rf on the source directory) could
run concurrently with checksum:validate for the log-viewer's node_modules, causing intermittent
build failures (fixes #2167).

Key changes:

  • New taskfiles/deps/log-viewer.yaml: Contains source, node-modules, and build tasks
    with proper dependency ordering. node-modules-checksum-validate ensures
    download-and-extract-tar completes before node_modules is validated (eliminating the race).
    The build task recomputes checksums after vite's build to account for node_modules/.vite-temp.
  • Move nodejs-22 to taskfiles/toolchains.yaml: Use yscope-dev-utils's
    download-and-extract-tar with pinned per-platform SHA256 hashes, replacing the old
    download-and-extract-tar and nodejs tasks in taskfile.yaml.
  • Decouple webui-node-modules from log-viewer: The webui's node-modules task no longer
    installs or checksums the log-viewer's node_modules; it only manages the webui package's own
    workspace dependencies.
  • Update clean-webui: Only cleans the webui package's node_modules and build output; the
    log-viewer's cleanup is handled by its own clean-node-modules task.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

1. deps:yscope-log-viewer caching after clean build

Verifies that after rm -rf .task/ build/, the second run is fully cached (no re-extraction,
no re-install, no rebuild).

Commands:

rm -rf .task/ build/
task deps:yscope-log-viewer   # Run 1
task deps:yscope-log-viewer   # Run 2

Run 2 output:

task: Task "deps:yscope-dev-utils:remote:download-and-extract-tar-/.../yscope-log-viewer" is up to date
task: Task "deps:yscope-log-viewer:node-modules" is up to date
task: Task "deps:yscope-log-viewer:build" is up to date

2. webui build succeeds and caches correctly

Verifies the full webui pipeline builds from a clean state and that log-viewer tasks are cached
on the second run.

Commands:

rm -rf .task/ build/
task webui   # Run 1
task webui   # Run 2

Run 2 output (log-viewer tasks):

task: Task "deps:yscope-dev-utils:remote:download-and-extract-tar-/.../yscope-log-viewer" is up to date
task: Task "deps:yscope-log-viewer:node-modules" is up to date
task: Task "deps:yscope-log-viewer:build" is up to date
task: Task "webui" is up to date

Note: webui-node-modules re-runs on the second invocation. This is a pre-existing issue
(confirmed on main) unrelated to this PR.

3. YAML lint passes

Command:

task lint:check-yaml

Output:

task: [lint:yaml] . ".../build/lint-venv/bin/activate"
yamllint --strict \
  --config-file "tools/yscope-dev-utils/exports/lint-configs/.yamllint.yml" \
  ".github" \
  "components/core/.clang-format" \
  ...
  "taskfile.yaml" \
  "taskfiles" \
  ...

No errors.

Summary by CodeRabbit

  • Chores
    • Moved log‑viewer dependency to an external yscope‑log‑viewer flow and simplified the Web UI node_modules pipeline.
    • Centralized checksum handling to validate only the Web UI top‑level node_modules.
    • Added a cleanup task that removes top‑level Web UI node_modules (client/common/server/top) without touching embedded log‑viewer modules.
    • Introduced Node.js 22 toolchain support for the node‑modules build flow and updated rebuild triggers accordingly.

@junhaoliao junhaoliao requested a review from a team as a code owner April 2, 2026 04:59
@junhaoliao junhaoliao changed the title fix(taskfile): Fix race between deps:log-viewer and `checksum:valid… fix(taskfile): Fix race between deps:log-viewer and checksum:validate for log-viewer node_modules (fixes #2167). Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Removed WebUI-specific Node.js 22 build/download tasks and log-viewer node_modules checksum wiring from taskfile.yaml; added internal clean-webui-package-node-modules. Introduced taskfiles/deps/yscope-log-viewer.yaml to fetch/build yscope-log-viewer node_modules and added a Node.js 22 toolchain in taskfiles/toolchains.yaml. webui-node-modules now depends on deps:yscope-log-viewer:node-modules and toolchains:nodejs-22.

Changes

Cohort / File(s) Summary
Top-level Taskfile
taskfile.yaml
Removed inline Node.js-22 build/download tasks and related vars (G_NODEJS_22_BUILD_DIR, G_NODEJS_22_BIN_DIR), removed G_WEBUI_LOG_VIEWER_NODE_MODULES_CHECKSUM_FILE, added internal clean-webui-package-node-modules; updated clean-webui, webui, and webui-node-modules to drop direct log-viewer checksum handling and rely on deps:yscope-log-viewer:node-modules and toolchains:nodejs-22.
Deps index
taskfiles/deps/main.yaml
Replaced local log-viewer inclusion with yscope-log-viewer via ./yscope-log-viewer.yaml; updated default.deps to include yscope-log-viewer; removed the old log-viewer task and its checksum var.
yscope log-viewer dep
taskfiles/deps/yscope-log-viewer.yaml
New Taskfile added defining source, node-modules, node-modules-checksum-validate, and clean-node-modules: downloads/extracts pinned yscope-log-viewer sources, runs npm clean-install under Node toolchain, computes/validates node_modules checksum, and exposes defaultnode-modules.
Toolchains
taskfiles/toolchains.yaml
Added Node.js 22 toolchain variables (G_NODEJS_22_BUILD_DIR, G_NODEJS_22_BIN_DIR, G_NODEJS_22_CHECKSUM_FILE) and a new internal nodejs-22 task to download/extract Node.js 22 (OS/arch-specific SHA256 templating).

Sequence Diagram(s)

sequenceDiagram
    participant Runner as Task Runner
    participant YSV as deps:yscope-log-viewer:node-modules
    participant TC as toolchains:nodejs-22
    participant Cleaner as clean-webui-package-node-modules
    participant WebUI as webui-node-modules
    participant Utils as :yscope-dev-utils:checksum

    Runner->>YSV: run source -> download & extract yscope-log-viewer
    YSV->>YSV: npm clean-install (uses Node 22 via TC)
    YSV->>Utils: compute/store yscope node_modules checksum
    YSV-->>Runner: node-modules artifact ready
    Runner->>TC: ensure nodejs-22 available
    TC-->>Runner: runtime/bin ready
    Runner->>Cleaner: remove top-level WebUI node_modules paths
    Cleaner-->>Runner: cleanup done
    Runner->>WebUI: run npm clean-install (uses nodejs-22)
    WebUI->>Utils: compute/store top-level webui node_modules checksum
    Utils-->>WebUI: checksum written/validated
    WebUI-->>Runner: webui-node-modules complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: refactoring log-viewer dependency tasks to isolate them and fix a race condition in the webui build pipeline.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@Bill-hbrhbr Bill-hbrhbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fundamental design issue is that we should put yscope-log-viewer along with its node-modules initialization into a separate module. What I suggest is the following refactor:

  • Put nodejs22 install into taskfiles/toolchain.yaml
  • Move deps:yscope-log-viewer into a standalone task file like taskfiles/deps/yscope-log-viewer.yaml and handle the log-viewer-specific node modules initialization there. We should also do the checksum over there, rather than inside the main taskfile.

@junhaoliao junhaoliao added this to the Mid-April 2026 milestone Apr 2, 2026
@junhaoliao junhaoliao requested a review from Bill-hbrhbr April 3, 2026 22:14
LOG_VIEWER_OUTPUT_DIR: "{{.G_WEBUI_SRC_DIR}}/yscope-log-viewer/node_modules"
PACKAGE_OUTPUT_DIR: "{{.G_WEBUI_SRC_DIR}}/node_modules"
sources:
- "{{.G_DEPS_LOG_VIEWER_CHECKSUM_FILE}}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should put this back? Will there be cases where log viewer source code changes, but nothing affects the node modules and its checksum.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. let me double check and add it back

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually i remember this is intentional. webui-node-modules should only be responsible for ensuring the webui components's node_modules are cleanly built.

do note that the log-viewer source code is consumed at

  • task webui, which depends on
  • task webui-node-modules, which depends on
  • task deps:yscope-log-viewer:node-modules, which depends on
  • task deps:yscope-log-viewer:node-modules-checksum-validate, which depends on
    deps:yscope-log-viewer:source.

we have seen that

  • webui includes G_WEBUI_PACKAGE_NODE_MODULES_CHECKSUM_FILE in its sources
  • webui-node-modules includes G_WEBUI_LOG_VIEWER_NODE_MODULES_CHECKSUM_FILE in its sources, and generates G_WEBUI_PACKAGE_NODE_MODULES_CHECKSUM_FILE
  • deps:yscope-log-viewer:node-modules includes G_DEPS_LOG_VIEWER_CHECKSUM_FILE in its sources, and generates G_WEBUI_LOG_VIEWER_NODE_MODULES_CHECKSUM_FILE
  • source generates G_DEPS_LOG_VIEWER_CHECKSUM_FILE

So any change to the log viewer source already propagates through the checksum chain. Additionally, webui has **/* (excluding node_modules and dist) in its sources, which directly catches log viewer source file changes.


Now i think about it, maybe we should move the log-viewer building to deps/yscope-log-viewer.yaml so the concerns will be cleanly isolated. let me try making the changes now

junhaoliao and others added 6 commits April 7, 2026 14:53
…code review

Co-authored-by: Bingran Hu <bingran.hu@yscope.com>
Co-authored-by: Bingran Hu <bingran.hu@yscope.com>
…de review

Co-authored-by: Bingran Hu <bingran.hu@yscope.com>
Co-authored-by: Bingran Hu <bingran.hu@yscope.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@taskfile.yaml`:
- Around line 99-103: The clean-webui task currently only removes node_modules
(via subtasks clean-webui-package-node-modules and
deps:yscope-log-viewer:clean-node-modules) but no longer deletes the built web
UI output or checksum files; update the clean-webui task to also remove the
build output directory ({{.G_WEBUI_BUILD_DIR}}) and any webui checksum files so
the task truly provides a clean rebuild boundary—add steps after the existing
cmds that delete {{.G_WEBUI_BUILD_DIR}} (rm -rf style) and remove the webui
checksum files (the checksum filename pattern used by the repo) so both
artifacts are cleaned when running task clean-webui.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f95a07c5-0c1e-4ad1-9e26-0a52276ba439

📥 Commits

Reviewing files that changed from the base of the PR and between 936bad1 and 33e1613.

📒 Files selected for processing (2)
  • taskfile.yaml
  • taskfiles/deps/yscope-log-viewer.yaml

taskfile.yaml Outdated
Comment on lines +99 to +103
clean-webui:
cmds:
- task: "clean-webui-package-node-modules"
- task: "deps:yscope-log-viewer:clean-node-modules"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

clean-webui no longer removes the built webui artefacts.

After this change, task clean-webui only deletes node_modules. {{.G_WEBUI_BUILD_DIR}} and the webui checksum files stay behind, so the task no longer gives you a clean webui rebuild boundary on its own.

Suggested fix
  clean-webui:
    cmds:
+      - "rm -rf '{{.G_WEBUI_BUILD_DIR}}'"
+      - "rm -f '{{.G_WEBUI_CHECKSUM_FILE}}' '{{.G_WEBUI_PACKAGE_NODE_MODULES_CHECKSUM_FILE}}'"
       - task: "clean-webui-package-node-modules"
       - task: "deps:yscope-log-viewer:clean-node-modules"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@taskfile.yaml` around lines 99 - 103, The clean-webui task currently only
removes node_modules (via subtasks clean-webui-package-node-modules and
deps:yscope-log-viewer:clean-node-modules) but no longer deletes the built web
UI output or checksum files; update the clean-webui task to also remove the
build output directory ({{.G_WEBUI_BUILD_DIR}}) and any webui checksum files so
the task truly provides a clean rebuild boundary—add steps after the existing
cmds that delete {{.G_WEBUI_BUILD_DIR}} (rm -rf style) and remove the webui
checksum files (the checksum filename pattern used by the repo) so both
artifacts are cleaned when running task clean-webui.

…y removing redundant `yscope-log-viewer` dependencies
@junhaoliao junhaoliao changed the title fix(taskfile): Fix race between deps:log-viewer and checksum:validate for log-viewer node_modules (fixes #2167). fix(taskfile): Isolate log-viewer dependency tasks to fix race condition in webui build (fixes #2167). Apr 8, 2026
@junhaoliao junhaoliao marked this pull request as draft April 8, 2026 14:17
@junhaoliao junhaoliao requested a review from Bill-hbrhbr April 8, 2026 15:24
@junhaoliao junhaoliao marked this pull request as ready for review April 8, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition in webui-node-modules between deps:log-viewer extraction and checksum validation

2 participants