Repository navigation
fix(workspace-cleanup): refuse removal when the owning host is not certain (STA-4343) - #14731
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughWorkspace cleanup now resolves host identity from execution-host and SSH connection data. Removal preflight records all scanned host associations and blocks removal when ownership is missing, ambiguous, mismatched, or absent from the refreshed scan. The change adds localized collision and unresolved-host errors. Regression tests cover colliding worktrees, missing host evidence, local cleanup, SSH cleanup, and refreshed host-qualified snapshots. Merge Risk: ⚪ Minimal · up to The PR adds a fail-closed ownership check that prevents unsafe workspace deletion and preserves existing valid cleanup behavior; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
🧹 Nitpick comments (1)
src/renderer/src/store/slices/workspace-cleanup-wrong-host-removal-guard.test.ts (1)
177-299: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winAdd a test for the route-mismatch branch of the guard.
These tests cover no-host-evidence and scan-ambiguity/stale-confirmation refusals. They do not cover the third fail-closed branch in
isWorkspaceCleanupRemovalHostCertain: a uniquely scanned host that matches the confirmed host, butrouteHostIdresolves to a different host.Add a scenario where
scannedHostIdscontains exactly one host matching the confirmed candidate, but the routing table resolvesremoveWorktreeto a different host. Assert the removal is refused and no directory is deleted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 49eaca26-71e3-4b69-8b75-a1634b50a0c8
📒 Files selected for processing (6)
src/renderer/src/i18n/locales/en.jsonsrc/renderer/src/store/slices/workspace-cleanup-removal-host-guard.tssrc/renderer/src/store/slices/workspace-cleanup-slice-test-harness.tssrc/renderer/src/store/slices/workspace-cleanup-wrong-host-removal-guard.test.tssrc/renderer/src/store/slices/workspace-cleanup.tssrc/shared/workspace-cleanup-host-identity.ts
Rendered proof (injected UI state — STA-4343)Supplemental full-toast captureThe supplemental capture makes the existing row-failed state and full toast text readable in one frame. Labeling this evidence accurately: this is an injected/rendered proof only, run against the branch at HEAD The backing filesystem proof is the automated test suite, not this UI run: No code changes, commits, or pushes made. |
Brennan's ruling: the same repo at the same path on two hosts is TWO workspaces. The confirmed row is therefore deletable, so #14731's blanket collision refusal is superseded by routing. Converted in the real-temp-dir rig (unchanged, still deletes for real): - confirming host B now DELETES host B and leaves ACTIVE host A intact. #14731 could only prove A survived; this proves B actually goes. - a mid-batch active-host change no longer redirects the second removal. - refusal survives only where the confirmed row cannot be attributed: no host evidence, or the refreshed scan no longer lists that host's row (now reported as "Workspace no longer exists", which is what it means). Also drops a stale toast.success expectation that rode along with the relocated timeout-recovery tests; main stopped toasting from that path.
…roven host Routing a colliding id depends on the HOST honouring `hostId`. Local main always does — it ships with this renderer, and it is the transport that carries the reported local-vs-SSH case. A paired remote server may be an older build that silently strips the field and routes by its own preference, which on a colliding id deletes the wrong workspace. #14731 refused EVERY collision. Replacing that with routing quietly widened the blast radius on the one transport that can still be an older build, against a field with no capability negotiation and clear in-repo precedent for exactly this hazard (WORKTREE_CREATE_IDEMPOTENCY_RUNTIME_CAPABILITY). Narrowing the refusal to remote-plus-collision keeps this no worse than main there while leaving every local and single-owner delete routed as intended. This is deliberately the conservative half of the fix. The proper one is a `worktree.rm` host-qualification capability so a NEW remote host routes the collision instead of sharing the old hosts' refusal; that is a wire change and is marked TODO at the guard. Extracts dispatch-worktree-removal.ts to stay under the 300-line cap.
* fix(sidebar): clear the delete state when a removal is refused Callers mark rows deleting up front for immediate sidebar feedback, but a refusal in beginHostQualifiedRemoval returns before removeWorktree's try/catch — the only other place that clears the flag. The failure toast auto-dismisses after 10s, so the workspace was left on a 'Deleting…' spinner indefinitely with no explanation still on screen. Also removes workspace-cleanup-removal-host-guard.ts: #14731 refused a colliding cleanup removal, #15013 replaced refusing with routing to the confirmed host, and nothing imports the module any more — not even its own tests. * test(sidebar): pin the two states that actually reach the removal refusal The existing case used an empty store, which proved the clear but not that a user can land there. Cover a stale folder-workspace id and a hostless row under an ambiguous legacy runtime — both resolve to no route from populated state. --------- Co-authored-by: QA <qa@local>
…rtain (STA-4343) (stablyai#14731) * fix(workspace-cleanup): refuse removal when the owning host is not certain (STA-4343) * fix(workspace-cleanup): distinguish host collisions * fix(workspace-cleanup): recheck host at removal boundary (cherry picked from commit 5b7f442)
…yai#15187) * fix(sidebar): clear the delete state when a removal is refused Callers mark rows deleting up front for immediate sidebar feedback, but a refusal in beginHostQualifiedRemoval returns before removeWorktree's try/catch — the only other place that clears the flag. The failure toast auto-dismisses after 10s, so the workspace was left on a 'Deleting…' spinner indefinitely with no explanation still on screen. Also removes workspace-cleanup-removal-host-guard.ts: stablyai#14731 refused a colliding cleanup removal, stablyai#15013 replaced refusing with routing to the confirmed host, and nothing imports the module any more — not even its own tests. * test(sidebar): pin the two states that actually reach the removal refusal The existing case used an empty store, which proved the clear but not that a user can land there. Cover a stale folder-workspace id and a hostless row under an ambiguous legacy runtime — both resolve to no route from populated state. --------- Co-authored-by: QA <qa@local>
…yai#15187) * fix(sidebar): clear the delete state when a removal is refused Callers mark rows deleting up front for immediate sidebar feedback, but a refusal in beginHostQualifiedRemoval returns before removeWorktree's try/catch — the only other place that clears the flag. The failure toast auto-dismisses after 10s, so the workspace was left on a 'Deleting…' spinner indefinitely with no explanation still on screen. Also removes workspace-cleanup-removal-host-guard.ts: stablyai#14731 refused a colliding cleanup removal, stablyai#15013 replaced refusing with routing to the confirmed host, and nothing imports the module any more — not even its own tests. * test(sidebar): pin the two states that actually reach the removal refusal The existing case used an empty store, which proved the clear but not that a user can land there. Cover a stale folder-workspace id and a hostless row under an ambiguous legacy runtime — both resolve to no route from populated state. --------- Co-authored-by: QA <qa@local>
…rtain (STA-4343) (stablyai#14731) * fix(workspace-cleanup): refuse removal when the owning host is not certain (STA-4343) * fix(workspace-cleanup): distinguish host collisions * fix(workspace-cleanup): recheck host at removal boundary
…yai#15187) * fix(sidebar): clear the delete state when a removal is refused Callers mark rows deleting up front for immediate sidebar feedback, but a refusal in beginHostQualifiedRemoval returns before removeWorktree's try/catch — the only other place that clears the flag. The failure toast auto-dismisses after 10s, so the workspace was left on a 'Deleting…' spinner indefinitely with no explanation still on screen. Also removes workspace-cleanup-removal-host-guard.ts: stablyai#14731 refused a colliding cleanup removal, stablyai#15013 replaced refusing with routing to the confirmed host, and nothing imports the module any more — not even its own tests. * test(sidebar): pin the two states that actually reach the removal refusal The existing case used an empty store, which proved the clear but not that a user can land there. Cover a stale folder-workspace id and a hostless row under an ambiguous legacy runtime — both resolve to no route from populated state. --------- Co-authored-by: QA <qa@local>


ELI5
Two computers can have a workspace with the exact same name. The cleanup dialog only remembered the name, so ticking the row for the remote machine could delete the folder with the same name on your laptop — with your uncommitted work in it. This PR does not teach cleanup how to reach the right machine. It teaches it to stop: right before it deletes anything, it checks that the workspace it is about to delete really belongs to the machine whose row you confirmed, and if it can't prove that, it refuses and tells you to refresh.
What Changed
P0 data-loss fix. This is the MINIMAL, fail-closed version, intended for the 1.4.184 cherry-pick. The complete fix is #14606 (~4000 lines, threads host-qualified identity through all seven cleanup stages), which is too large to pick into tomorrow's cut with confidence.
Workspace cleanup composes a candidate's
worktreeIdasrepoId::path, with no host component, so two execution hosts (local, SSH, or a paired runtime) can publish the same id. Selection, confirmation, preflight and removal all kept only that id, andresolveWorktreeOperationRouteResultconsults the ACTIVE workspace's host first — so confirming host B's row issuedworktrees.remove/worktree.rmagainst host A and deleted host A's worktree along with its uncommitted work.Three files, one guard, evaluated in
preflightWorkspaceCleanupCandidatesimmediately before the row reachesremoveWorktree(the only path toworktrees.remove/worktree.rm):src/shared/workspace-cleanup-host-identity.ts(new, 28 lines) —resolveWorkspaceCleanupRemovalHostId(). Returns the row's owning host from real host evidence (executionHostId, elseconnectionId), ornullfor a row that carries none. It deliberately does not fall back tolocal; a wrong guess is the bug.This is the same path, name and body as the module in fix(workspace-cleanup): delete on the confirmed host, never the active one (STA-4343) #14606, so the follow-up merges over it cleanly.
src/renderer/src/store/slices/workspace-cleanup-removal-host-guard.ts(new, 43 lines) —isWorkspaceCleanupRemovalHostCertain(). Certain only when all of:removeWorktreewould actually route to is that same host.A
nullroute is not a refusal here —removeWorktreealready fails an unroutable removal closed withWORKTREE_REMOVAL_AMBIGUOUS_ERRORbefore touching any transport, so duplicating that refusal would only change the message.src/renderer/src/store/slices/workspace-cleanup.ts(+48/-3) — records every owner the refreshed scan reported beforecandidatesByWorktreeIdcollapses a colliding id to one row, then fails colliding owners withError: this workspace exists on multiple hosts at the same path; stale or unknown ownership keeps thehostUnresolvedrefresh message. The refusal rides the existing per-row failure channel, so it renders in the dialog's row-failure UI with no UI change.en.json— adds the exact collision message while retaininghostUnresolvedfor stale or unknown ownership.What this deliberately does NOT do — all of it belongs to #14606:
repoId::pathexists on two hosts becomes un-cleanable through the dialog and shows the refusal message. Annoying, never destructive — and it is not a new lockout of anything that previously worked correctly: what previously "worked" was deleting the other host's data.worktree.rmhost qualification on the main/runtime side, no CLI change, no persistence or wire-format change.Net: +519 / −4 across 6 files: 122 production additions and 397 test/harness additions. One pre-existing test fixture gained
executionHostId: 'local'(2 lines) — see Testing.Why
This is a P0 data-loss path: the operation that ran was a real
git worktree remove/ directory delete on a machine the user never selected. Failing closed on an ambiguous or changed owner is the correct trade for a destructive path — a wrong guess destroys uncommitted work, while a refusal costs one refresh.Is a call-site guard actually sufficient, or does it need identity threaded through the earlier stages to be meaningful? It is sufficient for the safety property, and it does not depend on the earlier threading — but the reason is worth stating precisely, because the obvious reading says otherwise.
Under a collision the confirmed row's identity genuinely is untrustworthy: the dialog builds
new Map(rows.map((row) => [row.worktreeId, row.candidate])), so two colliding rows share a React key and the map keeps only the last one. Ticking the row you saw can hand the other host's candidate to confirmation. So the guard cannot trust "the host the row was confirmed against" to be what the user meant.It does not have to. The guard refuses on the collision itself: the refreshed preflight scan is what returns both owners for the id, and two owners is an unconditional refusal regardless of which candidate object reached confirmation. The confirmed-host comparison then handles the non-colliding cases (stale row, changed owner, wrong route). Every path where the confirmed identity could be wrong is a path where the scan shows ≥2 owners and nothing is deleted. That is why the split holds — and it is also exactly why the minimal version cannot route a colliding row correctly, which is the part left to #14606.
Cross-cutting concerns. Cleanup candidates are always built locally by
src/main/ipc/workspace-cleanup-candidate.ts, which host-qualifies every row viagetWorktreeExecutionHostId(); the persisted snapshot validator (workspace-cleanup-scan-snapshot.ts) also requiresexecutionHostIdto be a string, so snapshot-hydrated rows carry it too. Thenullbranch is therefore reachable only by a row that predates that contract, where refusing is the intended outcome. Remote wire: no wire change —WorkspaceCleanupCandidate.executionHostIdalready exists and is already populated, and the guard runs entirely in the renderer. Folder workspaces: they go through the same candidate builder and carry a host like any other row. Cross-platform: no path parsing or normalization added; the guard compares opaque host ids.Linked Issue
STA-4343 — https://linear.app/stably/issue/STA-4343 (P0 data loss; surface introduced by #13413)
Fixes STA-4343
Visual Proof
N/A— no visual change. The dialog renders the same rows with the same styling and the refusal rides the existing per-row failure channel, so the only user-visible difference is that a colliding row now reports "Error: this workspace exists on multiple hosts at the same path" instead of silently deleting another machine's workspace. That difference only appears when two hosts expose the samerepoId::path, which cannot be staged as a screenshot pair; the destructive outcome is proved on the filesystem by the tests below instead.Testing
The gate is filesystem state, not arguments.
src/renderer/src/store/slices/workspace-cleanup-wrong-host-removal-guard.test.tscreates two REAL temp directories (host A and host B) sharing onerepoId::pathidentity, each holding a marker file standing in for uncommitted work. The removal boundary (window.api.worktrees.remove) is the only fake, and it actuallyrmSync-deletes whichever host it is routed to.RED at
origin/main(5464525), with only the test file added:The routed host in that message —
hostId=localafter confirmingssh:ssh-1— is the bug itself.Coverage (all asserted as filesystem outcomes at the destructive boundary):
local+ ACTIVE, host Bssh:ssh-1confirmed → both markers survive,worktrees.removenever called, row fails with the exact collision message, host A's tabs/state untouchedlocal, single-hostssh:ssh-1, and host-qualified snapshot cleanup each still delete for real through the same rig, routed to the right host, with no failures. These three pass both before and after the change — as they must.Non-vacuity: reverting only the production wiring in
workspace-cleanup.ts(keeping the entire test file) turns exactly the 3 refusal tests RED again, while the 3 soundness controls stay green.One pre-existing fixture changed:
workspace-cleanup-slice-test-harness.ts'smakeCandidate()gainedexecutionHostId: 'local'. It was modelling a host-less candidate, whichsrc/main/ipc/workspace-cleanup-candidate.tshas never emitted since #13413 added the field; without it, seven existing tests were asserting deletion of a row that production would now (correctly) refuse. No assertions were weakened.Commands run locally (macOS), verbatim:
npx vitest run --config config/vitest.config.ts src/renderer/src/store/slices/workspace-cleanup-wrong-host-removal-guard.test.ts→ 6 passednpx vitest run --config config/vitest.config.ts src/renderer/src/store src/shared→ 640 files, 7419 passed (3 files / 19 tests skipped)npx vitest run --config config/vitest.config.ts src/renderer/src/components/workspace-cleanup src/main/ipc/workspace-cleanup src/main/workspace-cleanup→ 32 files, 241 passedpnpm typecheck→ cleannpx oxlint --config .oxlintrc.json src config tests --deny-warnings→ clean (exit 0; verified the gate is live by injecting ananyand seeing it flagged)npx oxlint --config config/oxlint-code-quality-native-plugins.json src config tests mobile --deny-warnings→ cleannpx oxlint --type-aware --config config/oxlint-code-quality-type-aware.json src config tests --deny-warnings→ cleannode config/scripts/check-changed-code-quality.mjs→ 0 new findings across 5 changed filesnode config/scripts/check-react-doctor-changed.mjs→ 0 issues across 5 changed filesnode config/scripts/check-max-lines-ratchet.mjs→ OK, no new bypasses (nomax-linesdisable added; the guard lives in a new module precisely so the grandfathered slice does not grow its bypass)node config/scripts/check-reliability-gates.mjs, localization catalog / extraction / coverage → cleanoxfmt(this repo does not use prettier); the 7--checkfindings repo-wide are pre-existing.md/.cjsfiles untouched herePlatforms: automated coverage runs on macOS; the guard compares opaque host ids with no path handling, and both the local IPC and SSH host identities are exercised. No Electron UI validation was needed — there is no UI change, and the refusal is proved deterministically at the destructive boundary.
Review
WorkspaceCleanupCandidate.executionHostIdalready existed and was already populated. An old cached snapshot with no host evidence fails closed rather than guessing.resolveWorktreeOperationRouteper row in the removal preflight (a path that already resolves the same route insideremoveWorktree, and which is bounded by the confirmed batch), plus aSetof host ids per scanned row.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm testpass locally (pnpm buildnot run locally; CI will cover)Author