Repository navigation
Make the browse tunnel auto-start share the start lock (GST-2117) - #4212
Merged
capy-ai[bot] merged 3 commits intoNov 9, 2026
Merged
Conversation
…k (GST-2117) #4210 made ctx.tunnel.start single-flight, but the BROWSE_TUNNEL=1 auto-start in start() called startTunnel() directly, so a /tunnel/start that overlapped it still opened a second ngrok session closeTunnel could not reach. The lock now lives in startTunnel itself, which both callers use. The unreleased changelog fragment names both paths. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
|
😎 This pull request was merged. |
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…GST-2117) 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.
A browse daemon started with
BROWSE_TUNNEL=1no longer leaks a second public ngrok tunnel when a/tunnel/startcall arrives while its own auto-start is still opening. This serves gstack's goal of a browser that agents can share remotely without exposing more than you asked for.What changed
The new auto-start overlap test opens two ngrok sessions on main and one with this fix.
Before/after as text: The new auto-start overlap test opens two ngrok sessions on main and one with this fix
browse/src/server.tsthe single-start lock now lives instartTunnel, which wrapsopenTunnel(the old body). The/tunnel/startroute and theBROWSE_TUNNEL=1auto-start instart()both go through it, so an overlapping start waits for the one in flight and gets the same URL.Tests
browse/test/tunnel-start-state.test.tsgains a case that runs the realstart()(headless Chromium, mocked@ngrok/ngrok,BROWSE_TUNNEL=1) in the same childbun testprobe, holds the auto-start insidengrok.forward(), and sendsPOST /tunnel/startto the daemon's real port. It fails on main ba2289e (openedis["session-1","session-2"]) and passes here. Thedual-listener.test.tssource-guard marker returns tostart: (authtoken) => startTunnel({.Blast radius
The product change is 8 lines in
browse/src/server.ts:startTunnelbecomes a wrapper that holds the lock, and the factory'stunnel.startcallback calls it instead of holding its own. Every throw inopenTunnelsits inside itstryand.finallyalways clears the lock, so a failed start can't leave it stuck (read at server.ts:404-411, confirmed by the adversarial reader). No network, secrets, permissions, workflow, install-script or dependency changes.Why
The #4210 review noted that the
BROWSE_TUNNEL=1auto-start "still calls startTunnel() directly", outside the lock. A/tunnel/startthat arrived during that start opened a second ngrok session that closing the tunnel never reached. Now there is one session, whichever path starts first.Summary
The auto-start and the route share one in-flight tunnel start, a new test drives the real
start()to prove it, and the changelog fragment says so.Test Coverage
All new code paths have test coverage. The new case in
browse/test/tunnel-start-state.test.tsruns the realstart()withBROWSE_TUNNEL=1and@ngrok/ngrokmocked, holds the auto-start's forward open, sends a/tunnel/startand checks one session and one URL. It fails on origin/main ba2289e (openedwas["session-1","session-2"]) and passes at c473d8b.dual-listener.test.ts's source-guard marker is back to the original call line; its assertion is unchanged.Pre-Landing Review
Pre-Landing Review: 1 issue — 0 auto-fixed, 1 asked (0 fixed, 1 skipped), 0 deferred, 0 noted. Adversarial (in-host, Claude): no findings in the range, one older note outside it. Outside voice (GPT-6.1 Sol): clean.
browse/test/tunnel-start-state.test.ts:113(the probe sleeps 100 ms before releasing the held forward). Below the blocking floor: if the route request were late, the probe would fail loudly, never pass falsely, and the same pattern from Stop concurrent browse tunnel starts from leaking an ngrok session (GST-2117) #4210 has run green in CI.Review notes
Below the blocking floor; recorded here and not fixed in this PR.
browse/test/tunnel-start-state.test.ts:113The overlap probe relies on a fixed 100 ms sleep for the routed/tunnel/startto join the in-flight auto-start beforerelease(); a deterministic join signal would remove the timing dependency.closeTunnel()does not wait for an in-flightopenTunnel, so a close during a start is a no-op and the start then marks the tunnel active. Same at ba2289e; it does not leak an ngrok session.Exploratory QA
Not run: no required probe for this change. The failing-first test is the functional check, and it drives the real
start()path.Design Review
No frontend files changed — design review skipped.
Eval Results
No prompt-related files changed — evals skipped.
Review bot comments
No review bot comments.
Plan Completion
Plan completion audit: not run (no plan is bound to this branch). Bug fix, plan review exempt; the failing-first test is the repro.
TODOS
No TODO items completed in this PR.
Issues
Refs #4210
Documentation
Status: current. No documentation changes were needed.
Scope: branch
fix-browse-tunnel-auto-start-shares-start-lock, base ba2289e to head d881bce: 2 commits and 4 files (browse/src/server.ts, two browse tests and one changelog.d fragment), with no staged, unstaged or new files. I grepped the tunnel docs in README.md, BROWSER.md, ARCHITECTURE.md, docs/REMOTE_BROWSER_ACCESS.md and docs/BROWSER_INTERNALS.md for start-lock and concurrency wording.Documentation health:
BROWSE_TUNNELvariable table is unchanged)BROWSE_TUNNEL=1 $B restartsetup is still valid)Coverage debt: none new. The change is an internal fix to the shared in-flight start lock in
startTunneland adds no public surface. The changelog.d fragment covers the user-visible effect.Diagram drift: none. No diagram names
startTunnelor the start lock.Test plan
bun run test: carried from CI free-tests run 42613170296/1 at tree b96d3ed890d1 (36831 tests, 0 failed)bun test browse/test/tunnel-start-state.test.ts: 2 pass, 1 fail on ba2289e; 3 pass at c473d8b🤖 Generated with Claude Code
Agent notes
Refs GST-2117. Lane GSTA-443 for GStack Minder. Follows #4210's review note on the
BROWSE_TUNNEL=1auto-start. The second commit only splits a changelog sentence at its colon (prose lint); the reviewed product tree is unchanged.Approvals
No approvals recorded for branch fix-browse-tunnel-auto-start-shares-start-lock.
Plan: exempt: bug fix
Plan check: exempt bug fix
REVIEW_LOOP: passes=1 blocking_found=0 deferred=0 noted=0 fixed=0 scope=frozen ledgers_read=2 dispatches=1
Gate edits: none detected (6 listed, 4 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)