fix(web): the desktop browser host answers every request that arrives together, not only the last #15965
main fromrefs/pull/15965/head·opened View on GitHubProblem#
When several threads use the browser at once, some of their preview_* calls are never answered. Each one waits out the broker's 15 s deadline and fails with Preview automation <op> timed out after 15000ms. The broker then disconnects the host, so the other threads' requests in flight fail with … disconnected during waitFor and the next calls get No preview automation host is available.
The desktop host reads its request stream through previewEnvironment.automationRequests, a stream atom. A stream atom keeps only the last element of each batch it pulls (makeStream sets Arr.lastNonEmpty(arr)). The broker queues requests for a host, so requests from several threads that are queued together reach the client in one batch, and the consumer only ever sees the last of them. The others are dropped without a response.
Change#
automationRequestsdelivers each batch whole (transform: Stream.chunks), so the atom's value is every event that arrived together, in order.createPreviewAutomationRequestConsumerAtomhandles each event of a batch the way it handled a single event before: the connection checks, stale-generation drops and request handling are unchanged.
Scope and approval#
A small, focused fix of an obvious bug: the desktop host silently drops automation requests, and each dropped one costs a 15 s timeout and a host disconnect. The fix only changes how the request stream reaches the existing consumer. It does not change the broker's timeout or eviction rules, which open PRs such as #12279, #12899 and #14552 address for specific operations.
Verification#
- Before: on current
main, a stream atom over[connected, r1, r2, r3]feedingcreatePreviewAutomationRequestConsumerAtomhandles only["r3"]. - After: the new consumer test "handles every request that arrives in one batch of the request stream" builds the same stream with
Stream.chunks, asautomationRequestsnow does, and the host answersrequest-1,request-2andrequest-3in order. The existing consumer tests were updated to deliver batches. vp test run apps/web/src/components/preview/previewAutomationRequestConsumer.test.ts apps/web/src/components/preview/PreviewAutomationHosts.test.tsx packages/client-runtime/src/state/preview.test.ts: 19 passed. Typecheck is clean forapps/webandpackages/client-runtime, and lint and format are clean for the changed files.- Found from agent threads on a Windows desktop: five Codex threads using the browser at the same time got
timed out after 15000ms,disconnected during waitForandNo preview automation host is availablewithin the same few minutes. - Not checked: a live run with several agents driving the desktop browser at once after the fix.
Claude Opus 5.5, Claude Code harness in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
37880abMacroscope's review found this PR approvable — This is a focused preview automation bug fix that preserves batched stream events and routes each request through the existing handler, with targeted tests covering multiple requests arriving together. It does not introduce schema, deployment, security, billing, product-default, or static-analysis changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
cd6cb612-5075-43df-8188-48bc1aadd041
📥 Commits
Reviewing files that changed from the base of the PR and between cf3e714b0f58e29c8fa8660db50d2187e3263b65 and 37880ab9f0b1a7f84e3bc8cdbb4f73d7f8ca4f89.
📒 Files selected for processing (4)
apps/web/src/components/preview/PreviewAutomationHosts.test.tsxapps/web/src/components/preview/previewAutomationRequestConsumer.test.tsapps/web/src/components/preview/previewAutomationRequestConsumer.tspackages/client-runtime/src/state/preview.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The automation request stream now retains batches of events. The request consumer processes every event in each batch and derives initial connection state from the batch’s last event.
Changes#
Preview automation event batches
Layer / File(s) Summary Preserve and consume event batches
packages/client-runtime/src/state/preview.ts,apps/web/src/components/preview/previewAutomationRequestConsumer.ts,apps/web/src/components/preview/previewAutomationRequestConsumer.test.ts,apps/web/src/components/preview/PreviewAutomationHosts.test.tsxThe stream subscription uses Stream.chunksto retain event batches. The consumer processes each event and uses the last event for initial connection state. Tests cover multiple requests in one batch and array-shaped stream values.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant Stream as Automation request stream participant Chunks as Stream.chunks participant Atom as requestsAtom participant Consumer as Preview automation request consumer Stream->>Chunks: Emit events Chunks->>Atom: Preserve event batch Atom->>Consumer: Provide array of events Consumer->>Consumer: Process each eventMerge Risk: ⚪ Minimal · up to
37880The change makes the preview automation host answer every request in a batch instead of only the last, which addresses the reported timeouts. No merge-blocking risk was identified.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
37880The fix delivers requests that were previously dropped while preserving existing browser targeting and connection checks. No new privilege or cross-environment access path was identified. Concurrent desktop behavior was assessed from source, not a live multi-thread run.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
- inferred — The changed execution surface is delivery cardinality within an existing desktop host, not a new environment or browser authority. Multiple threads can contribute requests to a batch, but each retains its own thread/tab target. Broker selection still filters by environment and supported operation and preserves provider-session host assignments.
Trust Boundaries and Controls
- observed — The broker creates a new connection identity and queues its connected event before requests. Once an explicit connection is announced, the consumer drops requests from other generations. Response acceptance atomically requires matching pending request, client and connection identities and removes the pending entry before resolution.
Resilience and Maintainability Implications
- observed — Consumer disposal does not cancel already-started browser handlers; this behavior predates the batch change. Broker retirement and pending cleanup prevent their late responses from resolving retired requests, but do not constitute cancellation of browser side effects. The host releases acquired browser activity in a finally block.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Title check ✅ Passed The title clearly describes the main fix: the desktop browser host now answers every request that arrives together. Description check ✅ Passed The description covers the problem, change, scope rationale, and focused verification. It also states the live multi-agent check that was not performed. 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. - Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.Closing: #15328 moved the browser host to the environment server, which removed the web request consumer and stream atom this fixed. The server host now handles each broker event with
Stream.runForEach, so requests that arrive together are no longer dropped.
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes