Skip to content

Route diffs by explicit worktree owner, not focused runtime (#8484) - #8509

Merged
nwparker merged 2 commits into
mainfrom
nwparker/bugbash-8484
Jul 14, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/bugbash-8484

Conversation

@nwparker

@nwparker nwparker commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Opening a diff/file for a worktree routed to the global Default runtime (settings.activeRuntimeEnvironmentId) whenever the worktree had no explicitly-populated owner, instead of using the worktree's own host and defaulting to LOCAL. When a remote/SSH runtime was focused but the diff's worktree was local (or a different owner), the diff/file-read was fetched from the wrong host. This aligns diff routing with the established #6957 owner-routing principle: route by the worktree's EXPLICIT owner, and treat "no known owner" as LOCAL — never the focused runtime.

Root cause

resolveDiffRuntimeEnvironmentId in src/renderer/src/store/slices/editor.ts:330 resolved the owner via getRuntimeEnvironmentIdForWorktree, whose final branch (src/renderer/src/lib/worktree-runtime-owner.ts:179) returns state.settings.activeRuntimeEnvironmentId. So a Source-Control caller that knows only the worktreeId — for an owner-less worktree — inherited the globally focused runtime and read the diff through that host's RPC.

The fix

Swap the fallback to getExplicitRuntimeEnvironmentIdForWorktree (already exported from worktree-runtime-owner.ts:182, same signature/return type), which returns the runtime env id only when worktree.hostId / repo executionHostId (or a restored runtime host / project-group owner for folder workspaces) explicitly names one, and null for legacy/local worktrees. null maps to undefined (LOCAL) via the existing ?? undefined.

Why zero-regression:

  • The caller-provided explicitRuntimeEnvironmentId early-return (including explicit null) is untouched.
  • For genuinely runtime-owned worktrees both helpers return the identical env id — the explicit-owner path (worktree host id, repo owner, folder project-group owner, restored runtime host) is fully preserved.
  • The only behavioral delta is exactly the bug: an owner-less worktree while a remote runtime is focused now reads LOCAL instead of the focused runtime. This applies uniformly to every resolveDiffRuntimeEnvironmentId caller (openDiff, openBranchDiff, and the combined-diff opens).
  • Return type is unchanged; the old import is fully removed with no dangling reference.

Evidence

New tests in editor.test.ts drive the real openDiff action and assert the stamped runtimeEnvironmentId. (A live UI screenshot would require multi-runtime host state that only exists at runtime — not reproducible in headless CI; the store test is authoritative.)

Before (failing on old code):

FAIL  createEditorSlice openDiff > keeps a diff for an owner-less worktree off the focused global runtime
- Expected  { id: "wt-1::diff::unstaged::file.ts", runtimeEnvironmentId: undefined }
+ Received  { id: "editor-diff:wt-1:focused-env:unstaged:file.ts", runtimeEnvironmentId: "focused-env" }

After (fix applied):

Test Files  2 passed (2)
     Tests  195 passed (195)

(editor.test.ts + worktree-runtime-owner.test.ts; typecheck typecheck:tsc:web clean; oxlint clean on changed files; nearby runtime-owner store tests 71 passed.)

ELI5

You open a diff for a folder on your own computer, but the app was showing the diff from a remote server you happened to have "focused." We now check who actually owns the folder — if nobody remote owns it, we read it from your computer, like it should.

Trade-offs

None. If a repo/worktree is genuinely on a runtime, its host is explicitly populated and still routes there.

Relationship to existing PR

None found (gh pr list --search "8484 in:body" empty). Written fresh following the in-repo #6957 explicit-owner pattern.

Review loops

1 (fresh reviewer, returned CLEAN).

⚠️ Bug-bash PR — please review; do not merge yet.

Fixes #8484

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 13, 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: 8e6ad0eb-3d6f-4722-ba77-2a60bb67a049

📥 Commits

Reviewing files that changed from the base of the PR and between 1875c54 and 603b730.

📒 Files selected for processing (2)
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts

📝 Walkthrough

Walkthrough

Diff runtime resolution now uses explicit worktree ownership. Explicit runtime IDs remain prioritized, while owner-less and SSH-owned worktrees resolve locally even when another runtime is globally focused. Tests cover local fallback, SSH-owned routing, and diffs routed to an explicitly assigned runtime.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it doesn't follow the required template sections for Screenshots, Testing, AI Review Report, Security Audit, or Notes. Add the missing sections, especially the testing checklist, screenshot note, AI review report, security audit, and platform-specific notes.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: routing diffs by explicit worktree owner instead of the focused runtime.
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.

…ined

resolveDiffRuntimeEnvironmentId returned getExplicitRuntimeEnvironmentIdForWorktree(...) ?? undefined.
For an owner-less/local worktree that stamps undefined, which settingsForRuntimeOwner treats as
"inherit the focused runtime" — so with a remote runtime focused, a local diff still read from the
wrong host and the reported bug persisted. Return null instead: settingsForRuntimeOwner(settings, null)
forces a LOCAL target, routing local via IPC and SSH via connectionId. Runtime-owned worktrees are
unchanged (explicit env id is truthy).

Tests: owner-less/local diffs now assert null; added an SSH-owned-worktree case (stamps null while a
runtime is focused). editor.test.ts 196 pass, typecheck:tsc:web + oxlint clean.

Co-authored-by: Orca <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor Author

Adversarial hardening review — 1 must-fix found & fixed

Ran 3 hostile review rounds (fresh reviewer each). Round 1 found a must-fix; the original one-line change did not actually fix the reported bug.

Must-fix: ?? undefined did not force a local read

resolveDiffRuntimeEnvironmentId returned getExplicitRuntimeEnvironmentIdForWorktree(...) ?? undefined. For an owner-less/local worktree the helper returns null, so the stamped OpenFile.runtimeEnvironmentId was undefined.

At diff-read time the stamp flows through settingsForRuntimeOwner(activeSettings, file.runtimeEnvironmentId) (useEditorPanelContentState.ts:228). That function distinguishes:

  • null → { activeRuntimeEnvironmentId: null } → getActiveRuntimeTarget → local
  • undefined → returns activeSettings unchanged → inherits the focused runtime

So with a remote runtime focused (settings.activeRuntimeEnvironmentId set — which is retained for legacy repos, settingsForKnownRepoOwner in worktrees.ts:807), a local worktree's diff still routed to the focused runtime and still failed with RuntimeRpcCallError: selector_not_found — exactly issue step 8. The old and new code produced the same read target; only the stamped field value and tab id changed.

The issue's own expected behavior states: "A local worktree should use local file/git IPC (runtimeEnvironmentId: null)", and the sibling openFile path already treats null as force-local vs undefined as inherit-focus (editor.ts:1636).

Fix

- return getExplicitRuntimeEnvironmentIdForWorktree(state, worktreeId) ?? undefined
+ return getExplicitRuntimeEnvironmentIdForWorktree(state, worktreeId) ?? null

null forces the LOCAL target: local reads go via IPC, SSH/relay via the independently-resolved connectionId (getRuntimeGitScope returns connectionId when the target is local). Runtime-owned worktrees are unchanged (explicit env id is truthy, so ?? null is a no-op). This matches the established repo-runtime-owner.ts precedent — "an owner-less repo is a local repo (#6957)".

Bonus: this also fixes the latent SSH+focused-runtime case (old undefined would have let a focused runtime override the SSH connectionId).

Tests

  • Owner-less/local diffs now assert runtimeEnvironmentId: null (discriminates: old code stamped focused-env/undefined).
  • Added an SSH-owned-worktree case (hostId ssh:conn-1) that stamps null while a runtime is focused — guards the "remote worktree still reaches its host" direction.

Verification

  • editor.test.ts 196 pass, worktree-runtime-owner.test.ts 16 pass; 882 adjacent store/editor tests pass.
  • typecheck:tsc:web clean, oxlint clean.
  • Rounds 2 & 3 (post-fix): CLEAN, no remaining must-fix/should-fix.

Verdicts

  • Correctness/regression: local↔runtime both directions now route correctly; runtime-owned unchanged; genuinely-unknown-owner → local is unreachable at diff-open (Source Control requires loaded records) and matches [Bug]: Merging PR on headless orca server errors #6957 intent.
  • SSH/relay: intact — routes via connectionId; no distinct relay host kind (ExecutionHostKind = local|ssh|runtime).
  • Perf: negligible (same indexed lookup, user-action path). Win/Linux/Mac: pure store logic, no platform branches.

⚠️ Bug-bash PR — still do not merge.

@nwparker
nwparker merged commit b667b72 into main Jul 14, 2026
1 check passed
@nwparker
nwparker deleted the nwparker/bugbash-8484 branch July 14, 2026 01:16
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Diff routing follows global default runtime instead of selected worktree owner

2 participants