Repository navigation
Description
Summary
On Windows, the browse daemon's terminal-agent watchdog gets stuck in a permanent respawn loop: it spawns a fresh bun run terminal-agent.ts every 60s (AGENT_WATCHDOG_TICK_MS) even though the previous agent is alive and its pid record is fresh. Each spawn flashes a visible bun.exe console window (polyfill drops windowsHide — fix in PR #2294), old agents are never reaped, and the respawn circuit-breaker can mathematically never trip.
Environment
- Windows 11 Pro, build 26200 (desktop)
- gstack @
a3259400(update-check reportsUP_TO_DATE 1.60.1.0) - Browse daemon running as
node.exe dist/server-node.mjswithbun-polyfill.cjs(the documented Windows fallback)
Measured behavior
Respawn cadence — process-creation watcher, one daemon (pid 35744), exact 60s beat:
13:19:43.206 START bun run ...\terminal-agent.ts (parent 35744)
13:20:43.368 START bun run ...\terminal-agent.ts (parent 35744)
13:21:43.500 START bun run ...\terminal-agent.ts (parent 35744)
A second daemon (pid 47248, different project state dir) interleaved its own 60s loop → a console flash every ~30s wall-clock.
Leak — 7 spawns vs 1 exit in a 6-minute capture; process count 3 → 9 in ~10 minutes, ~90 MB working set. One daemon had been orphaned (its parent process dead) and looping like this for 2 days. The daemon-side kill path (spawnTerminalAgent kills the pid in the record before spawning) doesn't cover them: 9 agents alive with only 2 pid records in existence.
The respawn happens despite a healthy agent. At the time of the respawns, the terminal-agent-pid records existed, were freshly written (seconds-old), and pointed at running pids.
isProcessAlive is exonerated. I ran the exact implementation under node --require bun-polyfill.cjs (the daemon's real runtime): it returned true for a live agent pid and false for a dead one, with clean tasklist CSV output. So the mis-detection is somewhere else — possibly a stateDir/projectDir mismatch between where the daemon looks and where the agent writes (I did not isolate it; occasionally a tick is skipped, so the check does sometimes pass).
The circuit-breaker is dead code. RESPAWN_GUARD_MAX = 3 within RESPAWN_GUARD_WINDOW_MS = 60_000, but the watchdog tick is also 60s — entries older than the window are pruned before counting, so respawnHistory can hold at most ~1 entry at each tick and the guard can never reach 3. The "manual restart required" log line is unreachable at default settings.
Suggested directions
- Merge PR fix(browse): pass windowsHide in bun-polyfill spawn wrappers (Windows console flash every 60s) #2294 (
windowsHidein the polyfill) — stops the visible flashing; no-op off Windows. - Find why the watchdog considers a live, freshly-recorded agent dead (stateDir resolution seems the prime suspect).
- Make the guard window meaningfully larger than the tick (e.g. 10 min window / tick 60s), so a genuine crash-loop actually trips it.
- Reap: kill the previous agent by pid before spawning even when the record lookup misses, or track children directly — observed agents do self-exit when their daemon dies, but not when superseded.
- Consider a daemon-side "am I orphaned?" check — the 2-day looper's parent was long dead.
Happy to provide the raw watcher logs or test a branch on this machine.
🤖 Generated with Claude Code
Activity
capy-ai commentedon Oct 2, 2026
Believed fixed on main (v1.91.13.0): every spawn site in
browse/srcnow passeswindowsHide(enforced by thebrowse/test/windows-spawn-hide.test.tssweep, passing on the Windows CI lane), the Node polyfill forwards it, and the terminal-agent watchdog fix withbrowse/test/terminal-agent-watchdog.test.tsshipped in v1.67.0.0. We can't prove console suppression or agent survival on a real Windows desktop from CI. Could you confirm on v1.91.13.0 or later? We'll close once you do, or reopen the investigation if it still happens.capy-ai commentedon Oct 8, 2026
Thanks for the very thorough diagnosis. The watchdog was reworked from v1.67 onward: it uses an identity-based agent record,
isProcessAliveuses signal 0, and the guard window scales with the tick, so it should no longer respawn-loop or leakbun.exe. We only have static tests on Linux, so a Windows confirmation would help.To confirm, upgrade with
/gstack-upgrade(orgit pull && ./setup) to v1.91.34.0 or later, retry, and reply here with the result and the output of~/.claude/skills/gstack/bin/gstack-doctor. If we don't hear back in 14 days, we'll close this as fixed (reopening is always welcome).adammartin0087 commentedon Oct 23, 2026
I checked this on Windows 11 (build 26200) with gstack v1.91.182.0, npm-global Bun 1.4.2, and Windows Terminal as the default terminal. It still happens, but the cause is different from the original report.
The watchdog rework is doing its job. The respawn happens because the agent really does die.
spawnTerminalAgentspawns a bare'bun'. Under the Node polyfill, cross-spawn resolves that to npm'sbun.cmd, which runs ascmd.exe /c bun run terminal-agent.ts:windowsHidehides only cmd.exe. The detached cmd.exe has no console, sobun.exeallocates a new visible one. Windows Terminal hosts it (WindowsTerminal.exe -Embedding), and it steals focus.record.pid === process.pid, throwsstartup record was not confirmed, and exits. The window closes, and 60 seconds later the watchdog respawns it. Each daemon does this 3 times before the guard trips.All 9 project
browse-server.logfiles on this machine showrespawned by watchdog×2–3 followed byrespawn guard tripped (3 crashes in 300s).PR with a fix and tests: #3357 (spawns the resolved
bun.exedirectly). I've confirmed it on this machine: no window opens, and the agent stays up.gstack-doctor
v1.91.193.0 fix(browse): spawn the real bun.exe for the terminal agen…
capy-ai commentedon Oct 25, 2026
The fix for this landed in #3388 (v1.91.193.0, ported from #3357 by @adammartin0087). With Bun from
npm install -g bun, the browse terminal agent now spawns the realbun.exeinstead of npm'sbun.cmdshim, so it should stop respawning every 60 seconds and stop flashing a console. @adammartin0087, could you confirm on your Windows 11 setup after upgrading? We'll close this once you do.adammartin0087 commentedon Oct 25, 2026
Confirmed on Windows 11 (26200), gstack v1.91.211.0, npm-global Bun 1.4.2, Windows Terminal as the default terminal. The terminal agent spawns as
bun.exedirectly, and the recorded PID matches the agent. Over 4 minutes and three watchdog ticks, no console window opened or took focus, the agent stayed alive, and there was only one respawn with no loop or guard trip. Page state held across separate calls. Fine to close.One minor leftover, as noted in #3357: on cold start, the first agent spawned by the CLI still dies once, and the watchdog's replacement survives. It's silent now and only delays the agent by up to 60s after a daemon starts.
capy-ai commentedon Oct 31, 2026
Thanks for the fix in #3357 and for confirming on Windows. #3388 (v1.91.193.0) now spawns the real bun.exe, and you verified it holds. Closing; please reopen or file the cold-start respawn separately if it matters.