Skip to content

fix(terminal): remount a pane left unbound by a spawn that returned no PTY id - #19223

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-frozen-pane-unbound-transport
Sep 7, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-frozen-pane-unbound-transport

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​315 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​315
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45

The bug

A terminal pane freezes: it shows its last frame forever, accepts input normally, and repaints stale content correctly on resize. orca terminal read on 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 registerData never runs.

Main keeps pushing pty:data for 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, and isMainDeliveryStalled requires inFlightTotalChars > 0, so main's delivery health reads green while the pane is dead. The visibility reconciler skips unbound panes (!requestedPtyId early return), so nothing rebinds one until the user remounts the tab.

Two detectors already fire and only console.warn:

  • pty-pre-handler-buffer.ts past 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

startFreshSpawn resolves null rather than rejecting — connectIpcPty swallows every non-SSH spawn error — and all 11 startFreshColdRestoreAgentResume call sites are floating (no await, 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 requestTerminalPaneRecovery remount 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

  • Red-green: ablating the call makes pty-connection-spawn-left-pane-unbound.test.ts fail with Number of calls: 0 at the recovery assertion; restoring it goes green.
  • Integration test drives the real connectPanePty with a null-resolving spawn, plus a direct-SSH case asserting no double recovery and a bound-spawn control.
  • Unit tests cover the SSH-lease handoff and the anomaly breadcrumb.
  • Full terminal-pane suite: 440 files / 4221 tests pass.
  • tc:web clean.

Notes for the reviewer

  • pnpm tc fails on main independently of this change: src/main/agent-hooks/first-work-branch-rename.test.ts declares lastActivityAt twice in one object literal (TS1117, lines 106 and 179). Main-process code, untouched here.
  • Deliberately out of scope, both worth their own PRs: the delivery watchdog is structurally blind to this failure (buffered-with-no-handler reads as healthy), and window.api.pty.spawn is a bare ipcRenderer.invoke with no timeout or abort.

Merge Sim added 2 commits September 6, 2026 23:43
…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.
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 3d68e0ce-3a9b-486c-870b-335eda55aebc

📥 Commits

Reviewing files that changed from the base of the PR and between 2ccf35b and c6ebf11.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/pty-connection-spawn-left-pane-unbound.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/unbound-pane-spawn-recovery.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/unbound-pane-spawn-recovery.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-recovery.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

Adds settleSpawnThatLeftPaneUnbound for fresh PTY spawns that resolve without a PTY id. The helper settles an active direct SSH retry as failed or requests terminal pane recovery with the spawn-left-pane-unbound reason. Fresh spawn handling now uses this helper. Tests cover retry ownership, recovery requests, lifecycle warnings, restored leaf IDs, and successful PTY binding.

Merge Risk: ⚪ Minimal · up to c6ebf

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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, Age… 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 …
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary fix: remounting a terminal pane when a spawn returns no PTY ID and leaves it unbound.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 settleSpawnThatLeftPaneUnbound helper — settles the direct-SSH retry lease as failed, then remounts the pane through the existing recovery seam when no lease owns recovery; mirrors the existing recoverUnverifiableDirectSshReattach handoff.
  • 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 to TerminalPaneRecoveryReason, carrying a null ptyId.
  • 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA at c6ebf11d3e7342ff5487642fd71b8a37a88b7ee1, using a freshly built background instance from the pr19223-electron-qa child worktree and Playwright CDP only. No product code changed.

  • Ordinary local terminal use passed: opened terminals, typed shell commands, observed incremental output, split a pane, switched tabs and returned, and resized the renderer from 1728×994 to 1440×900. This run used an isolated folder workspace.
  • Split recovery passed when invoking the existing requestTerminalPaneRecovery seam through CDP with ptyId: null and reason: 'spawn-left-pane-unbound'. Both original PTY IDs remained bound and reported live; left shell PID stayed 79878, right sibling PID stayed 83139, and the sibling variable remained preserved. Earlier output remained visible, and both panes accepted commands and rendered new output after recovery.
  • Coverage gap: could not reach an actual spawn resolving without a PTY ID from the UI. The injected recovery request validates remount/sibling behavior, not the missing-ID spawn trigger or buffered-output failure itself. SSH/Windows/Linux were not exercised.

All screenshots below are uncropped CDP captures of the hidden renderer and were inspected before upload.

Second terminal tab: the rendered terminal shows QA_SECOND_TAB_OK and a returned shell prompt.

Second terminal tab

Split tab after returning and resizing, before recovery: the left shows QA_LIVE_1 through QA_LIVE_3 and PID 79878; the right shows PID 83139 and QA_SIBLING_SCROLLBACK.

Split before recovery

After the CDP-invoked recovery: earlier output is still present, left shows QA_LEFT_AFTER_RECOVERY=79878 and QA_RECOVERED_INPUT_OK, and right shows QA_RIGHT_AFTER_RECOVERY=83139 and QA_SIBLING_STATE=preserved.

Split after recovery

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review completed at c6ebf11d3e7342ff5487642fd71b8a37a88b7ee1: the same-model independent review and start/end readiness audits found no proven regressions or meaningful fixes to make. No code changes were needed.

  • Spawn completion guards and recovery generation/instance fencing protect newer bindings; direct SSH retains its retry owner. Repeated empty spawns use the existing cooldown and three-per-five-minute retry budget, with lifecycle cleanup and no new polling or output-path work.
  • Validation passed: 45 focused tests, the 96-test neighboring recovery gate, 34 additional split/handoff/transport/startup tests, pnpm tc:web, and changed-file lint. Some suites overlap; these counts are separate runs.
  • Electron evidence and three screenshots show ordinary terminal use and a CDP-invoked recovery preserving both shell PIDs, sibling scrollback, and working input/output. QA used Codex after Grok hit its usage limit.

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 pnpm tc is known to fail on main independently of this PR: duplicate lastActivityAt properties cause TS1117 in src/main/agent-hooks/first-work-branch-rename.test.ts. The renderer typecheck passed here.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant