Repository navigation
fix(terminal): stop the recovery budget erasing itself during a remount - #19745
Conversation
A recovery remount disposes the pane's xterm, and the disposal handler released the tab's recovery budget whenever getTab said the tab was gone. getTab reads unifiedTabsByWorktree while remountTerminalTabForRecovery reads and mutates tabsByWorktree; on the direct-SSH path the two indices diverge, so every successful remount deleted the timestamp it had just written. The cap never engaged and the pane remounted at render speed. Report b5cfc6ca (1.4.198, Windows): 8878 remounts across 8 tabs in 122s, all reason=reattach-unverifiable, against a cap of 3 per tab per 5 min, ending in a Skia bitmap allocation abort. Gate the release on the same index that governs remounting, via a shared locateTerminalTabForRecovery so the two cannot drift apart again.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change introduces a shared Priority: ⬆️ High Merge Risk: ⚪ Minimal · up to Terminal recovery now uses consistent tab-index semantics, preventing the remount-loop regression while retaining genuine-close budget cleanup. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides strong technical context, rationale, trade-offs, regression evidence, and test results. However, it omits the required linked issue, visual proof or an explicit N/A explanation, and several template sections and checklist confirmations. Resolution Add a valid issue reference after “Fixes #”. Add visual proof, or write
✨ 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
- Release predicate corrected to the remount index —
registerTerminalPaneRecoveryInstance'sunregister()now releases the per-tab recovery budget viahasTerminalTabForRecovery(readstabsByWorktree) instead ofgetTab(readsunifiedTabsByWorktree), the index-drift that erased the budget each remount had just consumed. - Structural index consistency — a shared
locateTerminalTabForRecoveryhelper now backs bothremountTerminalTabForRecoveryand the newhasTerminalTabForRecovery, so the cap and its release cannot diverge again by convention drift. - Store-level predicate coverage —
hasTerminalTabForRecoveryis pinned for remountable tabs, tabs missing from the unified index, tabs absent fromtabsByWorktree, and a genuinecloseTab. - Storm regression test — a fake-timer reattachment storm (200 cycles at the observed 10ms median gap) asserts the remount count stays within the cap and demonstrably fails against the old predicate.
The fix is correct and scoped to renderer store state with no wire/RPC surface. getTab (tabs-focus-actions.ts:15) reads unifiedTabsByWorktree while remount mutates tabsByWorktree, confirming the reported drift; closeTab removes from tabsByWorktree inside its set() before reconciling the unified index (terminal-tab-close.ts), so a real close still releases the budget. The retained-budget case for reverse-diverged tabs self-expires via RECOVERY_WINDOW_MS as the PR documents — no cleanup regression.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
… scan Collapse the recovery lookup onto a single primitive, locateTerminalTab, and express the already-exported isTerminalTabPresent in terms of it. The budget release now calls isTerminalTabPresent directly, so the store drops the hasTerminalTabForRecovery action added alongside it. The native-chat ownership guard also consults tabsByWorktree: the unified tab index owns viewMode, but it can transiently drop a row the remount index still holds, and that hole used to read as "not chat-owned" and remount a chat-owned tab. Drops the storm control case that passed with and without the fix, and pins the surviving drift case to the exact remount count the cooldown produces.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Consolidated to one
tabsByWorktreescan — the previoushasTerminalTabForRecoverystore method and itslocateTerminalTabForRecoveryhelper were removed in favor of the pre-existingisTerminalTabPresent(terminal-tab-retirement.ts), which now delegates to a new sharedlocateTerminalTabinterminal-tab-location.ts. This eliminates the duplicate traversal the earlier review flagged as re-opening the drift class. - Structurally shared resolution —
createRemountTerminalTabForRecovery,isTerminalTabPresent, and the native-chat guard all resolve a tab through the samelocateTerminalTab, so the cap and its release cannot diverge again. - Chat guard hardened against index drift —
requestTerminalPaneRecoverynow checks both indices forviewMode === 'chat'(getTabandlocateTerminalTab(...).tab.viewMode), so a unified-index hole can no longer read a chat-owned terminal tab as recoverable. - Tests tightened — the storm assertion is now exact (
toBe(1), the 15s cooldown coalescing the whole 10ms-gap storm), a chat-guard drift test was added, and the redundant "visible to getTab" storm variant was removed since the predicate no longer consultsgetTabat all.
The refactor is behavior-preserving on the release path (verified against 7af0f10): isTerminalTabPresent reuses locateTerminalTab, which is semantically identical to its prior inline scan. The chat-guard's tabsByWorktree clause is a no-op on the local native path (viewMode is only patched on the unified tab there) and a genuine hardening on the paired/web-runtime path where TerminalTab.viewMode is host-tracked. Typecheck is clean and both affected test files pass (43 tests).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…p reads The narrowed chat-ownership guard read a field the session schema strips: terminalTabSchema never declared viewMode, so the terminal row lost it on every load while the unified tab kept it. After a restart the row read undefined and recovery would remount a chat-owned tab's hidden surface — the race #19745's guard exists to prevent. Declare viewMode on terminalTabSchema so the row is durable, and keep the disjunction rather than replacing it. The schema cannot retroactively add the field to sessions already on disk, so the first load after upgrade still has it only on the unified tab; and for a safety check over two partly-redundant sources, a hole in either index should err toward declining a heal. Also cover three structural guards that no test was holding: both remote ledger-carry paths (terminal-build, remote-workspace-session-merge) and the only success settle in the state machine, including its placement past the failure branches.
…p reads The narrowed chat-ownership guard read a field the session schema strips: terminalTabSchema never declared viewMode, so the terminal row lost it on every load while the unified tab kept it. After a restart the row read undefined and recovery would remount a chat-owned tab's hidden surface — the race #19745's guard exists to prevent. Declare viewMode on terminalTabSchema so the row is durable, and keep the disjunction rather than replacing it. The schema cannot retroactively add the field to sessions already on disk, so the first load after upgrade still has it only on the unified tab; and for a safety check over two partly-redundant sources, a hole in either index should err toward declining a heal. Also cover three structural guards that no test was holding: both remote ledger-carry paths (terminal-build, remote-workspace-session-merge) and the only success settle in the state machine, including its placement past the failure branches.
…on observed outcome (#20025) * fix(terminal): move the recovery ledger onto the tab row and gate it on outcome The recovery budget lived in module-level Maps keyed by tabId. Anything keyed outside the row needs a release path, and that release fired on every remount-driven pane disposal, so each remount erased the budget it had just consumed (crash b5cfc6ca). Put the ledger on TerminalTab and write it in the same set() as the generation bump: reading the budget is now reading the tab, so releasing it independently has no expression. Counting was also the wrong control. Every remount mounts a pane that captures a FRESH recovery epoch, so the epoch check can never refuse its request — recovery re-requested the exact action that had just failed with no evidence anything changed. Gate on an observed outcome instead, reusing the direct-SSH pane retry vocabulary (success | failed | timed-out | superseded) and its settle call sites: an unsettled attempt blocks the next one, and a settled failure refuses the same reason until a new trigger arrives (generation move, or the user's Retry). The 3-per-5min cap stays as a breadcrumb-emitting backstop, not the control. viewMode now also lands on the row from the local toggles, mirroring how pin already does it, so the chat-ownership guard reads one index instead of OR-ing two. * fix(terminal): persist the row's viewMode and keep both chat-ownership reads The narrowed chat-ownership guard read a field the session schema strips: terminalTabSchema never declared viewMode, so the terminal row lost it on every load while the unified tab kept it. After a restart the row read undefined and recovery would remount a chat-owned tab's hidden surface — the race #19745's guard exists to prevent. Declare viewMode on terminalTabSchema so the row is durable, and keep the disjunction rather than replacing it. The schema cannot retroactively add the field to sessions already on disk, so the first load after upgrade still has it only on the unified tab; and for a safety check over two partly-redundant sources, a hole in either index should err toward declining a heal. Also cover three structural guards that no test was holding: both remote ledger-carry paths (terminal-build, remote-workspace-session-merge) and the only success settle in the state machine, including its placement past the failure branches. * fix(terminal): settle a fresh spawn's outcome and prove the ownership guard across a reload spawn-left-pane-unbound was the one recovery reason with no success settle: its remount heals by spawning, not reattaching, so it reached none of the reattach settle points and left the attempt 'pending' for the full 31s bound. A fresh spawn that binds a PTY now reports it, the dual of the unbound settle that already reported failure. Two tests outside src/ still called remountTerminalTabForRecovery by its old boolean contract and broke CI; both are updated to the admission result. Also strips the client-local recovery ledger at the remote-workspace projection boundary, in the type as well as the destructure, so a future producer cannot put another machine's Date.now() on the wire. * fix(terminal): resolve the pane's tab row once for both epochs after the main merge #20034 replaced connect-pane-pty's inline tab resolution with findTerminalTabForPane, and this branch had rewritten the line below it to read the recovery epoch off the row that block used to bind. The merge was textually clean and semantically broken: `terminalTab` no longer existed, so typecheck failed and every test that connects a pane threw ReferenceError. Resolve the row once through the new helper and feed both epochs from it, which keeps #20034's refactor and this branch's reason for reading the row here — a second lookup would put another tabsByWorktree scan on the connect path. captureTabRecoveryGeneration is narrowed to the one field it reads so the helper's record type can carry it.

What
A terminal pane could remount itself in an unbounded loop until the renderer died. Report
b5cfc6ca(Orca 1.4.198, Windows 10.0.26200) shows 8,878 remounts across 8 tabs — ~1,110 each — inside 122 seconds, every one withreason=reattach-unverifiable, against a documented cap of 3 per tab per 5 minutes.Fix evidence
Straight from the user's diagnostic bundle (
crash.exit_code: -2147483645):The storm exhausted bitmap allocation and Chromium aborted:
The test fails without this fix and passes with it — verified by reverting only the production predicate:
Full suites, real output:
pnpm test src/renderer/src/components/terminal-pane/pnpm test src/renderer/src/store/slices/pnpm tcpnpm run check:code-quality:changedELI5
There is a safety rule: "a terminal tab may rebuild itself at most 3 times in 5 minutes." To enforce it, the code writes down a timestamp each time it rebuilds a tab.
The bug: rebuilding a tab tears down its old pane, and the teardown handler asks "does this tab still exist?" — if not, it throws away that tab's timestamps, since a closed tab needs no history.
But it asked the wrong list. Orca keeps two lists of tabs: terminal rows (
tabsByWorktree) and UI tabs (unifiedTabsByWorktree). The rebuild works off the first; the existence check read the second. On the direct-SSH path those two lists drift apart, so the check answered "gone" for a tab that was very much alive — and erased the exact timestamp just written.So every rebuild wiped its own evidence, the counter never reached 3, and the tab rebuilt forever at screen refresh speed until the renderer ran out of graphics memory and died.
The fix: ask the same list that governs rebuilding. The budget exists solely to throttle
remountTerminalTabForRecovery, so its release condition must be the negation of that function's success condition.Trade-offs
tabsByWorktree, tab genuinely gone from the UI). Cost is nil: timestamps expire on their own afterRECOVERY_WINDOW_MS, and a remount for such a tab would be legitimate anyway.tabsByWorktreeandunifiedTabsByWorktreecan still disagree, and that remains a live bug for anything else readinggetTababout a terminal tab. Unifying them is a large change with many writers (ssh-target-cleanup,direct-ssh-terminal-workspace-scope,set-active-worktree,terminal-tab-owner-index, hydration) and is deliberately out of scope — the recovery budget does not need the indices consistent, it needs the right one.closeTabremoves the row fromtabsByWorktreebefore the unified entry, so the new predicate goes false at least as early as the old one. Pinned by a new regression test.Adversarial review
1 loop to clean. The reviewer re-derived the mechanism independently rather than trusting the brief, confirmed
unregister()is the only non-test writer that clears the budget, traced the real call chain (connect-pane-pty.ts:93→session-reconcile-dispose.ts:203), and proved the regression test is genuine by temporarily reverting the predicate and watching it fail.Two findings, both fixed in that loop:
tabsByWorktreerather than exercisingcloseTab. Added realcloseTabcoverage.createHasTerminalTabForRecoveryduplicated the traversalcreateRemountTerminalTabForRecoveryperforms, re-opening the exact drift class that caused this crash. Extracted a sharedlocateTerminalTabForRecoveryso "same index" is enforced structurally, not by convention.Reviewer also cleared the alternate storm paths: the
viewMode === 'chat'guard fails open toward recovery (not a driver); a tab present in unified but absent fromtabsByWorktreemakes remount returnfalseand emitremount_unavailable(never a loop); pending retries are filtered at fire time byisCurrentTerminalRecoveryRequest. No wire/RPC surface touched — renderer store state only.Fixes the crash in report
b5cfc6ca.