fix(preview): reconnect automation hosts after stream eviction #12343
main fromrefs/pull/12343/head·opened View on GitHubWhat Changed#
Re-register preview automation 250 ms after its stream completes or is remotely interrupted, even while the WebSocket stays connected. Cancel pending recovery on unmount or session replacement, and leave transport failure handling with the existing supervisor. Timed-out commands are not replayed.
Why#
An unanswered preview request can evict the only desktop automation host, leaving later browser tools unavailable until the app restarts.
Fixes #12146. Complements #12279, which addresses the optional 500 ms metadata timeout in #12273. This PR contains only host recovery.
Validation#
- 60 focused tests passed across subscription, preview state, broker, and request-consumer tests.
- Client-runtime typecheck, targeted lint/format checks, and diff checks passed.
- Isolated macOS Electron: real 15-second timeout, temporary no-host error, then successful click/evaluation in the original tab. No new WebSocket or renderer reload; the timed-out action ran once.
The recording shows actual MCP requests/responses in T3’s terminal alongside the preview. It was captured with #12279 applied on the local validation branch; that change is excluded here. Cross-machine relay behavior was not tested.
Recording#
https://github.com/user-attachments/assets/8c3db952-8aa2-4f54-8891-9d17d5e975be
Model: GPT-6 (Astra) · Harness: Codex in T3 Code
Summary by CodeRabbit#
- Bug Fixes
- Preview automation connections now reconnect automatically after a stream ends, with a brief delay to improve reliability.
- Automation sessions can resume after completion or interruption while retaining the active session.
- Pending reconnections are cancelled when the preview is closed or the active session changes, preventing unwanted reconnects.
- 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:S
Approvability#
Verdict: Approved at
75786f0Macroscope's review found this PR approvable — This is a contained preview automation recovery fix: only the explicitly configured automation subscription retries after remote stream eviction, while existing subscriptions and cancellation behavior remain unchanged. The added behavior is covered by focused tests and introduces no schema, deployment, security, billing, or static-analysis changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Important
Review skipped#
We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting
@coderabbitai full review.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
88f1c6ab-0c9a-4fce-bfec-44c6f73b9be3📥 Commits
Reviewing files that changed from the base of the PR and between 3fd5d6439d8fd49d173503ecda96500463a39bd2 and 75786f01ad38592851a12dc697a902f8b42bb2db.
📒 Files selected for processing (3)
packages/client-runtime/src/rpc/client.test.tspackages/client-runtime/src/rpc/client.tspackages/client-runtime/src/state/preview.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The preview automation subscription now uses a callback with delayed resubscription after stream completion. RPC client tests cover reopening, session preservation, and cancellation during interruption or session replacement.
Changes#
Preview automation resubscription
Layer / File(s) Summary Preview automation subscription wiring
packages/client-runtime/src/state/preview.tsautomationRequestsnow subscribes topreviewAutomationConnectwithPreviewAutomationHostinput and resubscribes 250 milliseconds after stream completion.Delayed resubscription tests
packages/client-runtime/src/rpc/client.test.tsTests cover delayed reopening after completion or interruption, session preservation, and cancellation during consumer interruption or session replacement. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~15 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
75786The recovery path reconnects preview automation after stream termination while avoiding stale reconnections when the consumer or session changes. No actionable merge-blocking risk remains.
🚥 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 2 functions across 3 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 summarizes the primary change: reconnecting preview automation hosts after stream eviction. Description check ✅ Passed The description clearly explains what changed, why it changed, validation results, scope, and limitations. It omits the template Checklist section, but the required change rationale and validation det… Linked Issues check ✅ Passed Issue #12146requires preview automation to recover during the existing session after the host disappears.packages/client-runtime/src/state/preview.tsnow resubscribes topreviewAutomationConnect…Out of Scope Changes check ✅ Passed The changes remain within issue #12146. The production change adds delayed resubscription for the preview automation stream. The test changes validate delayed resubscription, session preservation, and…✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
Comment `@coderabbitai help` to get the list of available commands.Superseded by #12535 (merged), which lands the same host-registration recovery after request/stream timeouts. Closing this open PR as wash.
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes