Skip to content

fix(worktrees): a host-scoped purge leaves a surviving twin's tabs and edits alone - #30030

Merged
nwparker merged 1 commit into
mainfrom
nwparker/host-worktree-target-purge
Oct 17, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/host-worktree-target-purge

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​398 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​391
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​800 $\color{#cf222e}{\Huge{\mathbf{−}}}$​203 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​597

ELI5

Sometimes the same project folder is open twice in Orca: once on this computer and once on a remote machine (over SSH or on a paired Orca server). Both copies share one internal name. When Orca learned that one copy was gone, for example because the SSH host's scan stopped listing it, it threw away the open tabs and unsaved edits filed under that shared name. That included the copy that was still there. Now Orca throws away only what clearly belongs to the copy that went away.

What Changed

Before: a local checkout and an SSH (or paired-server) checkout of the same repo path share the worktree id repoId::path. If the SSH host's authoritative scan dropped that worktree, the purge wiped every tab, terminal, dirty document, draft, git cache and sleeping-agent record under the id. The local copy's work went with it, and it happened the other way round too. Folder workspaces published by two hosts had the same problem.

After: when a purge names a host and another host still publishes the same id, only state that can be tied to the purged host is removed:

  • terminals whose PTY id or tab stamp names that host;
  • files whose route or tab stamp names it;
  • browser tabs whose pages name it;
  • chats stamped with it, along with that host's recency, delete marker and sleeping-agent records that name its SSH connection.

State that cannot be tied to either host is kept for the surviving copy: tabs with no PTY, files with no provenance, worktree-keyed buckets such as git status, and the raw-id module stores (sleep intent, huge-repo warning dismissals, ambiguous-owner warnings, hosted-review generations, structured launches). If the active surface was removed, selection is derived again. If it pointed at the purged host, it moves to the survivor. When no other host publishes the id, the purge does exactly what it did before. A raw id string still purges everything.

Mechanism:

  • A new branded HostWorktreeTarget type, with its constructor hostWorktreeTarget(row), sits next to HostScopedWorktreeKey in src/shared/worktree/host-qualified-identity.ts.
  • purgeWorktreeTerminalState and buildWorktreePurgeState now take readonly (string | HostWorktreeTarget)[]. The old untyped { id, hostId } form is gone, so every host-scoped caller has to build the brand.
  • buildWorktreePurgeState looks for surviving publishers using the listing's own host matching (worktreeMatchesHost). Because of that, an unstamped legacy row, or a paired runtime's SSH row, counts as the purged copy and not as a twin. For folders, an unstamped folder under a project group that two hosts publish counts as either host's.
  • Host-scoped targets that have a twin go through the new host-twin-worktree-purge.ts. It reuses the attribution from project removal (fix(projects): removing one host's copy of a project keeps its same-path twin's shells, tabs and edits #29954) (collectRemovedHostTwinState, removedHostCanonicalizer, twinSelectionPatch) rather than writing a second one.
  • The purge's tab, PTY, pane, page and file omission moved into worktree-purge-surface-patch.ts, so both paths share it. The full path's output is field-for-field the same.
  • Layout writes for the twin case go through the existing removeWorktreeLayout writer, which takes a new optional kept argument. This adds no new renderer layout write sites.

Caller audit:

  • fetched-worktree-merge.ts passes a host (hostWorktreeTarget). This is the authoritative-scan removal, where the real-world leak happened.
  • worktree-event-runtime.ts passes a host when the event names one, and a raw id otherwise.
  • folder-workspace-catalog.ts (reconcileFailedFolderWorkspaceUpdate) now passes the owner host. It used to pass a raw key even though it had just removed only that host's folder row.
  • purge-stale-runtime-host-state.ts keeps the full purge (buildFullWorktreePurgeState). It already drops survivor ids unless the restored-session partition proves the bare-id state belonged to the removed host.
  • Raw ids, unchanged: repo-removal.ts (exclusive ids only; twins go through fix(projects): removing one host's copy of a project keeps its same-path twin's shells, tabs and edits #29954's teardown), fetch-all-worktrees.ts (hydration-stale keys), and folder-workspace-mutations.ts (purges only once no folder row remains).

Twin suite: all eight "purge terminal state" cells now assert isolation. That covers local+ssh, local+runtime, folder local+ssh and folder group local+ssh, targeting either host, and their KNOWN_TWIN_LEAKS entries are deleted. Kill, sleep and select remain known leaks; they are the next slice.

Why

The shared buckets stay keyed by the raw id on purpose. Re-keying around 55 store fields to host-qualified keys (rejected in design decision D7) would change behaviour for twins and change the persisted session payloads. A lint baseline on raw-id maps (D6/D51) would start at about 108 entries and would not catch this bug at all: the purge passes ids through a Set, which such a lint cannot see.

Typing the destructive entry point with a branded target, and filtering the shared buckets by owning host, fixes the bug with no wire change and no on-disk change. When the purge cannot tell which host owns something, it keeps it: an unattributable entry can at worst be left stale, but it can never cost the surviving copy its data.

Reusing #29954's attribution keeps project removal and purge on one definition of "this host's state". Its planned shrink (tracker follow-up) will then cover both paths.

Ratchets:

  • The focus-read baseline moves one count from worktree-purge-state.ts to purged-structured-launch-retirement.ts, where the same structuredAgentSessionTargetForTab call now lives. Five caller counts drop, because the discovery no longer propagates through the moved void helper; this was pruned with --prune.
  • The renderer layout-writer count is unchanged.

Linked Issue

Stage 1 row 1.3 (first slice) of the SSH hardening design. No public issue.

Visual Proof

N/A. This is store-state cleanup with no UI change of its own. The visible effect is that the surviving copy keeps its tabs and edits.

Testing

  • src/renderer/src/store/host-twin-isolation.test.ts: the eight purge cells now assert isolation. They fail on main once their leak entries are removed.

  • src/renderer/src/store/host-twin-worktree-purge.test.ts (new) covers:

    • a host-scoped purge with a surviving twin (SSH and runtime);
    • a full purge when no twin survives, and when every publishing host is targeted;
    • a raw id still reaching both copies;
    • a tabless SSH sleeping record;
    • selection after the active terminal is purged, and an untouched legacy selection;
    • a paired runtime's purge attributed to its SSH copy, including recency under both identities;
    • the source state of a purged Markdown preview.
  • Existing tests updated: worktree-event-lineage-refresh.test.ts (new target shape), and the brand type tests in host-qualified-identity.test.ts. The golden bytes of composeWorktreeHostIdentity were already frozen there and are reused, not duplicated.

  • Local runs:

    • pnpm tc;
    • unit tests for src/renderer/src/store, src/renderer/src/lib, src/renderer/src/components/sidebar, src/renderer/src/hooks/ipc-events and src/shared/worktree (1565 files pass);
    • a local mirror of the full static-analysis job, which passes.
  • Live verify: none. Covered by unit tests only.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

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: this is the case being fixed. Paired runtime aliases are resolved with the listing's host matching.
  • Folder workspaces: covered, including unstamped folders under a group that two hosts publish.
  • Compatibility: no wire or persisted change. The store keys and the bytes of composeWorktreeHostIdentity are unchanged.
  • Cross-platform: pure renderer state.
  • Performance: the twin path runs only when a host-scoped purge has a surviving publisher.

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 →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a2bf187-1683-4b3e-bb0c-4ad3ad6c2f18
📥 Commits

Reviewing files that changed from the base of the PR and between a2f6464 and 312dd36.

📒 Files selected for processing: 2
  • src/renderer/src/store/host-twin-worktree-purge.test.ts
  • src/renderer/src/store/slices/tabs/worktree-layout-lifecycle.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/store/slices/tabs/worktree-layout-lifecycle.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📝 Walkthrough

The changes add host-qualified worktree purge targets and use them to distinguish a purge of one host’s worktree copy from a full purge by raw ID. They add pruning for selected surfaces in retained worktrees and extract helpers for launch retirement and surface-state cleanup. New tests cover host-twin state preservation and removal, selection updates, sleeping-session attribution, and preview-source handling.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 312dd

Purging one host’s worktree copy can discard terminal state still needed by a surviving copy. Fix the unified-only terminal case before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the change, rationale, testing, compatibility, and visual-proof requirements. However, the required Linked Issue is missing because it states that there is no pu… Add the required linked issue reference in the Linked Issue section, including a valid Fixes #<issue-number> or equivalent repository issue link.
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 20 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: host-scoped purges no longer remove tabs and edits belonging to a surviving twin.
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.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, compatibility, and visual-proof requirements. However, the required Linked Issue is missing because it states that there is no public issue instead of providing an actual issue reference.

Resolution

Add the required linked issue reference in the Linked Issue section, including a valid Fixes #&lt;issue-number&gt; or equivalent repository issue link.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch nwparker/host-worktree-target-purge
  • 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.

@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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41e2ca9f-f8d0-497c-975d-1440b507196d
📥 Commits

Reviewing files that changed from the base of the PR and between ee4fd06 and df665a2.

📒 Files selected for processing: 20
  • config/focus-setting-read-baseline.txt
  • src/renderer/src/hooks/ipc-events/worktree-event-lineage-refresh.test.ts
  • src/renderer/src/hooks/ipc-events/worktree-event-runtime.ts
  • src/renderer/src/store/folder-workspaces/folder-workspace-catalog.ts
  • src/renderer/src/store/host-twin-isolation.test.ts
  • src/renderer/src/store/host-twin-worktree-purge.test.ts
  • src/renderer/src/store/repos/repo-removal-host-twin-teardown.ts
  • src/renderer/src/store/slices/tabs/kept-worktree-surface-pruning.ts
  • src/renderer/src/store/slices/tabs/worktree-layout-lifecycle.ts
  • src/renderer/src/store/slices/worktree-purge-target.ts
  • src/renderer/src/store/slices/worktrees/listing/fetched-worktree-merge.ts
  • src/renderer/src/store/slices/worktrees/session/worktree-slice-lookups.ts
  • src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts
  • src/renderer/src/store/slices/worktrees/teardown/purge-stale-runtime-host-state.ts
  • src/renderer/src/store/slices/worktrees/teardown/purged-structured-launch-retirement.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-doomed-ids.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-surface-patch.ts
  • src/shared/worktree/host-qualified-identity.test.ts
  • src/shared/worktree/host-qualified-identity.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 +28 to +45
function pruneGroup(group: TabGroup, removedIds: ReadonlySet<string>): TabGroup {
if (!group.tabOrder.some((id) => removedIds.has(id))) {
return group
}
const tabOrder = group.tabOrder.filter((id) => !removedIds.has(id))
const recentTabIds = sanitizeRecentTabIds(group.recentTabIds, tabOrder)
// Why MRU first: closing the active tab lands on the previously active one, as closeUnifiedTab does.
const activeTabId =
group.activeTabId && removedIds.has(group.activeTabId)
? (recentTabIds.at(-1) ?? tabOrder[0] ?? null)
: group.activeTabId
return {
...group,
tabOrder,
activeTabId,
...(group.recentTabIds ? { recentTabIds } : {})
}
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C3 'tabOrder\.length\s*===\s*0|collapseEmptyGroup|removeEmptyGroup|closeEmptyGroup' --type=ts src/renderer/src/store src/renderer/src/components/tab-group

Repository: stablyai/orca

Length of output: 8427


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- changed file ---'
nl -ba src/renderer/src/store/slices/tabs/kept-worktree-surface-pruning.ts | sed -n '1,260p'
printf '%s\n' '--- group actions ---'
nl -ba src/renderer/src/store/slices/tabs/tabs-group-actions.ts | sed -n '1,190p'
printf '%s\n' '--- layout removal references ---'
rg -n -F --glob '*.ts' -e 'removeWorktreeLayout' -e 'layoutByWorktree' -e 'activeGroupIdByWorktree' src/renderer/src/store | head -200
printf '%s\n' '--- pruner callers ---'
rg -n -F --glob '*.ts' -e 'createKeptWorktreeSurfacePruners' -e 'KeptWorktreeSurfaceRemoval' src/renderer/src
printf '%s\n' '--- relevant diff ---'
git diff --no-ext-diff --unified=30 03cefcb84cbb99b287135f226ae961baf5c170f1 df665a2523b4d40ac3ff652863856c74950393fa -- src/renderer/src/store/slices/tabs/kept-worktree-surface-pruning.ts src/renderer/src/store/slices/tabs/tabs-group-actions.ts src/renderer/src/store | sed -n '1,900p'

Repository: stablyai/orca

Length of output: 42302


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- layout tree and collapse behavior ---'
nl -ba src/shared/workspace-layout/tab-group-layout-tree.ts | sed -n '1,280p'
printf '%s\n' '--- renderer layout consumers ---'
rg -n -F --glob '*.{ts,tsx}' -e 'layoutByWorktree' -e 'groupsByWorktree' -e 'groupId' src/renderer/src/components src/renderer/src/store | head -260
printf '%s\n' '--- empty-group and group-tab rendering checks ---'
rg -n -P --glob '*.{ts,tsx}' 'tabOrder\.length|group\.tabOrder|groups\.find|find\(\(.*group|activeGroupIdByWorktree|collapseGroupLayout' src/renderer/src/components src/renderer/src/store src/shared/workspace-layout | head -300
printf '%s\n' '--- layout writer/persistence ---'
rg -n -P --glob '*.{ts,tsx}' 'layoutByWorktree|workspace.?layout|write.*layout|persist.*layout|serialize.*layout' src/renderer/src src/shared | head -300

Repository: stablyai/orca

Length of output: 41712


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- terminal pane files ---'
rg --files src/renderer/src/components | rg -i 'terminal.*pane|pane.*layout|workspace.*layout|tab.*group'
printf '%s\n' '--- pane rendering references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'TerminalPane' -e 'groupId:' -e 'groupsByWorktree[worktreeId]' src/renderer/src/components/terminal-pane src/renderer/src/components 2>/dev/null | head -220
printf '%s\n' '--- reconciliation implementation ---'
rg -n -F --glob '*.ts' -e 'nextGroupsWithEmpty' -e 'tabs-reconciliation' -e 'groupsWithEmpty' src/renderer/src/store
nl -ba src/renderer/src/store/slices/tabs/tabs-reconciliation.ts 2>/dev/null | sed -n '1,300p'
printf '%s\n' '--- workspace binding owner ---'
nl -ba src/renderer/src/components/use-terminal-workspace-store-bindings.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 41780


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- purge and layout-patch callers ---'
rg -n -F --glob '*.ts' -e 'purgeWorktreeTerminalState' -e 'removeWorktreeLayout(' -e 'reconcileWorktreeTabModel(' src/renderer/src/store src/renderer/src/components | head -260
printf '%s\n' '--- purge implementation context ---'
rg -n -F --glob '*.ts' -e 'function purgeWorktreeTerminalState' -e 'purgeWorktreeTerminalState:' -e 'create.*Purge' src/renderer/src/store
printf '%s\n' '--- layout writer sequencing ---'
rg -n -P --glob '*.ts' 'write.*(Layout|layout)|persist.*(Layout|layout)|layoutByWorktree.*=' src/renderer/src/store src/renderer/src/runtime | head -220

Repository: stablyai/orca

Length of output: 15720


🏁 Script executed:

set -o pipefail
nl -ba src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts | sed -n '160,250p'
nl -ba src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts | sed -n '90,165p'
nl -ba src/renderer/src/store/slices/tabs/tabs-session-actions.ts | sed -n '1,100p'

Repository: stablyai/orca

Length of output: 12688


Collapse empty split groups after host-twin pruning.

pruneGroup can leave a non-root group with tabOrder: []. The host-twin purge updates groupsByWorktree, but it leaves the retained worktree's layout unchanged. This can leave a stale split-layout leaf for a group with no tabs.

Remove or collapse emptied non-root groups during host-twin pruning. Preserve the canonical empty root group used by zero-tab worktrees.

Comment on lines +146 to +218
const removed = collectRemovedHostTwinState(s, twinIds, hostId, twinHostIds)
const canonical = (worktreeId: string) =>
removedHostCanonicalizer(s, worktreeId, hostId, twinHostIds.get(worktreeId) ?? [])
const cancelledSessionIds = cancelStructuredLaunchesForWorktrees(
twinIds,
(worktreeId, launchHostId) => canonical(worktreeId)(launchHostId) === hostId
)
const terminalTabs: { id: string; ptyId: string | null }[] = []
for (const worktreeId of twinIds) {
const legacyTabs = (s.tabsByWorktree[worktreeId] ?? []).filter((tab) =>
removed.terminalTabIds.has(tab.id)
)
terminalTabs.push(...legacyTabs)
retirePurgedTabLaunches(
s,
worktreeId,
legacyTabs,
(s.unifiedTabsByWorktree[worktreeId] ?? []).filter((tab) => removed.otherTabIds.has(tab.id)),
cancelledSessionIds
)
}
// Why: a hydrated terminal can exist only as a unified tab, with no legacy row.
for (const tabId of removed.terminalTabIds) {
if (!terminalTabs.some((tab) => tab.id === tabId)) {
terminalTabs.push({ id: tabId, ptyId: null })
}
}
// Why: a preview keys its source's editor state, unless a surviving file still uses that source.
const survivingFiles = s.openFiles.filter((file) => !removed.fileIds.has(file.id))
const previewSourceIds = s.openFiles.flatMap((file) =>
removed.fileIds.has(file.id) &&
file.markdownPreviewSourceFileId &&
!survivingFiles.some(
(other) =>
other.id === file.markdownPreviewSourceFileId ||
other.markdownPreviewSourceFileId === file.markdownPreviewSourceFileId
)
? [file.markdownPreviewSourceFileId]
: []
)
const doomed = collectSurfacePurgeDoomedIds(s, {
tabs: terminalTabs,
browserWorkspaceIds: removed.browserTabIds,
fileIds: [...removed.fileIds, ...previewSourceIds]
})
const omitters = createWorktreePurgeOmitters(s, new Set(), doomed)
const tabPrefixedSleeping = {
sleepingAgentSessionsByPaneKey: omitters.omitByPaneKeyTabPrefix(
s.sleepingAgentSessionsByPaneKey
),
agentLaunchConfigByPaneKey: omitters.omitByPaneKeyTabPrefix(s.agentLaunchConfigByPaneKey)
}
// Why SSH only: a record whose tab is gone names its host just by connection; null is ambiguous.
const sshRecordPaneKeys = Object.entries(s.sleepingAgentSessionsByPaneKey ?? {}).flatMap(
([paneKey, record]) =>
twinIds.has(record.worktreeId) &&
record.connectionId &&
canonical(record.worktreeId)(toSshExecutionHostId(record.connectionId)) === hostId
? [paneKey]
: []
)
const layout = removeWorktreeLayout(s, {
worktreeIds: new Set(),
tabIds: doomed.doomedTabIds,
activeFileCleared: s.activeFileId != null && removed.fileIds.has(s.activeFileId),
kept: {
worktreeIds: twinIds,
terminalTabIds: removed.terminalTabIds,
fileIds: removed.fileIds,
browserTabIds: removed.browserTabIds,
unifiedTabIds: removed.otherTabIds
}
})

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -nP -C4 '\bmixedTabPtyIds\b' --type=ts src/renderer/src
sed -n '130,239p' src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts
sed -n '160,200p' src/renderer/src/store/repos/repo-removal-host-twin-teardown.ts

Repository: stablyai/orca

Length of output: 11090


🏁 Script executed:

rg -n -F --glob '*.ts' -e 'collectRemovedHostTwinState' -e 'buildHostTwinPurgeState' -e 'mixedTabPtyIds' -e 'ptyIdsByTabId' -e 'terminalLayoutsByTabId' -e 'suppressedPtyExitIds' -e 'pendingCodexPaneRestartIds' -e 'codexRestartNoticeByPtyId' src/renderer/src || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 45667


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- purge symbols in production source ---'
rg -n -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' \
  -e 'collectRemovedHostTwinState' -e 'buildHostTwinPurgeState' -e 'createWorktreePurgeOmitters' \
  -e 'buildWorktreePurgeSurfacePatch' -e 'collectSurfacePurgeDoomedIds' -e 'mergeFetchedWorktrees' \
  -e 'shutdownWorktreeTerminals' -e 'ptyIdsByTabId' \
  src/renderer/src/store src/renderer/src/runtime src/renderer/src/components/terminal-pane || test "$?" -eq 1
printf '%s\n' '--- host twin purge source ---'
nl -ba src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts | sed -n '1,380p'
printf '%s\n' '--- attribution source ---'
nl -ba src/renderer/src/store/repos/repo-removal-host-twin-attribution.ts | sed -n '175,240p'
printf '%s\n' '--- helper definitions ---'
rg -l -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' \
  -e 'function createWorktreePurgeOmitters' -e 'function collectSurfacePurgeDoomedIds' -e 'function buildWorktreePurgeSurfacePatch' \
  src/renderer/src | while read -r f; do
  echo "FILE $f"
  rg -n -F -e 'function createWorktreePurgeOmitters' -e 'function collectSurfacePurgeDoomedIds' -e 'function buildWorktreePurgeSurfacePatch' "$f"
done

Repository: stablyai/orca

Length of output: 37209


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- doomed ids ---'
nl -ba src/renderer/src/store/slices/worktrees/teardown/worktree-purge-doomed-ids.ts | sed -n '1,130p'
printf '%s\n' '--- omitters ---'
nl -ba src/renderer/src/store/slices/worktrees/teardown/worktree-purge-omitters.ts | sed -n '1,220p'
printf '%s\n' '--- surface patch ---'
nl -ba src/renderer/src/store/slices/worktrees/teardown/worktree-purge-surface-patch.ts | sed -n '1,180p'
printf '%s\n' '--- purge state ---'
nl -ba src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts | sed -n '1,190p'
printf '%s\n' '--- purge lifecycle references ---'
rg -n -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' \
  -e 'purgeWorktrees' -e 'buildWorktreePurgeState' -e 'removedWorktreeRendererTeardown' \
  -e 'shutdownWorktreeTerminals' -e 'mergeFetchedWorktrees' \
  src/renderer/src/store/slices/worktrees src/renderer/src/store/repos src/renderer/src/store/terminals

Repository: stablyai/orca

Length of output: 27843


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- layout removal ---'
rg -n -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' -e 'export function removeWorktreeLayout' -e 'function removeWorktreeLayout' src/renderer/src
nl -ba src/renderer/src/store/slices/tabs/worktree-layout-lifecycle.ts | sed -n '1,230p'
printf '%s\n' '--- fetched merge purge and kill paths ---'
nl -ba src/renderer/src/store/slices/worktrees/listing/fetched-worktree-merge.ts | sed -n '230,315p'
nl -ba src/renderer/src/store/repos/repo-removal-host-twin-teardown.ts | sed -n '100,205p'
printf '%s\n' '--- PTY release and exit-related cleanup ---'
nl -ba src/renderer/src/store/terminals/terminal-pty-release.ts | sed -n '1,125p'
nl -ba src/renderer/src/store/terminals/terminal-shutdown-guards.ts | sed -n '70,115p'
printf '%s\n' '--- reconnect consumers ---'
nl -ba src/renderer/src/store/terminals/workspace-terminal-reconnect.ts | sed -n '1,145p'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts | sed -n '70,120p'

Repository: stablyai/orca

Length of output: 35920


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- host purge tests and mixed-tab coverage ---'
rg -n -F --glob '*host-twin*' --glob '*.ts' -e 'mixedTabPtyIds' -e 'ptyIdsByTabId' -e 'terminalLayoutsByTabId' -e 'buildHostTwinPurgeState' src/renderer/src/store || test "$?" -eq 1
printf '%s\n' '--- direct layout/pty binding consumers ---'
rg -n -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' \
  -e 'ptyIdsByLeafId' -e 'terminalLayoutsByTabId[tab.id]' -e 'terminalLayoutsByTabId?.[tab.id]' \
  src/renderer/src/components/terminal-pane src/renderer/src/store/terminals | head -n 180
printf '%s\n' '--- orphan/reconciliation production paths ---'
rg -n -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' \
  -e 'orphan' -e 'reconcile' -e 'pty.kill' -e 'ptyIdsByTabId' \
  src/renderer/src/store/slices/terminal-orphan-helpers.ts \
  src/renderer/src/runtime/web-session-terminal-orphan-recovery-surface.ts \
  src/renderer/src/store/slices/worktrees/listing/fetched-worktree-merge.ts \
  src/renderer/src/store/terminals \
  src/renderer/src/components/terminal-pane | head -n 260

Repository: stablyai/orca

Length of output: 42634


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- orphan helper implementation ---'
nl -ba src/renderer/src/store/slices/terminal-orphan-helpers.ts | sed -n '1,220p'
printf '%s\n' '--- mixed-tab tests ---'
for f in \
  src/renderer/src/store/bulk-worktree-purge-terminal-maps-leak.test.ts \
  src/renderer/src/store/project-removal-host-twin-state.test.ts \
  src/renderer/src/store/host-twin-worktree-purge.test.ts; do
  if test -f "$f"; then
    echo "FILE $f"
    nl -ba "$f" | sed -n '1,260p'
  fi
done
printf '%s\n' '--- direct retained-layout consumers ---'
nl -ba src/renderer/src/components/terminal-pane/terminal-handle-links.ts | sed -n '90,145p'
nl -ba src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.ts | sed -n '1,150p'
nl -ba src/renderer/src/components/terminal-pane/terminal-pane-frame-reconciliation.ts | sed -n '1,130p'

Repository: stablyai/orca

Length of output: 33288


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- PTY binding mutation helpers ---'
nl -ba src/renderer/src/store/terminals/terminal-pty-bindings.ts | sed -n '1,225p'
nl -ba src/renderer/src/store/terminals/terminal-layout-state.ts | sed -n '1,180p'
printf '%s\n' '--- existing per-PTY filtering helpers ---'
rg -n -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' \
  -e 'ptyIdsByLeafId' -e 'omitByPtyId' -e 'filter((ptyId)' -e 'filter((id)' \
  src/renderer/src/store/slices src/renderer/src/store/terminals | head -n 240
printf '%s\n' '--- mixed/shared host-twin test references ---'
rg -n -i --glob '*.ts' --glob '*host*twin*' -e 'mixed' -e 'shared.*pty' -e 'pty.*shared' -e 'remotePty' src/renderer/src/store || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 41530


🏁 Script executed:

nl -ba src/renderer/src/store/slices/terminal-session-row-hydration.ts | sed -n '1,135p'
rg -n -F --glob '*.ts' --glob '!*.test.ts' --glob '!*.spec.ts' \
  -e 'releasedPtyIds' -e 'filterReleased' -e 'ptyIdsByLeafId' \
  src/renderer/src/store/slices/terminal-session-row-hydration.ts src/renderer/src/store/slices/worktrees/teardown

Repository: stablyai/orca

Length of output: 8257


Release mixed-tab PTYs during the host-scoped purge.

collectRemovedHostTwinState records the removed host's PTYs in removed.mixedTabPtyIds, but buildHostTwinPurgeState only builds doomed IDs from wholly removed tabs. The surviving tab therefore keeps those PTYs in ptyIdsByTabId and terminalLayoutsByTabId[tab].ptyIdsByLeafId; PTY-keyed cleanup also misses them. The orphan sweep treats the retained tab as live, and terminal-handle lookup can resolve the dead PTY. The host-scoped fetch path reaches this code without terminal teardown.

At host-twin-worktree-purge.ts:186-237, release removed.mixedTabPtyIds from the retained tab's PTY index, layout leaf bindings, tab-level reconnect hints, and PTY-keyed maps. Keep the tab and the surviving host's PTYs. Do not add the shared tab to doomedTabIds.

@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: 1ab3caf0-c524-4e17-ac39-13751489e462
📥 Commits

Reviewing files that changed from the base of the PR and between 468e1a1 and d134a5f.

📒 Files selected for processing: 2
  • src/renderer/src/store/host-twin-worktree-purge.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +194 to +196
for (const tab of s.tabsByWorktree[worktreeId] ?? []) {
if (!doomed.doomedTabIds.has(tab.id)) {
for (const ptyId of collectPtyIdsForTab(s, tab.id, tab.ptyId)) {

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 | 🟠 Major | 🏗️ Heavy lift

Preserve PTYs bound to surviving unified-only terminals.

If a surviving terminal exists only in unifiedTabsByWorktree and binds a removed tab’s PTY, this loop never inspects that terminal. The PTY remains in doomed.doomedPtyIds, so the purge removes PTY-keyed state that the surviving terminal still needs. Include surviving unified terminal IDs when checking PTY bindings, and cover this case in the mixed-host test.

@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: 69907613-0745-4076-87f0-2cdf8d645820
📥 Commits

Reviewing files that changed from the base of the PR and between d134a5f and a2f6464.

📒 Files selected for processing: 2
  • src/renderer/src/store/host-twin-worktree-purge.test.ts
  • src/renderer/src/store/slices/tabs/worktree-layout-lifecycle.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@nwparker
nwparker force-pushed the nwparker/host-worktree-target-purge branch from 312dd36 to 0b29251 Compare October 17, 2026 23:01
@nwparker
nwparker merged commit 299dcb8 into main Oct 17, 2026
78 of 81 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