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