Skip to content

fix(worktrees): resolve id: worktree selectors by path equivalence (#16243) - #16494

Merged
OrcaWin merged 6 commits into
stablyai:mainfrom
LesleyMurfin:ai/16243-id-selector-normalization
Aug 27, 2026
Merged

OrcaWin merged 6 commits into
stablyai:mainfrom
LesleyMurfin:ai/16243-id-selector-normalization

Conversation

@LesleyMurfin

@LesleyMurfin LesleyMurfin commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Partially addresses #16243 — deliberately no closing keyword; see Linked Issue.

ELI5

Deleting a workspace from the sidebar did nothing, while deleting the same workspace from the CLI
worked. The UI can only ask for a workspace by its id, and the runtime matched that id letter for
letter — so if the id spelled the folder path even slightly differently from what git worktree list
reports (a trailing slash, a doubled slash, a Mac-composed accent), the runtime said "no such
workspace". The UI read that as "this row is stale junk", quietly forgot it locally, reported success,
and the row came back on the next refresh. A path: selector never had this problem, because it has
always compared paths through a normalizer. This PR makes an id: selector compare its path the same
way path: already does — and nothing more.

What Changed

  • src/shared/worktree/id.ts: adds worktreeIdComparisonKey(worktreeId) — the canonical comparison
    form of an id: repo id exact, path folded through the existing
    normalizeRuntimePathForComparison, folder-workspace instance suffix kept as part of the path.
    Returns null for malformed ids so callers keep exact matching for them.
  • src/main/runtime/orca-runtime.ts: the id: branch of resolveWorktreeSelector tries the exact
    match first and consults the comparison key only when nothing matched exactly.
  • src/main/runtime/repo-worktree-row-resolution.ts: resolveScopedWorktreeIdRow — the lookup a
    host-qualified removal takes — does the same, and accepts an equivalent row only when there is
    exactly one.
  • src/main/runtime/orca-runtime.ts: the pre-existing private runtimeWorktreeIdsEqual now derives
    from the same key, so the runtime has one normalizer instead of a parallel one. Its ~25 PTY- and
    session-identity callers are unchanged.

No renderer, CLI, or owner-routing changes. Six files, +473/-10, in six commits: the parity tests
(committed red), the production fix, an oxfmt/oxlint fixup on the new tests, then two review-driven
test commits — Windows spellings and malformed-id exactness, then the ID_SPELLINGS Windows row, the
fleet selector_ambiguous refusal, UNC/WSL key cases and the folder-workspace slash pin. The sixth
answers review feedback on this PR: it trims the test header to the one-line, why-not-how form
AGENTS.md asks for and adds short why-first JSDoc to worktreeIdComparisonKey and
resolveWorktreeSelector, so the two comparison entry points explain themselves at the call site.

Why

The mechanism

The renderer cannot address a workspace by path. toRuntimeWorktreeSelector
(src/renderer/src/runtime/runtime-worktree-selector.ts) always emits id:<repoId>::<path>, sent at
dispatch-worktree-removal.ts. The runtime resolved id: by exact string equality, while the path:
branch a few lines below has always compared through normalizeRuntimePathForComparison. Any
path-spelling divergence between the stored id and the scan therefore yielded selector_not_found
for the UI and a clean removal for the CLI. The renderer's removal path reads selector_not_found as
a stale local mirror, calls forgetLocal, and returns ok: true — no toast, and the row returns on
the next catalog refresh.

Regression origin

b82a8791f5 — perf(runtime): resolve an explicit worktree id without scanning every repo (#14399),
2026-08-14, first tag v1.4.186 — made id: the only selector kind not matched across the fleet,
resolving it by exact equality with no fallback. 64de8dd637 — (STA-4343) (#15013), 2026-08-17 —
then routed removal through that scoped resolver, turning a scoped miss into a hard
selector_not_found.

Live before/after

A/B against one variable: the same CLI, built from this branch, drove two runtimes on separate
ports with separate --user-data-dirs and their own throwaway repo and worktree — the installed
released 1.4.188 binary, and an orcad runtime built from this branch
(node config/scripts/build-orcad.mjs + tsc -p config/tsconfig.cli.json). Only the runtime version
differs between the two columns.

Selector 1.4.188 (before) This branch (after)
show id:<repo>::<path> ok: true ok: true
show id:<repo>::<path>/ selector_not_found ok: true, resolving to the canonical id
show path:<path>/ ok: true ok: true
show id:<foreign-repo>::<path> selector_not_found (correct) selector_not_found (still refuses)
rm id:<repo>::<path>/ selector_not_found, and the worktree was still there afterwards — a follow-up show of the exact id returned ok: true removed: true, and a follow-up show of the exact id returns selector_not_found, so it really went
rm path:<path>/ removed: true removed: true
rm id:<repo>::<path> removed: true removed: true
rm id:<foreign-repo>::<path> selector_not_found selector_not_found

The two columns differ in exactly the two trailing-slash id: rows. worktree show missed on the
same input worktree rm did, so this is the shared selector resolver, not something specific to
removal.

Dot-segment spellings (id:<repo>::<path>/., id:<repo>::/srv/projects/./workspaces/…) were not part of this
A/B. They were refused on 1.4.188 when first probed and they are still refused here, by both id:
and path: — see dot segments below. This PR does not fix them and does not claim to.

The field report that started this — a Windows client 1.4.188 paired to a Linux headless
orca serve, where the sidebar delete silently no-oped and the CLI delete worked — matches the
before column. The after artifact is the Node orcad runtime bundle: it executes the same
src/main/runtime code path a desktop client's runtime does, but it is not a packaged or signed
client build.

What stays fail-closed

  • Repo id compares exactly. Matching across repo ids would delete a workspace the caller never
    confirmed — the STA-4343 boundary.
  • Host qualification is untouched. A removal qualified to a host that does not own the repo id
    still refuses; the scoped resolver's owners.length !== 1 guard is unchanged.
  • Folder workspaces stay distinct. The ::workspace:<uuid> instance suffix stays part of the
    compared path, so sibling sessions in one directory never merge. Scope note: the parity this
    delivers is for plain worktree ids. In a folder-workspace id, a trailing slash placed before
    the instance suffix (<repo>::/a/b/::workspace:<uuid>) does not fold, because
    trimRuntimePathTrailingSlash only trims at end-of-string — that spelling keeps exact-match-only
    behaviour. It fails closed rather than matching the wrong workspace, and widening it is the same
    out-of-scope normalizer change as dot segments.
  • Ambiguity refuses. If two scanned rows spell one path, the scoped lookup returns null rather
    than guessing, and the fleet path rejects selector_ambiguous. Pinned by refuses a folded id when
    two same-repo rows spell one directory
    in worktree-rm-id-selector-path-spelling.test.ts — three
    reported rows, two of them spelling one directory (/srv/projects/workspaces/plugin-host and
    /srv/projects//workspaces/plugin-host), and a trailing-slash id matching neither exactly.
    This is a deliberate remaining asymmetry with path:, which dedupes equivalent rows on one host and
    resolves: id: keeps refusing, because this resolver is the one a destructive delete goes through
    and picking a winner there means deleting a workspace the caller never confirmed. Adopting path:'s
    dedupe for id: is out of scope.
  • Dot segments are not canonicalized. normalizeRuntimePathForComparison does not resolve /./,
    so id: and path: still agree on refusing it. The contract here is parity with path:, not
    universal path canonicalization — widening the normalizer would change every path comparison in the
    app and is deliberately out of scope.
  • The unstoppable-PTY invariant is upstream-independent. This change only affects whether a
    selector resolves; the destructive-delete gate runs after resolution. A provider-visible PTY that
    cannot be proven stopped still blocks a non-forced delete — pinned by
    src/main/runtime/worktree-teardown-unstopped-pty.test.ts (e.g. names the blocking PTYs and the
    escape hatch when one is still live
    , still fails closed on a sweep-level failure without force),
    which passes unchanged. If anything, this makes that gate reachable in cases where the delete
    previously never got that far. Relevant to the open test(worktree): lock fail-closed invariant behind the #9197 selector_not_found swallow #11073, which strengthens that same
    invariant; nothing here routes around it.

Performance (#14399 preserved)

The exact match is tried first and still wins outright, so a resolvable id costs exactly what it does
today. Neither site adds a scan: the fleet branch re-filters the array it had already listed, and the
scoped lookup re-filters the single owning repo's already-projected rows. An explicit id: still
never scans every repo.

Relationship to open PRs

Checked against upstream tip bc98655a39 before opening: worktreeIdComparisonKey does not exist in
src/shared/worktree/id.ts yet, and no fix for #16243 has landed, so this is still needed.

What this does not explain

#16243 contains two different observations, and this PR only accounts for one of them. The
difference matters, so here it is plainly.

The reporter and the first confirmer show a delete that never reached the runtime. The OP's
runtime trace grew by three git.exec lines with no worktree.remove span, where a successful
removal on that same host emits worktree.remove, worktree.remove.trash_rename and
worktree.remove.branch_delete. The macOS confirmer went further: in one instrumented ~90-second
session, a UI create reached the runtime and did 4.2 s of real git worktree add work, and the two
UI deletes seconds later produced not one line of runtime trace, while the CLI then removed the
same workspace with the expected spans. A selector miss cannot produce that: resolution happens
inside the runtime, so a miss requires the call to arrive. For those two reports, the delete was
never dispatched, and this PR does not fix that.

The third report is the one this PR fixes. A Windows client against a Linux headless
orca serve, both 1.4.188, captured the selector shapes directly against the runtime: the exact
id: form removed the workspace, the same path with a trailing slash answered selector_not_found,
and the path: form of that same trailing-slash path resolved. That is the asymmetry the A/B above
reproduces and this change removes.

So this closes one mechanism in that thread and leaves the other open. Nobody captured the selector
string the OP's or the confirmer's clients sent, and their traces argue their failures were something
else — most likely a renderer-side dispatch failure, which is a different fix in a different process.
#16243 should stay open until the non-dispatch reports are explained, which is why the reference
below is deliberately not a closing keyword.

Linked Issue

Partially addresses #16243.

Written without a closing keyword on purpose, so merging this cannot auto-close an issue whose other
reported mechanism is still unexplained (see What this does not explain). One consequence worth
naming so it does not read as an oversight: GitHub's Linked issues sidebar populates only from a
closing keyword, so it is intentionally empty here — the relationship lives in this reference and in
the cross-link on #16243's own timeline. Once the zero-runtime-trace reports are accounted for,
whoever closes #16243 can do it deliberately rather than have a merge do it silently, and adding the
keyword then is the right move.

Visual Proof

N/A — backend selector resolution only. There is no new or altered UI surface; the user-visible
difference is that a delete which silently no-oped now completes. #16295 is the PR that changes what
the UI says when a selector misses.

Testing

Written test-first: the tests were committed red, then the production change turned them green.

Reproduce (a reviewer can run all of this):

# Targeted. orca-runtime.test.ts is NOT modified by this branch — it is included deliberately
# because it holds #14399's no-fleet-scan guards, which this change must not break.
pnpm test \
  src/main/runtime/orca-runtime.test.ts \
  src/main/runtime/repo-worktree-row-resolution.test.ts \
  src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts \
  src/shared/worktree/id.test.ts
# Test Files 4 passed (4) · Tests 1257 passed | 1 skipped (1258)

# Same run without pnpm. The --config flag is required either way: without it the `@/` alias
# does not resolve in this repo.
# npx vitest run --config config/vitest.config.ts <the four paths above>

npx vitest run --config config/vitest.config.ts src/main/runtime
# 393 files, 4798 passed | 9 skipped

npx vitest run --config config/vitest.config.ts src/shared/worktree src/main/worktree-lineage-pruning.test.ts
# 16 files, 199 passed

pnpm typecheck   # exit 0 (also exit 0 on the base commit, for comparison)
pnpm lint        # exit 0 — oxlint, code-quality native + type-aware, reliability gates,
                 # max-lines ratchet, runtime-electron ratchet, skill/localization verifiers

pnpm lint and oxfmt --check were not clean when the fix was first committed: oxlint flagged
unicorn(no-useless-fallback-in-spread) in one new test, and both new test files were unformatted.
That is what the third commit fixes, so the green lint result above holds at the tip of the branch,
not at the fix commit. oxfmt --check reports the same 34 pre-existing offenders as the base commit —
this branch adds none.

Guard tests specifically re-run and green, unmodified: src/main/runtime/orca-runtime.test.ts
(including rejects a qualified removal when only another host has persisted ownership and its
no-fleet-scan assertion), worktree-teardown-unstopped-pty.test.ts, worktree-teardown.test.ts,
repo-worktree-resolution-scan.test.ts, worktree-scan-admin-fingerprint-gate.test.ts,
runtime-rpc-worktree-queries.test.ts, worktree-lineage-pruning.test.ts.

Non-vacuity, and what it does not cover. Two neutralization experiments, production files
restored byte-identical after each:

  • Neutralize both id: fallbacks — i.e. restore pre-fix behaviour — and 10 tests in
    worktree-rm-id-selector-path-spelling.test.ts go red, including both new Windows rows and the
    ambiguity refusal.
  • Make the fleet fallback pick the first folded match instead of refusing, and the ambiguity test
    goes red on its own.

Stated plainly because a reviewer would work it out anyway: four cases pass against pre-fix code
too
— malformed ids, dot segments, the POSIX backslash, and the folder-workspace mid-id slash pin.
Those are guards against widening the comparison, not evidence that this fix does anything. Only the
first bullet's ten are.

Platforms: this is platform-independent path comparison, and the spellings it folds — POSIX, Windows
drive and UNC, WSL aliases — are the ones normalizeRuntimePathForComparison already folds for
path:. Exercised on Linux (unit suites and the live runtime above); the reported scenario is a
Windows client against a Linux headless runtime over SSH.

Windows spellings are covered as a first-class axis, not by inference (#15598's defect class): the
comparison key, the fleet branch, and the scoped removal lookup each resolve a
repo::D:\Agentic\game2\battle-core id against the D:/Agentic/game2/battle-core spelling git
reports. The support is isWindowsAbsolutePathLike (src/shared/cross-platform-path.ts:6,
/^[A-Za-z]:[\\/]/), which gates separator folding and lowercasing at that module's lines 48 and 56.
The sites inherit normalizeRuntimePathForComparison's guarantees, including its deliberate
restraint. Pinned by name in src/shared/worktree/id.test.ts: folds Windows separator and
drive-letter case, as path: already does
and keeps a UNC or WSL root distinct from a drive-letter
location
; and at runtime level, folds drive-letter case only for Windows paths, never for a POSIX
path
and does not fold a backslash inside a POSIX path, where it is a valid filename character.
The case-fold test asserts both halves its name promises: a Windows-rooted path folds case
(d:/agentic/game2/battle-core resolves against the D:/Agentic/game2/battle-core row) while a
POSIX-rooted one does not (/SRV/projects/workspaces/plugin-host refuses with
selector_not_found). No production change was needed for that second half — POSIX case folding was
deliberately never introduced, because lowercasing would merge /srv/Foo with /srv/foo on Linux,
where they are two directories. The
fold is gated on platform semantics, not applied blindly.

All four invariants #15616 claims for the shared key hold here, tested at both sites and then
re-checked live on an isolated runtime against two real git repos with real worktrees:

  • Distinct repos stay distinct. Repo B's id against repo A's real path refuses, with and without
    a trailing slash; an rm attempted that way refused, and A stayed resolvable afterwards.
  • Distinct paths stay distinct. Prefix-overlapping sibling worktrees each resolve to themselves
    and never to each other.
  • Malformed ids keep exact-match behaviour. Pinned by src/shared/worktree/id.test.ts —
    returns null for ids with no repo boundary so callers keep exact matching: repo-a, repo-a::
    and a bare /srv/workspaces/plugin all key to null — and at both entry points by
    it.each('keeps exact matching for a malformed id with %s'), covering showManagedWorktree and
    resolveWorktreeRemovalTarget. repo-worktree-row-resolution.ts returns null on a null key and
    orca-runtime.ts leaves the empty exact-match candidate set alone. Live, all four malformed shapes
    refuse, and the scoped lookup refuses without scanning.
  • POSIX case is deliberately not folded. An uppercased POSIX path refuses — observed live and now
    asserted, per the case-fold test above.

The other three invariants are pinned by never merges different repos, workspaces, or folder
sessions
in the same file — distinct repo, distinct path, distinct ::workspace:<uuid> instance.

At the function level, against the real bundled source: D:\Agentic\game2\battle-core,
D:/Agentic/game2/battle-core and d:/agentic/game2/battle-core all fold to one key — so this
inherits #15616's separator, drive-letter and
drive-case guarantees — two folder instances of the same folder keep distinct keys, and dot segments
are not folded, which is exactly why the /./ spellings still refuse.

  • I manually tested these changes locally — the runtime A/B above: released 1.4.188 refuses the
    selector and leaves the worktree in place, a runtime built from this branch removes it. Linux
    host; the artifact was the Node orcad runtime bundle, not a packaged desktop client, so a
    client-side regression is covered by tests rather than by a live client build.
  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with AI agents throughout — investigation, the tests, the fix, and the live probes — driven by
xAI Grok 4.5 inside Orca's own agent harness. Every number, command, and matrix row in this PR was
produced by running it, not by asking a model to predict it. What this does not explain and the
unchanged and intended dot-segment note are there because those checks did not come out in this
change's favour.

Review

  • Security: the widening is bounded by an exact repo id, unchanged host qualification, and a
    refusal on ambiguity, so no id can now resolve a workspace on a host or repo the caller did not
    name. No new I/O, process, or external input; the destructive-delete gate is untouched and runs
    after resolution.
  • Cross-platform: no platform branch added. Path folding is delegated to the existing
    normalizeRuntimePathForComparison, which is what path: already uses on all three platforms, so
    id: and path: cannot diverge per-OS.
  • Remote SSH / local / paired runtime: host-side resolution only — no RPC params, stream frames,
    or published content change, so a new client against an old host and an old client against a new
    host both behave exactly as they do today (an old host keeps failing the divergent id; nothing
    breaks). SSH repos take the same listRepoWorktreesForResolution path as before, and perf(runtime): resolve an explicit worktree id without scanning every repo #14399's
    buildResolvedWorktreeFromId fallback is preserved.
  • Folder workspaces: the ::workspace:<uuid> suffix stays inside the compared path, so two
    sessions in one directory stay two workspaces.
  • Agents / integrations / git providers: none touched. This is selector-string comparison; no
    agent, provider, or Git command is involved, and no Git version boundary is crossed.
  • UI quality: no UI change (see Visual Proof).
  • Performance: measured reasoning above — exact match first, no added scan at either site.
  • Backwards compatibility: nothing persisted or serialized changes. Ids that resolve today resolve
    identically; only previously-failing ids now resolve.

Agent skill upstream boundary

  • Not applicable.

Notes

The one behavioural widening a reviewer should weigh: an id: whose path spelling differs from the
scan now resolves instead of failing. That is the point of the change, and it is fenced by an exact
repo id, unchanged host qualification, an ambiguity refusal, and no change to dot-segment handling.

Author

No X account.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint and pnpm typecheck pass locally at the tip of the branch; the src/main/runtime
    and src/shared/worktree suites pass locally. pnpm build was not run locally — CI covers it.

…tablyai#16243)

The renderer can only address a workspace by id (toRuntimeWorktreeSelector always
emits id:<repoId>::<path>), and the runtime matches that id byte for byte while a
path: selector has always compared through normalizeRuntimePathForComparison. A
stored id that spells its path differently from `git worktree list` therefore
resolves for the CLI and answers selector_not_found for the UI, which reads that
as a stale local mirror, calls forgetLocal, reports success, and lets the row
return on the next catalog refresh: a silent delete.

These tests fail on both resolution sites -- the fleet `id:` branch of
resolveWorktreeSelector and the scoped resolveScopedWorktreeIdRow a
host-qualified removal takes -- and pin what must stay closed: an exact repo id
(STA-4343), host qualification, dot segments neither selector canonicalizes, and
a refusal rather than a guess when two rows spell one path.

13 failing, 35 passing.
…tablyai#16243)

worktreeIdComparisonKey names one repo, one filesystem location, and one
folder-workspace instance, folding exactly the path spellings
normalizeRuntimePathForComparison already folds for a path: selector -- and
nothing more, so dot segments stay unresolved for both shapes. Both id:
resolution sites consult it only after an exact match finds nothing: the fleet
branch of resolveWorktreeSelector and resolveScopedWorktreeIdRow, which a
host-qualified removal takes. runtimeWorktreeIdsEqual now derives from the same
key so the runtime has one normalizer rather than a parallel one.

Not a pure refactor at that last site: runtimeWorktreeIdsEqual used to
normalize-compare ids that parse but carry an empty repoId or an empty path
('::/p', or 'repo::' against 'repo::/'), and worktreeIdComparisonKey returns
null for those, so across its call sites (PTY identity, refresh, mutation
queue) such ids now compare byte-exact instead. That narrows matching rather
than widening it, no real worktree carries such an id, and it is the behavior
stablyai#15616 guarantees for malformed ids -- but it is a behavior delta, not just a
tidy-up.

Perf (stablyai#14399): the exact match is still tried first and still wins outright, so
a resolvable id costs exactly what it did before. Neither site adds a scan --
the fleet branch re-filters the array it had already listed, the scoped lookup
re-filters the single owning repo's projected rows -- so an explicit id still
never scans every repo.

Fail-closed behavior is unchanged: the repo id compares exactly (STA-4343), host
qualification is untouched, the folder-workspace instance suffix stays part of
the path, and a scoped lookup with two equivalent rows refuses instead of
guessing. The bare unprefixed selector branch keeps byte-exact id matching,
since only the id: shape reaches a renderer caller.

Shares src/shared/worktree/id.ts with the open stablyai#15616, which introduces
worktreeIdComparisonKey for the same divergence in lineage pruning and
authoritative-scan purging; this adopts that helper rather than adding a second
one. Complementary to the open stablyai#16295, which makes the miss visible; this
removes the miss.
oxfmt --check flagged both new test files and oxlint's
unicorn/no-useless-fallback-in-spread flagged the store mock; the full
lint and format gates now match the pre-change baseline.
…ablyai#16243)

Review found two axes the first pass left unproven at the two id: resolution
sites. Both are the invariants the open stablyai#15616 guarantees for the shared
worktreeIdComparisonKey it introduces for stablyai#15598, so violating either here would
break a contract a sibling PR depends on.

Windows: stablyai#15598's whole defect is that one checkout is recorded under both
`D:\Agentic\game2` and `D:/Agentic/game2`. The fleet branch, the scoped removal
lookup, and the key itself now each resolve the backslash spelling against the
forward-slash spelling git reports, and fold drive-letter case -- while a
backslash inside a POSIX path stays a filename character and a POSIX root stays
case-sensitive, exactly as normalizeRuntimePathForComparison already decides for
a path: selector.

Malformed ids keep exact matching at both sites: an id with no repo boundary or
an empty path still refuses, and the scoped lookup still refuses it without
scanning.

Four of these fail without the production change (three fleet/removal Windows
cases and the scoped one); the malformed-id and POSIX-backslash cases are
invariant guards that hold either way.

Verified: 58 passed in the three files; 18 fail with the production hunks
reverted; orca-runtime.test.ts and worktree-teardown-unstopped-pty.test.ts green
(1270 passed | 1 skipped); pnpm tc:node clean.
…efusal (stablyai#16243)

The Windows backslash spelling now rides the ID_SPELLINGS rows, so it is driven
through both id: sites -- resolveWorktreeSelector and the scoped removal target --
and compared against what the same workspace's path: selector resolves, rather
than only through worktreeIdComparisonKey. That is the spelling stablyai#15598/stablyai#15616
found in the wild and the one the owner's Windows client produces.

The fleet path's ambiguity refusal had no test: two same-repo rows spelling one
directory, an id: matching neither exactly, must reject selector_ambiguous. It is
the fail-closed guard on a delete-capable resolver, and the property a later
refactor is most likely to turn into a silent pick.

Also records two limits at the source instead of leaving them to be rediscovered:
a UNC or WSL root never folds into a drive-letter location (while Windows' two
WSL UNC aliases do name one location), and a folder-workspace id keeps a trailing
slash placed before the ::workspace:<uuid> suffix, so that spelling stays
exact-match-only. Neither behavior changes here.

The file docblock overclaimed parity. path: collapses duplicate same-host
registrations to the first row while a folded id: refuses them; the contract this
file pins is path-spelling parity, not dedup parity, and the divergence is
deliberate because this resolver also serves delete.

Non-vacuity, verified by temporarily reverting the production hunks: neutralizing
both id: fallbacks turns 10 of these tests red, including both new Windows rows
and the ambiguity refusal (it degrades to selector_not_found). Making the fleet
fallback pick the first folded match instead of collecting all of them turns the
ambiguity test red on its own. The remaining cases -- malformed ids, dot
segments, the POSIX backslash, the folder-workspace slash -- pass against the
pre-fix code too: they guard against future widening rather than proving this
fix.

Drops the two Windows cases the ID_SPELLINGS row subsumes.

The drive-letter case test asserted only the Windows half its name promised; it
now also pins that a POSIX root does NOT fold case, since an unconditional
lowercase would merge /data/Foo with /data/foo on the platform CI runs on.

Fixture paths use the upstream-attested /srv/projects prefix (and a neutral
plugin-host leaf) instead of a local install root; the spelling variations the
tests exist to pin -- doubled separator, dot segment, trailing slash, uppercase
POSIX, cafe NFC/NFD, and the Windows D: rows -- are unchanged in form.
@coderabbitai

coderabbitai Bot commented Aug 25, 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: d903b8cb-040e-481d-b571-832313c26ad5

📥 Commits

Reviewing files that changed from the base of the PR and between 6927787 and 8e58718.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts
  • src/shared/worktree/id.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/runtime/orca-runtime.ts
  • src/shared/worktree/id.ts
  • src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts

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


📝 Walkthrough

Walkthrough

The change adds worktreeIdComparisonKey to normalize worktree ID paths with repository scoping. Scoped row resolution and runtime id: selectors now use exact matching first, followed by unique normalized matching. Ambiguous and malformed IDs fail closed. Runtime worktree equality uses the shared comparison key and retains exact comparison when normalization is unavailable. Tests cover path spelling, Unicode, Windows paths, scoping, ambiguity, suffixes, and malformed IDs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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 and concisely describes the primary change: resolving id: worktree selectors by path equivalence.
Description check ✅ Passed The description covers all template sections, explains the change and rationale, documents testing and platform impact, provides visual proof as N/A, and includes the linked issue reference. The delib…
Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. (1 skipped: 1 too large.)

Full details: Description check

Explanation

The description covers all template sections, explains the change and rationale, documents testing and platform impact, provides visual proof as N/A, and includes the linked issue reference. The deliberate omission of a closing keyword is clearly justified.


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.

🧹 Nitpick comments (1)
src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts (1)

1-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce the test header. Replace the issue history and implementation details with a one-line test scope note. As per coding guidelines, **/*.{ts,tsx,js,jsx} says: “DO NOT: be verbose, explain the obvious, walk through the code.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ada703e9-f7e8-4889-8726-fd68b8b5202f

📥 Commits

Reviewing files that changed from the base of the PR and between bc98655 and 6927787.

📒 Files selected for processing (6)
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/repo-worktree-row-resolution.test.ts
  • src/main/runtime/repo-worktree-row-resolution.ts
  • src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts
  • src/shared/worktree/id.test.ts
  • src/shared/worktree/id.ts

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

@AmethystLiang

Copy link
Copy Markdown
Contributor

@LesleyMurfin Thank you for the thorough investigation and for putting this PR together — we missed it initially. We have since confirmed that it addresses a distinct, reproduced id: selector path-spelling failure mode that is not covered by #16039, so this PR is still needed and we are keeping it open.

We will also review your other open PRs and work to get the ready ones merged. Thanks again for the careful scope, fail-closed behavior, and coverage here.

@OrcaWin
OrcaWin merged commit de6fe8b into stablyai:main Aug 27, 2026
48 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
…tablyai#16243) (stablyai#16494)

* test(worktrees): cover id: selector path-spelling parity with path: (stablyai#16243)

The renderer can only address a workspace by id (toRuntimeWorktreeSelector always
emits id:<repoId>::<path>), and the runtime matches that id byte for byte while a
path: selector has always compared through normalizeRuntimePathForComparison. A
stored id that spells its path differently from `git worktree list` therefore
resolves for the CLI and answers selector_not_found for the UI, which reads that
as a stale local mirror, calls forgetLocal, reports success, and lets the row
return on the next catalog refresh: a silent delete.

These tests fail on both resolution sites -- the fleet `id:` branch of
resolveWorktreeSelector and the scoped resolveScopedWorktreeIdRow a
host-qualified removal takes -- and pin what must stay closed: an exact repo id
(STA-4343), host qualification, dot segments neither selector canonicalizes, and
a refusal rather than a guess when two rows spell one path.

13 failing, 35 passing.

* fix(worktrees): resolve id: worktree selectors by path equivalence (stablyai#16243)

worktreeIdComparisonKey names one repo, one filesystem location, and one
folder-workspace instance, folding exactly the path spellings
normalizeRuntimePathForComparison already folds for a path: selector -- and
nothing more, so dot segments stay unresolved for both shapes. Both id:
resolution sites consult it only after an exact match finds nothing: the fleet
branch of resolveWorktreeSelector and resolveScopedWorktreeIdRow, which a
host-qualified removal takes. runtimeWorktreeIdsEqual now derives from the same
key so the runtime has one normalizer rather than a parallel one.

Not a pure refactor at that last site: runtimeWorktreeIdsEqual used to
normalize-compare ids that parse but carry an empty repoId or an empty path
('::/p', or 'repo::' against 'repo::/'), and worktreeIdComparisonKey returns
null for those, so across its call sites (PTY identity, refresh, mutation
queue) such ids now compare byte-exact instead. That narrows matching rather
than widening it, no real worktree carries such an id, and it is the behavior
stablyai#15616 guarantees for malformed ids -- but it is a behavior delta, not just a
tidy-up.

Perf (stablyai#14399): the exact match is still tried first and still wins outright, so
a resolvable id costs exactly what it did before. Neither site adds a scan --
the fleet branch re-filters the array it had already listed, the scoped lookup
re-filters the single owning repo's projected rows -- so an explicit id still
never scans every repo.

Fail-closed behavior is unchanged: the repo id compares exactly (STA-4343), host
qualification is untouched, the folder-workspace instance suffix stays part of
the path, and a scoped lookup with two equivalent rows refuses instead of
guessing. The bare unprefixed selector branch keeps byte-exact id matching,
since only the id: shape reaches a renderer caller.

Shares src/shared/worktree/id.ts with the open stablyai#15616, which introduces
worktreeIdComparisonKey for the same divergence in lineage pruning and
authoritative-scan purging; this adopts that helper rather than adding a second
one. Complementary to the open stablyai#16295, which makes the miss visible; this
removes the miss.

* chore(worktrees): satisfy oxfmt and oxlint on stablyai#16243 tests

oxfmt --check flagged both new test files and oxlint's
unicorn/no-useless-fallback-in-spread flagged the store mock; the full
lint and format gates now match the pre-change baseline.

* test(worktrees): pin Windows spellings and malformed-id exactness (stablyai#16243)

Review found two axes the first pass left unproven at the two id: resolution
sites. Both are the invariants the open stablyai#15616 guarantees for the shared
worktreeIdComparisonKey it introduces for stablyai#15598, so violating either here would
break a contract a sibling PR depends on.

Windows: stablyai#15598's whole defect is that one checkout is recorded under both
`D:\Agentic\game2` and `D:/Agentic/game2`. The fleet branch, the scoped removal
lookup, and the key itself now each resolve the backslash spelling against the
forward-slash spelling git reports, and fold drive-letter case -- while a
backslash inside a POSIX path stays a filename character and a POSIX root stays
case-sensitive, exactly as normalizeRuntimePathForComparison already decides for
a path: selector.

Malformed ids keep exact matching at both sites: an id with no repo boundary or
an empty path still refuses, and the scoped lookup still refuses it without
scanning.

Four of these fail without the production change (three fleet/removal Windows
cases and the scoped one); the malformed-id and POSIX-backslash cases are
invariant guards that hold either way.

Verified: 58 passed in the three files; 18 fail with the production hunks
reverted; orca-runtime.test.ts and worktree-teardown-unstopped-pty.test.ts green
(1270 passed | 1 skipped); pnpm tc:node clean.

* test(worktrees): pin Windows id: spelling folds and fleet ambiguity refusal (stablyai#16243)

The Windows backslash spelling now rides the ID_SPELLINGS rows, so it is driven
through both id: sites -- resolveWorktreeSelector and the scoped removal target --
and compared against what the same workspace's path: selector resolves, rather
than only through worktreeIdComparisonKey. That is the spelling stablyai#15598/stablyai#15616
found in the wild and the one the owner's Windows client produces.

The fleet path's ambiguity refusal had no test: two same-repo rows spelling one
directory, an id: matching neither exactly, must reject selector_ambiguous. It is
the fail-closed guard on a delete-capable resolver, and the property a later
refactor is most likely to turn into a silent pick.

Also records two limits at the source instead of leaving them to be rediscovered:
a UNC or WSL root never folds into a drive-letter location (while Windows' two
WSL UNC aliases do name one location), and a folder-workspace id keeps a trailing
slash placed before the ::workspace:<uuid> suffix, so that spelling stays
exact-match-only. Neither behavior changes here.

The file docblock overclaimed parity. path: collapses duplicate same-host
registrations to the first row while a folded id: refuses them; the contract this
file pins is path-spelling parity, not dedup parity, and the divergence is
deliberate because this resolver also serves delete.

Non-vacuity, verified by temporarily reverting the production hunks: neutralizing
both id: fallbacks turns 10 of these tests red, including both new Windows rows
and the ambiguity refusal (it degrades to selector_not_found). Making the fleet
fallback pick the first folded match instead of collecting all of them turns the
ambiguity test red on its own. The remaining cases -- malformed ids, dot
segments, the POSIX backslash, the folder-workspace slash -- pass against the
pre-fix code too: they guard against future widening rather than proving this
fix.

Drops the two Windows cases the ID_SPELLINGS row subsumes.

The drive-letter case test asserted only the Windows half its name promised; it
now also pins that a POSIX root does NOT fold case, since an unconditional
lowercase would merge /data/Foo with /data/foo on the platform CI runs on.

Fixture paths use the upstream-attested /srv/projects prefix (and a neutral
plugin-host leaf) instead of a local install root; the spelling variations the
tests exist to pin -- doubled separator, dot segment, trailing slash, uppercase
POSIX, cafe NFC/NFD, and the Windows D: rows -- are unchanged in form.

* docs(worktrees): trim the id: selector test header and document the comparison key (stablyai#16243)

(cherry picked from commit de6fe8b)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#16243) (stablyai#16494)

* test(worktrees): cover id: selector path-spelling parity with path: (stablyai#16243)

The renderer can only address a workspace by id (toRuntimeWorktreeSelector always
emits id:<repoId>::<path>), and the runtime matches that id byte for byte while a
path: selector has always compared through normalizeRuntimePathForComparison. A
stored id that spells its path differently from `git worktree list` therefore
resolves for the CLI and answers selector_not_found for the UI, which reads that
as a stale local mirror, calls forgetLocal, reports success, and lets the row
return on the next catalog refresh: a silent delete.

These tests fail on both resolution sites -- the fleet `id:` branch of
resolveWorktreeSelector and the scoped resolveScopedWorktreeIdRow a
host-qualified removal takes -- and pin what must stay closed: an exact repo id
(STA-4343), host qualification, dot segments neither selector canonicalizes, and
a refusal rather than a guess when two rows spell one path.

13 failing, 35 passing.

* fix(worktrees): resolve id: worktree selectors by path equivalence (stablyai#16243)

worktreeIdComparisonKey names one repo, one filesystem location, and one
folder-workspace instance, folding exactly the path spellings
normalizeRuntimePathForComparison already folds for a path: selector -- and
nothing more, so dot segments stay unresolved for both shapes. Both id:
resolution sites consult it only after an exact match finds nothing: the fleet
branch of resolveWorktreeSelector and resolveScopedWorktreeIdRow, which a
host-qualified removal takes. runtimeWorktreeIdsEqual now derives from the same
key so the runtime has one normalizer rather than a parallel one.

Not a pure refactor at that last site: runtimeWorktreeIdsEqual used to
normalize-compare ids that parse but carry an empty repoId or an empty path
('::/p', or 'repo::' against 'repo::/'), and worktreeIdComparisonKey returns
null for those, so across its call sites (PTY identity, refresh, mutation
queue) such ids now compare byte-exact instead. That narrows matching rather
than widening it, no real worktree carries such an id, and it is the behavior
stablyai#15616 guarantees for malformed ids -- but it is a behavior delta, not just a
tidy-up.

Perf (stablyai#14399): the exact match is still tried first and still wins outright, so
a resolvable id costs exactly what it did before. Neither site adds a scan --
the fleet branch re-filters the array it had already listed, the scoped lookup
re-filters the single owning repo's projected rows -- so an explicit id still
never scans every repo.

Fail-closed behavior is unchanged: the repo id compares exactly (STA-4343), host
qualification is untouched, the folder-workspace instance suffix stays part of
the path, and a scoped lookup with two equivalent rows refuses instead of
guessing. The bare unprefixed selector branch keeps byte-exact id matching,
since only the id: shape reaches a renderer caller.

Shares src/shared/worktree/id.ts with the open stablyai#15616, which introduces
worktreeIdComparisonKey for the same divergence in lineage pruning and
authoritative-scan purging; this adopts that helper rather than adding a second
one. Complementary to the open stablyai#16295, which makes the miss visible; this
removes the miss.

* chore(worktrees): satisfy oxfmt and oxlint on stablyai#16243 tests

oxfmt --check flagged both new test files and oxlint's
unicorn/no-useless-fallback-in-spread flagged the store mock; the full
lint and format gates now match the pre-change baseline.

* test(worktrees): pin Windows spellings and malformed-id exactness (stablyai#16243)

Review found two axes the first pass left unproven at the two id: resolution
sites. Both are the invariants the open stablyai#15616 guarantees for the shared
worktreeIdComparisonKey it introduces for stablyai#15598, so violating either here would
break a contract a sibling PR depends on.

Windows: stablyai#15598's whole defect is that one checkout is recorded under both
`D:\Agentic\game2` and `D:/Agentic/game2`. The fleet branch, the scoped removal
lookup, and the key itself now each resolve the backslash spelling against the
forward-slash spelling git reports, and fold drive-letter case -- while a
backslash inside a POSIX path stays a filename character and a POSIX root stays
case-sensitive, exactly as normalizeRuntimePathForComparison already decides for
a path: selector.

Malformed ids keep exact matching at both sites: an id with no repo boundary or
an empty path still refuses, and the scoped lookup still refuses it without
scanning.

Four of these fail without the production change (three fleet/removal Windows
cases and the scoped one); the malformed-id and POSIX-backslash cases are
invariant guards that hold either way.

Verified: 58 passed in the three files; 18 fail with the production hunks
reverted; orca-runtime.test.ts and worktree-teardown-unstopped-pty.test.ts green
(1270 passed | 1 skipped); pnpm tc:node clean.

* test(worktrees): pin Windows id: spelling folds and fleet ambiguity refusal (stablyai#16243)

The Windows backslash spelling now rides the ID_SPELLINGS rows, so it is driven
through both id: sites -- resolveWorktreeSelector and the scoped removal target --
and compared against what the same workspace's path: selector resolves, rather
than only through worktreeIdComparisonKey. That is the spelling stablyai#15598/stablyai#15616
found in the wild and the one the owner's Windows client produces.

The fleet path's ambiguity refusal had no test: two same-repo rows spelling one
directory, an id: matching neither exactly, must reject selector_ambiguous. It is
the fail-closed guard on a delete-capable resolver, and the property a later
refactor is most likely to turn into a silent pick.

Also records two limits at the source instead of leaving them to be rediscovered:
a UNC or WSL root never folds into a drive-letter location (while Windows' two
WSL UNC aliases do name one location), and a folder-workspace id keeps a trailing
slash placed before the ::workspace:<uuid> suffix, so that spelling stays
exact-match-only. Neither behavior changes here.

The file docblock overclaimed parity. path: collapses duplicate same-host
registrations to the first row while a folded id: refuses them; the contract this
file pins is path-spelling parity, not dedup parity, and the divergence is
deliberate because this resolver also serves delete.

Non-vacuity, verified by temporarily reverting the production hunks: neutralizing
both id: fallbacks turns 10 of these tests red, including both new Windows rows
and the ambiguity refusal (it degrades to selector_not_found). Making the fleet
fallback pick the first folded match instead of collecting all of them turns the
ambiguity test red on its own. The remaining cases -- malformed ids, dot
segments, the POSIX backslash, the folder-workspace slash -- pass against the
pre-fix code too: they guard against future widening rather than proving this
fix.

Drops the two Windows cases the ID_SPELLINGS row subsumes.

The drive-letter case test asserted only the Windows half its name promised; it
now also pins that a POSIX root does NOT fold case, since an unconditional
lowercase would merge /data/Foo with /data/foo on the platform CI runs on.

Fixture paths use the upstream-attested /srv/projects prefix (and a neutral
plugin-host leaf) instead of a local install root; the spelling variations the
tests exist to pin -- doubled separator, dot segment, trailing slash, uppercase
POSIX, cafe NFC/NFD, and the Windows D: rows -- are unchanged in form.

* docs(worktrees): trim the id: selector test header and document the comparison key (stablyai#16243)
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.

[Bug]: "Delete Workspace" silently does nothing — row disappears and returns in ~200ms, no runtime call, no log entry

3 participants