Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedmaria-rcksmerged 4 commits intomain fromrefs/pull/25028/headmerged by maria-rcks View on GitHub

maria-rckscommented

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 (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. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at a0799ef

      Macroscope'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).
    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB−29 B (−0.6%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB−29 B (−2.3%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.6 KiB21.5 KiB−41 B (−0.2%)24.4 KiB✅
      CodexLive turn messages21−1 (−50.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.3 KiB1.3 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: c6ef3b4 · PR result: a0799ef · 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.

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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 914a9dd81b9d461683b172b9ecc97463c1dfc376 and a0799ef8a9ec316b44311a66afa45ba4a72d0132.

      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; 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.ts
      Pending openings count toward capacity limits. openTab reserves 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.ts
      Popup creation uses openTab, and the notification uses the returned tab ID. Manager events call ensureTab only 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: bugfix

      Suggested reviewers: juliusmarminge

      Merge Risk: Minimal · up to a0799

      No demonstrated issue remains that should prevent merging after normal checks.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: reserving capacity before opening browser tabs.
      Description checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. 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.

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

    6. maria-rcks merged this52b0ab2

    7. maria-rcks closed this

Sign in to join this conversation.