Skip to content

fix(sidebar): clear the delete state when a removal is refused - #15187

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/clear-delete-state-on-refusal
Aug 18, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/clear-delete-state-on-refusal

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7 $\color{#cf222e}{\Huge{\mathbf{−}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​36

Defensive hardening plus a dead-code removal. Read the reachability note before landing — I could not reproduce this in the running app.

What it changes

Callers mark rows deleting up front so the sidebar shows progress immediately (worktree-delete-execution.ts). The two refusals in beginHostQualifiedRemoval return before removeWorktree's try/catch — the only other place that clears the flag — so on those paths nothing clears it and the row keeps a "Deleting…" spinner after the 10s failure toast has gone. This adds the clear on both.

Reachability — honest limits

I originally observed the stuck row on pre-#15013 code and fixed it there. #15013 then re-keyed delete state by host identity and its catch clears on every throwing path, which appears to have already resolved the observed case.

Against post-#15013 code I tried four times to reproduce it and could not:

attempt result
unqualified row + unresolvable owner, deleted from the sidebar deleted successfully, no refusal
two-host collision, deleted from the sidebar routed correctly and deleted
mismatched confirmed host, via the exact markWorktreesDeleting + removeWorktree sequence the executor uses reached the backend, threw, and the catch cleared it
unit probing with a confirmed host the route always resolves, so the early return never fires

So the guarded returns are reached on the unqualified path — a caller naming no host with no resolvable owner — which I can exercise in a unit test but could not stage through the UI.

This is therefore correct, cheap, tested hardening, not a fix for a demonstrable user-facing bug today. No screenshots, because staging one would misrepresent that.

Dead code

Deletes workspace-cleanup-removal-host-guard.ts. #14731 added it to refuse 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, which pass unchanged without it. That part stands on its own merits.

Verification

typecheck 0 · changed-code quality 0 findings · 524 files / 4,901 tests green across store slices and sidebar. The new test is mutation-tested: reverting the clearWorktreeDeleteState calls turns it red.

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

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: db121406-68e9-47b9-9638-0404b279427d

📥 Commits

Reviewing files that changed from the base of the PR and between 1cd0145 and 172f6ec.

📒 Files selected for processing (1)
  • src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts

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


📝 Walkthrough

Walkthrough

Removed the workspace cleanup removal-host guard. Updated beginHostQualifiedRemoval to clear worktree delete state when route resolution fails or the resolved host differs from the confirmed host. Added regression tests for unresolved routes, ambiguous runtime environments, and missing folder workspace owners.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the code changes and testing, but omits several required template sections, including Linked Issue, Visual Proof, and checklist items. Complete the required template sections, add the linked issue, state Visual Proof as N/A with a reason, and complete the testing and checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the primary change: clearing sidebar delete state when removal is refused.
✨ Finishing Touches
📝 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

🧹 Nitpick comments (2)
src/renderer/src/store/slices/worktrees/teardown/host-qualified-worktree-removal.ts (1)

81-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep the new comments concise in both files.

Both comments include detailed operational context. Keep only the invariant and the test purpose.

As per coding guidelines, comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.

  • src/renderer/src/store/slices/worktrees/teardown/host-qualified-worktree-removal.ts#L81-L85: reduce the refusal rationale to one concise statement.
  • src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts#L6-L14: reduce the test rationale to a concise statement about refusal cleanup.

Source: Coding guidelines

src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts (1)

32-43: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the host-mismatch refusal branch.

This test covers only an unresolved route with no confirmed host. It does not exercise the branch at Line 95, where a resolved route differs from requiredExecutionHostId. Add a case that asserts refusal and clearWorktreeDeleteState(WORKTREE_ID).


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c432692-a417-47c3-a1ef-941e1ca94989

📥 Commits

Reviewing files that changed from the base of the PR and between 8cd3383 and 1cd0145.

📒 Files selected for processing (3)
  • src/renderer/src/store/slices/workspace-cleanup-removal-host-guard.ts
  • src/renderer/src/store/slices/worktrees/teardown/host-qualified-removal-refusal.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/host-qualified-worktree-removal.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/store/slices/workspace-cleanup-removal-host-guard.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 6 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review loop status

CI is green. The earlier tests node 26 4/16 / verify failure was
native-chat/transcript-watch-liveness.test.ts > "replaces a same-size prefix rewrite with an unchanged trailing boundary" — unrelated to this diff (native-chat watcher vs. worktree
removal). It passes locally on this head and on origin/main; a re-run of the failed jobs
came back clean, so it was a flake.

The reachability question, answered

This PR clears the delete state on two refusal early-returns. They are not equally real.

leg verdict
host-mismatch (WORKTREE_REMOVAL_HOST_CHANGED_ERROR) unreachable
unqualified no-route (WORKTREE_REMOVAL_AMBIGUOUS_ERROR) reachable in principle, unproven in practice

After #15013, resolveWorktreeOperationRouteForHost returns a route for any parseable
confirmed host, so the host-mismatch refusal cannot fire. The data-loss case this PR was
originally written for does not exist on current main.

The no-route leg is structurally reachable: Worktree.hostId is optional
(shared/worktree/types.ts:67), so toWorktreeRemovalTarget maps a missing host to null
and an unqualified caller can refuse. Both returns precede removeWorktree's try/catch —
the only other place that clears the flag — so the row keeps a "Deleting…" spinner after
the failure toast auto-dismisses.

It is not reproducible through the UI. Four staged attempts failed: unqualified row with
unresolvable owner, two-host collision, mismatched confirmed host driven through the
executor's exact markWorktreesDeleting + removeWorktree sequence, and unit probing. So
part 1 is insurance against a representable state, not a fix for an observed one.

Dead code removal

Sound and independent of the above. workspace-cleanup-removal-host-guard.ts refused a
colliding cleanup removal; #15013 replaced refusing with routing to the confirmed host.
Nothing imports it, including its own tests, which pass unchanged without it.

Not done, deliberately

No Electron screenshots. The refusal state is unstageable for the same reason the bug is
unreproducible, so screenshots would require manufacturing a repro rather than capturing
one. Recording that honestly instead.

Open decision

Land as cheap insurance on the unqualified leg with the description corrected to drop the
unreachable justification, or keep only the dead-code removal and close part 1. No code
changes were made during this review.

…usal

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

Copy link
Copy Markdown
Contributor Author

Correction: the refusal IS reachable — my earlier comment was wrong

My previous comment said the no-route refusal was "reachable in principle, unproven in
practice," and I offered closing part 1 as a reasonable outcome. That was based on failing
to reproduce it — but I was re-running the pre-#15013 repro, whose mechanism #15013
removed. I never tested the paths that still reach it.

Tracing resolveWorktreeOperationRouteResult found two, both now pinned by tests.

1. Stale folder workspace

worktree-operation-route.ts:182 — folder workspaces fail closed by design:

if (!findFolderWorkspaceOwner(state, folderWorkspaceId)) {
  // Why: deleted/stale folder ids keep failing closed like unknown worktrees.
  return { kind: 'missing' }
}

A row whose folder record is gone refuses instead of routing.

2. Hostless row + ambiguous legacy runtime

worktree-operation-route.ts:157 returns missing when activeRuntimeEnvironmentId is set
and the saved runtime environments are not a single matching entry — the pre-owner-projection
case the comment above it describes.

Reaching it needs a row with no hostId, which has real producers. Folder-workspace meta is
created at orca-runtime.ts:2244 with instanceId/displayName/lastActivityAt and
never hostId, and mergeRuntimeFolderWorkspace then omits the field entirely
(runtime-folder-workspace.ts:33). Every other worktree construction site falls back to
getRepoExecutionHostId(repo); the folder-workspace one does not.

Why it matters

Both returns precede removeWorktree's try/catch — the only other place that clears the
flag — so the row keeps its "Deleting…" spinner while the 10s failure toast disappears. The
user is left with a workspace that looks like it is mid-delete forever.

Tests

172f6ec7e2 adds both cases. The pre-existing test used an empty store, which proved the
clear but not that a user could land there; these route through populated state. All three
were mutation-verified — removing the two clearWorktreeDeleteState calls turns all three
red.

Still true from before

The host-mismatch refusal remains unreachable for canonical host ids, so this PR is
justified by the no-route leg only. The dead-code removal of
workspace-cleanup-removal-host-guard.ts is independent and unaffected.

Follow-up, not in this PR

The missing getRepoExecutionHostId(repo) fallback in mergeRuntimeFolderWorkspace looks
like a genuine inconsistency rather than an intentional omission. Worth its own change.

@brennanb2025
brennanb2025 merged commit f71ef7e into main Aug 18, 2026
46 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…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>
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…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>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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>
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