Repository navigation
fix(browse): spawn bun.exe directly for the terminal-agent on Windows (#2295) - #3357
Closed
adammartin0087 wants to merge 1 commit into
Closed
adammartin0087 wants to merge 1 commit into
adammartin0087 wants to merge 1 commit into
Conversation
Under the Node polyfill a bare 'bun' resolved (via cross-spawn) to npm's bun.cmd shim and ran as `cmd.exe /c bun run terminal-agent.ts`. windowsHide only hid cmd.exe, and the detached cmd.exe had no console, so bun.exe allocated a visible one that stole focus on every spawn. proc.pid was cmd.exe's, so the agent's startup check (record.pid === process.pid) never matched; it exited after 2s and the 60s watchdog respawned it (garrytan#2295). resolveBunExecutable() finds the real bun.exe (own execPath under bun, BUN_INSTALL, PATH, the npm-global node_modules layout, ~/.bun) and falls back to 'bun'. POSIX is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
This was referenced Oct 24, 2026
Contributor
|
Thank you @adammartin0087, great diagnosis of the |
garrytan
added a commit
that referenced
this pull request
Oct 24, 2026
…le() (#3357) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
capy-ai Bot
added a commit
that referenced
this pull request
Oct 25, 2026
…t on Windows (#2295, port of #3357) (#3388) * fix(browse): spawn bun.exe directly for the terminal-agent on Windows Under the Node polyfill a bare 'bun' resolved (via cross-spawn) to npm's bun.cmd shim and ran as `cmd.exe /c bun run terminal-agent.ts`. windowsHide only hid cmd.exe, and the detached cmd.exe had no console, so bun.exe allocated a visible one that stole focus on every spawn. proc.pid was cmd.exe's, so the agent's startup check (record.pid === process.pid) never matched; it exited after 2s and the 60s watchdog respawned it (#2295). resolveBunExecutable() finds the real bun.exe (own execPath under bun, BUN_INSTALL, PATH, the npm-global node_modules layout, ~/.bun) and falls back to 'bun'. POSIX is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(browse): one Windows bun.exe lookup for the terminal agent and the native cookie-import worker (#2295) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(changelog): Windows terminal agent spawns bun.exe directly (#2295, port of #3357) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(browse): the terminal-agent spawn pin expects resolveBunExecutable() (#3357) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: Adam Martin <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the console flash and 60s respawn loop that #2295 reported. Those were still happening on v1.91.182.0 (Windows 11 26200, npm-global Bun 1.4.2), after the v1.67+ watchdog rework and the polyfill
windowsHideforwarding.Root cause
spawnTerminalAgentspawns a bare'bun'. Under the Node polyfill, cross-spawn resolves it to npm'sbun.cmdshim and runscmd.exe /d /s /c "bun run ... terminal-agent.ts". That breaks two things:windowsHideapplies only to cmd.exe.detached: truegives cmd.exeDETACHED_PROCESS, so it has no console. It then startsbun.exe, which allocates a fresh, visible console. With Windows Terminal as the default terminal, that console opens as a WT window (WindowsTerminal.exe -Embedding) that steals focus for about 2 seconds.proc.pidis cmd.exe's PID, so the reservation records the wrong process.terminal-agent.tsmain()waits up to 2000 ms forrecord.pid === process.pid, then throwsstartup record was not confirmedand exits. That is why the window lasts exactly about 2 seconds. The watchdog sees a dead record and respawns 60 seconds later. The guard trips after 3 respawns, and the cycle restarts with every new daemon.Process trace (one daemon, node
server-node.mjsPID 4636):Every one of the 9 project
.gstack/browse-*.logfiles on this machine shows the same respawn-and-trip pattern.Fix
resolveBunExecutable()interminal-agent-control.tsfinds a realbun.exe. It checks, in order: the current executable when running underbun.exe(a compiledbrowse.exeis not treated as bun),BUN_INSTALL\bin,bun.exeon PATH, the npm-global layout (<dir>\bun.cmd→<dir>\node_modules\bun\bin\bun.exe), and%USERPROFILE%\.bun\bin. It falls back to'bun', so behavior is unchanged when nothing is found. POSIX is unchanged.spawnTerminalAgentspawns through it. With no cmd.exe in between,windowsHideanddetachedapply to the agent itself, andproc.pidis the agent's own PID.The
#2637requirement still holds: the agent stays detached and outlives the CLI.Verification (Windows 11, the user's real install)
browse/test/terminal-agent-bun-exe.test.tscovers resolution order, npm-shim resolution, the compiled-binary case, the fallback, and that the spawn site uses the resolver: 7 pass.bun-child-config.test.ts: 6 pass.bun run typecheckis clean.windowsHide,detached,stdio: ignore) getsbun.exeasproc.pid, and no OpenConsole or WindowsTerminal process appears.dist/server-node.mjsrunsbun.exe ... terminal-agent.tswith the daemon as its direct parent. The agent stays alive, publishesterminal-port, and no console window opens during a 4-minute session.terminal-agent-lifecycle.test.tsfails 7 of 14 on unmodifiedmainon this machine, and 4 of 14 with this change. Both runs used the same box and no other changes. The remaining 4 are pre-existing Windows timing failures, not touched here.Not in this PR
On the cold-start path (the compiled CLI spawns the agent, then exits), the first agent still dies once. The watchdog's next spawn survives. I suspect the CLI's job object takes the child down with it even though it's
detached, but I haven't verified that. It's now silent, but it costs up to 60 seconds of terminal-agent availability after each daemon start.🤖 Generated with Claude Code