Skip to content

Let a timed-out remote terminal pane reconnect when the host session is still alive - #12213

Merged
nwparker merged 6 commits into
mainfrom
nwparker/bugbash-12097
Aug 4, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/bugbash-12097

Conversation

@nwparker

@nwparker nwparker commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A remote-runtime terminal pane that missed the 60-second auto-recovery window latched to disconnected forever, even though the host session was alive and streaming (terminal.list reporting connected=true, orphaned=false). The cutoff severed every path back at the same instant:

  • armDeadline's expiry called clearRetryTimer() (remote-runtime-pty-recovery-state.ts:162 on main), which dropped pendingRetry and did scheduledRecoveries.delete(this). Window online and powerMonitor 'resume' — the only two automatic triggers (src/renderer/src/runtime/use-remote-runtime-recovery-triggers.ts:11-15) — became permanent no-ops for that pane.
  • The recovery onChange handler called clearPublishedHandleWait() on disconnected (remote-runtime-pty-transport.ts:238-240 on main), unsubscribing the accepted-host-snapshot listener, which after bounded inventory polling stops is the pane's only event-driven path back.
  • That listener was already inert for the reported case anyway: waitForPublishedHostSessionHandle ignored any snapshot whose terminalHandle === previousHandle (remote-runtime-pty-transport.ts:1332 on main), and a host that keeps a live surface only ever republishes the same handle.

Renderer-only changes (line numbers are on this branch):

  1. remote-runtime-pty-recovery-state.ts:205-217 — split clearRetryTimer() into a private stopRetryTimer() (timer handle only) and the existing full teardown. The deadline now calls stopRetryTimer() (armDeadline, :184-198, call at :191-192), so a latched pane keeps its pending retry and stays in scheduledRecoveries while arming no timer of its own.
  2. remote-runtime-pty-recovery-state.ts:123-145 — retryNow() also fires for disconnected, opening a fresh epoch (epoch += 1, attempt = 0, new deadline) so the transport's requestedRecoveryEpoch satisfies isCurrent().
  3. remote-runtime-pty-recovery-state.ts:104-113 — new parkRetryForExternalTrigger(): a wait that ends with no liveness evidence (bounded inventory exhausted, or a require-replacement policy with no replacement published) arms no backoff timer at all, so before this change there was nothing for online/resume to advance. The transport parks an unarmed retry there (remote-runtime-pty-transport.ts:1479-1485). Because retryNow() still requires backoff or disconnected, a parked retry cannot fire while recovery is still running — it only becomes reachable after the cutoff.
  4. remote-runtime-pty-recovery-state.ts:115-121 — new discardPendingRetry(): waitForHostSessionAttachRetry is single-shot, so it drops its own scheduled retry when it settles (remote-runtime-pty-transport.ts:563-587). Without this, replaying that wait after the cutoff would strand the pane in recovering with no RPC in flight.
  5. remote-runtime-pty-transport.ts:242-253 — clearPublishedHandleWait() moves to a disposed-only branch; the stream close and subscriptionGeneration bump stay on disconnected, so the listener survives the latch. The same block sets a new autoRecoveryWindowSpent flag on disconnected and clears it on idle.
  6. remote-runtime-pty-transport.ts:1350-1370 — a post-cutoff snapshot republishing the same handle is now accepted as reattach evidence. It is gated on autoRecoveryWindowSpent (set only when a full 60 s window expired, cleared on a healthy idle and consumed by each accepted reattach), on there being no live multiplexed stream for that handle, and on surfacePresent host evidence (:1343-1346 retires the pane otherwise). The resubscribe is issued as subscribeToHandle(epoch, /* sameHandleEndRecovery */ true), so a successful reattach is recorded by recordSameHandleEndReuse and feeds the existing HOST_SESSION_SAME_HANDLE_END_REUSE_LIMIT escalation. A post-cutoff rotated handle re-opens a recovery epoch before rebinding (:1367-1370), so a failed resubscribe isn't swallowed as already-latched.
  7. remote-runtime-pty-transport.ts:1553-1559,1579 — the require-replacement published-wait early return is scoped to its own recovery epoch via publishedHandleWaitEpoch. Because the wait now survives the latch (change 5), the unscoped guard would otherwise silently swallow the Reconnect button and every online/resume revive.

Net: disconnected still means "automatic retrying stopped" — no timer, no self-initiated RPC — but a host snapshot (rotated or same handle), online/system-resume, and the Reconnect button all reach a fresh subscribe again.

Closes #12097 — the reported failure mode (a pane latched at auto-retry stopped while the host session is alive and streaming, with Reconnect not restoring it). Two of the issue's suggested fixes are deliberately not implemented: there is no new tab-visibility/focus trigger, and no low-frequency background retry loop while latched. The pane is revived by host evidence the client already receives, by online/system-resume, or by Reconnect — see Limitations.

ELI5

Your terminal window connects to a machine somewhere else. If the connection drops, the app spends a minute quietly trying to get it back. Before this change, once that minute ran out the app threw away all its notes — so even when the other machine said "I'm right here, still running," nothing was listening, and clicking Reconnect went nowhere. Now the app stops trying on its own after a minute, but keeps its notes. The moment the other machine says it's alive, or your laptop wakes up, or your network comes back, the window quietly reconnects.

Fix proof

The throwaway repro used while diagnosing (remote-runtime-pty-transport.bug-12097.test.ts) is not part of this diff — it was reworked into permanent, correctly-named suites: remote-runtime-pty-deadline-reattach.test.ts (new, transport-level, following the remote-runtime-pty-snapshot-escape-tail.test.ts / remote-runtime-pty-query-reply-immediate.test.ts focused-file idiom in the same directory) and rewritten/added cases in the existing remote-runtime-pty-recovery-state.test.ts. Coverage corrections and additions made while reworking:

  • The repro's unit case scheduled a retry with RECOVERY_DELAYS_MS[0] (250 ms), so it fired long before the 60 s cutoff and left nothing pending to preserve. The real backoff ladder (250, 500, 1000, 2000, 4000, 8000, 15_000, 30_000) sums to 60,750 ms, i.e. the 8th attempt is armed at t=30.75 s and is still pending when the cutoff lands. The permanent test models that.
  • The repro covered two cases (post-cutoff rotated-handle reattach, and re-arming on online/resume). The permanent transport suite has six, adding: the actual reported case (host republishes the same handle after the cutoff), a negative case proving the same-handle fence is untouched before the cutoff, the Reconnect window, and a pane latched during the attach wait (where replaying the single-shot wait must be refused).
  • remote-runtime-pty-recovery-state.test.ts gains two new cases beyond the rewritten registry test: reviving a parked retry that never armed a backoff timer, and refusing to park over an armed backoff or a stale epoch.

Permanent suites against unfixed source (both changed source files reverted to main, tests kept) — 7 failures:

 ❯ src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.test.ts (15 tests | 3 failed) 10ms
 ❯ src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts (6 tests | 4 failed) 3070ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 7 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ...deadline-reattach.test.ts > reattaches from a rotated host handle published after the recovery cutoff
 FAIL  ...deadline-reattach.test.ts > reattaches when the post-cutoff snapshot republishes the same live handle
 FAIL  ...deadline-reattach.test.ts > reattaches from a same-handle snapshot delivered inside the Reconnect window
 FAIL  ...deadline-reattach.test.ts > revives a latched require-replacement pane when online or system resume fires
 FAIL  ...recovery-state.test.ts > keeps a timed-out pane revivable through the scheduled recovery registry
 FAIL  ...recovery-state.test.ts > revives a parked retry that never armed a backoff timer
 FAIL  ...recovery-state.test.ts > refuses to park over an armed backoff or a stale epoch
 Test Files  2 failed (2)
      Tests  7 failed | 14 passed (21)

The two cases that pass without the fix are the intended negatives: ignores a same-handle snapshot while automatic recovery is still running (the #7718 fence must stay intact pre-cutoff) and leaves Reconnect available when online fires on a pane latched during the attach wait.

Same suites with the fix — all green:

 RUN  v4.1.5

 Test Files  2 passed (2)
      Tests  21 passed (21)
   Duration  2.94s (transform 1.68s, setup 0ms, import 86ms, tests 2.81s, environment 0ms)

No regressions

All neighbouring terminal-pane suites plus every suite importing the two changed modules.

$ npx vitest run --config config/vitest.config.ts \
    src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts \
    src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.test.ts \
    src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts \
    src/renderer/src/components/terminal-pane/remote-runtime-pty-batching.test.ts \
    src/renderer/src/components/terminal-pane/remote-runtime-pty-query-reply-immediate.test.ts \
    src/renderer/src/components/terminal-pane/remote-runtime-pty-snapshot-escape-tail.test.ts \
    src/renderer/src/components/terminal-pane/terminal-remote-runtime-recovery-ui-state.test.ts

 Test Files  7 passed (7)
      Tests  140 passed (140)
   Duration  18.77s (transform 16.49s, setup 0ms, import 3.21s, tests 32.13s, environment 0ms)
$ npx vitest run --config config/vitest.config.ts \
    src/renderer/src/runtime/use-remote-runtime-recovery-triggers.test.ts \
    src/renderer/src/runtime/web-session-terminal-handle-events.test.ts \
    src/renderer/src/components/terminal-pane/terminal-pane-recovery.test.ts \
    src/renderer/src/hooks/direct-ssh-runtime-wake-isolation.test.tsx

 Test Files  4 passed (4)
      Tests  31 passed (31)
   Duration  6.17s (transform 4.62s, setup 0ms, import 6.07s, tests 63ms, environment 805ms)
$ npx vitest run --config config/vitest.config.ts \
    src/renderer/src/components/terminal-pane/pty-connection.test.ts \
    src/renderer/src/components/terminal-pane/pty-transport.test.ts

 Test Files  2 passed (2)
      Tests  631 passed (631)
   Duration  21.13s (transform 2.49s, setup 0ms, import 1.00s, tests 22.27s, environment 0ms)

Specifically preserved: remote-runtime-pty-transport.test.ts "reattaches from a later host snapshot after bounded replacement polling stops" (including its subscriber-count 1 → 1 → 0 sequence and its "user input must not turn a bounded reconnect into recurring host-inventory polling" assertion), the post-cutoff quiescence assertions elsewhere in that file (runtimeCall/runtimeSubscribe call counts unchanged across 5 minutes after the cutoff), and the it.each registry test asserting markHealthy/markDisconnected/cancel/dispose still evict a pane from scheduledRecoveries.

Trade-offs

These are real user-visible changes, not zero-cost:

  • A pane can now silently self-heal out of the "auto-retry stopped" banner. That is the intended win, but the banner is no longer a terminal state. The copy stays literally true — the deadline itself re-arms nothing; only host evidence or an explicit trigger does.
  • A latched pane can now close itself. The accepted-snapshot listener now lives while a pane is latched, so if the host stops publishing the surface the pane is retired (retireRemoteTerminalId → onPtyExit) instead of sitting there with a Reconnect button. This is the correct pre-deadline behavior, but it is new for latched panes.
  • More banner churn on a flapping link. After a revive the pane shows recovering; if the reattach fails it re-latches after a fresh 60 s window rather than staying latched.
  • The #7718 same-handle fence is deliberately narrowed. A post-cutoff same-handle snapshot now re-subscribes a handle a stale error previously fenced off. It is gated on a full 60 s window having been spent (autoRecoveryWindowSpent), on there being no live multiplexed stream, and on fresh surfacePresent host evidence. The reattach is counted by recordSameHandleEndReuse — it is not blocked by HOST_SESSION_SAME_HANDLE_END_REUSE_LIMIT; the counter's effect is to escalate the replacement policy on the following stream-end cycles. Same-handle behavior before the deadline is unchanged, and a dedicated negative test pins it.
  • Per-revive inventory budget resets. Each revive bumps the recovery epoch, and beginResubscribeInventoryWindow is keyed on epoch, so HOST_SESSION_INVENTORY_MAX_WINDOWS_PER_RECOVERY becomes a per-online/resume-event cap rather than a lifetime cap. Bounded per event, unbounded in aggregate across many events on a flapping link.

Cross-platform

Pure renderer TypeScript over setTimeout/clearTimeout and in-memory Set/Map. No platform-conditional code, no keyboard shortcuts (no metaKey/ctrlKey), no Electron accelerators, no shortcut labels, no filesystem paths (so no path.join need). Identical on macOS, Linux and Windows.

window.api.ui.onSystemResumed (main-process powerMonitor 'resume') and the online event are pre-existing triggers whose plumbing is untouched; this change only makes them effective for latched panes, on every OS.

SSH / remote: this is the remote path. The bug only exists for remote-runtime PTY panes reached over a runtime environment (the report is a VPN'd ws://host:6768), and the fix is specifically about tolerating a slow reconnect instead of giving up permanently. Nothing assumes local execution, and the same-handle reattach consumes an event the client already receives rather than issuing a new round trip — the right shape for a high-latency link.

Folder workspaces (non-git): unaffected. worktreeId is used purely as a runtime session selector via toRuntimeWorktreeSelector; no Git is run, no .git is inspected, and nothing assumes the workspace is a worktree. No Git subcommand, option, capability probe, or GitCapabilityCache entry is added or changed, so the Git 2.25 baseline and GitHub/GitLab provider compatibility are untouched.

Performance

  • No new timers, no new polling, no new IPC. The cutoff still stops the retry timer, and a parked retry arms none, so a latched pane continues to issue zero self-initiated RPCs; the post-cutoff "no further calls for 5 minutes" assertions remain green.
  • Steady-state cost of a latched pane: one Set entry and one accepted-snapshot subscriber that previously would have been released. queueAcceptedWebSessionTerminalSnapshot early-returns when there are no subscribers for the session key, and otherwise only iterates subscribers for snapshots the client is already receiving; resolveSubscriberUpdate is a filter over one snapshot's tab list.
  • Same-handle reattach costs zero requests. It consumes the same RuntimeMobileSessionTabsResult an inventory poll would have fetched, so it is strictly better evidence than a session.tabs.list at no request cost. The regression test asserts the session.tabs.list count is unchanged across the reattach.
  • Bounded firing rate. The same-handle path clears autoRecoveryWindowSpent before resubscribing and calls recovery.begin(), so further snapshots are ignored until another full 60 s window has been spent — at most one same-handle resubscribe per 60 s per latched pane.
  • No added React renders on any hot path: emitRecoveryState is already de-duplicated by lastRecoveryStateKey.

Security

No change. No IPC surface added or modified, no command execution, no path handling, no auth or credential surface touched. The change is confined to renderer-side recovery scheduling and to which already-received host snapshot events are acted on. The #7718 stale-handle fence is narrowed (see Trade-offs), but it still requires fresh host evidence that the surface is present — it cannot attach to an arbitrary or attacker-chosen handle, only to the handle the host itself is currently publishing for this pane.

Limitations

  • Verified by automated unit tests only, run on macOS. There is no manual end-to-end verification against a real remote runtime over a high-latency/VPN link, and no CI coverage on Linux or Windows for this specific path. The reasoning that behavior is OS-identical is the argument in Cross-platform above, not an observation.
  • Revival still needs an external event. A latched pane recovers when the host publishes an accepted session.tabs snapshot for its surface, when online/system-resume fires, or when the user clicks Reconnect. If a client somehow stops receiving session-tabs snapshots for that worktree and neither trigger fires, the pane stays latched until Reconnect is clicked. The issue's suggested "re-arm on tab visible/focused" and "low-frequency retry while latched" were not implemented.
  • The banner text was not changed. A pane can now self-heal out of "auto-retry stopped" without the user doing anything, which may read as inconsistent even though the wording remains literally accurate.

AI Review Report

Reviewed by independent subagents in a loop until clean, across two hostile lenses — correctness/regressions and cross-platform + remote + performance.

  • Review loop count: 2 round(s)
  • Final verdict: CLEAN
  • Outstanding findings: none. The final round returned zero blocker/major findings from both lenses.

Remediation applied between rounds: 1 pass(es). Findings judged false-positive were rejected with evidence rather than coded around.

Made with Orca 🐋

A remote-runtime PTY pane that missed the 60s auto-recovery window latched to
"disconnected" permanently, even while the host kept the session alive and
streaming. The cutoff destroyed every path back at once: it dropped the pending
retry and evicted the pane from the shared retry registry (so window `online`
and system-resume became no-ops), and the transport tore down the accepted
host-snapshot listener. The listener was also inert for the common case, since a
host that keeps publishing the same live handle never rotates it.

The cutoff now only stops the retry timer; the pane keeps its pending retry and
stays revivable. The accepted-snapshot listener survives the latch, and a
post-cutoff snapshot is accepted as reattach evidence whether the host rotated
the handle or republished the same one. The require-replacement published-wait
guard is scoped to its own recovery epoch so Reconnect and online/resume are no
longer swallowed.

No new polling: a latched pane still issues zero self-initiated RPCs, and the
same-handle reattach consumes a snapshot the client already receives.

Closes #12097
@coderabbitai

coderabbitai Bot commented Aug 3, 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: Pro Plus

Run ID: b9d08009-85dc-44b6-9777-22898d9c8361

📥 Commits

Reviewing files that changed from the base of the PR and between 92ecfc8 and c04d522.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts

📝 Walkthrough

Walkthrough

The changes update remote PTY recovery and reattachment behavior. Recovery preserves pending retries after deadline expiration and allows disconnected panes to start new recovery epochs. The transport tracks recovery epochs for published-handle waits, retries subscriptions for republished handles, and continues rebinding for replacement handles. Tests cover timeout cleanup, manual revival, same-handle reattachment, rotated handles, retry polling, callbacks, and cleanup.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: reconnecting timed-out remote terminal panes when the host session remains alive.
Description check ✅ Passed The description covers the change, testing evidence, AI review, security, cross-platform behavior, trade-offs, and limitations, with only minor template omissions.
Linked Issues check ✅ Passed The changes address issue #12097 by restoring post-timeout recovery through host snapshots, Reconnect, online, and system-resume triggers.
Out of Scope Changes check ✅ Passed The modified source and test files directly support the linked issue and stated recovery objectives; no unrelated code changes are evident.
✨ 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.

@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/remote-runtime-pty-transport.ts (1)

1347-1355: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Use the returned epoch for the resubscribe call.

recovery.begin() returns the new epoch, so subscribeToHandle(...) can use that exact value instead of reading recovery.currentEpoch.

♻️ Optional use of the returned epoch
-          recovery.begin()
+          const reattachEpoch = recovery.begin()
           clearPublishedHandleWait()
           const reusedPtyId = remotePtyId
-          void subscribeToHandle(recovery.currentEpoch, true).catch((error) => {
+          void subscribeToHandle(reattachEpoch, true).catch((error) => {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 06be15ba-29f8-43f8-9d5c-6309a4a47337

📥 Commits

Reviewing files that changed from the base of the PR and between c9a37f5 and 5f16d2c.

📒 Files selected for processing (4)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts

nwparker and others added 2 commits August 2, 2026 22:40
… lands

The recovery cutoff now keeps a pending retry so online/resume can revive a
latched pane, but the host-session attach wait schedules a single-shot closure
that the cutoff itself resolves. Retaining it left the pane registered as
revivable work: 'online' would bump the epoch, arm a fresh 60s deadline and flip
the phase to 'recovering' while invoking a no-op, hiding the working Reconnect
button and the same-handle snapshot reattach for a full minute.

The attach wait now discards its own scheduled retry as it settles, so a pane
latched on that path stays 'disconnected' and Reconnect keeps working. Retries
scheduled by the resubscribe paths re-enter real work and are unaffected.

Co-authored-by: Orca <[email protected]>

@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/remote-runtime-pty-deadline-reattach.test.ts (1)

327-332: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Strengthen the "no RPC in flight" claim with a call-count assertion.

The comment at Line 330 states that replaying the settled attach wait would happen "with no RPC in flight," but the test only asserts that retryAllRemoteRuntimePtyRecoveriesNow() returns 0 advanced recoveries. retryNow() could still issue an RPC through runtimeCall without counting as "advanced," so the current assertion does not directly verify the claim in the comment. Capture runtimeCall.mock.calls.length before Line 331 and assert it is unchanged afterward, to directly validate the exact regression this PR fixes.

♻️ Proposed strengthening of the assertion
+      const callCountBeforeRetry = runtimeCall.mock.calls.length
       // The attach wait is single-shot and the cutoff already settled it; replaying it would spin the banner with no RPC in flight.
       expect(retryAllRemoteRuntimePtyRecoveriesNow()).toBe(0)
       expect(transport.getRecoveryState?.().phase).toBe('disconnected')
+      expect(runtimeCall.mock.calls.length).toBe(callCountBeforeRetry)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d5388f36-d497-49e3-975a-b6f07862630d

📥 Commits

Reviewing files that changed from the base of the PR and between 5f16d2c and 52815c2.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts

…onnect and resume

Reconnect and the online/system-resume trigger both opened a fresh recovery
epoch, which switched off the accepted-snapshot reattach path (gated on the
'disconnected' phase) for 60s while the require-replacement inventory wait
dead-ended without scheduling anything.

Gate the same-handle reattach on a spent auto-recovery window instead of the
live phase, consumed once per window, and park an unarmed retry at the
require-replacement dead end so online/resume/Reconnect have work to revive.

Co-authored-by: Orca <[email protected]>
nwparker and others added 2 commits August 3, 2026 22:24
…gistry entry

The recovery cutoff now keeps the retry-registry entry and the accepted-snapshot
listener alive, so cover the two module-global collections that could accumulate:
destroy/detach cycles, concurrent latched panes, revive storms and snapshot churn
all return to baseline.

Co-authored-by: Orca <[email protected]>
…C claim

Addresses both CodeRabbit nitpicks: subscribeToHandle now takes the epoch begin()
returned rather than re-reading currentEpoch, and the latched attach-wait test
asserts the runtime call count is unchanged instead of only the advanced count.

Co-authored-by: Orca <[email protected]>

@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 (2)
src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts (2)

290-294: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the reattached handle.

The length check proves only that a second subscription exists. It does not prove that the new subscription uses terminal-stale. Assert the latest subscribed handle, or the exact expected handle sequence, in both tests.

Also applies to: 321-325


305-317: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Exercise the online and system-resume triggers.

Line 317 calls retryAllRemoteRuntimePtyRecoveriesNow() directly. This verifies the scheduler, not that the online listener or system-resume listener invokes it. Add explicit coverage for both triggers, or rename this test and add integration coverage for the event bridge.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bd2c9873-f7b0-4b17-87cc-5518854417ad

📥 Commits

Reviewing files that changed from the base of the PR and between 52815c2 and 92ecfc8.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-deadline-reattach.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-latched-pane-retention.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts

@nwparker
nwparker merged commit dbbeca0 into main Aug 4, 2026
42 checks passed
@nwparker
nwparker deleted the nwparker/bugbash-12097 branch August 4, 2026 06:05
AmethystLiang pushed a commit that referenced this pull request Aug 4, 2026
…is still alive (#12213)

* fix(terminal): let a timed-out remote terminal pane reconnect again

A remote-runtime PTY pane that missed the 60s auto-recovery window latched to
"disconnected" permanently, even while the host kept the session alive and
streaming. The cutoff destroyed every path back at once: it dropped the pending
retry and evicted the pane from the shared retry registry (so window `online`
and system-resume became no-ops), and the transport tore down the accepted
host-snapshot listener. The listener was also inert for the common case, since a
host that keeps publishing the same live handle never rotates it.

The cutoff now only stops the retry timer; the pane keeps its pending retry and
stays revivable. The accepted-snapshot listener survives the latch, and a
post-cutoff snapshot is accepted as reattach evidence whether the host rotated
the handle or republished the same one. The require-replacement published-wait
guard is scoped to its own recovery epoch so Reconnect and online/resume are no
longer swallowed.

No new polling: a latched pane still issues zero self-initiated RPCs, and the
same-handle reattach consumes a snapshot the client already receives.

Closes #12097

* fix(terminal): drop the settled attach retry when the recovery cutoff lands

The recovery cutoff now keeps a pending retry so online/resume can revive a
latched pane, but the host-session attach wait schedules a single-shot closure
that the cutoff itself resolves. Retaining it left the pane registered as
revivable work: 'online' would bump the epoch, arm a fresh 60s deadline and flip
the phase to 'recovering' while invoking a no-op, hiding the working Reconnect
button and the same-handle snapshot reattach for a full minute.

The attach wait now discards its own scheduled retry as it settles, so a pane
latched on that path stays 'disconnected' and Reconnect keeps working. Retries
scheduled by the resubscribe paths re-enter real work and are unaffected.

Co-authored-by: Orca <[email protected]>

* fix(test): type the reattach host snapshot factory so status narrows to 'ready'

Co-authored-by: Orca <[email protected]>

* fix(terminal): keep an exhausted remote pane reattachable through Reconnect and resume

Reconnect and the online/system-resume trigger both opened a fresh recovery
epoch, which switched off the accepted-snapshot reattach path (gated on the
'disconnected' phase) for 60s while the require-replacement inventory wait
dead-ended without scheduling anything.

Gate the same-handle reattach on a spent auto-recovery window instead of the
live phase, consumed once per window, and park an unarmed retry at the
require-replacement dead end so online/resume/Reconnect have work to revive.

Co-authored-by: Orca <[email protected]>

* test(terminal): pin latched-pane retention to one listener and one registry entry

The recovery cutoff now keeps the retry-registry entry and the accepted-snapshot
listener alive, so cover the two module-global collections that could accumulate:
destroy/detach cycles, concurrent latched panes, revive storms and snapshot churn
all return to baseline.

Co-authored-by: Orca <[email protected]>

* refactor(terminal): use the returned reattach epoch and pin the no-RPC claim

Addresses both CodeRabbit nitpicks: subscribeToHandle now takes the epoch begin()
returned rather than re-reading currentEpoch, and the latched attach-wait test
asserts the runtime call count is unchanged instead of only the advanced count.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…is still alive (stablyai#12213)

* fix(terminal): let a timed-out remote terminal pane reconnect again

A remote-runtime PTY pane that missed the 60s auto-recovery window latched to
"disconnected" permanently, even while the host kept the session alive and
streaming. The cutoff destroyed every path back at once: it dropped the pending
retry and evicted the pane from the shared retry registry (so window `online`
and system-resume became no-ops), and the transport tore down the accepted
host-snapshot listener. The listener was also inert for the common case, since a
host that keeps publishing the same live handle never rotates it.

The cutoff now only stops the retry timer; the pane keeps its pending retry and
stays revivable. The accepted-snapshot listener survives the latch, and a
post-cutoff snapshot is accepted as reattach evidence whether the host rotated
the handle or republished the same one. The require-replacement published-wait
guard is scoped to its own recovery epoch so Reconnect and online/resume are no
longer swallowed.

No new polling: a latched pane still issues zero self-initiated RPCs, and the
same-handle reattach consumes a snapshot the client already receives.

Closes stablyai#12097

* fix(terminal): drop the settled attach retry when the recovery cutoff lands

The recovery cutoff now keeps a pending retry so online/resume can revive a
latched pane, but the host-session attach wait schedules a single-shot closure
that the cutoff itself resolves. Retaining it left the pane registered as
revivable work: 'online' would bump the epoch, arm a fresh 60s deadline and flip
the phase to 'recovering' while invoking a no-op, hiding the working Reconnect
button and the same-handle snapshot reattach for a full minute.

The attach wait now discards its own scheduled retry as it settles, so a pane
latched on that path stays 'disconnected' and Reconnect keeps working. Retries
scheduled by the resubscribe paths re-enter real work and are unaffected.

Co-authored-by: Orca <[email protected]>

* fix(test): type the reattach host snapshot factory so status narrows to 'ready'

Co-authored-by: Orca <[email protected]>

* fix(terminal): keep an exhausted remote pane reattachable through Reconnect and resume

Reconnect and the online/system-resume trigger both opened a fresh recovery
epoch, which switched off the accepted-snapshot reattach path (gated on the
'disconnected' phase) for 60s while the require-replacement inventory wait
dead-ended without scheduling anything.

Gate the same-handle reattach on a spent auto-recovery window instead of the
live phase, consumed once per window, and park an unarmed retry at the
require-replacement dead end so online/resume/Reconnect have work to revive.

Co-authored-by: Orca <[email protected]>

* test(terminal): pin latched-pane retention to one listener and one registry entry

The recovery cutoff now keeps the retry-registry entry and the accepted-snapshot
listener alive, so cover the two module-global collections that could accumulate:
destroy/detach cycles, concurrent latched panes, revive storms and snapshot churn
all return to baseline.

Co-authored-by: Orca <[email protected]>

* refactor(terminal): use the returned reattach epoch and pin the no-RPC claim

Addresses both CodeRabbit nitpicks: subscribeToHandle now takes the epoch begin()
returned rather than re-reading currentEpoch, and the latched attach-wait test
asserts the runtime call count is unchanged instead of only the advanced count.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
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.

[Bug]: Remote-runtime terminal pane stuck "disconnected / auto-retry stopped" while the session is alive and streaming server-side

1 participant