Skip to content

fix(runtime): persist acknowledged terminal tab retirement - #21020

Merged
nwparker merged 4 commits into
mainfrom
np-oom-scan-acknowledged-tab-retirement
Sep 20, 2026
Merged

nwparker merged 4 commits into
mainfrom
np-oom-scan-acknowledged-tab-retirement

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​804 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​804
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​810 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​807

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.

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

✅ 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) — snapshots createdAt, generation, tab ptyId, remoteSessionId, and per-leaf ptyId/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 !matches republishes and returns a stale-terminal refusal, otherwise keeps the runtime-owned-headless branch and adds else 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c8b68c9f-bdf4-4529-b359-72679ccd785e

📥 Commits

Reviewing files that changed from the base of the PR and between ee8d1c0 and c5c2b6d.

📒 Files selected for processing (4)
  • docs/audits/acknowledged-tab-retirement/fixture.test.ts
  • docs/audits/acknowledged-tab-retirement/results.json
  • src/main/runtime/acknowledged-terminal-tab-retirement-fixture.ts
  • src/main/runtime/acknowledged-terminal-tab-retirement.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/main/runtime/acknowledged-terminal-tab-retirement.test.ts
  • docs/audits/acknowledged-tab-retirement/results.json
  • docs/audits/acknowledged-tab-retirement/fixture.test.ts
  • src/main/runtime/acknowledged-terminal-tab-retirement-fixture.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

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

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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 th… Add all missing template sections. Change the linked issue to Fixes #17344`` if applicable. Complete the testing checklist with the platforms tested and the exact validation commands or CI coverage. Complete the AI Disclosure section unless…
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: persisting acknowledged terminal-tab retirement at runtime.
Full details: Docstring Coverage

Explanation

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 check

Explanation

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 Fixes # linked-issue format, and does not provide the requested platform-specific testing or checkbox status.

Resolution

Add all missing template sections. Change the linked issue to Fixes #17344`` if applicable. Complete the testing checklist with the platforms tested and the exact validation commands or CI coverage. Complete the AI Disclosure section unless the contributor is exempt.

  • Fix all pre-merge checks with AI
✨ 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 04fe0e07-18c6-4bbb-8a39-eb4f1d31dfdb

📥 Commits

Reviewing files that changed from the base of the PR and between 291b4dd and ee8d1c0.

📒 Files selected for processing (9)
  • docs/audits/acknowledged-tab-retirement/README.md
  • docs/audits/acknowledged-tab-retirement/fix.patch
  • docs/audits/acknowledged-tab-retirement/fixture.test.ts
  • docs/audits/acknowledged-tab-retirement/reproduce.mjs
  • docs/audits/acknowledged-tab-retirement/results.json
  • src/main/runtime/acknowledged-terminal-tab-retirement-fixture.ts
  • src/main/runtime/acknowledged-terminal-tab-retirement.test.ts
  • src/main/runtime/orca-runtime-close-mobile-session-tab.ts
  • src/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.

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

✅ 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) — dispose is now async and runs store.flush(), store.freezeWrites(), await store.waitForPendingWrite() before rmSync; the test's afterEach awaits it.
  • Audit teardown drain (docs/audits/acknowledged-tab-retirement/fixture.test.ts) — cleanup entries now return Promise<void>, afterEach awaits 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) — current hashes regenerated for the two fixtures and the audit test; they match the working tree (sha256sum re-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.

Pullfrog  | View workflow run | Using 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`.
@nwparker
nwparker merged commit f87359c into main Sep 20, 2026
1 check passed
@nwparker
nwparker deleted the np-oom-scan-acknowledged-tab-retirement branch September 20, 2026 00:38
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.

2 participants