fix: scope headed-Chromium profile per project, not machine-wide - #2492
Open
himiaocc wants to merge 2 commits into
Open
fix: scope headed-Chromium profile per project, not machine-wide#2492himiaocc wants to merge 2 commits into
himiaocc wants to merge 2 commits into
Conversation
resolveChromiumProfile() defaulted to a single $HOME/.gstack/chromium-profile shared by every daemon on the machine, even though each daemon is already isolated per git repo root (resolveConfig().stateDir). Every daemon restart runs killOrphanChromium(), which reads the profile's SingletonLock and kills whatever PID holds it with no way to distinguish a dead orphan from another project's live headed window. Two concurrent projects both driving a captcha-gated headed login would intermittently kill each other's browser. Default now resolves to <project stateDir>/chromium-profile. Also fixes two call sites (browser-manager.ts handoff(), cli.ts chromiumProfileDir()) that had their own hardcoded copies of the old global path instead of going through the shared resolver, and adds a cleanSingletonLocks() call to handoff() to match launchHeaded()'s pre-launch safety. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
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 |
Separate bug from the profile-collision fix earlier in this branch — this one reproduces with a single isolated project, no concurrency involved, and is likely the dominant cause of the original crash reports. handoff() transitions an already-running headless daemon to headed mode in-place. BROWSE_PARENT_PID on that daemon was set at its original headless spawn, pointing at whatever short-lived CLI process happened to trigger the first `browse` command — normally harmless, since headless mode's watchdog branch tolerates a dead parent (Claude Code's Bash tool kills the parent shell between every invocation; this is expected and already handled). But once handoff() flips connectionMode to 'headed', the watchdog's dynamic mode check takes the OTHER branch on its next 15s tick: "headed + parent gone -> shutdown" (intended for /pair-agent and /open-gstack-browser, where BROWSE_PARENT_PID is deliberately a real long-lived owner process). Applied to a handoff-transitioned daemon, that same already-dead CLI parent now triggers a shutdown almost immediately after every handoff succeeds -- killing the browser out from under the user mid-captcha, indistinguishable from a real crash. Fix: track whether headed mode was reached via handoff() specifically (BrowserManager.handoffTransition / didHandoffTransition()) and have the watchdog treat "headed via handoff, parent gone" the same as plain headless (stay alive) instead of the launchHeaded()/connect shutdown branch. Verified with a real handoff against a live captcha-gated site: same PID, still headed, still responsive to commands after 75s (5 watchdog ticks) -- not just a single successful call, which is what let this regress unnoticed before. Adds a subprocess-based regression test (watchdog.test.ts) using a new BROWSE_TEST_FORCE_HANDOFF_HEADED env hook to simulate handoff()'s resulting state without launching a real browser. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.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.
Summary
Two separate bugs, both causing the same visible symptom (headed browser opens then vanishes within seconds — reported as a persistent crash by a user running two sibling project windows concurrently, both driving a captcha-gated login).
1. Chromium profile shared machine-wide, not per-project
resolveChromiumProfile()defaulted to a single$HOME/.gstack/chromium-profile, even though each browse daemon is already isolated per git repo root (resolveConfig().stateDir).killOrphanChromium()(cli.ts), which reads the profile'sSingletonLockand kills whatever PID holds it — no way to distinguish a genuinely dead orphan from another project's live headed window.<project stateDir>/chromium-profile. Also fixed two call sites (browser-manager.tshandoff(),cli.tschromiumProfileDir()) that had their own hardcoded copies of the old global path instead of going through the shared resolver.2. Parent-process watchdog was killing
handoff()sessions within ~15s (found during verification of fix #1 — turned out to be the dominant cause, reproduces with zero concurrency)handoff()transitions an already-running headless daemon to headed mode in-place.BROWSE_PARENT_PIDon that daemon was set at its original headless spawn — some short-lived CLI process that's expected to exit almost immediately (headless mode's watchdog branch already tolerates this).handoff()flipsconnectionModeto'headed', the watchdog's next 15s tick took the OTHER branch: "headed + parent gone → shutdown", intended for/pair-agent//open-gstack-browserwhereBROWSE_PARENT_PIDis deliberately a real long-lived owner. Applied to a handoff-transitioned daemon, the already-dead CLI parent triggered a shutdown almost immediately after every handoff succeeded.handoff()specifically (BrowserManager.handoffTransition/didHandoffTransition()) and have the watchdog treat "headed via handoff, parent gone" the same as plain headless (stay alive).Test plan
bun test browse/test/config.test.ts browse/test/handoff.test.ts browse/test/browser-manager-unit.test.ts browse/test/watchdog.test.ts browse/test/server-factory.test.ts— all pass (config 42, handoff+browser-manager+config combined 81, watchdog 4 incl. new regression test, server-factory 33)git stashthat a fullbun test browse/test/run truncates identically on unmodifiedmain— pre-existing test-runner quirk, unrelated to this changewatchdog.test.ts(BROWSE_TEST_FORCE_HANDOFF_HEADEDenv hook) proving the daemon stays alive when its parent dies while in handoff-headed statehandoff, then waited 75s (5 watchdog ticks) checkingstatus+ actually driving the browser withtext— same PID throughout, still headed, still responsive. (First verification pass only checked the immediatehandoff()return value and missed bug refactor: reorganize codebase into modular structure #2 entirely — this is the corrected, patient verification.)🤖 Generated with Claude Code