Repository navigation
fix(terminal): remount a pane left unbound by a spawn that returned no PTY id - #19223
Conversation
…o PTY id A restored-PTY reattach that resolves without a PTY id leaves the pane mounted with no transport binding, so registerData never runs. Main keeps pushing pty:data for the id; the dispatcher finds no handler and parks the bytes in the pre-handler buffer, which claims no delivery credit and so ACKs them anyway — main's flow control reads healthy while the pane shows its last frame forever. The visibility reconciler skips unbound panes, so nothing rebinds one until the user remounts the tab. Every startFreshColdRestoreAgentResume call site is floating (no await, no catch) and startFreshSpawn resolves null rather than rejecting, so no caller could see the failure. Settle it at the completion hook they all funnel through, whose guards already mean "no pty, pane alive, still unbound, nobody else spawning" — it settled the direct-SSH lease there and did nothing for local panes. Route those to the existing remount seam instead; the SSH retry ledger keeps ownership so the two never race. Observed in the field on three concurrent panes, each parked just past the 64KB pre-handler warn threshold.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughAdds Merge Risk: ⚪ Minimal · up to Terminal panes left unbound after a spawn without a PTY ID now recover through the existing remount path while direct-SSH retries retain ownership. The covered behaviors indicate the change is ready to merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the bug, root cause, fix, scope, and verification results. However, it omits the required Linked Issue, Visual Proof or an explicit N/A explanation, AI Disclosure, Review, Agent skill upstream boundary, and Checklist sections. It also does not follow the required template headings closely enough. Resolution Add the missing template sections. Include a linked issue after "Fixes #", attach before/after visual proof or write N/A with a reason, complete the AI Disclosure section as applicable, address Review and Agent skill upstream boundary, and complete the checklist items.
✨ Finishing Touches 💡 1📝 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.
✅ No new issues found.
Reviewed changes
The PR fixes a frozen-pane failure mode where a restarted/fresh terminal resolves with no PTY id, leaving the pane mounted with no transport binding while main's flow control reads healthy.
- New
settleSpawnThatLeftPaneUnboundhelper — settles the direct-SSH retry lease asfailed, then remounts the pane through the existing recovery seam when no lease owns recovery; mirrors the existingrecoverUnverifiableDirectSshReattachhandoff. - Call-site swap in
startFreshSpawn— the guarded post-spawn completion hook (previously only settled the direct-SSH lease) now routes no-PTY outcomes to the helper, so all 11 floating call sites are covered without editing them. - New
'spawn-left-pane-unbound'recovery reason — added toTerminalPaneRecoveryReason, carrying a nullptyId. - Tests — an integration test driving real
connectPanePty(null-resolving spawn, direct-SSH no-double-recovery, bound-spawn control) plus five unit tests for the helper.
I traced the direct-SSH handoff (directSshRetryAttempt → settleDirectSshPaneRetry → retrySettledDirectSshTerminalPane), the recovery budget/cooldown/retry path (requestTerminalPaneRecovery), and the void-ed result (no unhandled rejection for this reason — the only await is the input-undeliverable liveness probe). The change is correctly scoped to the single funnel point and reuses the proven remount seam; the recovery breadcrumb (terminal_pane_recovery_remount) gives field diagnostics a trace the old console.warn-only detectors lacked.
Verified locally: both test files pass (8/8) and tc:web is clean.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Electron QA at
All screenshots below are uncropped CDP captures of the hidden renderer and were inspected before upload. Second terminal tab: the rendered terminal shows Split tab after returning and resizing, before recovery: the left shows After the CDP-invoked recovery: earlier output is still present, left shows |
|
Review completed at
Regression evidence is local macOS only. The actual spawn-resolves-without-a-PTY-ID trigger could not be reproduced through the UI. The new tests cover that trigger with a mocked transport, and Electron exercised the recovery seam directly; the original freeze and buffered-output recovery were therefore not verified end to end. SSH, Windows, and Linux were not exercised. Full The delivery watchdog's pre-handler credit accounting and never-settling spawn IPC remain separate issues; this focused change addresses a spawn that has completed while leaving its pane unbound. Code review is clean, with the validation gaps above still open. |




The bug
A terminal pane freezes: it shows its last frame forever, accepts input normally, and repaints stale content correctly on resize.
orca terminal readon the same terminal returns content thousands of tokens ahead of the display, so the bytes reach the daemon and stop at the renderer.Observed in the field on three panes at once, each parked just past the 64 KB pre-handler warn threshold.
Root cause
A restored-PTY reattach resolves with no PTY id. The pane stays mounted with no transport binding, so
registerDatanever runs.Main keeps pushing
pty:datafor that id. The dispatcher finds no handler and parks the bytes in the pre-handler buffer — which claims no delivery credit, so the unclaimed credit settles at return and the bytes are ACKed anyway. In-flight debt for a frozen pane is therefore zero, andisMainDeliveryStalledrequiresinFlightTotalChars > 0, so main's delivery health reads green while the pane is dead. The visibility reconciler skips unbound panes (!requestedPtyIdearly return), so nothing rebinds one until the user remounts the tab.Two detectors already fire and only
console.warn:pty-pre-handler-buffer.tspast 64 KB — "bytes buffered with no registered data handler; the owning pane may have lost its handler to a detach/attach race"graph-publication.ts— "mounted terminal leaf has saved PTY but no live transport" (!ptyId && savedPtyId)Neither reaches a trace sink, CLI verb, or crash bundle, so a user hitting this in the field cannot produce evidence of it.
Why no caller noticed
startFreshSpawnresolvesnullrather than rejecting —connectIpcPtyswallows every non-SSH spawn error — and all 11startFreshColdRestoreAgentResumecall sites are floating (noawait, no.catch). No caller could see the failure, so no caller could react to it.The fix
One change at the spawn completion hook every path funnels through. Its guards already mean "no pty, pane alive, still unbound, nobody else spawning" — exactly the frozen-pane state. It settled the direct-SSH retry lease there and did nothing for local panes; those now route to the existing
requestTerminalPaneRecoveryremount seam, which already carries a budget, cooldown, retry and liveness probe. A remount reattaches over the still-live PTY and drains the buffer.This covers all 11 floating call sites without editing any of them. The direct-SSH retry ledger keeps ownership when it holds a lease, so the two never race.
Verification
pty-connection-spawn-left-pane-unbound.test.tsfail withNumber of calls: 0at the recovery assertion; restoring it goes green.connectPanePtywith a null-resolving spawn, plus a direct-SSH case asserting no double recovery and a bound-spawn control.terminal-panesuite: 440 files / 4221 tests pass.tc:webclean.Notes for the reviewer
pnpm tcfails onmainindependently of this change:src/main/agent-hooks/first-work-branch-rename.test.tsdeclareslastActivityAttwice in one object literal (TS1117, lines 106 and 179). Main-process code, untouched here.window.api.pty.spawnis a bareipcRenderer.invokewith no timeout or abort.