Repository navigation
fix(cleanup): route workspace cleanup by resolved execution host, not repo connectionId - #18358
Conversation
… repo connectionId The workspace-cleanup scan threaded `provider: IGitProvider | null`, derived from a raw `repo.connectionId` read, through listing, activity and git evidence. That `null` spelled "this is local", "the host is remote but unreachable" and "the host is a runtime environment" with one value, so a row naming its owner only as `executionHostId: 'ssh:<target>'` listed worktrees, statted paths and ran `git status` for a *remote* checkout on this client (#11163). The three sites had to move together: the `provider!` assertions in workspace-cleanup-git-evidence.ts were sound only because they re-read the same field that workspace-cleanup-worktree-listing.ts used to decide whether `provider` was populated. Migrating one alone turns them into crashes. Routing now goes through the shared resolution layer -- `getRepoExecutionHostId` for the repo that produces the listing, `getWorktreeExecutionHostId` for the workspace's own host -- into `resolveGitRouteForHost` from #18296's host-keyed dispatch. The ambiguous carrier is removed rather than supplemented, so every reader became a compile error; unlike #18325's family, workspace-cleanup carries no `@ts-nocheck`, so that guarantee is real here. `runtime:<env>` is not a route variant. Its Git runs on that environment's own server and the SSH target on its repo row is that server's nested one, addressable only as (environmentId, targetId); handing it to this client's SSH table dials a same-named target in the wrong namespace. It throws, matching workspace-space-repo-scan and repos:listForExecutionHost. No wire change: `WorkspaceCleanupCandidate` (including `connectionId` and `executionHostId`) and the workspaceCleanup RPC UI-state schema are untouched.
📝 WalkthroughWalkthroughWorkspace cleanup now uses explicit local and SSH Git routes. Route resolution handles disconnected SSH providers, runtime hosts, and worktree host mismatches. Scanning passes routes through worktree listing, activity checks, candidate construction, and Git evidence reads. Remote routes avoid local filesystem probes and use SSH provider operations. New tests cover local, remote, disconnected, runtime, and mismatched-host behavior. Merge Risk: 🟡 Moderate · up to Workspace cleanup can incorrectly treat a host-mismatched remote worktree as recently active when a coincident local path exists, hiding it from broad cleanup instead of reporting it as protected. Resolve the worktree host before filesystem activity checks before merging. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed technical context, rationale, behavior changes, scope, and verification results. However, it does not follow the required template structure and omits or leaves incomplete several required sections, including ELI5, What Changed, Why, Linked Issue with an issue reference, Visual Proof or an explicit N/A explanation, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist items. Resolution Reformat the description using the repository template. Add concise content for ELI5, What Changed, and Why. Provide a valid Linked Issue entry such as Fixes
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 806e23a4-919c-49c4-aeb7-23f5799938e6
📒 Files selected for processing (9)
src/main/ipc/workspace-cleanup-activity.test.tssrc/main/ipc/workspace-cleanup-activity.tssrc/main/ipc/workspace-cleanup-candidate.tssrc/main/ipc/workspace-cleanup-execution-host-routing.test.tssrc/main/ipc/workspace-cleanup-git-evidence.tssrc/main/ipc/workspace-cleanup-git-route.tssrc/main/ipc/workspace-cleanup-scan.tssrc/main/ipc/workspace-cleanup-worktree-listing.tssrc/main/ipc/workspace-cleanup.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| if (repo.connectionId) { | ||
| // Why: the probes below are local filesystem reads. Statting a remote path here answers | ||
| // about whatever this machine happens to have at that path, or nothing at all. | ||
| if (route.kind !== 'local') { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Resolve the worktree host before local activity probes.
Line 86 checks only the repository listing route. If a locally listed row resolves to an SSH host, this path still reads its path with local filesystem APIs before Git evidence detects the host mismatch. A coincident local path can mark the remote row as recent and omit it from a broad scan instead of reporting a protected git-status-error candidate.
Pass a worktree-resolved route into this function, or skip filesystem probes unless the worktree execution host matches the local route.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
workspace-cleanup-* swap their provider: IGitProvider | null carrier (a raw repo.connectionId read) for a non-nullable discriminated route resolved from getRepoExecutionHostId / getWorktreeExecutionHostId, so executionHostId-only and runtime: rows route correctly instead of silently running remote work on this client.
workspace-cleanup-git-route.ts— newlocal/sshroute union plus ahost-mismatchworktree variant;runtime:throwsExecutionHostNotDispatchableErrorrather than collapsing to local.- Worktree listing —
listCleanupGitWorktreesresolves the route up front;handleRepoWorktreeListErrorkeys broad-scan suppression onisRemoteWorkspaceCleanupHostinstead ofrepo.connectionId. - Git evidence —
getStatus/rev-list --countroute through the resolved worktree route and refuse on a worktree-vs-listing host disagreement, replacing the deletedprovider!assertions with a fail-closed unavailable-host throw. - Activity — non-local routes return persisted activity only, so remote paths are never
lstated on this client. - Tests — a 313-line routing suite registers two SSH targets plus
runtime:(with/without a nested target), with a documented failed-first proof.
I traced resolveGitRouteForHost / readWorktreeMetaForHost / getRepoExecutionHostId semantics, confirmed every changed symbol's callers stay within the family, and checked that leaving candidate.connectionId as raw repo.connectionId is safe — the destructive path prefers executionHostId via resolveWorkspaceCleanupRemovalHostId. Confirmed the new routing test passes (10/10).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…host `removeManagedWorktree` resolved its host once — for the metadata prune (`cleanupHostId ?? getRepoExecutionHostId(repo)`) — and then read raw `repo.connectionId` for every step that touches the filesystem: the `git worktree list` deciding whether the path is registered, the provider handed to the unregistered-removal branch, the registered-remote-vs-local fork, and the PTY/history teardown. One function, two spellings. For a row naming its owner only as `executionHostId: 'ssh:<target>'` — the exact class #18296 names — the list ran on the client against a remote path, `removeRuntimeUnregisteredWorktree` was entered with `provider: null`, and the metadata was pruned under `ssh:<target>` while a same-named *local* directory was the one considered for deletion (#11163). #18358 made this reachable: it migrated the cleanup scan, so `executionHostId`-only rows now surface as removable candidates, but removal did not move with it. Routing is now one answer for the whole removal, taken from the host the prune already used, through #18296's host-keyed dispatch. The ambiguous `provider: SshGitProvider | null` carrier is deleted from the callees rather than supplemented, so every remaining reader is a compile error in the typed modules that do the destructive work (`runtime-unregistered-worktree-removal`, `runtime-registered-remote-worktree-removal`, `runtime-worktree-filesystem`). The orchestrator itself carries `@ts-nocheck` from its mechanical split, so that guarantee does not reach it — tests cover it instead. Every change is in the refusing direction; nothing became more aggressive: - an `ssh:` host with no registered provider throws instead of deleting a client-side path (`requireSshGitProvider` already threw for rows that spelled the same host as `connectionId`); - `runtime:<env>` throws rather than dialling a same-named target in this client's namespace, matching `workspace-cleanup-git-route` and `runtime-git-command-target`; - the folder-workspace teardown resolves its connection instead of reading the raw field, so a `runtime:` row stops dialling the wrong namespace. No wire or persistence change: `removeWorktreeMetadataAndHistory` already took the resolved host, and the removal RPC result shape is untouched.
…host (#18529) `removeManagedWorktree` resolved its host once — for the metadata prune (`cleanupHostId ?? getRepoExecutionHostId(repo)`) — and then read raw `repo.connectionId` for every step that touches the filesystem: the `git worktree list` deciding whether the path is registered, the provider handed to the unregistered-removal branch, the registered-remote-vs-local fork, and the PTY/history teardown. One function, two spellings. For a row naming its owner only as `executionHostId: 'ssh:<target>'` — the exact class #18296 names — the list ran on the client against a remote path, `removeRuntimeUnregisteredWorktree` was entered with `provider: null`, and the metadata was pruned under `ssh:<target>` while a same-named *local* directory was the one considered for deletion (#11163). #18358 made this reachable: it migrated the cleanup scan, so `executionHostId`-only rows now surface as removable candidates, but removal did not move with it. Routing is now one answer for the whole removal, taken from the host the prune already used, through #18296's host-keyed dispatch. The ambiguous `provider: SshGitProvider | null` carrier is deleted from the callees rather than supplemented, so every remaining reader is a compile error in the typed modules that do the destructive work (`runtime-unregistered-worktree-removal`, `runtime-registered-remote-worktree-removal`, `runtime-worktree-filesystem`). The orchestrator itself carries `@ts-nocheck` from its mechanical split, so that guarantee does not reach it — tests cover it instead. Every change is in the refusing direction; nothing became more aggressive: - an `ssh:` host with no registered provider throws instead of deleting a client-side path (`requireSshGitProvider` already threw for rows that spelled the same host as `connectionId`); - `runtime:<env>` throws rather than dialling a same-named target in this client's namespace, matching `workspace-cleanup-git-route` and `runtime-git-command-target`; - the folder-workspace teardown resolves its connection instead of reading the raw field, so a `runtime:` row stops dialling the wrong namespace. No wire or persistence change: `removeWorktreeMetadataAndHistory` already took the resolved host, and the removal RPC result shape is untouched.
… repo connectionId (stablyai#18358) The workspace-cleanup scan threaded `provider: IGitProvider | null`, derived from a raw `repo.connectionId` read, through listing, activity and git evidence. That `null` spelled "this is local", "the host is remote but unreachable" and "the host is a runtime environment" with one value, so a row naming its owner only as `executionHostId: 'ssh:<target>'` listed worktrees, statted paths and ran `git status` for a *remote* checkout on this client (stablyai#11163). The three sites had to move together: the `provider!` assertions in workspace-cleanup-git-evidence.ts were sound only because they re-read the same field that workspace-cleanup-worktree-listing.ts used to decide whether `provider` was populated. Migrating one alone turns them into crashes. Routing now goes through the shared resolution layer -- `getRepoExecutionHostId` for the repo that produces the listing, `getWorktreeExecutionHostId` for the workspace's own host -- into `resolveGitRouteForHost` from stablyai#18296's host-keyed dispatch. The ambiguous carrier is removed rather than supplemented, so every reader became a compile error; unlike stablyai#18325's family, workspace-cleanup carries no `@ts-nocheck`, so that guarantee is real here. `runtime:<env>` is not a route variant. Its Git runs on that environment's own server and the SSH target on its repo row is that server's nested one, addressable only as (environmentId, targetId); handing it to this client's SSH table dials a same-named target in the wrong namespace. It throws, matching workspace-space-repo-scan and repos:listForExecutionHost. No wire change: `WorkspaceCleanupCandidate` (including `connectionId` and `executionHostId`) and the workspaceCleanup RPC UI-state schema are untouched.
…host (stablyai#18529) `removeManagedWorktree` resolved its host once — for the metadata prune (`cleanupHostId ?? getRepoExecutionHostId(repo)`) — and then read raw `repo.connectionId` for every step that touches the filesystem: the `git worktree list` deciding whether the path is registered, the provider handed to the unregistered-removal branch, the registered-remote-vs-local fork, and the PTY/history teardown. One function, two spellings. For a row naming its owner only as `executionHostId: 'ssh:<target>'` — the exact class stablyai#18296 names — the list ran on the client against a remote path, `removeRuntimeUnregisteredWorktree` was entered with `provider: null`, and the metadata was pruned under `ssh:<target>` while a same-named *local* directory was the one considered for deletion (stablyai#11163). stablyai#18358 made this reachable: it migrated the cleanup scan, so `executionHostId`-only rows now surface as removable candidates, but removal did not move with it. Routing is now one answer for the whole removal, taken from the host the prune already used, through stablyai#18296's host-keyed dispatch. The ambiguous `provider: SshGitProvider | null` carrier is deleted from the callees rather than supplemented, so every remaining reader is a compile error in the typed modules that do the destructive work (`runtime-unregistered-worktree-removal`, `runtime-registered-remote-worktree-removal`, `runtime-worktree-filesystem`). The orchestrator itself carries `@ts-nocheck` from its mechanical split, so that guarantee does not reach it — tests cover it instead. Every change is in the refusing direction; nothing became more aggressive: - an `ssh:` host with no registered provider throws instead of deleting a client-side path (`requireSshGitProvider` already threw for rows that spelled the same host as `connectionId`); - `runtime:<env>` throws rather than dialling a same-named target in this client's namespace, matching `workspace-cleanup-git-route` and `runtime-git-command-target`; - the folder-workspace teardown resolves its connection instead of reading the raw field, so a `runtime:` row stops dialling the wrong namespace. No wire or persistence change: `removeWorktreeMetadataAndHistory` already took the resolved host, and the removal RPC result shape is untouched.

Step 4 of the execution-host routing sweep, after #18296 (host-keyed dispatch), #18307 (
RuntimeGitTarget) and #18325 (RuntimeFileTarget).The defect
The
workspace-cleanup-*family threadedprovider: IGitProvider | null— derived from a rawrepo.connectionIdread — fromlistCleanupGitWorktreesthrough the scan into activity resolution and git evidence. Thatnullspelled three different things with one value: "this is local", "the host is remote but unreachable", and "the host is a runtime environment". So a repo row naming its owner only asexecutionHostId: 'ssh:<target>'— withconnectionIdabsent — listed worktrees withlistRepoWorktrees,lstated the remote paths, and rangetStatuson this machine. That is #11163 exactly.The three sites had to move together. The
provider!assertions atworkspace-cleanup-git-evidence.ts:46and:110were sound only because they re-read the samerepo.connectionIdthatworkspace-cleanup-worktree-listing.ts:31used to decide whetherproviderwas populated. Migrating one alone converts them from a wrong answer into a crash.The technique
Same as #18307: the ambiguous carrier is removed, not supplemented.
provider: IGitProvider | nullis gone from the internal call chain, replaced by a non-nullable discriminated route. Every reader became a compile error rather than silently inheriting a changed meaning.#18325 could not get that guarantee because its family carries
@ts-nocheck;workspace-cleanup-*does not. All 36 non-test files insrc/main/ipc/workspace-cleanup*,src/main/workspace-cleanup*andsrc/shared/workspace-cleanup*are compiler-checked, so no text ratchet is needed here — the type change alone caught every site, andpnpm tcproved it (the only errors were the 11 call sites inworkspace-cleanup-activity.test.ts).What resolves where
No new resolver. Routing goes through the layer that already exists:
listCleanupGitWorktrees, the listing that produces the worktrees):getRepoExecutionHostId(repo)→resolveGitRouteForHostfrom feat(providers): dispatch git and filesystem providers by execution host #18296.readWorkspaceCleanupGitEvidence):getWorktreeExecutionHostId(worktree, repo), which readsworktree.hostIdfirst.mergeWorktreecarriesmeta.hostIdonto the worktree, so this is live data, not a formality.When the two disagree — legacy unqualified metadata on a repo id whose row has since moved hosts — that is its own
host-mismatchanswer and the scan refuses. Reading one host's checkout whilecandidate.executionHostId(alreadygetWorktreeExecutionHostId) labels the row with the other's is the cross-host leak; the row still appears,git-status-error, tierprotected."What may this client dial", verified not assumed
Every migrated site needs the dial question, as in both prior migrations. Checked explicitly:
rev-list --count,sharedLinkPaths, and the local activity stat are all things this process executes — aruntime:host arriving is a routing error, because its calls are forwarded and normalized to that server's ownlocal, and the SSH target on its repo row is that server's nested one, addressable only as(environmentId, targetId).runtime:therefore throwsExecutionHostNotDispatchableError, matchingworkspace-space-repo-scan(the closest sibling, already migrated) andrepos:listForExecutionHost.WorkspaceCleanupCandidate.connectionId(repo.connectionId ?? null), which is published content and is left untouched — see out of scope below.Behavior changes vs no-ops
Fixed (behavior changes):
executionHostId: 'ssh:<t>'-only row now lists worktrees through that host instead of locally.git status/rev-listthrough that host instead of locally.lstats the remote workspace path on this client for activity.sharedLinkPathsinto a remote status read.ssh-disconnectedrows instead of scanning locally.runtime:row is refused instead of scanning locally (no nested target) or dialing this client's same-named SSH target (nested target present).executionHostId: 'local'andconnectionId: 'x') now routes local —getRepoExecutionHostIdprefers the explicit host, and the row declares itself local.handleRepoWorktreeListError's broad-scan error suppression now keys on "host is not local" rather thanconnectionId, soexecutionHostId-only andruntime:rows are omitted rather than bannered — the rule that already applied to every other remote repo.Intended no-ops: every row spelled the legacy way (
connectionId: 'x', noexecutionHostId) and every genuinely local row route exactly as before —getRepoExecutionHostIdmapsconnectionId: 'x'tossh:xand absence tolocal. All 73 pre-existing tests in the family pass unchanged.provider!: both assertions are deleted. The SSH branch now goes throughrequireWorkspaceCleanupGitProvider, which throwsSSH_GIT_PROVIDER_UNAVAILABLE_MESSAGEfor an unreachable host — never falls through to the local branch. That isdocs/reference/ssh-execution-boundary.mdrule 1: a missing SSH provider is not permission to answer locally.Failed-first proof
Patching
resolveWorkspaceCleanupRepoGitRouteback torepo.connectionId ? 'ssh:'+connectionId : 'local',resolveWorkspaceCleanupWorktreeGitRouteback to a passthrough, andisRemoteWorkspaceCleanupHostback toBoolean(repo.connectionId):9 of 10 new tests fail. The one that passes — "still routes a genuinely local repo to this machine" — is the deliberate no-op control proving the migration did not push local work onto a remote host. (#18307 got 6/8, #18325 got 7/9.)
Coverage per the brief: every case registers two distinct SSH hosts (
alpha,beta) simultaneously, andruntime:is covered both with and without a nested SSH target — including the case where the nested target's name (alpha) is also registered on this client, which is what proves refusal rather than a wrong-host dial.No wire change
WorkspaceCleanupCandidate(includingconnectionIdandexecutionHostId), theworkspaceCleanup:*IPC args, and theWorkspaceCleanupRPC UI-state schema insrc/main/runtime/rpc/methods/workspace-cleanup-ui-schema.tsare all untouched. The change is confined to how main picks a provider; nothing a paired client and host exchange moved.Out of scope, reported not fixed
workspaceCleanup:hasKillableLocalProcessesdialsgetSshPtyProvider(args.connectionId)from an IPC argument fed bycandidate.connectionId(repo.connectionId ?? null). For aruntime:row that would enumerate PTYs on this client's same-named target — a wrong host. It is not live: no renderer code callshasKillableLocalProcessestoday (only the preload bridge and test harnesses reference it). Fixing it means changing published content, so it belongs in its own change underdocs/reference/remote-wire-compatibility.md.Verification
pnpm tc— clean.pnpm test src— whole tree, run twice. 5–6 failures each run in largely disjoint sets (browser-route-webrtc-egress.electron,terminal-output-frame-chunks-equivalence800-iteration fuzz timeout,ssh-remote-commands,AgentMapTimeRangeField,remote-runtime-shared-control-connection,structured-tui-transcript-catchup). Confirmed pre-existing: with this branch stashed, the same file set still fails on the base commit. None import anything in this change.pnpm test src/main/ipc/workspace-cleanup— 7 files, 83 tests, all pass.pnpm run check:code-quality:changed— 0 new findings across 9 files (oxlint, type-aware, React Doctor).pnpm run check:max-lines-ratchet— OK, no new bypasses.max-linesproven to fire first with a 320-line positive control before clearing the changed files.pnpm run test:e2e:ssh-docker— 24 passed, exit 0 (18.0m).