Skip to content

fix: fall back to wrappers when bun compile fails - #412

Closed
malikrohail wants to merge 2 commits into
garrytan:mainfrom
malikrohail:malikrohail/fix-virtiofs-browse-fallback
Closed

malikrohail wants to merge 2 commits into
garrytan:mainfrom
malikrohail:malikrohail/fix-virtiofs-browse-fallback

Conversation

@malikrohail

Copy link
Copy Markdown
Contributor

Summary

Fixes the failure mode behind #407 where bun build --compile can fail on virtiofs/devcontainer mounts but ./setup still reports success.

What changed

  • Move build orchestration into scripts/build-artifacts.sh
  • Replace the blanket || true build tail with explicit build_or_wrap handling
  • When bun build --compile fails, write executable bun run wrappers for:
    • browse/dist/browse
    • browse/dist/find-browse
    • bin/gstack-global-discover
  • Keep the normal compiled-binary path unchanged when compile succeeds
  • Add static coverage for the new build helper in test/gen-skill-docs.test.ts

Why this fixes the bug

On virtiofs mounts, Bun can fail the final rename step for compiled binaries. The old build command hid that failure behind || true, so setup could continue with stale artifacts.

This change makes the failure explicit and recovers by installing wrapper entrypoints instead of leaving stale binaries in place.

Verification

  • bun run build
  • bun run gen:skill-docs --dry-run
  • bun test test/gen-skill-docs.test.ts -t "build script validation"
  • bun test

Refs #407

@FeilixX

FeilixX commented Mar 25, 2026

Copy link
Copy Markdown

Great work on this PR! We hit a related but distinct issue on WSL2 (filed as #494).

Your PR fixes: compile failure → wrapper fallback. ✅

Our additional finding: Even when compile succeeds, Bun.spawn inside the compiled binary hangs on WSL because stdio pipes don't connect properly. The process tree spawns fine (bun + chrome-headless all visible via pstree), but the parent CLI never receives data from the pipe.

Second issue we found: If the system has HTTP_PROXY set (common on WSL with clash/v2ray), the health check curl http://127.0.0.1:$port/health gets routed through the proxy → 502. Adding --noproxy '*' or no_proxy=localhost,127.0.0.1 to internal HTTP calls fixes this.

Our workaround: A bash wrapper (~80 lines) that uses nohup bun run server.ts instead of Bun.spawn, and adds --noproxy '*' to all curl calls. This could be integrated into the build_or_wrap approach as an additional fallback layer.

Would be happy to contribute this as a follow-up PR if useful.

@malikrohail

Copy link
Copy Markdown
Contributor Author

Great work on this PR! We hit a related but distinct issue on WSL2 (filed as #494).

Your PR fixes: compile failure → wrapper fallback. ✅

Our additional finding: Even when compile succeeds, Bun.spawn inside the compiled binary hangs on WSL because stdio pipes don't connect properly. The process tree spawns fine (bun + chrome-headless all visible via pstree), but the parent CLI never receives data from the pipe.

Second issue we found: If the system has HTTP_PROXY set (common on WSL with clash/v2ray), the health check curl http://127.0.0.1:$port/health gets routed through the proxy → 502. Adding --noproxy '*' or no_proxy=localhost,127.0.0.1 to internal HTTP calls fixes this.

Our workaround: A bash wrapper (~80 lines) that uses nohup bun run server.ts instead of Bun.spawn, and adds --noproxy '*' to all curl calls. This could be integrated into the build_or_wrap approach as an additional fallback layer.

Would be happy to contribute this as a follow-up PR if useful.

I will patch a commit with the fixes you just mentioned momentarily.

@malikrohail

Copy link
Copy Markdown
Contributor Author

@FeilixX can you test it now pls?
works on my end now

@FeilixX

FeilixX commented Mar 26, 2026 •

Copy link
Copy Markdown

@malikrohail Tested your PR in an isolated git worktree. Here's what I found:

Good news: The detached-bun strategy works — nodeSpawn with detached: true successfully starts the server. State file is written, server is healthy on the port, process is alive.

Bad news: The CLI still times out because requestLoopback can't reach the server when HTTP_PROXY is set.

Root cause — Bun vs Node.js proxy behavior difference:

Bun automatically applies HTTP_PROXY to all HTTP APIs (fetch and node:http.request). Node.js does not. Same code, different behavior:

# Runtime API HTTP_PROXY set Result
1 Bun http.request({hostname:'127.0.0.1'}) Yes 502 — proxied
2 Node http.request({hostname:'127.0.0.1'}) Yes 404 — direct
3 Bun http.request No 404 — direct
4 Node http.request No 404 — direct
5 Bun fetch('http://127.0.0.1') Yes 502 — proxied
6 Node fetch('http://127.0.0.1') Yes 404 — direct
7 Bun http.request Yes + NO_PROXY=127.0.0.1 404 — direct ✅

Your requestLoopback uses http.request({ hostname: '127.0.0.1' }) which works in Node.js (ignores proxy) but gets proxied in Bun runtime.

Simplest fix: Add NO_PROXY=127.0.0.1,localhost to the environment when spawning the server, or set it before health checks. Test 7 confirms Bun respects NO_PROXY correctly.

// In ensureServer / startServer:
const loopbackEnv = { ...process.env, NO_PROXY: '127.0.0.1,localhost' };

Our env: WSL2 Ubuntu 24.04, Bun 1.3.11, HTTP_PROXY=http://127.0.0.1:12334 (clash proxy)

@time-attack

Copy link
Copy Markdown
Contributor

Thanks for this. The branch combines the virtiofs fallback with separate WSL behavior and would omit parts of the current five-artifact build flow. Split the WSL work, rebase the fallback onto the current build script, preserve all artifacts, and verify virtiofs and WSL paths separately.

@capy-ai

capy-ai Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, @malikrohail. The fix is now on main: scripts/build.sh runs under set -e and setup no longer masks a failed build with || true, so a failed compile no longer reports success (already on main as of v1.91.16.0). Closing as superseded; if you still see the problem on the latest gstack, please open an issue with ./setup --status output.

@capy-ai capy-ai Bot closed this Oct 3, 2026
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.

3 participants