Repository navigation
fix(terminal): removing a workspace prunes that workspace's close records - #23683
Conversation
… without one Both branches now made the same call; the split only existed to keep the old two-argument arity.
…nd the store derives what goes with it Replaces the pruneCloseRecords boolean with a required cause: removed, forgotten or unlisted. Only the scan path is unlisted, and it keeps close records; every other cause drops them. Also pins that removing one host's copy of a same-id worktree leaves the other host's records.
…t the workspace is gone The runtime removal wrapper hard-coded 'removed' for every caller, including the orphan path that leaves the directory and its git registration in place. Callers now pass their cause, as the desktop wrapper's callers already do, and the orphan path says 'forgotten' like the desktop Forget it mirrors. Pruning is unchanged: both causes drop the close records.
…ne typed helper Adding the cause argument touched seven calls that each cast their fixture store; one helper now carries the single justified cast.
…s the records too
…its close records Every caller of the owner-removal chokepoint is an explicit removal, and the only host-driven one runs after a successful git scan, so the removal cause threaded through the removal paths decided nothing. Drop it, prune unconditionally, and seed the deregistered-repo sweep from close records so a project moved to another profile does not leave them behind.
…er worktree-named records The standalone pruner and its shared helper only existed to be skipped for one removal cause; with the cause gone they are a second scan beside the one that already walks every record naming a worktree.
Review status: ready for reviewHead What changed during review
Reviews
Checks: node typecheck, the changed-code quality gate, oxlint and CI all pass. Live run on a second Mac: passed.
This PR, Known and not changed here: the renderer's in-memory copy of close records is cleared only at the next reload. It predates this PR and belongs with the planned shared "is this tab closed" check. Project removal, Forget and SSH partitions were covered by unit tests, not the live run. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe change adds close-tab tombstones to workspace-owner pruning and deregistered-repo scanning. Tests cover removal across local and SSH session partitions, folder and project removal, and tombstone capacity. A separate renderer test checks that a rejected runtime-host scan leaves metadata and worktree rows unchanged. Comments describe tombstone removal during workspace-row cleanup. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to This change prunes terminal close records when a workspace is removed. No blocking risk was found. A small test-strictness improvement is suggested. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The cleanup is scoped to workspace records and has evidence that it preserves records belonging to other workspaces and hosts. No new security exposure was established. Recovery after a failed save or an interrupted project move remains unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
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: cf7da067-6f3c-4f9d-a6a0-d5890e27a6dd
📒 Files selected for processing (8)
src/main/orca-profiles/profile-project-session-field-disposition.tssrc/main/persistence-deregistered-repo-residue.test.tssrc/main/persistence/restoring-sessions/session-owner-removal.tssrc/main/persistence/tracking-repos/deregistered-repo-residue.tssrc/main/persistence/tracking-repos/repo-worktree-pruning.tssrc/main/worktree-removal-close-records.test.tssrc/renderer/src/store/slices/worktrees-runtime-host-metadata-retirement.test.tssrc/shared/closed-terminal-tab-tombstones.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| await store | ||
| .getState() | ||
| .fetchWorktrees(REPO_ID, { executionHostId: HOST_ID }) | ||
| .catch(() => undefined) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the handled scan failure instead of swallowing a rejection.
fetchWorktreesAttempt catches scan errors and returns false. This test also passes if fetchWorktrees unexpectedly rejects, provided the rows remain unchanged. Assert a false result so the test detects a regression in the fetch error contract.
Proposed change
- await store
- .getState()
- .fetchWorktrees(REPO_ID, { executionHostId: HOST_ID })
- .catch(() => undefined)
+ await expect(
+ store.getState().fetchWorktrees(REPO_ID, { executionHostId: HOST_ID })
+ ).resolves.toBe(false)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| await store | |
| .getState() | |
| .fetchWorktrees(REPO_ID, { executionHostId: HOST_ID }) | |
| .catch(() => undefined) | |
| await expect( | |
| store.getState().fetchWorktrees(REPO_ID, { executionHostId: HOST_ID }) | |
| ).resolves.toBe(false) |
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Close records now die with their workspace —
deleteScannedSessionFieldsForOwnersscansclosedTerminalTabTombstonesByTabIdand deletes entries whoserecord.worktreeIdmatches the removed owner. BothremoveWorkspaceSessionOwner(direct, and the every-partition form) and the batchremoveWorkspaceSessionOwnersroute through it, so every removal path prunes records in the same session write that drops the workspace's rows. - Repo/project pruning seeds from close records —
repo-worktree-pruning.tscollects close-recordworktreeIds (host-qualified keys handled bycollectPrefixedKeys) so a worktree known only by a record is still pruned, andcollectDeregisteredRepoIdsseeds orphan repo ids from close records so a moved project's source records no longer await TTL. - Disposition doc —
closedTerminalTabTombstonesByTabIdis reclassified as owner-scoped by the removal scan, and the type JSDoc records the third death path. - Tests — 6-case
worktree-removal-close-records.test.ts(local, SSH partition, same-id other host, folder workspace, project removal, cap-slot freeing), a deregistered-residue case, and an unreachable-runtime-host regression asserting no retirement on lost contact.
I ran the three touched suites locally (20 tests pass) and confirmed the new removal tests are not theatre by disabling the close-record scan: all 6 turn red, including the project-removal and cap-slot cases. I also traced the same-id-other-host partition gating and the runtime paired-host retention paths; neither regresses.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏



Follow-up to #22955.
ELI5
When you close a terminal tab, Orca keeps a small note that says "this tab was closed". Until now those notes only disappeared after 30 days, or when a host collected more than 500 of them. Removing a worktree, a folder workspace or a whole project left its notes behind. Now removing a workspace takes its notes with it, in the same save that removes the workspace.
What Changed
Before
After
orca worktree rm);Mechanism
removeWorkspaceSessionOwnerand its batch form now also drop the close records that name the removed owner, in the same scan that already drops the other records naming a worktree (sleeping agents, surface tombstones). Every removal path already goes through these two functions (directly, through the every-partition form, or throughStore.removeWorktreeMeta), so no caller changes.Why
Differences from the common pattern
profile-project-session-field-disposition.ts).Linked Issue
No public issue. Follow-up to #22955, requested during its review.
Visual Proof
Live Electron run on a second Mac (isolated profile and home), at 44a755a against
main3c1af16. The close records were read from the saved profile database with sqlite after each step; the screenshots show the app at the same points.1. Delete a worktree, then recreate it at the same path. Two worktrees,
prune-aandprune-keep, each with one closed terminal tab, so each has one close record.main, after deletingprune-aboth records are still saved, including the one naming the deleted worktree. Recreatingprune-agives it the same id, so the new worktree inherits the old record.prune-aonlyprune-keep's record is saved. The recreatedprune-ahas no record, opens a working terminal, and after a restart still has none whileprune-keep's record survives.main, after deletingprune-a(its record is still saved):This PR, before and after deleting
prune-a:This PR,
prune-arecreated at the same path, with a working terminal, and after a restart:2. Remove a folder workspace. With a closed tab in a folder workspace, removing the workspace drops its record and keeps
prune-keep's.3. Normal close still works. A tab closed in
prune-keepstays closed after a restart, with areason: "user"record, and new terminals run normally.Not exercised live: project removal, Forget, and SSH partitions (covered by the unit tests above). The run also saw two things that predate this PR: removing a folder workspace has no confirmation and leaves its empty project group in the sidebar.
Testing
New
src/main/worktree-removal-close-records.test.ts, on the SQLite test store:Also new:
persistence-deregistered-repo-residue.test.ts: a close record that is an unregistered project's only leftover is swept at startup and does not come back.worktrees-runtime-host-metadata-retirement.test.ts: a runtime host that does not answer triggers no removal. Existing tests in that file and inworktrees-fetch-persisted-metadata-fallback.test.tsalready cover a failed scan, the SSH fallback listing and a legacy listing.Each was checked by deleting the code it protects:
Also run: typecheck (node), the removal, sweep, host-partition, partition-fencing and SSH scan-forget suites (66 tests), the runtime-host retirement suite, the changed-code quality gate and oxlint.
AI Disclosure
Written with Claude.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Author X handle: @BrennanKB5
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)