Repository navigation
fix(terminal): keep unresolved snapshot-capability verdicts re-askable - #14676
Conversation
📝 WalkthroughWalkthroughTerminal provider capability tracking now retains unresolved states and retries them every five minutes. Capability revisions notify the hook and trigger terminal parking reevaluation. The hook collects PTYs from tabs, mappings, pending reconnects, and layouts. Retention logic classifies exemption routes and reports categorized counts in warnings and renderer crash breadcrumbs. Regression tests cover retry resettlement, route classification, retention growth, hook collection, and React 185 capability flips. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ 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 |
31297d0 to
cf11b9a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-hidden-worktree-retention.ts (1)
80-115: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename the
splitPanebucket to match what it actually counts.
classifyEvictionExemptTerminalPtyreturnsnullfor four different tabs: a tab with noptyId, a remote-runtime pty, an SSH pty, and a same-worktree pty that already has an authoritative snapshot.countEvictionExemptTabRoutesfiles all four undersplitPane.Inside the all-exempt force-park branch in
Terminal.tsxthe split-pane inference usually holds, but the counter is exported and generic. A caller outside that branch reads clean, evictable tabs as split-pane exemptions, which misdirects the triage the breadcrumb exists for.A name such as
unclassifiedTabkeeps the count useful in every context. Update the assertion interminal-provider-snapshot-capability-resettlement.test.ts(lines 122-130) andformatEvictionExemptRouteCountswith it.♻️ Proposed rename
export type EvictionExemptRouteCounts = { failOpen: number foreignWorktree: number capabilityUnknown: number - /** Tab-level pty classifies clean, so the exemption came from a split pane's pty. */ - splitPane: number + /** Tab-level pty classifies clean (absent, SSH, remote-runtime, or authoritative), + * so in the all-exempt branch the exemption came from a split pane's pty. */ + unclassifiedTab: number }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a95dd16a-5e01-4bc1-814f-a47bb2cf6a4f
📥 Commits
Reviewing files that changed from the base of the PR and between e570cad and 31297d0c2a1a6aaafcc24c44793b49a50738be8b.
📒 Files selected for processing (9)
src/renderer/src/components/Terminal.tsxsrc/renderer/src/components/terminal-pane/terminal-cold-park-exempt-flip.react185.test.tsxsrc/renderer/src/components/terminal-pane/terminal-hidden-worktree-retention.tssrc/renderer/src/components/terminal-pane/terminal-retention-exempt-growth.test.tssrc/renderer/src/components/terminal/terminal-provider-snapshot-capability-resettlement.test.tssrc/renderer/src/components/terminal/terminal-provider-snapshot-capability.test.tssrc/renderer/src/components/terminal/terminal-provider-snapshot-capability.tssrc/renderer/src/components/terminal/use-terminal-provider-snapshot-capability.test.tsxsrc/renderer/src/components/terminal/use-terminal-provider-snapshot-capability.ts
9b24279 to
b6cca5a
Compare
A daemon that could not answer the snapshot-capability probe within the ~91s startup ladder had its ptys settled 'no authoritative snapshot' permanently: settled ids were excluded from every later synchronization, and the only refresh callers run during renderer startup. Because the eviction-exemption predicate treats absent/unknown capability as exempt, one slow daemon start converted every local pty into a permanently eviction-exempt tab — the hidden-worktree retention budget could free nothing for the rest of the session (its own degenerate-case log: 'retention force-park freed no panes'). Three changes, none touching the safety direction (unknown still means exempt, panes stay mounted): - The retry ladder now decays to a slow 5-minute re-ask instead of a permanent verdict, so a recovered daemon is consulted again without any event wiring; the synchronization loop's existing timer carries it. - The ongoing collector now gathers the same fields the startup refresh does (layouts, pending reconnect ids), keyed on the sorted id set — synchronization prunes cached verdicts outside its collected ids, so the narrower collector could evict valid split-leaf answers back into the exempt-by-default state. - The degenerate-case log now carries per-route exemption counts (fail-open / foreign-worktree / capability-unknown / split-pane) and a matching crash breadcrumb, so field bundles can say which route dominates instead of a fourth investigation. Guard: exemption flips are a pin-unreachable input to the rendered park verdict, so capability verdicts must only change between commits — the new react185 harness force-parks a worktree, lets pane mounts write layouts/titles, flips capability repeatedly, and asserts every flip settles far from React's nested-update limit. Gates (previously red): a recovered resolver is re-consulted and the exemption clears; retained mounted tabs stay bounded by the retention limit as hidden worktrees accumulate after daemon recovery. Scope honesty: this bounds an unbounded-by-design retention residual; it is NOT the fix for the unexplained multi-GB field OOM cluster, whose retainer remains unidentified (field sessions crash with <= 1 mounted manager).
…oute buckets Review found two unpinned pieces of the re-settlement fix: reverting the ongoing collector to the narrow field set (dropping split-leaf layout and pending-reconnect ptys, which the sync would then prune back to exempt unknown) survived every existing test, and the force-park breadcrumb's route counters had no coverage at all. Both mutations now fail.
…maps The widened collector ran collect+sort+join on every Terminal render and the memo-dep completeness was unpinned. Memoize the key on the four map identities (behavior-identical; the string-keyed second memo still damps layout-only churn) and pin the layouts dep with a staleness test — a missing dep silently drops new split-leaf ptys from the sync.
Review loop 2: a synchronization pass cancelled by a newer generation returned null, which ends the caller's timer chain — but the winner (the startup refresh) ignores its own return value, so unknowns it leaves behind had no scheduler left; recovery then waited on an id-set change. Return 0 instead: the superseded chain re-checks immediately and the early-outs collapse the re-check when nothing is pending. Also pin the collect-key memo's remaining deps at runtime (pending reconnect, tabs, pty ids) — exhaustive-deps is only a warn here, and loop 1's staleness test covered the layouts dep alone.
…y prune Review loop 3: mutation testing showed the chain's own re-ask path was unpinned — collapsing the first early-out to identity-only (returning null whenever the live-set reference is unchanged) passed every test, yet it kills the timer chain after one backoff: the hook refires with the SAME memoized array, so that mutation is the settled-forever bug in a worse shape. Pin it at both levels: a module test drives two passes over one array identity, and a hook test drives the real timer chain through a backoff refire with no id churn. Also pin the closed-pty retry prune (its removal survived the battery): the empty-set pass must return null — a leaked entry keeps a phantom 5-minute timer for the session — and a reappeared id must restart the 1s ladder rather than resume the decayed cadence.
b6cca5a to
399b300
Compare
#14676) * fix(terminal): keep unresolved snapshot-capability verdicts re-askable A daemon that could not answer the snapshot-capability probe within the ~91s startup ladder had its ptys settled 'no authoritative snapshot' permanently: settled ids were excluded from every later synchronization, and the only refresh callers run during renderer startup. Because the eviction-exemption predicate treats absent/unknown capability as exempt, one slow daemon start converted every local pty into a permanently eviction-exempt tab — the hidden-worktree retention budget could free nothing for the rest of the session (its own degenerate-case log: 'retention force-park freed no panes'). Three changes, none touching the safety direction (unknown still means exempt, panes stay mounted): - The retry ladder now decays to a slow 5-minute re-ask instead of a permanent verdict, so a recovered daemon is consulted again without any event wiring; the synchronization loop's existing timer carries it. - The ongoing collector now gathers the same fields the startup refresh does (layouts, pending reconnect ids), keyed on the sorted id set — synchronization prunes cached verdicts outside its collected ids, so the narrower collector could evict valid split-leaf answers back into the exempt-by-default state. - The degenerate-case log now carries per-route exemption counts (fail-open / foreign-worktree / capability-unknown / split-pane) and a matching crash breadcrumb, so field bundles can say which route dominates instead of a fourth investigation. Guard: exemption flips are a pin-unreachable input to the rendered park verdict, so capability verdicts must only change between commits — the new react185 harness force-parks a worktree, lets pane mounts write layouts/titles, flips capability repeatedly, and asserts every flip settles far from React's nested-update limit. Gates (previously red): a recovered resolver is re-consulted and the exemption clears; retained mounted tabs stay bounded by the retention limit as hidden worktrees accumulate after daemon recovery. Scope honesty: this bounds an unbounded-by-design retention residual; it is NOT the fix for the unexplained multi-GB field OOM cluster, whose retainer remains unidentified (field sessions crash with <= 1 mounted manager). * test(terminal): pin the widened capability collector and breadcrumb route buckets Review found two unpinned pieces of the re-settlement fix: reverting the ongoing collector to the narrow field set (dropping split-leaf layout and pending-reconnect ptys, which the sync would then prune back to exempt unknown) survived every existing test, and the force-park breadcrumb's route counters had no coverage at all. Both mutations now fail. * perf(terminal): memoize the capability collect key on its four store maps The widened collector ran collect+sort+join on every Terminal render and the memo-dep completeness was unpinned. Memoize the key on the four map identities (behavior-identical; the string-keyed second memo still damps layout-only churn) and pin the layouts dep with a staleness test — a missing dep silently drops new split-leaf ptys from the sync. * fix(terminal): keep a superseded capability pass's re-ask chain alive Review loop 2: a synchronization pass cancelled by a newer generation returned null, which ends the caller's timer chain — but the winner (the startup refresh) ignores its own return value, so unknowns it leaves behind had no scheduler left; recovery then waited on an id-set change. Return 0 instead: the superseded chain re-checks immediately and the early-outs collapse the re-check when nothing is pending. Also pin the collect-key memo's remaining deps at runtime (pending reconnect, tabs, pty ids) — exhaustive-deps is only a warn here, and loop 1's staleness test covered the layouts dep alone. * test(terminal): pin the same-identity re-ask path and closed-pty retry prune Review loop 3: mutation testing showed the chain's own re-ask path was unpinned — collapsing the first early-out to identity-only (returning null whenever the live-set reference is unchanged) passed every test, yet it kills the timer chain after one backoff: the hook refires with the SAME memoized array, so that mutation is the settled-forever bug in a worse shape. Pin it at both levels: a module test drives two passes over one array identity, and a hook test drives the real timer chain through a backoff refire with no id churn. Also pin the closed-pty retry prune (its removal survived the battery): the empty-set pass must return null — a leaked entry keeps a phantom 5-minute timer for the session — and a reappeared id must restart the 1s ladder rather than resume the decayed cadence. * fix(terminal): apply recovered snapshot capabilities * test(terminal): remove stale lint suppression * test(terminal): clean up capability prefetch hook
stablyai#14676 replaced the exemption predicate with a route classifier so the force-park breadcrumb can say WHY a force-park freed nothing. This branch adds a reason that classifier did not have: a remote or SSH pty whose owner this worktree cannot prove. Folded in as a `remote-unowned` route rather than left out — a remote pty exempt by ownership would otherwise bucket as `split-pane`, which is the one bucket that means "the tab-level pty classified clean". The counts feed field triage, so a silently mis-bucketed route sends it the wrong way. The classifier and the tab-route counter now take the worktree owner, and Terminal.tsx resolves it from the same owner state the exemption selector reads. The two eviction-exemption describes moved to terminal-eviction-exempt-tabs.ts's own test file: both sides appended to terminal-parked-tab-watchers.test.ts and the merged file crossed the 800-line budget. They test a different module anyway.
stablyai#14676) * fix(terminal): keep unresolved snapshot-capability verdicts re-askable A daemon that could not answer the snapshot-capability probe within the ~91s startup ladder had its ptys settled 'no authoritative snapshot' permanently: settled ids were excluded from every later synchronization, and the only refresh callers run during renderer startup. Because the eviction-exemption predicate treats absent/unknown capability as exempt, one slow daemon start converted every local pty into a permanently eviction-exempt tab — the hidden-worktree retention budget could free nothing for the rest of the session (its own degenerate-case log: 'retention force-park freed no panes'). Three changes, none touching the safety direction (unknown still means exempt, panes stay mounted): - The retry ladder now decays to a slow 5-minute re-ask instead of a permanent verdict, so a recovered daemon is consulted again without any event wiring; the synchronization loop's existing timer carries it. - The ongoing collector now gathers the same fields the startup refresh does (layouts, pending reconnect ids), keyed on the sorted id set — synchronization prunes cached verdicts outside its collected ids, so the narrower collector could evict valid split-leaf answers back into the exempt-by-default state. - The degenerate-case log now carries per-route exemption counts (fail-open / foreign-worktree / capability-unknown / split-pane) and a matching crash breadcrumb, so field bundles can say which route dominates instead of a fourth investigation. Guard: exemption flips are a pin-unreachable input to the rendered park verdict, so capability verdicts must only change between commits — the new react185 harness force-parks a worktree, lets pane mounts write layouts/titles, flips capability repeatedly, and asserts every flip settles far from React's nested-update limit. Gates (previously red): a recovered resolver is re-consulted and the exemption clears; retained mounted tabs stay bounded by the retention limit as hidden worktrees accumulate after daemon recovery. Scope honesty: this bounds an unbounded-by-design retention residual; it is NOT the fix for the unexplained multi-GB field OOM cluster, whose retainer remains unidentified (field sessions crash with <= 1 mounted manager). * test(terminal): pin the widened capability collector and breadcrumb route buckets Review found two unpinned pieces of the re-settlement fix: reverting the ongoing collector to the narrow field set (dropping split-leaf layout and pending-reconnect ptys, which the sync would then prune back to exempt unknown) survived every existing test, and the force-park breadcrumb's route counters had no coverage at all. Both mutations now fail. * perf(terminal): memoize the capability collect key on its four store maps The widened collector ran collect+sort+join on every Terminal render and the memo-dep completeness was unpinned. Memoize the key on the four map identities (behavior-identical; the string-keyed second memo still damps layout-only churn) and pin the layouts dep with a staleness test — a missing dep silently drops new split-leaf ptys from the sync. * fix(terminal): keep a superseded capability pass's re-ask chain alive Review loop 2: a synchronization pass cancelled by a newer generation returned null, which ends the caller's timer chain — but the winner (the startup refresh) ignores its own return value, so unknowns it leaves behind had no scheduler left; recovery then waited on an id-set change. Return 0 instead: the superseded chain re-checks immediately and the early-outs collapse the re-check when nothing is pending. Also pin the collect-key memo's remaining deps at runtime (pending reconnect, tabs, pty ids) — exhaustive-deps is only a warn here, and loop 1's staleness test covered the layouts dep alone. * test(terminal): pin the same-identity re-ask path and closed-pty retry prune Review loop 3: mutation testing showed the chain's own re-ask path was unpinned — collapsing the first early-out to identity-only (returning null whenever the live-set reference is unchanged) passed every test, yet it kills the timer chain after one backoff: the hook refires with the SAME memoized array, so that mutation is the settled-forever bug in a worse shape. Pin it at both levels: a module test drives two passes over one array identity, and a hook test drives the real timer chain through a backoff refire with no id churn. Also pin the closed-pty retry prune (its removal survived the battery): the empty-set pass must return null — a leaked entry keeps a phantom 5-minute timer for the session — and a reappeared id must restart the 1s ladder rather than resume the decayed cadence. * fix(terminal): apply recovered snapshot capabilities * test(terminal): remove stale lint suppression * test(terminal): clean up capability prefetch hook






ELI5
Orca saves memory by unloading terminal views that have been hidden for a while. It may only unload a pane when the terminal process can be reattached and a replay source will survive the unmount; otherwise the user loses scrollback and the shell can be orphaned.
When Orca could not determine that replay capability, it correctly kept the pane mounted—but after about 91 seconds of failed probes it stopped asking forever. One slow daemon startup could therefore make every local terminal permanently ineligible for eviction for the rest of the app session. This change keeps the conservative safety behavior and re-asks every five minutes, allowing a recovered daemon to make those panes safely evictable.
What changed
1/2/4/8/16/30/30sunknown-capability ladder now decays to a bounded five-minute re-ask instead of synthesizing a permanentfalseverdict. Unknown remains eviction-exempt throughout.fail-open,foreign-worktree,capability-unknown,split-pane) in a counts-only crash breadcrumb. No worktree IDs or filesystem paths enter the breadcrumb.The broader
terminal_parking_passinstrumentation was split into #14660 and is intentionally not part of this focused fix.Why
This fixes a real latent defect, not a defect observed firing in the crash sweep. The retained field snapshot from the separately investigated leak showed the exemption system idle, and this change does not explain that leak or the renderer OOM cluster. The defect here is reproduced by focused unit/React gates.
The safety invariant remains: no pane may unmount unless both process reattachment and surviving replay are known. A failed, timed-out, missing, or
nullcapability answer never becomes permission to evict.Honest limitation
A stale cached authoritative
trueremains unchanged frommain. If a provider later loses replay without invalidating that cached result, it remains the pre-existing route by which a pane could be unmounted without restorable scrollback. The five-minute re-ask applies only to unresolved answers and does not narrow that stale-true window; provider-generation/liveness invalidation is a separate follow-up.Scope and compatibility
Testing
Focused post-rebase verification:
terminal-provider-snapshot-capability.test.tsterminal-provider-snapshot-capability-resettlement.test.tsuse-terminal-provider-snapshot-capability.test.tsxterminal-retention-exempt-growth.test.tsterminal-cold-park-exempt-flip.react185.test.tsxThe gates cover the full retry ladder and slow re-ask, same-array-identity timer refires, superseded generations, closed-PTY pruning, collector parity for split leaves and reconnects, newline-bearing PTY IDs, React invalidation, retention bounds after recovery, and repeated park-verdict flips without a React #185 loop. Targeted standard and type-aware lint also pass.
CI on the previous pushed head passed typecheck, package (macOS and Windows), cross-version wire compatibility, Git compatibility, shell contracts, and all 32 test shards. The sole static-analysis failure was an unused test suppression, removed in the next commit; final CI will rerun on the rebased head.
Adversarial review
Eight loops were run to clean:
renderHookstayed mounted, so a later capability publication logged a real assertion error even while Vitest reported green; fixed by explicitly unmounting the hook.b6cca5a26cand returned clean with no P0/P1/P2 findings.Open-source precedent review supports the design: detach/unmount is safe only with process persistence plus replay, unknown capability stays mounted, and recovery is retried or event-driven instead of converting transient uncertainty into a durable verdict. The bounded re-ask and explicit React invalidation are conventional, focused mechanisms.
Visual proof
Electron QA ran through Playwright CDP on a dedicated dev instance at reviewed head
cf11b9aeba(the final rebase adds only the lint-suppression cleanup and new base commits). The parking delay was reduced to 2 seconds for exerciseability; capability and replay behavior were production paths.The passing rendered flow was park → terminate only the dedicated profile's daemon process → daemon recovery → reveal; the marker survived and was visible after scrolling to the top. Orca's explicit
pty.management.restart()is intentionally destructive: it synthesized session exits and retired the parked tab, so reveal was impossible and that API cannot serve as session-preserving proof.Live visual proof of “unknown capability stays mounted” remains blocked: the context-bridged capability IPC is immutable, and the dedicated daemon auto-respawned quickly enough that new PTYs resolved authoritative before force-park. This gap is stated rather than replaced with store inspection; the safety direction is covered by the focused unit/React gates.
Follow-ups
Checklist
Author