Skip to content

fix(preview): reconnect automation hosts after stream eviction - #12343

Closed
waffleflopper wants to merge 3 commits into
pingdotgg:mainfrom
waffleflopper:fix/preview-automation-reconnect
Closed

waffleflopper wants to merge 3 commits into
pingdotgg:mainfrom
waffleflopper:fix/preview-automation-reconnect

Conversation

@waffleflopper

@waffleflopper waffleflopper commented Sep 18, 2026 •

Copy link
Copy Markdown

What 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

recovery-terminal.mp4

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Sep 18, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 75786f0

Macroscope'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.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

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_status to false in 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 3fd5d64 and 75786f0.

📒 Files selected for processing (3)
  • packages/client-runtime/src/rpc/client.test.ts
  • packages/client-runtime/src/rpc/client.ts
  • packages/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.ts
automationRequests now subscribes to previewAutomationConnect with PreviewAutomationHost input and resubscribes 250 milliseconds after stream completion.
Delayed resubscription tests
packages/client-runtime/src/rpc/client.test.ts
Tests 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: juliusmarminge

Merge Risk: ⚪ Minimal · up to 75786

The 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 #12146 requires preview automation to recover during the existing session after the host disappears. packages/client-runtime/src/state/preview.ts now resubscribes to previewAutomationConnect…
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.

sandscooling pushed a commit to sandscooling/t3code that referenced this pull request Sep 18, 2026
Carried from open upstream PR pingdotgg#12343 (head e4ef141),
taking only its own diff to the three files it touches so the PR's
merges of newer upstream main do not come along.

Re-registers the preview automation host 250 ms after the broker ends
its stream, so one timed-out request no longer leaves every session
without a browser host until the app restarts. Fixes upstream pingdotgg#12146.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

Superseded by #12535 (merged), which lands the same host-registration recovery after request/stream timeouts. Closing this open PR as wash.

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

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Preview automation host disappears mid-session ("No preview automation host is available for <op> in environment …") and never reconnects

2 participants