Repository navigation
fix(remote-terminal): reattach a healthy remote pane promptly after a worktree switch - #29210
Conversation
… worktree switch (#27178) A remote pane whose stream ended while the host still reported its terminal ready waited the whole 15s inventory window before reusing it, and a third end within 60s demanded a replacement handle that never comes, parking recovery with no timer until the ~3 min deadline. Unknown-liveness outcomes on the attach and resubscribe paths also parked for online/resume events that a healthy link never fires. - Reuse a still-ready handle as soon as the host reports it, unless a terminal.send to it is unanswered (it may still come back stale). - Pace repeated ends on the same handle with growing delays instead of requiring a replacement; only ends within 10s of a reattach count. - Schedule unknown-liveness retries on the backoff ladder instead of parking; the existing deadline still latches Reconnect for a genuinely lost link. Co-Authored-By: Claude <noreply@anthropic.com>
…ng ladder is spent Each paced reattach marked the pane healthy and reset the recovery deadline, so a handle that ended after every reattach retried forever without ever offering Reconnect. After the last rung it now falls back to the replacement wait, whose deadline latches Reconnect. Co-Authored-By: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
ELI5
A terminal on a remote machine sometimes sat on "Reconnecting to remote runtime" for minutes after you switched to another workspace and back, even though the connection was fine. Clicking Reconnect fixed it instantly. The terminal now reconnects by itself within about a second.
What Changed
Before: after switching back to a remote workspace, the terminal showed the reconnect banner for about 15 seconds. If you switched a few times in a minute, it sat there for about 3 minutes, then said "Automatic retries stopped" until you clicked Reconnect.
After: the terminal reattaches within about a second. Repeated drops slow the retries down instead of stopping them. A connection that is really gone still shows Reconnecting, and after the same ~3 minute window it still offers the Reconnect button.
Older remote hosts (1.4.224 and earlier) end a terminal's output stream when a hidden workspace becomes visible again. The host keeps that terminal running and keeps reporting it as ready. The client handled that end in three slow ways (all in
remote-runtime-pty-transport.ts):RemoteRuntimePtyRecoveryState.scheduletakes an optional delay so the repeated-drop pacing reuses the existing recovery timer and deadline.Why
Linked Issue
Fixes #27178
Also addresses the ~20 s "Reconnect to remote runtime" banner on tab switch in #19647 (same host stream-end + 15 s replacement wait). Not closing it: its second symptom, a frozen pane with no banner while output keeps flowing on the host until a client restart, is a different mechanism this PR does not touch.
Visual Proof
N/A. The visible behavior is how long the reconnect banner stays up. Fake-timer tests pin that timing. I did not run an end-to-end check against a 1.4.224 host (see Testing).
Testing
New
remote-runtime-pty-transport-healthy-link-reattach.test.ts, red onmain(5/6 failing) and green with this change:disconnectedwith Reconnect availableI updated the tests that pinned the old parking behavior. Two-window inventory cap → keeps polling on the ladder until the deadline, then goes quiet. Third flap requires replacement → paced reuse. Pending attach phase
recovering→backoff. The prior-ready-evidence test is now fenced by an unanswered send, so it still covers the end-of-window fallback.All
terminal-pane/remote-runtime-*suites, pluspty-connection-remote-runtime-attachandterminal-remote-runtime-recovery-ui-state, pass locally (macOS).pnpm tc:webandcheck:code-quality:changedare clean.Not tested end to end against a real 1.4.224 host.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)