Skip to content

fix(preview): reserve capacity before opening browser tabs - #25028

Open
maria-rcks wants to merge 3 commits into
mainfrom
maria/takeover-pr-18431
Open

maria-rcks wants to merge 3 commits into
mainfrom
maria/takeover-pr-18431

Conversation

@maria-rcks

@maria-rcks maria-rcks commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

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.ts cases pass on the current merge head, including popup admission, pending viewport changes, reuse, and close/reopen.
  • Blacksmith vp run check:changed passed 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 (a2398c2) with merge commit 914a9dd. 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.

Co-authored-by: Alex Southwell <4596216+saphid@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Oct 25, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Oct 25, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 914a9dd

Macroscope's review found this PR approvable — This is a focused server-side fix that reserves existing browser-tab capacity across concurrent opens and cleans up failed launches. It preserves existing APIs and limits, with targeted coverage for concurrent opens, popups, failures, and tab closure.

You can add or adjust custom eligibility rules. Learn more.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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 0 B (0.0%) 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 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅
Codex Live turn messages 2 2 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB −7 B (−0.1%) 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.2 KiB 1.2 KiB −7 B (−0.6%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅
Claude Live turn messages 2 2 0 (0.0%) 8 ✅

Baseline: a2398c2 · PR result: 914a9dd · Source CI: success

Scenario 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.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between cb1ec03 and 914a9dd.

Files selected for processing: 2
  • apps/server/src/preview/ServerBrowser.test.ts
  • apps/server/src/preview/ServerBrowser.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 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.ts
Pending openings count toward capacity limits. openTab reserves capacity through tab creation and releases it afterward. Tests cover limits, concurrent openings, launch failures, and slot reuse.
Popup and manager event integration
apps/server/src/preview/ServerBrowser.ts
Popup creation uses openTab, and the success callback uses the created tab ID. Manager events call ensureTab only for unowned sessions or sessions with a matching pending reservation or live tab.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • pingdotgg/t3code#24186: Both PRs change tab admission at capacity. This PR also counts pending openings toward capacity limits.

Suggested labels: bugfix

Suggested reviewers: juliusmarminge, saphid

Merge Risk: Minimal · up to 914a9

No identified issue blocks merging the preview tab-capacity change after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reserving capacity before opening preview browser tabs.
Description check Passed The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, approval context, test results, and unverified areas. It is s…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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 bug, implementation, approval context, test results, and unverified areas. It is sufficiently complete for review.

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

Comment @coderabbitai help to get the list of available commands.

maria-rcks and others added 2 commits October 26, 2026 00:07
Co-authored-by: Alex Southwell <4596216+saphid@users.noreply.github.com>

Copy link
Copy Markdown
Collaborator Author

Note

Written by gpt-6.1-sol on behalf of Maria

The 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.

@macroscopeapp
macroscopeapp Bot dismissed their stale review October 27, 2026 01:02

Dismissing prior approval to re-evaluate 914a9dd

Copy link
Copy Markdown
Collaborator Author

Note

Written by gpt-6.1-sol on behalf of Maria

Verified in a real dev environment

verified unchanged head 914a9dd81b9d461683b172b9ecc97463c1dfc376 on a linux boat vm. main baseline was c3858bf1f7 from github/main. each checkout was installed with vp i and ran separately with vp run dev; main was stopped before the pr server started.

created a real git project and codex gpt-6.1-sol threads 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        0

the 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.allSettled MCP 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.ts cases, plus vp 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.

short command transcript

main: the real provider reports 13 adopted tabs after 12 synchronous popups

pr: eight adopted tabs, overflow rejection, reuse, close/reopen and cleanup

web composer through real codex preview tools: popup check, loaded page and cleanup

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant