Skip to content

fix(cleanup): route workspace cleanup by resolved execution host, not repo connectionId - #18358

Merged
nwparker merged 1 commit into
mainfrom
worktree-agent-ab7af2124675c9c26
Sep 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
worktree-agent-ab7af2124675c9c26

Conversation

@nwparker

@nwparker nwparker commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​332 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​312
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​167 $\color{#cf222e}{\Huge{\mathbf{−}}}$​47 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​120

Step 4 of the execution-host routing sweep, after #18296 (host-keyed dispatch), #18307 (RuntimeGitTarget) and #18325 (RuntimeFileTarget).

The defect

The workspace-cleanup-* family threaded provider: IGitProvider | null — derived from a raw repo.connectionId read — from listCleanupGitWorktrees through the scan into activity resolution and git evidence. That null spelled 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 as executionHostId: 'ssh:<target>' — with connectionId absent — listed worktrees with listRepoWorktrees, lstated the remote paths, and ran getStatus on this machine. That is #11163 exactly.

The three sites had to move together. The provider! assertions at workspace-cleanup-git-evidence.ts:46 and :110 were sound only because they re-read the same repo.connectionId that workspace-cleanup-worktree-listing.ts:31 used to decide whether provider was 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 | null is 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 in src/main/ipc/workspace-cleanup*, src/main/workspace-cleanup* and src/shared/workspace-cleanup* are compiler-checked, so no text ratchet is needed here — the type change alone caught every site, and pnpm tc proved it (the only errors were the 11 call sites in workspace-cleanup-activity.test.ts).

What resolves where

No new resolver. Routing goes through the layer that already exists:

  • repo-level (listCleanupGitWorktrees, the listing that produces the worktrees): getRepoExecutionHostId(repo) → resolveGitRouteForHost from feat(providers): dispatch git and filesystem providers by execution host #18296.
  • workspace-level (readWorkspaceCleanupGitEvidence): getWorktreeExecutionHostId(worktree, repo), which reads worktree.hostId first. mergeWorktree carries meta.hostId onto 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-mismatch answer and the scan refuses. Reading one host's checkout while candidate.executionHostId (already getWorktreeExecutionHostId) labels the row with the other's is the cross-host leak; the row still appears, git-status-error, tier protected.

"What may this client dial", verified not assumed

Every migrated site needs the dial question, as in both prior migrations. Checked explicitly:

  • listing, git status, rev-list --count, sharedLinkPaths, and the local activity stat are all things this process executes — a runtime: host arriving is a routing error, because its calls are forwarded and normalized to that server's own local, and the SSH target on its repo row is that server's nested one, addressable only as (environmentId, targetId).
  • runtime: therefore throws ExecutionHostNotDispatchableError, matching workspace-space-repo-scan (the closest sibling, already migrated) and repos:listForExecutionHost.
  • The one site that genuinely wants "which host holds the files" is 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):

  1. An executionHostId: 'ssh:<t>'-only row now lists worktrees through that host instead of locally.
  2. …now reads git status / rev-list through that host instead of locally.
  3. …no longer lstats the remote workspace path on this client for activity.
  4. …no longer passes this machine's sharedLinkPaths into a remote status read.
  5. …when disconnected, now synthesizes ssh-disconnected rows instead of scanning locally.
  6. A runtime: row is refused instead of scanning locally (no nested target) or dialing this client's same-named SSH target (nested target present).
  7. A contradictory row (executionHostId: 'local' and connectionId: 'x') now routes local — getRepoExecutionHostId prefers the explicit host, and the row declares itself local.
  8. A workspace whose own host disagrees with the listing host is refused rather than read on the wrong one.
  9. handleRepoWorktreeListError's broad-scan error suppression now keys on "host is not local" rather than connectionId, so executionHostId-only and runtime: 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', no executionHostId) and every genuinely local row route exactly as before — getRepoExecutionHostId maps connectionId: 'x' to ssh:x and absence to local. All 73 pre-existing tests in the family pass unchanged.

provider!: both assertions are deleted. The SSH branch now goes through requireWorkspaceCleanupGitProvider, which throws SSH_GIT_PROVIDER_UNAVAILABLE_MESSAGE for an unreachable host — never falls through to the local branch. That is docs/reference/ssh-execution-boundary.md rule 1: a missing SSH provider is not permission to answer locally.

Failed-first proof

Patching resolveWorkspaceCleanupRepoGitRoute back to repo.connectionId ? 'ssh:'+connectionId : 'local', resolveWorkspaceCleanupWorktreeGitRoute back to a passthrough, and isRemoteWorkspaceCleanupHost back to Boolean(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, and runtime: 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 (including connectionId and executionHostId), the workspaceCleanup:* IPC args, and the WorkspaceCleanup RPC UI-state schema in src/main/runtime/rpc/methods/workspace-cleanup-ui-schema.ts are 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:hasKillableLocalProcesses dials getSshPtyProvider(args.connectionId) from an IPC argument fed by candidate.connectionId (repo.connectionId ?? null). For a runtime: row that would enumerate PTYs on this client's same-named target — a wrong host. It is not live: no renderer code calls hasKillableLocalProcesses today (only the preload bridge and test harnesses reference it). Fixing it means changing published content, so it belongs in its own change under docs/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-equivalence 800-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-lines proven 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).

… 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.
@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Workspace 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 9372e

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 incom… 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 #12345. Add Visual Proof or write exactly N/A with a brief reason if there is no U…
Docstring Coverage ⚠️ Warning Docstring coverage is 15.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: workspace cleanup now routes by resolved execution host instead of repo connectionId. It is concise and specific.
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 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 #12345. Add Visual Proof or write exactly N/A with a brief reason if there is no UI or interaction change. Complete AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. Keep the existing testing details in the Testing section and document the reported pre-existing full-tree test failures.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 806e23a4-919c-49c4-aeb7-23f5799938e6

📥 Commits

Reviewing files that changed from the base of the PR and between b52614c and 9372e2b.

📒 Files selected for processing (9)
  • src/main/ipc/workspace-cleanup-activity.test.ts
  • src/main/ipc/workspace-cleanup-activity.ts
  • src/main/ipc/workspace-cleanup-candidate.ts
  • src/main/ipc/workspace-cleanup-execution-host-routing.test.ts
  • src/main/ipc/workspace-cleanup-git-evidence.ts
  • src/main/ipc/workspace-cleanup-git-route.ts
  • src/main/ipc/workspace-cleanup-scan.ts
  • src/main/ipc/workspace-cleanup-worktree-listing.ts
  • src/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') {

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 | 🟠 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.

@pullfrog pullfrog 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.

✅ 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 — new local / ssh route union plus a host-mismatch worktree variant; runtime: throws ExecutionHostNotDispatchableError rather than collapsing to local.
  • Worktree listing — listCleanupGitWorktrees resolves the route up front; handleRepoWorktreeListError keys broad-scan suppression on isRemoteWorkspaceCleanupHost instead of repo.connectionId.
  • Git evidence — getStatus / rev-list --count route through the resolved worktree route and refuse on a worktree-vs-listing host disagreement, replacing the deleted provider! 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).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit fe5efb2 into main Sep 3, 2026
29 checks passed
nwparker added a commit that referenced this pull request Sep 3, 2026
…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.
nwparker added a commit that referenced this pull request Sep 3, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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