Repository navigation
Conversation
…tion (stablyai#9197) Deleting a worktree in a WSL-runtime project failed with `selector_not_found` and left it half-deleted. Destructive removal runs `killAllProcessesForWorktree`, whose runtime sweep calls `stopTerminalsForWorktree(worktreeId)` → `resolveWorktreeSelector(worktreeId)`. That resolves the selector before touching any PTY. Passed a raw composite id (no `id:`/`path:` prefix), it falls to the exact-string else-branch (`worktree.id === selector`). On WSL the removal preflight matches tolerantly (folding the `\wsl.localhost` ↔ `\wsl$` UNC aliases + distro casing, so the delete begins), but the exact id-match then misses and throws `selector_not_found`. The teardown fail-closes on every error except `runtime_unavailable`, so that throw aborted the whole delete. A slow WSL `git worktree list` degrading to an empty list reproduces the same asymmetry. The runtime sweep only stops renderer-graph terminals; "no worktree resolved" just means there are none to stop, which must never fail-close a delete. Treat `selector_not_found` as benign there, exactly like `runtime_unavailable`. The independent provider (cwd-tolerant) and registry sweeps plus the physical-stop gate remain the proof that any PTY that truly exists was stopped, so this does not weaken teardown. The invariant holds on native/SSH too, so those paths are untouched. Regression test drives the runtime sweep to reject with `selector_not_found` under `requirePhysicalStop` and asserts the delete still completes while the provider sweep tears down a live PTY. Fixes stablyai#9197
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated worktree teardown error handling to treat 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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: Pro
Run ID: 261fe937-7db1-4fa5-93bd-bd2ccabb8054
📒 Files selected for processing (2)
src/main/runtime/worktree-teardown.test.tssrc/main/runtime/worktree-teardown.ts
| const stopTerminalsForWorktree = vi.fn().mockRejectedValue(new Error('selector_not_found')) | ||
| const runtime = { | ||
| stopTerminalsForWorktree | ||
| } as unknown as Parameters<typeof killAllProcessesForWorktree>[1]['runtime'] | ||
| const localProvider = createProviderStub(async () => [ | ||
| { id: `${worktreeId}@@live-1`, cwd: '/wsl/wt', title: 'shell' } | ||
| ]) | ||
| listRegisteredPtysMock.mockReturnValue([]) | ||
|
|
||
| const result = await killAllProcessesForWorktree(worktreeId, { | ||
| runtime, | ||
| localProvider, | ||
| requirePhysicalStop: true | ||
| }) | ||
|
|
||
| expect(result.runtimeStopped).toBe(0) | ||
| expect(result.providerStopped).toBe(1) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the implementation and nearby tests relevant to killAllProcessesForWorktree.
echo "== file list =="
git ls-files 'src/main/runtime/*worktree*'
echo
echo "== outline of implementation and test file =="
ast-grep outline src/main/runtime/worktree-teardown.ts --view expanded || true
echo "---"
ast-grep outline src/main/runtime/worktree-teardown.test.ts --view expanded || true
echo
echo "== relevant implementation slice =="
nl -ba src/main/runtime/worktree-teardown.ts | sed -n '1,260p'
echo
echo "== relevant test slice =="
nl -ba src/main/runtime/worktree-teardown.test.ts | sed -n '520,660p'Repository: stablyai/orca
Length of output: 1299
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Search for existing assertions on stopTerminalsForWorktree to judge duplication/coverage.
rg -n "stopTerminalsForWorktree|killAllProcessesForWorktree|selector_not_found|runtimeStopped|providerStopped" src/main/runtime/worktree-teardown.test.ts src/main/runtime/worktree-teardown.tsRepository: stablyai/orca
Length of output: 9581
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== implementation around runtime call =="
sed -n '75,130p' src/main/runtime/worktree-teardown.ts
echo
echo "== tests around runtime call and benign-error cases =="
sed -n '300,380p' src/main/runtime/worktree-teardown.test.ts
echo
echo "== tests around selector_not_found case =="
sed -n '548,616p' src/main/runtime/worktree-teardown.test.tsRepository: stablyai/orca
Length of output: 8123
Assert the runtime call in the selector_not_found case. The current result checks still pass if killAllProcessesForWorktree skips runtime.stopTerminalsForWorktree entirely here. Add an assertion that stopTerminalsForWorktree was called with worktreeId and the expected options so this test covers the benign-error branch.
|
Did a deep review of this fix (logic + regression tests + native/SSH impact). It holds up well — the core reasoning is sound:
One change I pushed ( Full worktree-teardown suite (23 tests) + typecheck are green. No production-code changes needed. Residual risk is low and pre-existing: if a PTY were ever spawned under a different UNC-alias id form than the deletion target, all three sweeps (including the old runtime sweep) would miss it equally — this fix neither introduces nor worsens that. LGTM. 🚢 |
|
Closing as superseded — What happenedThe production change in this PR is the runtime-sweep predicate in The two changes are semantically identical — same two error messages, same Verified, not assumedI grafted this PR's own WSL reproduction tests (the Against this PR's base commit ( So the repro is valid and Why not just merge it anywayRebasing would be a net regression risk rather than a no-op. Note on the root-cause analysisThe write-up in this PR and in #9197 is careful and correct, and worth preserving for anyone who hits this again: The underlying id-normalization asymmetry is not fixed by either patch — both only stop it from aborting the delete. Worth a separate issue if it resurfaces elsewhere. SalvageableOne test here covers a combination Thanks @OrcaWin — the diagnosis was right and independently arrived at the same fix that shipped; it just lost a race by about half a day. |
Problem — Fixes #9197
Deleting a worktree in a WSL-runtime project fails with
Error invoking remote method 'worktrees:remove': Error: selector_not_foundand leaves the worktree half-deleted. Triggers when the project lives at
\wsl.localhost\Ubuntu\...with worktrees under\wsl.localhost\Ubuntu\root\orca\workspaces.Root cause (code-verified)
Destructive removal runs
stopPtysForDestructiveWorktreeRemoval→killAllProcessesForWorktree(worktreeId)→ the runtime sweepruntime.stopTerminalsForWorktree(worktreeId)→resolveWorktreeSelector(worktreeId), which resolves the selector beforetouching any PTY.
killAllProcessesForWorktreepasses the raw composite id (repoId::path, noid:/path:prefix), soresolveWorktreeSelectorfalls to the exact-stringelse-branch (
worktree.id === selector,orca-runtime.ts).the
\wsl.localhost↔\wsl$UNC aliases + distro casing), so the removalpreflight matches and the delete begins — then the exact id-match misses
and
resolveWorktreeSelectorthrowsselector_not_found.runtime_unavailable(
worktree-teardown.ts), so that throw propagates and aborts the whole delete.A slow WSL
git worktree listexceedingRESOLVED_WORKTREE_REPO_TIMEOUT_MS(degrades to an empty list) reproduces the same asymmetry. Distinct from
#9045,which fails later at the PTY-kill gate.
Fix
The runtime sweep only stops renderer-graph terminals. If the runtime can't
resolve the worktree at all, there are simply no such terminals to stop — that
must never fail-close a destructive delete. So
selector_not_foundis treated asbenign there, exactly like
runtime_unavailable(matching existing precedent thatalready swallows
selector_not_foundelsewhere inorca-runtime.ts).Safety is preserved: the independent provider sweep (which also matches PTYs by
cwd-inside-worktree, tolerant of the UNC aliasing) and registry sweep, plus the
requirePhysicalStopgate, remain the proof that any PTY that truly exists wasphysically stopped. The invariant ("nothing to stop must never abort a delete")
holds on native/SSH too, so those paths are untouched — a generic runtime-sweep
error still fails closed.
Reproduction & verification
A live slow-WSL Electron host is impractical to drive deterministically, so — as the
issue's own repro note allows — this uses a focused unit reproduction that forces
the exact failure mode: the runtime sweep rejects with
selector_not_foundunderrequirePhysicalStop, using a\wsl.localhostcomposite id.Error: selector_not_found— the destructiveteardown aborts (reproduces [Bug]: Cannot delete worktree in WSL environment (selector_not_found) #9197).
runtimeStopped: 0, and the provider sweepstill tears down the live PTY (
providerStopped: 1).worktree-teardown.test.tssuite: 22/22 pass.oxlintclean;tsc -p config/tsconfig.node.jsonclean.Trade-offs / user-visible changes
None beyond the fix: WSL worktree deletion now completes instead of aborting with
selector_not_found. No behavior change for native or SSH removal. A live WSLElectron end-to-end pass is still worth a maintainer's confirmation before merge.