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:<id> 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 <neil@stably.ai>
This commit is contained in:
audichuang
2026-10-26 05:03:44 -07:00
committed by GitHub
co-authored by Neil
parent f5b2cc5a79
commit 015996d1b1
2 changed files with 8 additions and 1 deletions
@@ -475,6 +475,7 @@ describe('Store host-partitioned workspace sessions', () => {
const makeSession = (): ReturnType<typeof makeHostSession> => ({
...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 }
})
@@ -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) {