Skip to content

perf(runtime): resolve an explicit worktree id without scanning every repo - #14399

Merged
nwparker merged 3 commits into
mainfrom
nwparker/scoped-explicit-worktree-id-resolution
Aug 14, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/scoped-explicit-worktree-id-resolution

Conversation

@nwparker

@nwparker nwparker commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If you ask "where is worktree X?", and X's id already says which repo it lives in, we were still checking all ten repos to answer. Now we check the one.

What Changed

resolveWorktreeSelector gains one branch for explicit id: selectors:

id: selector, fleet snapshot cold
  └─ owning repo resolvable, registered exactly once?
       ├─ no  → fleet scan (today's behaviour)
       └─ yes → scan only that repo, project lineage over its rows
                 └─ worktree not in the result? → fall back to the fleet scan

The per-repo body of computeResolvedWorktrees is extracted into resolveRepoWorktreeRows, shared by the fleet path and the scoped path so the two cannot drift.

Why

resolveWorktreeSelector has 39 call sites and resolved every selector kind from the whole-fleet snapshot. A targeted id:<repoId>::<path> lookup therefore fanned git worktree list across every registered repo to answer a question about exactly one of them — even though the id names its own repo.

With a warm scan cache that costs about 0.5 ms. With a cold one — app startup, or the first lookup after a mutation clears the snapshot — it is one subprocess per repo. git worktree list measured at ~17 ms per call, so a ten-repo fleet paid roughly 170 ms to find one worktree.

A new test measures the fan-out directly:

repos scanned for one id: lookup
before 10
after 1

Why only id:

Every other selector kind is matched across the fleet, and its selector_ambiguous contract is defined over all repos. Scoping branch:, name:, issue:, or a bare selector to one repo would silently resolve an ambiguity that today correctly throws — a branch:main matching three repos would start returning one of them. A test pins the current behaviour: branch:main across ten repos still throws selector_ambiguous and still scans all ten.

Why lineage stays correct

Lineage edges are intra-repo by construction: sharesResolvedWorktreeLineageBoundary requires a matching repoId. Projecting lineage over one repo's rows therefore produces the same parentWorktreeId and childWorktreeIds the fleet scan would.

The scoped path returns null and falls back whenever that reasoning does not hold:

  • a repo id registered on several execution hosts — only the full scan can adjudicate between their rows
  • an unknown repo id, or an unparseable worktree id
  • a worktree the scoped scan does not contain, which preserves the existing SSH buildResolvedWorktreeFromId fallback and the selector_not_found contract

A warm fleet snapshot always wins, since it answers every selector for free.

Linked Issue

N/A — follow-up to #14207, no tracking issue.

Visual Proof

N/A — no UI or interaction change. Selector resolution returns the same ResolvedWorktree rows, including lineage; only the number of repos scanned to produce them changes.

Testing

Four tests added to src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts, all asserting on the actual set of repo paths scanned:

  • an id: selector on a cold cache scans only the owning repo
  • an id: selector for a different repo scans only that repo (proves it targets correctly, not just narrowly)
  • branch:main across ten repos still throws selector_ambiguous and still scans all ten
  • an id naming no registered repo falls back to the fleet path and still throws selector_not_found

Gates run locally on macOS: npm run typecheck, npm run lint (incl. max-lines ratchet), oxfmt --check, and the full src/main/runtime/ suite — 275 files / 4049 tests green.

Platforms: macOS locally; Linux via CI. No platform-dependent code paths are touched — this is repo-set selection, not filesystem or process work. The two Windows-boundary suites from #14378 are in the same file and continue to run on the Windows runner.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Claude Opus 4.5 via Claude Code.

Review

  • Security: no new I/O, no new process, no new external input. The scoped path reads the same store and runs the same scan the fleet path already ran for that repo.
  • Cross-platform: no path or process logic changed; repo selection only.
  • Remote SSH: SSH repos take the same listRepoWorktreesForResolution path as before. The existing buildResolvedWorktreeFromId fallback for disconnected SSH repos is preserved by falling through to the fleet path when the scoped scan finds nothing.
  • Mobile / remote wire: no RPC params, stream frames, or published content changed.
  • Backwards compatibility: nothing persisted; no schema or serialized contract touched.
  • Performance: measured above. One behavioural note — a scoped lookup runs pruneLineageForMissingRepoWorktrees for its own repo only, so other repos are pruned on the next fleet scan rather than on a targeted call. Fleet scans still happen on every untargeted read (worktree ps, listManagedWorktrees, orchestration refresh), so this changes prune frequency, not correctness.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 2e581c46-ac6e-4199-a632-ab3c91aa346c

📥 Commits

Reviewing files that changed from the base of the PR and between a6a6443 and 295e1d6.

📒 Files selected for processing (4)
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/repo-worktree-row-resolution.ts
  • src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts
  • src/shared/promise-timeout-fallback.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/shared/promise-timeout-fallback.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/repo-worktree-row-resolution.ts
  • src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts

📝 Walkthrough

Walkthrough

The runtime now resolves explicit worktree IDs through the owning repository when the resolved-worktree cache is stale. Shared repository row construction supports folder and Git repositories, timeout fallback, metadata merging, and lineage handling. The runtime uses shared persisted-row reconstruction and timeout utilities. Tests cover scoped success, fleet fallback, branch ambiguity, and unregistered repository IDs.

Merge Risk: ⚪ Minimal · up to 295e1

This change narrows explicit worktree ID lookups to the owning repository while preserving fleet fallback behavior and existing selector contracts; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, rationale, testing, and review areas, but it does not provide the required linked issue. Add a valid linked issue reference, such as Fixes #14207``, or provide the required tracking issue before merging.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the optimization for explicit worktree ID resolution.
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.
✨ 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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 09faa572-2061-4f45-80c1-5b0aa300bd74

📥 Commits

Reviewing files that changed from the base of the PR and between 94df72d and 609d837.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts

@nwparker
nwparker force-pushed the nwparker/scoped-explicit-worktree-id-resolution branch from 6c954a8 to 0238be8 Compare August 14, 2026 04:59
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

nwparker and others added 3 commits August 14, 2026 01:06
… repo

`resolveWorktreeSelector` resolved every selector kind from the whole-fleet
snapshot, so a targeted `id:<repoId>::<path>` lookup fanned `git worktree list`
across every registered repo to answer a question about one of them. With a cold
scan cache -- app startup, or the first lookup after a mutation clears the
snapshot -- that is one subprocess per repo, ~17ms each, to find a worktree whose
owning repo the id already names.

Scope only `id:`. Every other selector kind is matched across the fleet and its
`selector_ambiguous` contract is defined over all repos, so scoping `branch:`,
`name:`, `issue:`, or a bare selector would silently pick a winner where they
correctly refuse today. A test pins that: `branch:main` across ten repos still
throws `selector_ambiguous` and still scans all ten.

Lineage stays correct because edges are intra-repo by construction --
`sharesResolvedWorktreeLineageBoundary` requires a matching repoId -- so
projecting one repo's rows yields the same parent and child ids the fleet scan
would. The scoped path returns null and falls back whenever that does not hold:
a repo id registered on several execution hosts (only the full scan can
adjudicate between their rows), an unknown repo id, or a worktree the scoped
scan does not contain. A warm fleet snapshot always wins, since it answers for
free.

The per-repo body of `computeResolvedWorktrees` moves into
`resolveRepoWorktreeRows`, shared by both paths so they cannot drift.

Measured on a ten-repo fleet: one `id:` lookup scans 10 repos before and 1 after.
orca-runtime.ts is ~38k lines, so the scoped-resolution work should not add to
it. Move the row-resolution logic into `repo-worktree-row-resolution.ts`:
per-repo row building, the persisted-row fallback for a degraded scan, and the
scoped `id:` resolver.

The module owns no state. The two runtime-owned behaviours it needs -- the
cache-aware per-repo scan and folder-workspace identity stamping -- are injected
through `RepoWorktreeRowDeps`, so the scan cache stays where it lives today.

`withTimeout` moves to `src/shared/promise-timeout-fallback.ts` since both files
now need it.

Net effect: orca-runtime.ts is 113 lines shorter than on main, with the feature
added rather than removed.
@nwparker
nwparker force-pushed the nwparker/scoped-explicit-worktree-id-resolution branch from 3d39136 to 295e1d6 Compare August 14, 2026 08:09
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker
nwparker merged commit b82a879 into main Aug 14, 2026
44 checks passed
OrcaWin pushed a commit that referenced this pull request Aug 27, 2026
…16243) (#16494)

* test(worktrees): cover id: selector path-spelling parity with path: (#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 (#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
#15616 guarantees for malformed ids -- but it is a behavior delta, not just a
tidy-up.

Perf (#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 #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 #16295, which makes the miss visible; this
removes the miss.

* chore(worktrees): satisfy oxfmt and oxlint on #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 (#16243)

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

Windows: #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 (#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 #15598/#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 (#16243)
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
… repo (stablyai#14399)

`resolveWorktreeSelector` resolved every selector kind from the whole-fleet snapshot, so a targeted `id:<repoId>::<path>` lookup fanned `git worktree list` across every registered repo to answer a question about one of them. With a cold scan cache -- app startup, or the first lookup after a mutation clears the snapshot -- that is one subprocess per repo, ~17ms each, to find a worktree whose owning repo the id already names. Measured on a ten-repo fleet: one `id:` lookup scans 10 repos before and 1 after.

Scope only `id:`. Every other selector kind is matched across the fleet and its `selector_ambiguous` contract is defined over all repos, so scoping `branch:`, `name:`, `issue:`, or a bare selector would silently pick a winner where they correctly refuse today. A test pins that: `branch:main` across ten repos still throws `selector_ambiguous` and still scans all ten.

Lineage stays correct because edges are intra-repo by construction. The scoped path returns null and falls back whenever that does not hold: a repo id registered on several execution hosts, an unknown repo id, or a worktree the scoped scan does not contain. A warm fleet snapshot always wins.

Row resolution moves out of orca-runtime.ts into repo-worktree-row-resolution.ts, which owns no state -- the cache-aware scan and folder-workspace stamping are injected. orca-runtime.ts ends up 65 lines shorter than before despite the added feature.
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.

1 participant