Skip to content

fix(projects): removing one host's copy of a project keeps its same-path twin's shells, tabs and edits - #29954

Merged
nwparker merged 26 commits into
mainfrom
nwparker/remote-project-removal-host-twin
Oct 17, 2026
Merged

nwparker merged 26 commits into
mainfrom
nwparker/remote-project-removal-host-twin

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​659 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​651
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​663 $\color{#cf222e}{\Huge{\mathbf{−}}}$​47 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​616

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: removeProject used 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:

  • the host stamp on each tab (Tab.executionHostId)
  • the host each PTY id names (getPtyExecutionHost)
  • an open file's own host (getOpenFileExecutionHostId)
  • a browser page's runtime environment
  • a sleeping record's connectionId
  • the removed worktree's paired-runtime alias (isExecutionHostAliasForWorktree)

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. closeFile takes an optional captureRecentlyClosed: false. Closing a background workspace's file no longer resets which surface the focused workspace shows, or deselects it (covered by editor-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.ts uses 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.ts and repos-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 closeFile in the teardown; instead, that was fixed in closeFile itself.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Project removal now distinguishes state attributed to a removed host from state shared with surviving hosts. It rechecks surviving hosts after removal, tears down attributed state, and purges terminal state only for exclusive worktrees. The changes also add host-aware structured-launch cancellation and tests for removal behavior. Closing a file in a background worktree no longer changes the focused worktree's active surface, and cleanup closes can skip recently closed history.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 3559c

Removing a project on a paired web client may leave stale chat drafts behind. This is a bounded issue that can be fixed with a small change.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description is detailed and covers the required user impact, implementation, rationale, testing, visual proof, and compatibility considerations. However, it does not provide the mandatory linked i… Add an actual linked issue using the required Fixes #... entry, or obtain and document the repository-approved maintainer exception for omitting a needless issue link.
Passed Passed checks: 3 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the primary change: preserving shells, tabs, and edits for a same-path project twin when the other host copy is removed.
Full details: Description check

Explanation

The description is detailed and covers the required user impact, implementation, rationale, testing, visual proof, and compatibility considerations. However, it does not provide the mandatory linked issue and explicitly states that no GitHub issue exists.

Resolution

Add an actual linked issue using the required Fixes #... entry, or obtain and document the repository-approved maintainer exception for omitting a needless issue link.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

nwparker and others added 26 commits October 16, 2026 20:11
…ep its files out of reopen history

Co-Authored-By: Claude <[email protected]>
…sed surface on background twin removal

Co-Authored-By: Claude <[email protected]>
…se; background file close keeps focus

Co-Authored-By: Claude <[email protected]>
… history; layout-only hints prove nothing

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker force-pushed the nwparker/remote-project-removal-host-twin branch from 089b5d1 to 3559c86 Compare October 17, 2026 03:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ca302a80-a926-464c-a26f-4cf9b5f93df5
📥 Commits

Reviewing files that changed from the base of the PR and between ad6b318 and 3559c86.

📒 Files selected for processing: 11
  • src/renderer/src/store/repos/repo-removal-host-twin-attribution.ts
  • src/renderer/src/store/repos/repo-removal-host-twin-teardown.ts
  • src/renderer/src/store/repos/repo-removal.ts
  • src/renderer/src/store/slices/editor-close-background-file.test.ts
  • src/renderer/src/store/slices/editor/actions/close-file-action.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts
  • src/renderer/src/store/slices/project-removal-host-twin-state.test.ts
  • src/renderer/src/store/slices/project-removal-owner-host.test.ts
  • src/renderer/src/store/slices/repos-host-identity-routing.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-worktree-chat-drafts.ts
  • src/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.

Comment on lines +123 to +141
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 }
: {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.ts

Repository: 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/src

Repository: 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/src

Repository: 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/src

Repository: 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.ts

Repository: 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,

@nwparker
nwparker merged commit 15b1217 into main Oct 17, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant