Skip to content

fix(build): add WSL detection to bundle-a2ui.sh#33321

Open
BinHPdev wants to merge 3 commits intoopenclaw:mainfrom
BinHPdev:fix/wsl-bundle-detection
Open

fix(build): add WSL detection to bundle-a2ui.sh#33321
BinHPdev wants to merge 3 commits intoopenclaw:mainfrom
BinHPdev:fix/wsl-bundle-detection

Conversation

@BinHPdev
Copy link
Copy Markdown
Contributor

@BinHPdev BinHPdev commented Mar 3, 2026

Summary

  • Add WSL environment detection to scripts/bundle-a2ui.sh that exits early using the prebuilt bundle, mirroring the existing Docker fallback pattern
  • On Windows, pnpm resolves bash to C:\Windows\System32\bash.exe (WSL), where native Node.js is typically absent — this causes compute_hash (node --input-type=module) and pnpm exec tsc/rolldown to fail

This is a minimal, focused extract from #26070 — only the WSL detection guard, no hash algorithm changes (preserves existing cache semantics).

Relates to #10070

Changes

Adds a WSL check (grep -qi microsoft /proc/version) before the hash/build pipeline:

  • If prebuilt bundle exists → use it and exit 0
  • If no prebuilt bundle → print guidance to build outside WSL (Git Bash / cmd) and exit 1

No changes to compute_hash, no changes to cache behavior.

Test plan

  • pnpm build completes on Windows 11 + WSL2 (WSL bash detects WSL, uses prebuilt bundle, exits 0)
  • pnpm canvas:a2ui:bundle works normally on macOS / Linux / Git Bash (WSL guard is skipped)
  • Hash cache behavior unchanged: running bundle twice in non-WSL env still skips with "A2UI bundle up to date; skipping."

🤖 Generated with Claude Code

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR adds a WSL detection guard to scripts/bundle-a2ui.sh to prevent build failures when Windows pnpm resolves bash to C:\Windows\System32\bash.exe (WSL bash), where native Node.js is typically absent. The pattern mirrors the existing Docker fallback block.

However, the WSL detection condition on line 32 is overly broad. It triggers for all WSL environments, not just the specific failure case (Windows pnpm spawning WSL bash without Node.js available). This creates a regression: developers using WSL2 as their primary development environment with Node.js installed inside WSL would be forced to use a potentially stale prebuilt bundle or blocked from building entirely if no prebuilt bundle exists.

The guard should also check that Node.js is absent (&& ! command -v node >/dev/null 2>&1) to target the actual failure condition, allowing capable WSL environments to build normally while protecting the Windows+WSL scenario.

Confidence Score: 2/5

  • The PR correctly solves the Windows+WSL issue but introduces a regression for WSL-primary developers who have Node.js installed.
  • The change correctly solves the specific problem stated in the PR (Windows pnpm spawning WSL bash where Node.js is absent), and the scripting patterns are sound. However, the WSL detection condition is overly broad and would prevent legitimate WSL development environments (with Node.js installed) from building when a prebuilt bundle is unavailable. This is a concrete regression, not speculation. Adding a node availability check (&& ! command -v node >/dev/null 2>&1) is a simple fix that would resolve this issue.
  • scripts/bundle-a2ui.sh — line 32 requires narrowing the WSL detection condition to also verify Node.js is not available

Last reviewed commit: 6c42eaa

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +32 to +39
if grep -qi microsoft /proc/version 2>/dev/null; then
if [[ -f "$OUTPUT_FILE" ]]; then
echo "WSL detected; using prebuilt A2UI bundle."
exit 0
fi
echo "WSL environment detected but no prebuilt bundle found at: $OUTPUT_FILE" >&2
echo "Build outside WSL first (e.g. Git Bash): pnpm canvas:a2ui:bundle" >&2
exit 1
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.

WSL guard too broad — breaks WSL-primary developers

This guard triggers for all WSL environments, not just the specific failure case described in the PR (Windows pnpm spawning WSL bash where Node.js is absent).

A developer using WSL2 as their primary environment with Node.js installed inside WSL would hit this guard and either be forced to use a potentially stale prebuilt bundle (line 34) or fail entirely (line 39) if no prebuilt bundle exists. This blocks a legitimate development scenario.

The actual failure condition is WSL and Node.js absent. Adding a check for node availability would narrow the guard precisely:

Suggested change
if grep -qi microsoft /proc/version 2>/dev/null; then
if [[ -f "$OUTPUT_FILE" ]]; then
echo "WSL detected; using prebuilt A2UI bundle."
exit 0
fi
echo "WSL environment detected but no prebuilt bundle found at: $OUTPUT_FILE" >&2
echo "Build outside WSL first (e.g. Git Bash): pnpm canvas:a2ui:bundle" >&2
exit 1
if grep -qi microsoft /proc/version 2>/dev/null && ! command -v node >/dev/null 2>&1; then
if [[ -f "$OUTPUT_FILE" ]]; then
echo "WSL detected (no Node.js available); using prebuilt A2UI bundle."
exit 0
fi
echo "WSL environment detected but no prebuilt bundle found at: $OUTPUT_FILE" >&2
echo "Build outside WSL first (e.g. Git Bash): pnpm canvas:a2ui:bundle" >&2
exit 1
fi

This allows WSL developers with Node.js installed to build normally, while still protecting against the Windows-pnpm-to-WSL-bash scenario.

Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/bundle-a2ui.sh
Line: 32-39

Comment:
**WSL guard too broad — breaks WSL-primary developers**

This guard triggers for *all* WSL environments, not just the specific failure case described in the PR (Windows `pnpm` spawning WSL bash where Node.js is absent). 

A developer using WSL2 as their primary environment with Node.js installed inside WSL would hit this guard and either be forced to use a potentially stale prebuilt bundle (line 34) or fail entirely (line 39) if no prebuilt bundle exists. This blocks a legitimate development scenario.

The actual failure condition is WSL *and* Node.js absent. Adding a check for node availability would narrow the guard precisely:

```suggestion
if grep -qi microsoft /proc/version 2>/dev/null && ! command -v node >/dev/null 2>&1; then
  if [[ -f "$OUTPUT_FILE" ]]; then
    echo "WSL detected (no Node.js available); using prebuilt A2UI bundle."
    exit 0
  fi
  echo "WSL environment detected but no prebuilt bundle found at: $OUTPUT_FILE" >&2
  echo "Build outside WSL first (e.g. Git Bash): pnpm canvas:a2ui:bundle" >&2
  exit 1
fi
```

This allows WSL developers with Node.js installed to build normally, while still protecting against the Windows-pnpm-to-WSL-bash scenario.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — narrowed the guard to grep -qi microsoft /proc/version && \! command -v node in f54b881. WSL-primary developers with Node.js installed will now build normally.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c42eaaae2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# The pnpm wrappers for tsc/rolldown also invoke node internally, so the
# entire build pipeline fails. Use the prebuilt bundle when available;
# otherwise guide the user to build outside WSL where Windows node is on PATH.
if grep -qi microsoft /proc/version 2>/dev/null; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid blocking all WSL builds when bundle is absent

This guard makes pnpm canvas:a2ui:bundle fail unconditionally on any WSL host when src/canvas-host/a2ui/a2ui.bundle.js is not already present, even if Node/tsc/rolldown are correctly installed in WSL. Because src/canvas-host/a2ui/*.bundle.js is gitignored, a clean checkout in WSL will hit this path and cannot produce the bundle at all, which is a regression from the previous behavior where WSL users could build locally.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f54b881 — the guard now only triggers when WSL is detected and node is not on PATH. Clean WSL checkouts with Node.js installed can build normally.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f54b881fef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +33 to +35
if [[ -f "$OUTPUT_FILE" ]]; then
echo "WSL detected (no Node.js available); using prebuilt A2UI bundle."
exit 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate prebuilt bundle freshness before exiting on WSL

In the new WSL fallback branch, if WSL is detected and node is missing, the script now exits 0 as soon as a2ui.bundle.js exists, without checking whether it matches current A2UI sources. This means a stale bundle from a previous checkout/build can be silently reused when vendor/a2ui/renderers/lit or apps/shared/OpenClawKit/Tools/CanvasA2UI changed, producing outdated assets in pnpm build outputs instead of forcing regeneration.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f75941a94

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +33 to +35
if [[ -f "$OUTPUT_FILE" ]]; then
echo "WSL detected (no Node.js available); using prebuilt A2UI bundle."
exit 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check bundle freshness before WSL early exit

Fresh evidence in be7a32c is that the new WSL/no-Node branch returns success as soon as a2ui.bundle.js exists, but this happens before compute_hash runs, so source changes in vendor/a2ui/renderers/lit or apps/shared/OpenClawKit/Tools/CanvasA2UI are never detected in that path. In WSL environments without Node installed, this can let pnpm build succeed with an outdated bundle instead of forcing regeneration or a hard failure.

Useful? React with 👍 / 👎.

@liangguohao66
Copy link
Copy Markdown

still open ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scripts Repository scripts size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants