fix(preview): reserve capacity before opening browser tabs #25028
main fromrefs/pull/25028/head·merged by maria-rcks View on GitHubProblem#
Concurrent preview opens can exceed the eight-tab agent limit and 32-tab server limit because capacity is checked before asynchronous session creation. Failed browser launches also leave sessions that can be relaunched later.
Change#
Reserve a slot synchronously in the existing pending-tab map, retaining its owner until the browser finishes opening. Opens and popups share admission and failed-session cleanup; reuse at capacity and settings changes during launch keep working. The fix stays in the browser service without changing broker cancellation handling.
Verification#
- The original verification reproduced three regressions on the pre-fix base: concurrent agent/server admission and failed-launch cleanup. All 32
ServerBrowser.test.tscases pass on the current merge head, including popup admission, pending viewport changes, reuse, and close/reopen. - Blacksmith
vp run check:changedpassed format, lint, both knip checks, GraphQL, affected typechecks, and focused tests. - Real system Chrome through the preview broker, with 12 concurrent opens:
main: 12 accepted, 0 rejected
candidate: 8 accepted, 4 rejected with tabLimit
candidate: reuse at capacity returns the same tab
candidate: close then reopen succeeds, retaining 8 tabs
This changes server admission logic, with no client UI changes. Full provider/HTTP MCP transport, web/Electron/mobile interactions, and remote/relay/tunnel operation are unverified.
Merged current main (a2398c2ce33c) with merge commit 914a9dd81b9d. Both conflicts preserve the reservation fix and main's runtime-aware effect runner. Blacksmith vp run check:changed passed format, lint, both knip checks, GraphQL, affected typechecks, and all 32 browser tests. System Chrome through the real preview broker accepted 8 of 12 concurrent opens, rejected 4 with tabLimit, reused the same tab at capacity, and retained 8 tabs after close/reopen. Two independent read-only reviews found no introduced issues on this head.
Scope and approval#
Maintainer-directed takeover of https://git.cafe/pingdotgg/t3code/pulls/18431. This localized server admission fix preserves existing APIs, limits, and client UI.
Takeover#
Replaces https://git.cafe/pingdotgg/t3code/pulls/18431, with thanks to @saphid for the original implementation.
Built with GPT-6.1-Sol in the Codex harness on T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
a0799efMacroscope's review found this PR approvable — Server preview launches and popups now reserve capacity before opening, so concurrent launches count toward existing tab limits. Cleanup is tied to launch completion, with no change to product defaults or permissions.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB −29 B (−0.6%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB −29 B (−2.3%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.6 KiB 21.5 KiB −41 B (−0.2%) 24.4 KiB ✅ Codex Live turn messages 2 1 −1 (−50.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.3 KiB 1.3 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
c6ef3b4· PR result:a0799ef· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: maria/takeover-pr-18431
- File: .coderabbit.config.ts
- Commit: a0799ef
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6ae1e2bc-98d2-4ce1-869d-aee3e64bc218
Commits-
Reviewing files that changed from the base of the PR and between 914a9dd81b9d461683b172b9ecc97463c1dfc376 and a0799ef8a9ec316b44311a66afa45ba4a72d0132.
Files selected for processing: 2-
apps/server/src/preview/ServerBrowser.test.tsapps/server/src/preview/ServerBrowser.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
-
Walkthrough
-
Pending tab openings now count toward the 8-tab per-agent and 32-tab server limits. Agent and popup opens use a shared reservation flow. Failed creation releases the reservation, and closing a tab makes capacity available again.
Changes: Preview tab capacity
Layer / File(s) Summary Capacity accounting and tab opening
apps/server/src/preview/ServerBrowser.ts,apps/server/src/preview/ServerBrowser.test.tsPending openings count toward capacity limits. openTabreserves capacity through tab creation and releases it afterward. Tests cover limits, pending openings, failures, and slot reuse.Popup and manager event integration
apps/server/src/preview/ServerBrowser.tsPopup creation uses openTab, and the notification uses the returned tab ID. Manager events callensureTabonly for unowned sessions or sessions with a matching pending reservation or loaded tab.Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Suggested labels:
bugfixSuggested reviewers:
juliusmarminge
Merge Risk:
Minimal · up toa0799-
No demonstrated issue remains that should prevent merging after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main change: reserving capacity before opening browser tabs. Description check The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the failure mode, implementation, approval context, focused tests, observed results, a… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Description check
-
Explanation
The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the failure mode, implementation, approval context, focused tests, observed results, and unverified areas. It does not include an explicit approval comment, but the description is otherwise complete.
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
Written by
gpt-6.1-solon behalf of MariaThe scope warning is covered by this maintainer-directed takeover of https://git.cafe/pingdotgg/t3code/pulls/18431; the description now records that approval context. No API or client UI change is included.
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
verified unchanged head
914a9dd81b9d461683b172b9ecc97463c1dfc376on a linux boat vm. main baseline wasc3858bf1f7fromgithub/main. each checkout was installed withvp iand ran separately withvp run dev; main was stopped before the pr server started.created a real git project and codex
gpt-6.1-solthreads through the running app. used playwright from the repo with/usr/bin/google-chrome, including sending the pr verification turns from the web composer. the provider invoked the real HTTP MCP preview tools and server chrome, with no mocks or fixtures. i checked the provider's actual tool results against the rendered replies.one agent-owned blank preview + 12 synchronous window.open popups: main pr window.open returned 12 12 adopted tabs 13 8 extra open at capacity - rejected explicit tab reuse succeeds succeeds close one + reopen rejected succeeds, 8 tabs final cleanup 0 0the exact main popup race reproduced and the pr capped adoption at eight. nearby behavior passed: explicit reuse at capacity, release/reuse of a closed slot, navigation, waiting for the loaded pairing page, snapshots, and closing all tabs. the final navigation snapshot showed "Pair with this environment", "Pairing token", "Continue", and "Reload app".
an initial
Promise.allSettledMCP open burst was serialized by the codex harness, as confirmed by provider timestamps. i do not count it as concurrent-open proof; the popup reproduction executed all 12 opens synchronously inside chrome.blacksmith checks passed this run: all 32 existing
ServerBrowser.test.tscases, plusvp run check:changed a2398c2ce33c4b964b4d9814644ac6b83521da60(format, lint, both knip checks, graphql, typechecks for three packages, and focused tests). the worker needed a depth-two fetch of the pr head for its shallow history. no code changes or pushes were needed.

Not verified#
native electron, ios/android, windows/macos, and remote/relay/tunnel clients were not exercised on this linux vm. the running-app pass did not exhaust the 32-tab cross-agent ceiling, induce a chromium launch failure, or change settings during a pending launch. existing focused tests cover those server cases, but they are not claimed as real-app proof. direct concurrent MCP opens were not reproduced because this codex harness serialized them.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
maria-rcks merged this52b0ab2
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed