Skip to content

fix(persistence): a session write cannot bring back a tab its partition recorded as closed - #27125

Merged
OrcaWin merged 3 commits into
mainfrom
np/p395-ct-b2-closed-row-write
Oct 10, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
np/p395-ct-b2-closed-row-write

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​192 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​178
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46

ELI5

When you close a terminal tab, the app saves a note saying "this tab is closed". Some saves ignored that note and wrote the closed tab back, so it returned after a restart. Now every save checks the note first.

What Changed

  • Before: main records every terminal close in the saved section it was closed in (closedTerminalTabTombstonesByTabId). Only two writers respected that record: PTY bindings and orphan adoption. Three kinds of write could put a closed tab back:
    • a renderer save that still listed the tab, when no topology revision fenced that save yet (the close landed before the save that first listed the tab);
    • a relay write;
    • a fast unifiedTabs-only patch, which skips full normalization.
  • After: every full session write (set, stage-before-unload, the host-partition writer) and every unifiedTabs patch removes the terminal tabs the same partition has a live close record for. The removal is a full forced close of that tab: row, layout, unified tab, group order, active tab and sleeping records. It uses the same transform the close transaction uses.
  • Mechanism: new dropClosedTerminalTabs(session) in src/main/persistence/closed-terminal-tab-write-fence.ts. It runs right after preserveRuntimeAuthoredWorkspaceSessionFields at that function's two call sites, and on the unifiedTabs fast patch lane.

Why

  • Tab ids are uuids, so an id that was closed is never a new tab. Reopening a closed tab creates a new id. Each record is scoped to its own worktree, and records past the 30-day TTL stop suppressing.
  • It sits at the existing write boundary that every full write already passes, so no caller can forget it. That boundary is the one that already keeps main's close records across renderer saves.
  • The unifiedTabs patch lane gets a filter instead of full normalization. Full normalization on every tab-activation patch would cost far more than this lookup.
  • Main's rollback path stays exempt. It restores a pre-mutation state, which can include rows a failed close never committed.
  • Legacy profiles that hold rows next to close records for those same rows (the [Bug]: Closed SSH terminal tabs resurrect: reattach re-creates persisted tabs, erases close tombstones, and auto-runs claude --resume on old sessions #12447 report: 151 rows next to 43 records) are cleaned up on their next write.

Linked Issue

Refs #12447: this is the residual write-side half. The leftover SSH lease and relay slot items in that issue belong to another cluster.

Visual Proof

N/A: persistence-only change with no UI change.

Testing

  • New src/main/persistence/closed-terminal-tab-write-fence.test.ts, on a real SQLite store with reload. It covers a late local or SSH renderer save that still lists a closed tab, and a unifiedTabs-only patch: on origin/main all three fail. A same-id tab under another worktree is kept.

  • One existing test in orca-runtime-terminal-close-records.test.ts relied on a listed tab sitting next to its own close record. That state is now impossible to write, so the test now checks that the write drops the tab and keeps the record.

  • src/main/persistence (the 3 profile-state backup timeouts also fail on origin/main on this machine), the runtime close suites, and orca-runtime.test.ts.

  • pnpm tc, oxlint, and pnpm run check:code-quality:changed.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Main-only and partition-local: a record in one partition never suppresses a row in another. No wire change. SSH partitions get the same rule. A client's own close records in its ssh: partition already suppress host rows in the renderer merge, so this matches that rule.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 15e7cac0-b833-4b73-8c5d-ad6b0ce135a9

📥 Commits

Reviewing files that changed from the base of the PR and between 18dc3190fbaa80cd4a4f3f65bc78947d4b9e31a2 and a9d9f99.


📒 Files selected for processing (6)
  • src/main/persistence/closed-terminal-tab-write-fence.test.ts
  • src/main/persistence/closed-terminal-tab-write-fence.ts
  • src/main/persistence/loading-store/session-host-partitions.ts
  • src/main/persistence/loading-store/session-snapshot-operations.ts
  • src/main/persistence/loading-store/workspace-session-snapshot-publication.ts
  • src/main/runtime/orca-runtime-terminal-close-records.test.ts

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

Workspace session snapshots and patches that include unifiedTabs now pass through a filter that removes tabs covered by qualifying close records. Regression tests check local and SSH late saves, unified-tab-only patches, worktree scoping, and preservation of an existing tombstone.





Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 18dc3

Closed tabs are now kept from reappearing. However, when the same tab ID exists in two worktrees, the surviving tab can lose its layout and session binding. Make that cleanup worktree-aware before merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 6 files. 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 and concisely describes the main persistence fix: preventing session writes from restoring terminal tabs recorded as closed.
Description check Passed The description is complete and aligned with the template. It explains the problem, implementation, scope, testing, issue reference, visual-proof rationale, and checklist status. Manual testing was no…
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.





✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR





  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: 2b74935f-f0d3-41d6-b2da-253befeb9547
📥 Commits

Reviewing files that changed from the base of the PR and between 4ec973f and 18dc3190fbaa80cd4a4f3f65bc78947d4b9e31a2.

📒 Files selected for processing (6)
  • src/main/persistence/closed-terminal-tab-write-fence.test.ts
  • src/main/persistence/closed-terminal-tab-write-fence.ts
  • src/main/persistence/loading-store/session-host-partitions.ts
  • src/main/persistence/loading-store/session-snapshot-operations.ts
  • src/main/persistence/loading-store/workspace-session-snapshot-publication.ts
  • src/main/runtime/orca-runtime-terminal-close-records.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment on lines +23 to +25
next = closeTerminalTabInWorkspaceSession(next, record.worktreeId, tabId, {
force: true
}).session

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Keep metadata for a same-ID tab in another worktree.

If a snapshot lists tabId in both worktrees, this call closes the recorded worktree's row. closeTerminalTabInWorkspaceSession also deletes the tab ID's global layout, remote-session binding, and sleeping records. The other worktree keeps its tab row but loses that metadata. Make the cleanup account for a surviving same-ID tab before applying the worktree-scoped fence.

m4air added 3 commits October 9, 2026 21:20
…on recorded as closed

Main records every terminal close, but only PTY bindings and orphan
adoption honoured the record. A renderer save that still listed the tab
(when no topology revision fenced it yet), a relay write, or a fast
unified-tabs patch could write the closed tab back. Every full write and
unified-tabs patch now removes tabs the same partition has a live close
record for, scoped to the record's worktree. Rollback stays exempt.
…nal maps

A host slice with no terminal rows omits tabsByWorktree, and the forced
close transform indexed it, so a browser-only save to a partition with a
live close record threw and never persisted. Close only tabs actually
listed, with the terminal maps supplied.
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.

1 participant