Repository navigation
fix(terminal): let pane recovery reach input stuck behind a never-settling connect - #8673
Conversation
…tling connect Follow-up to the pane self-heal: its input-undeliverable detector is gated off while a transport connect is settling (correct — remounting mid-reattach used to kill the resolving shell), but the gate had no timeout. A connect that never settles (the SSH RPC-timeout class) left the one state recovery still could not reach: no output flows, so no other detector fires, and every keystroke is silently dropped forever. Two changes that only make sense together: - the gate becomes a 60s settle grace; past it, undeliverable input may request recovery again (still pty:hasPty-confirmed). - the transport's destroyed-while-connecting check now kills only what the connect CREATED. A fresh spawn is ours to reap; a reattach (sessionId) resolves to a pre-existing session owned by the tab lifecycle — tab close kills it by id through its own path, so killing it here turned a remount racing a slow reattach into the loss of a live shell. This is what makes the grace safe: recovery firing at 60s against a connect that resolves at 61s now costs a wasted view rebuild, not the user's session. Verified: transport unit test pins the reattach/fresh-spawn kill split; the recovery e2e pair passes 6/6 consecutive iterations with this change (an earlier flaky signal bisected to machine load: failures only under parallel-build load, two unrelated failure modes, 4/4 then 6/6 green on quiet hardware with and without the change re-applied).
📝 WalkthroughWalkthroughUpdates PTY transport teardown so delayed reattach connections do not kill pre-existing sessions. Replaces the connection in-flight boolean with a timestamp-based 60-second settling window for undeliverable-input recovery. Applies the gating consistently to fresh spawn, SSH reattach, and deferred reattach flows, with a regression test covering destruction during reattach. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)
3339-3362: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider using
performance.now()instead ofDate.now()for the grace window.The rest of this file (e.g.,
lastTerminalInputAt) usesperformance.now()for measuring elapsed time. Usingperformance.now()fortransportConnectInFlightSinceprovides a monotonically increasing timestamp that is immune to system clock shifts, ensuring the 60-second grace period is evaluated correctly even if the system time changes.💡 Proposed refactor
Replace
Date.now()withperformance.now()at the assignment sites and the grace window check.- Date.now() - transportConnectInFlightSince < TRANSPORT_CONNECT_SETTLE_GRACE_MS + performance.now() - transportConnectInFlightSince < TRANSPORT_CONNECT_SETTLE_GRACE_MSAnd update the three assignment sites:
- transportConnectInFlightSince = Date.now() + transportConnectInFlightSince = performance.now()Also applies to: 4384-4407, 6967-7000, 7159-7191
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bc31a683-68d3-4fb3-bcfe-a7f4469d0ece
📒 Files selected for processing (3)
src/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-transport.test.tssrc/renderer/src/components/terminal-pane/pty-transport.ts
…tling connect (stablyai#8673) Follow-up to the pane self-heal: its input-undeliverable detector is gated off while a transport connect is settling (correct — remounting mid-reattach used to kill the resolving shell), but the gate had no timeout. A connect that never settles (the SSH RPC-timeout class) left the one state recovery still could not reach: no output flows, so no other detector fires, and every keystroke is silently dropped forever. Two changes that only make sense together: - the gate becomes a 60s settle grace; past it, undeliverable input may request recovery again (still pty:hasPty-confirmed). - the transport's destroyed-while-connecting check now kills only what the connect CREATED. A fresh spawn is ours to reap; a reattach (sessionId) resolves to a pre-existing session owned by the tab lifecycle — tab close kills it by id through its own path, so killing it here turned a remount racing a slow reattach into the loss of a live shell. This is what makes the grace safe: recovery firing at 60s against a connect that resolves at 61s now costs a wasted view rebuild, not the user's session. Verified: transport unit test pins the reattach/fresh-spawn kill split; the recovery e2e pair passes 6/6 consecutive iterations with this change (an earlier flaky signal bisected to machine load: failures only under parallel-build load, two unrelated failure modes, 4/4 then 6/6 green on quiet hardware with and without the change re-applied).
Follow-up to #8630 (pane self-heal), closing its one remaining blind spot.
Problem
The self-heal's input-undeliverable detector is suppressed while a transport connect/reattach is settling — correct, because remounting mid-reattach previously destroyed the unbound transport and the transport's destroyed-check then killed the live session the reattach resolved to (found in review). But the suppression had no timeout: a connect that never settles (the SSH RPC-timeout class) leaves a pane where no output flows (so the stall-watch and replay-guard detectors can never fire) and every keystroke is silently dropped forever — the one state the merged fix still couldn't reach.
Fix (two halves that only make sense together)
pty:hasPty-confirmed, still budgeted).sessionId) resolves to a pre-existing session owned by the tab lifecycle — tab close already kills it by id through its own path. This was flagged in fix(terminal): self-heal panes whose renderer dies while the PTY stays alive #8630's review as a pre-existing hazard, and it's what makes the grace safe: recovery firing at 60s against a connect resolving at 61s now costs a wasted view rebuild, not the user's shell.Verification