Repository navigation
Resolve host-split repo owners by worktree path for hostless worktrees (#8484 follow-up) - #8906
brennanb2025 wants to merge 1 commit into
Conversation
#8484 follow-up) PR #8509 routes diffs by the worktree's explicit owner, but a worktree with no hostId (legacy / pre-project-host metadata) still resolves its owning repo via the host-blind first-by-id index. A project registered on both local and a paired runtime keeps several repo records under one repoId, so which host such a worktree routes to depends on record order: runtime-record-first sends a local worktree's diff to the runtime (selector_not_found); local-first forces a runtime worktree's diff to a local read (access denied). The same lookup also backs terminal host resolution (getResolvedExecutionHostIdForWorktree) and the runtime-owner resolvers used by terminals, browser, and tabs. Fix: when a hostless worktree's repoId spans multiple host records, pick the owning record by the worktree's own filesystem path (longest shared path-segment prefix via normalizeRuntimePathForComparison). A cross-host tie stays ambiguous and keeps the prior first-indexed behavior; explicit worktree hostId always wins; single-host repos resolve exactly as before. The repo index becomes group-aware (records-per-id, built once per immutable array) so the common single-host case stays O(1) and the existing perf guard holds. Tests: host-split unit suite (fails 4/7 on main before the fix), an openDiff store-level case proving composition with #8509's null-forcing diff routing, and a resolved-execution-host host-split case.
|
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 (7)
📝 WalkthroughWalkthroughRepo owner records are now grouped by repository id and can be selected using normalized worktree and repo paths when multiple hosts share an id. Runtime environment and execution host resolution functions use this worktree-aware selection, while existing explicit and fallback behavior remains. New tests cover host-split routing, ordering, overrides, ties, legacy records, single-host behavior, and editor diff resolution. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-18T16:47:45Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes. |
|
Superseded by #33818. |
Summary
Follow-up hardening to #8509 / #8484. #8509 correctly routes diffs by the worktree's explicit owner (
getExplicitRuntimeEnvironmentIdForWorktree(...) ?? null), but a worktree with nohostId(legacy / pre-project-host metadata) still resolves its owning repo through the host-blind first-by-id index. A project registered on both local and a paired runtime keeps several repo records under onerepoId, so which host such a worktree routes to depends on record order:RuntimeRpcCallError: selector_not_foundfs:readFileaccess deniedThe same host-blind lookup also backs
getResolvedExecutionHostIdForWorktree(terminal host resolution inTerminal.tsx) and the runtime-owner resolvers used by terminals, browser panes, and tabs — so the defect is broader than diffs.Fix
worktree-runtime-owner-repo-match.ts: when a hostless worktree'srepoIdspans multiple host records, pick the owning record by the worktree's own filesystem path (longest shared path-segment prefix via the existingnormalizeRuntimePathForComparison). A cross-host tie stays ambiguous and keeps the prior first-indexed behavior; an explicit worktreehostIdalways wins; single-host repos resolve byte-for-byte as before (matches.length <= 1 → matches[0]).worktree-runtime-owner-index.ts: repo index becomes group-aware (records-per-id, built once per immutable array) so the single-host fast path stays O(1) — the existing indexed-reads perf guard still passes unchanged. The now-unusedfindIndexedRepoOwneris removed.getRuntimeEnvironmentIdForWorktree,getExplicitRuntimeEnvironmentIdForWorktree,getExecutionHostIdForWorktree, andgetResolvedExecutionHostIdForWorktree.editor.ts— Route diffs by explicit worktree owner, not focused runtime (#8484) #8509's diff-routing semantics are kept as-is; this PR only makes the owner resolution underneath it host-aware.Screenshots
No visual change — owner-resolution fix beneath existing routing. The user-visible effect is that legacy (hostless-metadata) worktrees in a project shared across local + a paired runtime route diffs/terminals to their own host regardless of repo record order.
Testing
pnpm lintpnpm typecheck(all three projects)pnpm test— ran the directly-affected surface (src/renderer/src/lib/, editor, repos*, terminals, browser, tabs, diffComments,runtime/): 3,267 tests green. Full suite in CI.worktree-runtime-owner-host-split.test.ts— 4 of 7 cases fail on current main (proving the residual bug), including order-independence ofgetExplicitRuntimeEnvironmentIdForWorktree(the Route diffs by explicit worktree owner, not focused runtime (#8484) #8509 diff entry point); also covershostId-wins-over-path, cross-host path-tie parity, and single-host no-change.editor.test.ts— anopenDiffstore-level case proving composition with Route diffs by explicit worktree owner, not focused runtime (#8484) #8509's null-forcing routing: hostless local worktree stampsnull, hostless runtime worktree stamps its env, with runtime-record-first ordering (fails on main without this fix — verified by stashing the lib changes).resolved-worktree-execution-host.test.ts— host-split case for the terminal-host resolver.AI Review Report
This PR ports the surviving pieces of the closed #8601 (whose diff-layer half was superseded by #8509), re-verified against current main. The prior
/code-review highpass over this code flagged: (1) deadfindIndexedRepoOwnerafter the swap — removed here (main gained a new consumer,resolved-worktree-execution-host.ts, which this PR converts to the host-aware helper, keeping the export dead); (2) the cross-host path-tie limitation — now covered by an explicit test asserting parity with prior behavior. Verified cross-file: allfindIndexedRepoOwnerconsumers converted; the perf-guard test for indexed owner reads passes unchanged.Cross-platform (macOS/Linux/Windows): path comparison uses the shared
normalizeRuntimePathForComparison(separator normalization + Windows drive-letter lower-casing) and splits only after normalization — no hardcoded separators. SSH-owned repos resolve viaconnectionIdexactly as before (explicitly tested); runtime paths are POSIX. No shortcuts, labels, or shell behavior touched.Security Audit
Low risk. Pure in-renderer owner resolution — no new input handling, command execution, secrets, auth, or IPC surface. Paths are compared (segment prefix), never executed or read; the resolved owner only selects an already-authorized IPC/RPC channel. No dependency changes.
Notes
null, runtime → its env, with runtime as global default). Not re-run for this port; the logic is identical and the composition with Route diffs by explicit worktree owner, not focused runtime (#8484) #8509 is covered by the store-level test.repo.id-across-hosts model), Remote runtime File Explorer open/retry can fall back to local fs:readFile #6440/Fix remote File Explorer opening files via local fs:readFile (#6440) #6562/Fix remote runtime branch diffs #6942 (prior remote routing fixes).