Skip to content

Resolve host-split repo owners by worktree path for hostless worktrees (#8484 follow-up) - #8906

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/8484-hostless-host-split-owner
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/8484-hostless-host-split-owner

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Follow-up hardening to #8509 / #8484. #8509 correctly routes diffs by the worktree's explicit owner (getExplicitRuntimeEnvironmentIdForWorktree(...) ?? null), but a worktree with no hostId (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 one repoId, so which host such a worktree routes to depends on record order:

  • runtime-record-first → a legacy local worktree's diff stamps the runtime env → RuntimeRpcCallError: selector_not_found
  • local-record-first → a legacy runtime worktree's diff is forced to a local read → fs:readFile access denied

The same host-blind lookup also backs getResolvedExecutionHostIdForWorktree (terminal host resolution in Terminal.tsx) and the runtime-owner resolvers used by terminals, browser panes, and tabs — so the defect is broader than diffs.

Fix

  • New worktree-runtime-owner-repo-match.ts: 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 the existing normalizeRuntimePathForComparison). A cross-host tie stays ambiguous and keeps the prior first-indexed behavior; an explicit worktree hostId always 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-unused findIndexedRepoOwner is removed.
  • Wired through all four resolvers: getRuntimeEnvironmentIdForWorktree, getExplicitRuntimeEnvironmentIdForWorktree, getExecutionHostIdForWorktree, and getResolvedExecutionHostIdForWorktree.
  • No changes to 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 lint
  • pnpm 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.
  • Added high-quality regression tests that fail without the fix:
    • worktree-runtime-owner-host-split.test.ts — 4 of 7 cases fail on current main (proving the residual bug), including order-independence of getExplicitRuntimeEnvironmentIdForWorktree (the Route diffs by explicit worktree owner, not focused runtime (#8484) #8509 diff entry point); also covers hostId-wins-over-path, cross-host path-tie parity, and single-host no-change.
    • editor.test.ts — an openDiff store-level case proving composition with Route diffs by explicit worktree owner, not focused runtime (#8484) #8509's null-forcing routing: hostless local worktree stamps null, 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 high pass over this code flagged: (1) dead findIndexedRepoOwner after 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: all findIndexedRepoOwner consumers 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 via connectionId exactly 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

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

coderabbitai Bot commented Jul 15, 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

Run ID: b3aef6b8-61fc-466d-8469-127280bf213d

📥 Commits

Reviewing files that changed from the base of the PR and between 0690be5 and 210c26a.

📒 Files selected for processing (7)
  • src/renderer/src/lib/resolved-worktree-execution-host.test.ts
  • src/renderer/src/lib/resolved-worktree-execution-host.ts
  • src/renderer/src/lib/worktree-runtime-owner-host-split.test.ts
  • src/renderer/src/lib/worktree-runtime-owner-index.ts
  • src/renderer/src/lib/worktree-runtime-owner-repo-match.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts
  • src/renderer/src/store/slices/editor.test.ts

📝 Walkthrough

Walkthrough

Repo 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the host-aware worktree ownership fix and matches the PR's main change.
Description check ✅ Passed The description includes all required sections and covers summary, testing, review, security, and notes with sufficient detail.
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.

@AmethystLiang AmethystLiang self-assigned this Jul 18, 2026
@AmethystLiang
AmethystLiang self-requested a review July 18, 2026 16:47
@OrcaWin
OrcaWin marked this pull request as draft October 27, 2026 09:47
@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded by #33818.

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.

3 participants