Repository navigation
fix(runtime): persist acknowledged terminal tab retirement - #21020
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed the single commit ee8d1c0c4a against main (291b4dd), replacing the acknowledged-close trust in "the renderer already flushed" with a captured-and-rechecked persisted identity before the host commits retirement.
- Identity capture (
src/main/runtime/workspace-session-terminal-tab-retirement-identity.ts) — snapshotscreatedAt,generation, tabptyId,remoteSessionId, and per-leafptyId/incarnation, plus live-surface pty ids and incarnations, then re-reads them after the relay ack. - Acknowledged relay branch (
src/main/runtime/orca-runtime-close-mobile-session-tab.ts:180) — captures before the relay; on!matchesrepublishes and returns astale-terminalrefusal, otherwise keeps the runtime-owned-headless branch and addselse if (retirement.hasPersistedTab) commitHeadlessTerminalTabRetirement(...)so the host persists the retirement even when the renderer's flush was rebased. - Audit + tests — new
src/main/runtime/acknowledged-terminal-tab-retirement.test.ts(11 cases),docs/audits/acknowledged-tab-retirement/reproduce harness, results, and README.
I verified this run: pnpm run tc:node passes, oxlint is clean on the four source files, and the 11 new tests pass. Deleting the added commit branch fails 5 of them (durable-retirement and pin cases), so the coverage is not theatre. The results.json sourceHashes match the current sha256sum of the changed files, and the related mobile-close-preserved-resurrection, terminal-close-continuity, and retirement-proof-publication suites stay green. The matches guard is conservatively scoped: the recheck keeps the prior tab object verbatim when the renderer omits it, so the captured identity survives the Store rebase; a false accept would require a byte-identical replacement row, while a false reject is the safe refusal. Scope limits in the README (unified-only metadata, direct renderer-only closes, failed-flush rollback) match the code.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
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 (4)
🚧 Files skipped from review as they are similar to previous changes (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change adds acknowledged terminal-tab retirement identity tracking. The close flow captures host, session, tab, PTY, leaf, and surface state before renderer acknowledgement. It rejects stale changes, republishes the snapshot, and commits matching persisted retirements. New fixtures and tests cover replacement, pinning, PTY exits, persistence failures, host changes, graph ordering, and asynchronous cleanup. Audit files reproduce the before-and-after results. Priority: ⬇️ Low 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 6 files. (1 skipped: 1 unsupported.) Full details: Description checkExplanation The description explains the problem, mechanism, tradeoff, testing, and lack of UI changes. However, it omits the required Agent skill upstream boundary, Notes, and Checklist sections, does not use the required Resolution Add all missing template sections. Change the linked issue to
✨ 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 04fe0e07-18c6-4bbb-8a39-eb4f1d31dfdb
📒 Files selected for processing (9)
docs/audits/acknowledged-tab-retirement/README.mddocs/audits/acknowledged-tab-retirement/fix.patchdocs/audits/acknowledged-tab-retirement/fixture.test.tsdocs/audits/acknowledged-tab-retirement/reproduce.mjsdocs/audits/acknowledged-tab-retirement/results.jsonsrc/main/runtime/acknowledged-terminal-tab-retirement-fixture.tssrc/main/runtime/acknowledged-terminal-tab-retirement.test.tssrc/main/runtime/orca-runtime-close-mobile-session-tab.tssrc/main/runtime/workspace-session-terminal-tab-retirement-identity.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed the incremental commit c5c2b6d745 since the prior pullfrog review (ee8d1c0c4a): a test/audit teardown hardening that drains pending Store writes before removing the fixture directory.
- Fixture teardown drain (
src/main/runtime/acknowledged-terminal-tab-retirement-fixture.ts) —disposeis now async and runsstore.flush(),store.freezeWrites(),await store.waitForPendingWrite()beforermSync; the test'safterEachawaits it. - Audit teardown drain (
docs/audits/acknowledged-tab-retirement/fixture.test.ts) —cleanupentries now returnPromise<void>,afterEachawaits them, and the per-test cleanup freezes writes and awaits the pending write before deleting the temp dir. - Hash refresh (
docs/audits/acknowledged-tab-retirement/results.json) —currenthashes regenerated for the two fixtures and the audit test; they match the working tree (sha256sumre-verified).
The drain is correct: Store.flush() is synchronous (WriteFlushBarrierOperations.flush → flushOrThrow → writeToDiskSync), so it leaves no pending async write of its own; freezeWrites() no-ops any not-yet-started queued write, and waitForPendingWrite() awaits an already-in-flight write (including rename and backup rotation) so rmSync cannot race it. The 11-case suite passes, and CI on c5c2b6d is green for typecheck, static analysis, and package. This resolves the prior CodeRabbit teardown comment.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The Sleep-workspace path threw the raw refusal enum ("stale-terminal") as an
Error message, which reaches a CLI user verbatim and a Sleep toast via
describeSleepFailure. Map each refusal reason to a sentence instead.
Also pins two behaviours that had no coverage: the user-visible outcome of a
republished stale-terminal refusal on the web client (the caller cannot tell it
from a real close), and the one-call-per-close invariant that keeps a successor
terminal alive.
The bounded close retry was NOT implemented: notifier.closeTerminalTab carries
only a tab id, so a second call destroys whatever successor took that id.
The changed-code quality gate rejects new `as` casts. Replace the branded-outcome cast with refusedMobileSessionTabClose, and model the wire-skew reason as a decoded host answer instead of `as never`.

ELI5
A terminal tab could report that it closed but still remain in saved state, then return after restarting Orca. This change makes a successful host-requested close remove the same tab from saved state.
What Changed
Capture the tab and terminal identities before requesting close. After acknowledgment, verify that those owners were not replaced, then use the existing host retirement transaction to persist removal.
Why
Waiting for a later renderer update can leave the old tab on disk. Deleting solely by ID could remove a replacement created while the close request was pending.
Tradeoff
If ownership changes during closing, Orca can refuse the close and require another attempt. That retry is safer than deleting the wrong successor. Existing failed-save rollback limits remain.
Linked Issue
Related to #17344. This fixes tab-restoration correctness; the small saved rows do not explain a large production OOM.
Visual Proof
N/A — no intended interface layout change.
Testing
The recorded proof exercises renderer close, saved-state reload, runtime graph ownership, replacement owners, and the headless SSH shutdown path. Thirty-one before/after cases passed in the portable proof.
Audit evidence:
docs/audits/acknowledged-tab-retirement/.Review
The retirement applies when an updated owning host asks the renderer to close a whole terminal tab and receives acknowledgment. It persists the correct local or SSH host partition and is exercised for local and SSH folder workspaces, paired/mobile/web session dispatch, and the existing headless SSH shutdown path. If ownership changes during the request, it refuses deletion so a replacement cannot be removed by mistake. Thirty-one proof cases passed, and current typecheck, static analysis, and full CI pass.