Skip to content

fix(terminal): let pane recovery reach input stuck behind a never-settling connect - #8673

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/pane-recovery-connect-grace
Jul 14, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/pane-recovery-connect-grace

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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)

  1. 60s settle grace on the in-flight gate: past it, undeliverable input may request recovery again (still pty:hasPty-confirmed, still budgeted).
  2. Reattach-safe destroy in the transport: the 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 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

  • New transport unit test pins the kill split (fresh spawn after destroy → killed; sessionId reattach after destroy → not killed); all 506 tests across the transport/connection/recovery suites pass.
  • The fix(terminal): self-heal panes whose renderer dies while the PTY stays alive #8630 recovery e2e pair passes 6/6 consecutive iterations with this change. (An earlier flaky signal was bisected: failures occurred only under parallel-build machine load with two unrelated failure modes — including the known startup-binding harness flake — and both 4/4 without and 6/6 with the change pass on quiet hardware.)
  • Typecheck and lint green on the branch.

…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).
@brennanb2025
brennanb2025 merged commit 8b86e7e into main Jul 14, 2026
3 checks passed
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updates 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, problem, fix, and verification, but omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including screenshots or no visual change, the AI review report, the security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main fix to pane recovery during never-settling connects.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 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.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)

3339-3362: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider using performance.now() instead of Date.now() for the grace window.

The rest of this file (e.g., lastTerminalInputAt) uses performance.now() for measuring elapsed time. Using performance.now() for transportConnectInFlightSince provides 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() with performance.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_MS

And 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab2e00 and 183c923.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/pty-transport.ts

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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).
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