From 015996d1b1c7fd2debc80b7022a5d197868cecdc Mon Sep 17 00:00:00 2001 From: audichuang <72485427+audichuang@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:03:44 +0800 Subject: [PATCH] fix(persistence): clear canonical active workspace key on worktree owner removal (#6255) Worktree session owners are removed by their raw id, but activeWorkspaceKey stores the canonical worktree: form, so deleting a worktree left the persisted active key pointing at the removed workspace in every partition. Match both forms in deleteOwnerKeyedSessionFields so every owner-removal path (worktree delete, repo pruning, invalid-layout purge) clears it. Co-authored-by: Neil --- .../persistence-host-partitioned-sessions.test.ts | 2 ++ .../persistence/restoring-sessions/session-owner-fields.ts | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/persistence/persistence-host-partitioned-sessions.test.ts b/src/main/persistence/persistence-host-partitioned-sessions.test.ts index 8cb04214bb3..2813d66aaab 100644 --- a/src/main/persistence/persistence-host-partitioned-sessions.test.ts +++ b/src/main/persistence/persistence-host-partitioned-sessions.test.ts @@ -475,6 +475,7 @@ describe('Store host-partitioned workspace sessions', () => { const makeSession = (): ReturnType => ({ ...makeHostSession('repo-ssh'), activeWorktreeId: worktreeId, + activeWorkspaceKey: worktreeWorkspaceKey(worktreeId), lastVisitedAtByWorktreeId: { [worktreeId]: 123 }, tabsByWorktree: { [worktreeId]: [makeTerminalTab({ id: 'stale-tab', worktreeId })] @@ -493,6 +494,7 @@ describe('Store host-partitioned workspace sessions', () => { expect(store.getWorkspaceSession(hostId)).toMatchObject({ tabsByWorktree: {}, activeWorktreeId: null, + activeWorkspaceKey: null, lastVisitedAtByWorktreeId: {}, terminalTopologyRevisionByRepoId: { 'repo-ssh': 1 } }) diff --git a/src/main/persistence/restoring-sessions/session-owner-fields.ts b/src/main/persistence/restoring-sessions/session-owner-fields.ts index 041f79eda28..b7af9e2ec60 100644 --- a/src/main/persistence/restoring-sessions/session-owner-fields.ts +++ b/src/main/persistence/restoring-sessions/session-owner-fields.ts @@ -5,6 +5,7 @@ import { getWorktreeIdFromHostIdentity, isWorktreeHostIdentity } from '../../../shared/worktree/host-qualified-identity' +import { worktreeWorkspaceKey } from '../../../shared/workspace-scope' import { SESSION_FIELDS_PRUNED_BY_OWNER_KEY } from '../../orca-profiles/profile-project-session-field-disposition' // Repo-keyed topology revisions advance rather than delete; host-qualified recency keys need a scan. @@ -91,7 +92,11 @@ export function deleteOwnerKeyedSessionFields( } } } - if (next.activeWorkspaceKey === ownerKey) { + // Worktree owners are raw ids, but the active key stores their canonical worktree: form. + if ( + next.activeWorkspaceKey === ownerKey || + next.activeWorkspaceKey === worktreeWorkspaceKey(ownerKey) + ) { next.activeWorkspaceKey = null } if (next.activeWorktreeId === ownerKey) {