Repository navigation
fix(projects): removing one host's copy of a project keeps its same-path twin's shells, tabs and edits - #29954
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
… shells, tabs and edits Co-Authored-By: Claude <[email protected]>
… under a twin id Co-Authored-By: Claude <[email protected]>
… SSH included Co-Authored-By: Claude <[email protected]>
…ep its files out of reopen history Co-Authored-By: Claude <[email protected]>
…n stack Co-Authored-By: Claude <[email protected]>
…open order in step Co-Authored-By: Claude <[email protected]>
… browsers Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
…d survive Co-Authored-By: Claude <[email protected]>
…mped editor tabs Co-Authored-By: Claude <[email protected]>
…p tabless sleeping records Co-Authored-By: Claude <[email protected]>
…s, prune its local editors Co-Authored-By: Claude <[email protected]>
…sed surface on background twin removal Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
…surface Co-Authored-By: Claude <[email protected]>
…bution Co-Authored-By: Claude <[email protected]>
… own host stamp Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
…se; background file close keeps focus Co-Authored-By: Claude <[email protected]>
…win attribution Co-Authored-By: Claude <[email protected]>
…ane keeps Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
… history; layout-only hints prove nothing Co-Authored-By: Claude <[email protected]>
…lias Co-Authored-By: Claude <[email protected]>
…ckground file close Co-Authored-By: Claude <[email protected]>
089b5d1 to
3559c86
Compare
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:
ca302a80-a926-464c-a26f-4cf9b5f93df5
📒 Files selected for processing: 11
src/renderer/src/store/repos/repo-removal-host-twin-attribution.tssrc/renderer/src/store/repos/repo-removal-host-twin-teardown.tssrc/renderer/src/store/repos/repo-removal.tssrc/renderer/src/store/slices/editor-close-background-file.test.tssrc/renderer/src/store/slices/editor/actions/close-file-action.tssrc/renderer/src/store/slices/editor/types/editor-files-slice.tssrc/renderer/src/store/slices/project-removal-host-twin-state.test.tssrc/renderer/src/store/slices/project-removal-owner-host.test.tssrc/renderer/src/store/slices/repos-host-identity-routing.test.tssrc/renderer/src/store/slices/worktrees/teardown/removed-worktree-chat-drafts.tssrc/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
| const survivingTwinHostIds = getSurvivingTwinHostIds(get(), projectId, ownerHostId) | ||
| const removedTwinState = collectRemovedHostTwinState( | ||
| get(), | ||
| new Set(survivingTwinHostIds.keys()), | ||
| ownerHostId, | ||
| survivingTwinHostIds | ||
| ) | ||
| const removedTwinEntityIds = new Set([ | ||
| ...removedTwinState.terminalTabIds, | ||
| ...removedTwinState.conversationIds | ||
| ]) | ||
| const chatDraftKeys = captureWorkspaceChatDraftKeys( | ||
| get(), | ||
| getKnownRepoWorktreeIds(get(), projectId, ownerHostId).map((workspaceId) => ({ | ||
| workspaceId, | ||
| executionHostId: ownerHostId | ||
| executionHostId: ownerHostId, | ||
| ...(survivingTwinHostIds.has(workspaceId) | ||
| ? { onlyEntityIds: removedTwinEntityIds } | ||
| : {}) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
rg -nP -C4 'deleteNativeChatComposerDraftsOwnedBy\s*\(' src/renderer
rg -nP -C3 'executionHostId' src/renderer/src/components/native-chat/native-chat-composer-draft-storage.tsRepository: stablyai/orca
Length of output: 7085
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- capture/delete definitions and callers ---'
rg -n -F --glob '*.ts' -e 'captureWorkspaceChatDraftKeys' -e 'deleteWorkspaceChatDrafts' -e 'NativeChatComposerDraftOwner' -e 'parseExecutionHostId' src/renderer/src
printf '%s\n' '--- relevant source excerpts ---'
sed -n '1,180p' src/renderer/src/store/slices/worktrees/teardown/removed-worktree-chat-drafts.ts
sed -n '110,165p' src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts
sed -n '280,320p' src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts
printf '%s\n' '--- execution host declarations and alias handling ---'
rg -n -F --glob '*.ts' -e 'type ExecutionHostId' -e 'ExecutionHostId =' -e 'runtime alias' -e 'runtimeAlias' -e 'executionHostId:' src/renderer/srcRepository: stablyai/orca
Length of output: 45667
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- owner resolver ---'
nl -ba src/renderer/src/lib/native-chat-draft-owner.ts
printf '%s\n' '--- chat draft teardown ---'
nl -ba src/renderer/src/store/slices/worktrees/teardown/removed-worktree-chat-drafts.ts
printf '%s\n' '--- draft owner write and normalization ---'
rg -n -F --glob '*.ts' -e 'setNativeChatComposerDraftOwnerResolver' -e 'resolveNativeChatComposerDraftOwner' -e 'owner:' -e 'writeNativeChat' src/renderer/src/components/native-chat src/renderer/src/lib src/renderer/src/app-shell
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts | sed -n '1,180p'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts | sed -n '180,330p'
printf '%s\n' '--- capture definition ---'
rg -n -F --glob '*.ts' 'function captureWorkspaceChatDraftKeys' src/renderer/srcRepository: stablyai/orca
Length of output: 41707
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- removal control flow ---'
nl -ba src/renderer/src/store/repos/repo-removal.ts | sed -n '80,155p'
nl -ba src/renderer/src/store/repos/repo-removal.ts | sed -n '200,235p'
printf '%s\n' '--- operation route ---'
nl -ba src/renderer/src/lib/worktree-operation-route.ts
printf '%s\n' '--- host parser and normalization ---'
rg -n -F --glob '*.{ts,tsx}' -e 'function parseExecutionHostId' -e 'function normalizeExecutionHostId' -e 'toRuntimeExecutionHostId' -e 'type ExecutionHostId' src/shared src/renderer/srcRepository: stablyai/orca
Length of output: 41985
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- paired host transformation ---'
nl -ba src/renderer/src/lib/paired-web-client-host.ts
printf '%s\n' '--- repo host identity ---'
rg -n -F --glob '*.ts' -e 'function getRepoExecutionHostId' -e 'export function getRepoExecutionHostId' -e 'function repoMatchesHostIdentity' src/renderer/src src/shared
nl -ba src/shared/execution-host.ts | sed -n '1,190p'
printf '%s\n' '--- direct owner route helpers ---'
nl -ba src/renderer/src/store/repos/repo-removal-host-twin-attribution.ts | sed -n '1,140p'Repository: stablyai/orca
Length of output: 16894
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- repo-removal imports and setup ---'
nl -ba src/renderer/src/store/repos/repo-removal.ts | sed -n '1,75p'
printf '%s\n' '--- repo host helper ---'
nl -ba src/shared/execution-host.ts | sed -n '190,215p'
printf '%s\n' '--- route and owner resolver imports ---'
rg -n -F --glob '*.ts' -e 'resolveWorktreeOperationRoute' -e 'resolveNativeChatDraftOwner' src/renderer/src/store/repos/repo-removal.ts src/renderer/src/lib/native-chat-draft-owner.tsRepository: stablyai/orca
Length of output: 5515
Capture drafts with the resolved operation host.
On a paired web client, onPairedWebClientHost can change local to runtime:<environment>. Draft creation records that resolved host, but removeProject passes the repo row's ownerHostId directly to captureWorkspaceChatDraftKeys. Exact host matching then leaves the draft undeleted.
Use the same resolved worktree route for draft capture that resolveNativeChatDraftOwner uses.
🐛 Suggested fix
+import { resolveWorktreeOperationRoute } from '@/lib/worktree-operation-route'- executionHostId: ownerHostId,
+ executionHostId:
+ resolveWorktreeOperationRoute(get(), workspaceId)?.executionHostId ?? ownerHostId,
ELI5
A project can be added twice: once on this computer and once on a remote machine, both at the same folder path. Orca gives the two copies the same internal workspace id. When you removed the remote copy, Orca also cleaned up everything under that id, so it killed the shell in your local copy and threw away your unsaved local edits. Removing one copy now only touches that copy's things.
What Changed
Before: say a local project and a remote copy share a repo id and worktree path, and you remove the remote copy. The local copy's row stays in the sidebar, but its terminal is killed, its tabs close, its dirty document is discarded, and its unsaved editor draft and chat draft are deleted.
After: the local copy keeps its shell, tabs, dirty documents and drafts. Only the removed copy's terminals, editors, browsers, chats and simulators close. Its shells are stopped, its pending chat launches are cancelled, and its closed tabs drop out of the reopen stack. The same holds in reverse (removing the local copy while a remote copy stays) and for SSH copies.
Mechanism:
removeProjectused to tear down by raw worktree id: it killed every non-remote PTY under the id and passed the id to the bulk purge (buildWorktreePurgeState). That purge clears every tab, file and draft keyed by the id, whichever host owns them. Now, for an id that another host still publishes, removal skips the bulk purge. It works out which of that id's surfaces belong to the removed host, using evidence that is already recorded:Tab.executionHostId)getPtyExecutionHost)getOpenFileExecutionHostId)connectionIdisExecutionHostAliasForWorktree)Only those surfaces are closed, through the existing close actions (
closeTab,closeFile,closeBrowserTab,closeUnifiedTab). Terminal teardown goes through the existing retirement planner, so a PTY that another tab still binds survives. Anything without host evidence is kept, because it may belong to the copy that stays. If both copies are removed at once, the survivor check runs again after the host call, and the full purge applies.By design, a legacy tab from the removed copy that carries no host evidence can stay in the surviving workspace. It shows up as a visible orphan the user can close, which is safer than closing something that might belong to the survivor. Narrowing the attribution further is a follow-up.
Two small helper changes support this.
closeFiletakes an optionalcaptureRecentlyClosed: false. Closing a background workspace's file no longer resets which surface the focused workspace shows, or deselects it (covered byeditor-close-background-file.test.ts). With no surviving twin, removal leaves the selection to the bulk purge as before.Why
The alternative is the rule single-worktree removal uses (STA-4343): when another host still owns the id, keep every shared renderer surface. That would also keep the removed copy's tabs, which then show up inside the surviving workspace. Attributing each surface by the host evidence it already carries keeps the survivor intact and still removes what was the removed host's. When the evidence is missing, the code keeps the surface rather than guessing.
Linked Issue
Second external Codex SSH review, finding 1 (P1). No GitHub issue.
Visual Proof
N/A: this changes store state cleanup. The before and after states are listed above and covered by tests.
Testing
New
src/renderer/src/store/slices/project-removal-host-twin-state.test.tsuses a local and a remote twin. Removing the remote copy keeps the local shell, tab, dirty document, editor draft and chat draft. Removing the local copy keeps the remote copy's state. It also covers SSH copies, PTYs that another tab shares, tabs that mix panes from two hosts, and tabs opened while the removal is in flight. Other cases: removing both copies at the same time, reopen history, sleeping records, and selection repair.Updated
project-removal-owner-host.test.tsandrepos-host-identity-routing.test.ts. A tab with no host evidence under a twin id now stays.Ran the store, repos, editor, tabs, terminals, browser and worktrees test folders on a single worker: all pass. Ran
pnpm tc, plus the static-analysis job's lint, anti-slop, code-quality, max-lines, layout-writer, focus-read and other ratchet steps locally.Live: not verified on a real machine. A managed host with a local twin checkout at the same path could not be set up under host isolation, so this fix is covered only by store-level tests.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Ran Codex review (gpt-6.1-sol, high) until clean. Every finding was fixed except one. Codex suggested restoring the focused surface after
closeFilein the teardown; instead, that was fixed incloseFileitself.Agent skill upstream boundary
Notes
SSH and remote: execution-host ownership is the core of the fix. There are no wire changes. Folder workspaces use the same worktree-id path.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)