Repository navigation
Conversation
📝 WalkthroughWalkthroughProject removal now collects affected worktree owner keys before deleting worktree metadata. It prunes matching entries from global workspace session state and host-scoped workspace session partitions. Tests cover global and host-scoped cleanup, including shared repository identities across local and multiple remote hosts while preserving unrelated entries. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
|
Thanks for tackling #9024. I tested the current head and confirmed that the full I found one cross-host regression in the host-scoped Reproduction: register the same repo ID and path on local and Could the cleanup be scoped to the selected host when Otherwise, the fix looks focused and the full-removal behavior appears correct. |
|
@e-jung Thanks for the careful review and the concrete repro — you're right, that was a real cross-host bug. I pushed
I also added the two regression tests you suggested, both using the same owner key on two hosts:
Would you mind taking another look when you have a moment? Thanks again. |
e-jung
left a comment
There was a problem hiding this comment.
Re-reviewed commit 53e7f18. The host-scoped cleanup now preserves surviving local, SSH, and paired-remote session partitions while full remove still clears every partition.
I verified both new regression tests fail against the previously reviewed head 4b05fa0 and pass on the current head. The complete persistence suite passes 375 of 375 tests, the touched files pass node TypeScript checking and oxlint, and an additional two-SSH-host reproduction also passes.
The earlier cross-host blocker is resolved. The remaining observations are non-blocking: worktreeMeta still has a pre-existing identical-path cross-host ambiguity, and a third-surviving-host fixture could be useful future coverage. Approving this revision. Thanks for the careful fix.
|
Sure. I will add a /3rd host/ test case to cover it :) |
|
Thanks for the thorough review @e-jung 🙏 This is approved and green (the host-scoped cleanup regression you caught is resolved, and the persistence suite passes). I don't have merge access on the upstream — could you (or another maintainer) squash-merge this when you have a moment? Happy to rebase if it's gone stale. |
|
Hi @e-jung — |
removeProject → pruneWorktreeStateForRepo cleared worktreeMeta, lineage, and workspace lineage, but left the removed repo's worktrees behind in workspaceSession (lastVisitedAtByWorktreeId, sleepingAgentSessionsByPaneKey, tab state, …) and in every workspaceSessionsByHostId partition. Those dangling references caused the runtime to treat the deleted repo's worktrees as recently-active on the next launch and re-materialize their worktreeMeta. With no owning project left, the UI rendered them as an orphaned "unknown" workspace that returned after every restart. Reuse the existing removeWorkspaceSessionOwner cleanup (already used by removeFolderWorkspace and deleteProjectGroup) against the legacy session blob and each per-host partition, collecting owner keys before the worktreeMeta delete loop so host classification still works. Fixes stablyai#9024 Co-Authored-By: Claude Fable 5 <[email protected]>
The workspace-session cleanup applied every collected owner key to the legacy
(local) session blob AND every workspaceSessionsByHostId partition. Owner keys
are `${repoId}::${path}` and carry no host, so a host-scoped removal
(removeProjectForHost) of one host wrongly wiped a surviving host's session for
a shared repo id/path — discarding its lastVisitedAt, tabs, sleeping-agent
state, and active-worktree pointer.
Scope the session prune to the removed host: prune the legacy blob only when the
target host is local (or on a full removeProject where hostId is null), and
prune only the matching workspaceSessionsByHostId partition for a non-local
host; a full removal still clears every partition. Collect session owner keys by
`${repoId}::` prefix (not belongsToHost, which is worktreeMeta-host-classified)
so a partition-only key is still prunable.
Adds regression tests for a shared repo id + path across local and an SSH host,
covering removeProjectForHost on the SSH host (local session survives) and on
the local host (SSH session survives).
Addresses review feedback on stablyai#9024.
Co-Authored-By: Claude Fable 5 <[email protected]>
Add a regression case where a shared repo id + path exists on local and two SSH hosts. Removing one non-local host must prune only that host's session partition, leaving both the legacy/local session and the other surviving SSH host's partition intact. Locks in that the host-scoped cleanup never touches a non-targeted third partition (per review feedback on stablyai#9024). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Project removal collected every owner key to prune, then called removeWorkspaceSessionOwner once per owner AND per host partition. Each call structuredClones and scans the entire session, so removal was O(worktrees x hosts x session size) in full-session clones on the main thread. Add removeWorkspaceSessionOwners(session, ownerKeys) which clones once and scans each collection once for the whole set, and route pruneWorktreeStateForRepo through it. The per-owner O(1) field deletes and the single-scan pane-key passes are factored into shared functions so removeWorkspaceSessionOwner keeps identical behavior for its other callers. No behavior change. Co-authored-by: Orca <[email protected]>
c0adefa to
1e8fdd4
Compare
…r exists
`hydrateHeadlessMobileSessionTabsFromWorkspaceSession` iterates
`workspaceSession.tabsByWorktree` with no repo gate. Those keys are
`${repoId}::${path}` and are not pruned when a repo disappears from this
client's view, so a stale key re-materializes a phantom "unknown"/duplicate
workspace with no live repo behind it, on boot, with no `session-created` event.
Skip entries whose parsed repoId is not in the live `repos`; leave unparseable
keys alone (conservative). Defensive complement to the delete-path (stablyai#9025) and
load-time (stablyai#9200) fixes — this closes the mobile/headless hydration path.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks so much for this, @PannenetsF — prune workspace session state when a project is removed (#9024). Verified (fail-on-main/pass-on-branch), rebased on latest |
…r exists (#9343) `hydrateHeadlessMobileSessionTabsFromWorkspaceSession` iterates `workspaceSession.tabsByWorktree` with no repo gate. Those keys are `${repoId}::${path}` and are not pruned when a repo disappears from this client's view, so a stale key re-materializes a phantom "unknown"/duplicate workspace with no live repo behind it, on boot, with no `session-created` event. Skip entries whose parsed repoId is not in the live `repos`; leave unparseable keys alone (conservative). Defensive complement to the delete-path (#9025) and load-time (#9200) fixes — this closes the mobile/headless hydration path. Co-authored-by: fanyunqian.1 <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
`pruneWorktreeStateForRepo` only runs via `removeProject`/`removeProjectForHost`, both of which require the repo to still be in `repos`. A repo id that leaves `repos` by any other path (a partial/interrupted delete, a repo-id re-key migration, or a crash between the filter and the save) is never routed through prune again, so its `worktreeMeta`/lineage rows and `workspaceSession` owner keys are orphaned permanently. `gcStaleWorktreeMeta` cannot reclaim them either: it keeps an entry whose path still exists on disk (a duplicate that shares a live repo's path — `existsSync` is true) or whose meta carries a remote `hostId`. The ownerless `worktreeMeta` row is then restored verbatim on every load, and its `workspaceSession` `tabsByWorktree` twin is re-materialized into a phantom "unknown"/duplicate workspace on the next launch (`hydrateHeadlessMobileSessionTabsFromWorkspaceSession` iterates `tabsByWorktree` with no repo gate). Add `gcOrphanedRepoState`, a load-time sweep that removes `worktreeMeta` / lineage / `workspaceLineage` entries and `workspaceSession`(+ByHostId) owner keys whose repo id is absent from both `repos` and `projects`, reusing `removeWorkspaceSessionOwner` so the sweep and the delete path share one cleanup. Skips when there are zero live owners so an anomalous empty-`repos` load can never wipe all state. This is the load-side companion to stablyai#9025, which fixes only the forward delete path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…i#9024) (stablyai#9025) * fix: prune workspace session state when a project is removed removeProject → pruneWorktreeStateForRepo cleared worktreeMeta, lineage, and workspace lineage, but left the removed repo's worktrees behind in workspaceSession (lastVisitedAtByWorktreeId, sleepingAgentSessionsByPaneKey, tab state, …) and in every workspaceSessionsByHostId partition. Those dangling references caused the runtime to treat the deleted repo's worktrees as recently-active on the next launch and re-materialize their worktreeMeta. With no owning project left, the UI rendered them as an orphaned "unknown" workspace that returned after every restart. Reuse the existing removeWorkspaceSessionOwner cleanup (already used by removeFolderWorkspace and deleteProjectGroup) against the legacy session blob and each per-host partition, collecting owner keys before the worktreeMeta delete loop so host classification still works. Fixes stablyai#9024 Co-Authored-By: Claude Fable 5 <[email protected]> * fix: scope session cleanup to the removed host in removeProjectForHost The workspace-session cleanup applied every collected owner key to the legacy (local) session blob AND every workspaceSessionsByHostId partition. Owner keys are `${repoId}::${path}` and carry no host, so a host-scoped removal (removeProjectForHost) of one host wrongly wiped a surviving host's session for a shared repo id/path — discarding its lastVisitedAt, tabs, sleeping-agent state, and active-worktree pointer. Scope the session prune to the removed host: prune the legacy blob only when the target host is local (or on a full removeProject where hostId is null), and prune only the matching workspaceSessionsByHostId partition for a non-local host; a full removal still clears every partition. Collect session owner keys by `${repoId}::` prefix (not belongsToHost, which is worktreeMeta-host-classified) so a partition-only key is still prunable. Adds regression tests for a shared repo id + path across local and an SSH host, covering removeProjectForHost on the SSH host (local session survives) and on the local host (SSH session survives). Addresses review feedback on stablyai#9024. Co-Authored-By: Claude Fable 5 <[email protected]> * test: cover third surviving host in removeProjectForHost session prune Add a regression case where a shared repo id + path exists on local and two SSH hosts. Removing one non-local host must prune only that host's session partition, leaving both the legacy/local session and the other surviving SSH host's partition intact. Locks in that the host-scoped cleanup never touches a non-targeted third partition (per review feedback on stablyai#9024). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * perf: prune workspace session in a single clone+scan per partition Project removal collected every owner key to prune, then called removeWorkspaceSessionOwner once per owner AND per host partition. Each call structuredClones and scans the entire session, so removal was O(worktrees x hosts x session size) in full-session clones on the main thread. Add removeWorkspaceSessionOwners(session, ownerKeys) which clones once and scans each collection once for the whole set, and route pruneWorktreeStateForRepo through it. The per-owner O(1) field deletes and the single-scan pane-key passes are factored into shared functions so removeWorkspaceSessionOwner keeps identical behavior for its other callers. No behavior change. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: PannenetsF <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Neil <[email protected]> Co-authored-by: Orca <[email protected]>
…r exists (stablyai#9343) `hydrateHeadlessMobileSessionTabsFromWorkspaceSession` iterates `workspaceSession.tabsByWorktree` with no repo gate. Those keys are `${repoId}::${path}` and are not pruned when a repo disappears from this client's view, so a stale key re-materializes a phantom "unknown"/duplicate workspace with no live repo behind it, on boot, with no `session-created` event. Skip entries whose parsed repoId is not in the live `repos`; leave unparseable keys alone (conservative). Defensive complement to the delete-path (stablyai#9025) and load-time (stablyai#9200) fixes — this closes the mobile/headless hydration path. Co-authored-by: fanyunqian.1 <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Deleting a project no longer leaves an orphaned "unknown" workspace that reappears in the sidebar after every restart (#9024).
ELI5: When you removed a project, the app forgot to fully forget it — a ghost copy kept coming back each time you reopened the app. Now it's cleaned up completely.
Root cause & fix:
removeProject→pruneWorktreeStateForRepoonly cleanedworktreeMetaand the lineage maps, but never removed the deleted repo's worktrees from the workspace session state (the legacyworkspaceSessionblob and the per-hostworkspaceSessionsByHostIdpartitions). BecauselastVisitedAtByWorktreeIdstill referenced the gone worktrees, the next launch treated them as recently-active and re-materializedworktreeMeta, rendering them as an orphaned "unknown" workspace.The fix collects the repo's owner keys (
${repoId}::${path}) before theworktreeMetadelete loop — fromworktreeMeta, the legacy session, and every host partition — so host classification can still readmeta.hostId(including orphan keys present only in the session maps). It then runs the existing session-owner cleanup against the legacy/local session and every matching host partition, reusing the path already used byremoveFolderWorkspaceanddeleteProjectGroup. Host gating is preserved: a host-scoped removal (hostId != null) only prunes that host's partition; a full removal (hostId === null) clears every host, so a shared repo id/path on a surviving host keeps its session.This session also added a behavior-preserving refactor:
removeWorkspaceSessionOwneris split intodeleteOwnerKeyedSessionFields(O(1) owner-keyed deletes) anddeleteScannedSessionFieldsForOwners(single pass over the pane-key maps and the shutdown list), plus a new batchremoveWorkspaceSessionOwners. This drops the per-ownerstructuredClone(previously O(worktrees × hosts)) to one clone + one scan per session partition.Original fix by @PannenetsF; validated, rebased onto latest main during 2026-07-23 bug-bash triage, and optimized as described above.
Screenshots
No visual change. This PR only touches main-process persistence logic (
src/main/persistence.tsand its tests); no renderer UI is affected. The user-observable behavior change is the absence of the orphaned "unknown" sidebar workspace after restart, which cannot be captured as a static screenshot here.Testing
pnpm lintpnpm typecheckpnpm testpnpm buildAuthor-reported (I cannot run pnpm in this environment, so these reflect the original body's claims, and the commands run were scoped to the changed file rather than the full
pnpmscripts):oxlint src/main/persistence.tsexit 0, nomax-linesdisable added.tsc --noEmit -p config/tsconfig.node.jsonexit 0.npx vitest run --config config/vitest.config.ts src/main/persistence.test.ts→ 407 passed, including the 2removeProjectsession-prune regression tests and the 3 host-scopedremoveProjectForHostprune tests. The 2 regression tests were confirmed to fail onmain(stale keys survive) and pass with the fix.pnpm buildwas not reported as run.AI Review Report
Reviewed the full diff for correctness and edge cases:
worktreeMeta, the legacy session, and all host partitions before theworktreeMetadelete loop, so orphan keys that exist only in session maps (and would otherwise lose theirmeta.hostIdclassification) are still captured. This is the crux of the fix.pruneLegacyLocalSessionfires forhostId === nullor the local host id;pruneAllHostPartitionsonly forhostId === null; otherwise partitions are skipped unlesspartitionHostId === hostId. This prevents wiping a surviving host's session for a shared repo id/path — directly covered by the three newremoveProjectForHosttests.removeWorkspaceSessionOwnerthreadsremovedTabIdsthrough the O(1) deletes into the scan phase, matching the prior single-owner behavior; theisRemovedOwnerpredicate generalizes the oldworktreeId === ownerKeycheck to set membership for the batch path. TheterminalPtyIncarnationsByPaneKeylastIndexOf(':')/separator < 1guard is carried over unchanged.removeWorkspaceSessionOwners(returns the original reference), preserving prior semantics.advanceTerminalTopologyRevisionis only forwarded on the single-owner path, matching pre-existing behavior (the batch project-removal path did not advance it before, either).${repoId}::${path}strings compared by equality/prefix; no path separator assumptions are introduced. Nothing here diverges by OS.No fabricated results; the above is based solely on the diff.
Security Audit
No security-relevant surface is changed. The diff is pure in-memory state pruning:
The change only removes stale entries from existing persisted session structures, which is a strict cleanup with no widening of trust boundaries.
Notes
workspaceSessionsByHostId).pnpm buildand the fullpnpm lint/pnpm typecheck/pnpm testsuites should be confirmed green in CI, since the author's local runs were scoped to the changed file.🤖 Generated with Claude Code