Skip to content

fix(renderer): resolveOwner refuses folder and project-group twins instead of guessing this computer - #30009

Merged
nwparker merged 3 commits into
mainfrom
nwparker/resolve-owner-folder-twins
Oct 17, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/resolve-owner-folder-twins

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​141 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​344 $\color{#cf222e}{\Huge{\mathbf{−}}}$​37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​307

ELI5

The same folder workspace, or the project group a folder inherits its machine from, can be published by two hosts at once (for example this computer and an SSH host). When nothing says which copy the user means, Orca's owner lookup guessed this computer. Folder edits, deletes, file writes and git actions could then reach the wrong machine. Now the lookup answers "ambiguous", and those actions refuse instead of guessing.

What Changed

  • src/renderer/src/lib/resolve-owner.ts resolveOwner (the existing host-aware owner lookup, which keeps the server and the SSH target behind it) now returns ambiguous for a folder workspace when no host is named and either:

    • the folder id is published by two hosts. Before, this returned missing, which file-owner-runtime-target.ts mapped to this computer.
    • the folder row names no host or SSH connection of its own, and its project group is published by two hosts. Before, this resolved to this computer.

    A caller that names the host (hostId, or the active workspace's selected host) resolves exactly as before. A folder that names its own host or SSH connection is unaffected.

  • worktree-runtime-owner-index.ts: unqualified folder and project-group lookups now report ambiguous separately from missing. The existing lookups are rebuilt on top of them, with the same results.

  • getRuntimeEnvironmentIdForWorktree / resolveRuntimeOwnerForWorktree are marked @deprecated → resolveOwner, with no code change. A 76-case golden matrix captured on main pins their mapping.

  • Twin suite: adds a "folder in a twin project group" kind. A folder delete that names no host now refuses for folder twins and project-group twins, and touches neither copy (it failed before this change for the project-group twin).

Callers audited (all 19 resolveOwner / runtimeTargetForWorkspaceOwner call sites): none now falls back to local where it didn't before. These now refuse where they used to act locally:

  • folder update/delete
  • file save/drop/paste
  • git push/pull
  • browser tab create/close
  • Ports panel ("unknown")
  • git status polling

One pre-existing local fallback remains: the board's Linear status sync (use-workspace-board-task-status-sync.ts:135, ?? { kind: 'local' }). It behaves as before and is logged for the next PR (1a.3).

Why

The design called for a typed owner result that keeps the host and the transport and reports twins. resolveOwner already is that (#27275). A first draft of this PR added a second resolver alongside it. That would have been a parallel implementation, so it was dropped in favour of fixing the two folder gaps in the existing one. Refusing on ambiguity follows the SSH rule that loss of attribution is never evidence the work is local.

Linked Issue

N/A (maintainer; SSH hardening design, tracker row 1a.1)

Visual Proof

N/A: no UI change. In the twin cases only, actions that used to hit this computer now refuse.

Testing

  • resolve-owner.test.ts: new rows cover a folder twin with no host named, the same twin with a host named, a project-group twin with an unstamped folder, a stamped folder in a twin group, and a legacy folder that names its own SSH connection. Each runs with all three Active Server settings. The twin rows fail before the fix.

  • runtime-owner-alias-golden.test.ts: deprecated aliases equal the main-captured golden over 76 cases.

  • host-twin-isolation.test.ts: the no-host folder delete refuses and touches neither twin. This fails before the fix for the project-group twin.

  • Unit folders around and importing the changed files (src/renderer/src/{lib,store,hooks,runtime} plus the sidebar, right-sidebar, native-chat and automations components): 2737 files and 25,603 tests pass.

  • Local copy of the "static analysis and typecheck" job: pass.

  • Live verify: none. This is a renderer-only resolver change, and the twin cases are covered by store-level tests. Reproducing it live needs one folder published by two hosts at once, which no current host set-up does without the twin state these tests build.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Codex (gpt-6.1-sol, high) round 1 found a P2: a legacy folder that names its own SSH connection was refused. That is fixed, and round 2 was clean.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No wire or on-disk change. Folder workspaces are the focus, and git worktrees are unchanged. Mixed versions are unaffected, since this is renderer-only.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds indexed folder-workspace and project-group owner resolvers that report resolved, missing, or ambiguous results. resolveOwner checks for ambiguous folder ownership before unqualified route resolution. New fixtures and tests cover folder and project-group ownership, deprecated resolver results, and host-twin isolation, including hostless folder deletion.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to b4749

Folder actions that name no host are meant to refuse when ownership is ambiguous. However, duplicate folders that inherit different hosts from their project groups can still be routed to one host. Fix or rule out this case before merging. The new isolation test also has a small coverage gap.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: resolveOwner now refuses ambiguous folder and project-group twins instead of falling back to the local computer.
Description check Passed The description follows the repository template and explains the user impact, implementation, rationale, linked-issue exception, testing, scope, and checklist status. It documents that no manual or li…
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.
Full details: Description check

Explanation

The description follows the repository template and explains the user impact, implementation, rationale, linked-issue exception, testing, scope, and checklist status. It documents that no manual or live verification was performed while reporting extensive automated validation.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af4146ca-d154-49a8-b39d-9a8568c4c932
📥 Commits

Reviewing files that changed from the base of the PR and between 035588e and b4749ef.

📒 Files selected for processing: 9
  • src/renderer/src/lib/resolve-owner.test.ts
  • src/renderer/src/lib/resolve-owner.ts
  • src/renderer/src/lib/runtime-owner-alias-golden.test-fixture.ts
  • src/renderer/src/lib/runtime-owner-alias-golden.test.ts
  • src/renderer/src/lib/runtime-owner-alias-matrix.test-fixture.ts
  • src/renderer/src/lib/worktree-runtime-owner-index.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts
  • src/renderer/src/store/host-twin-isolation.test.ts
  • src/renderer/src/store/host-twin.test-fixture.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

* their unqualified lookups collapse a twin to "no row" before any host fallback runs.
*/
function isFolderTwin(state: WorktreeOperationRouteState, folderWorkspaceId: string): boolean {
const folder = resolveIndexedFolderWorkspaceOwner(state.folderWorkspaces, folderWorkspaceId)

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.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- diff target ---'
git diff --unified=80 573388796704a74fbf24625f91f0cfc7e2d4a181 b4749efb5799507d2f8c47e4fe9716b74c923931 -- src/renderer/src/lib/resolve-owner.ts
printf '%s\n' '--- target references and definitions ---'
rg -n -F --glob '*.{ts,tsx}' -e 'resolveIndexedFolderWorkspaceOwner' -e 'resolveIndexedProjectGroupOwner' -e 'isFolderTwin' -e 'resolveWorktreeOperationRouteResult' -e 'function resolveOwner' -e 'const resolveOwner' src/renderer/src
printf '%s\n' '--- target file ---'
nl -ba src/renderer/src/lib/resolve-owner.ts | sed -n '1,240p'
printf '%s\n' '--- relevant resolver definitions ---'
rg -l -F --glob '*.{ts,tsx}' -e 'resolveIndexedFolderWorkspaceOwner' -e 'resolveIndexedProjectGroupOwner' src | while read -r f; do
  echo "### $f"
  nl -ba "$f" | sed -n '1,280p'
done
printf '%s\n' '--- route resolver definitions ---'
rg -l -F --glob '*.{ts,tsx}' -e 'resolveWorktreeOperationRouteResult' src | while read -r f; do
  echo "### $f"
  nl -ba "$f" | sed -n '1,360p'
done

Repository: stablyai/orca

Length of output: 42052


🏁 Script executed:

set -eu
printf '%s\n' '--- diff target ---'
git diff --unified=80 573388796704a74fbf24625f91f0cfc7e2d4a181 b4749efb5799507d2f8c47e4fe9716b74c923931 -- src/renderer/src/lib/resolve-owner.ts
printf '%s\n' '--- references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'resolveIndexedFolderWorkspaceOwner' -e 'resolveIndexedProjectGroupOwner' -e 'isFolderTwin' -e 'resolveWorktreeOperationRouteResult' -e 'function resolveOwner' -e 'const resolveOwner' src/renderer/src || test $? -eq 1
printf '%s\n' '--- target ---'
nl -ba src/renderer/src/lib/resolve-owner.ts | sed -n '1,260p'
printf '%s\n' '--- resolver files ---'
rg -l -F --glob '*.{ts,tsx}' -e 'resolveIndexedFolderWorkspaceOwner' -e 'resolveIndexedProjectGroupOwner' src | while read -r f; do
  echo "### $f"
  nl -ba "$f" | sed -n '1,320p'
done
printf '%s\n' '--- route files ---'
rg -l -F --glob '*.{ts,tsx}' -e 'resolveWorktreeOperationRouteResult' src | while read -r f; do
  echo "### $f"
  nl -ba "$f" | sed -n '1,400p'
done

Repository: stablyai/orca

Length of output: 42275


🏁 Script executed:

set -eu
printf '%s\n' '--- indexed owner resolver ---'
nl -ba src/renderer/src/lib/worktree-runtime-owner-index.ts | sed -n '1,370p'
printf '%s\n' '--- operation route resolver ---'
nl -ba src/renderer/src/lib/worktree-operation-route.ts | sed -n '1,330p'
printf '%s\n' '--- relevant types and catalog helpers ---'
rg -n -F --glob '*.{ts,tsx}' -e 'type FolderWorkspace' -e 'interface FolderWorkspace' -e 'type ProjectGroup' -e 'interface ProjectGroup' -e 'executionHostId' -e 'projectGroupId' src/renderer/src/shared src/shared src/renderer/src | head -200

Repository: stablyai/orca

Length of output: 42384


🏁 Script executed:

set -eu
printf '%s\n' '--- unqualified route branch ---'
nl -ba src/renderer/src/lib/worktree-operation-route.ts | sed -n '220,360p'
printf '%s\n' '--- folder runtime owner helpers ---'
nl -ba src/renderer/src/lib/folder-workspace-runtime-owner.ts | sed -n '1,300p'
printf '%s\n' '--- execution host derivation ---'
nl -ba src/shared/execution-host.ts | sed -n '180,285p'

Repository: stablyai/orca

Length of output: 20846


🏁 Script executed:

nl -ba src/renderer/src/lib/worktree-operation-route.ts | sed -n '350,395p'

Repository: stablyai/orca

Length of output: 1359


Reject folder IDs with conflicting inherited hosts.

Two unstamped folder rows with the same ID can have different project groups. The folder index compares only each folder row’s own effective host, so both rows resolve as local and the index returns the first row. isFolderTwin then checks only that row’s project group.

The unqualified route uses the same selected row and can resolve the operation to one host instead of returning ambiguous. Compare the effective inherited host of every matching folder row before selecting an owner, or enforce an equivalent catalog invariant.

const calls = vi.mocked(window.api.runtimeEnvironments.call).mock.calls
expect(calls.map(([request]) => request.method)).not.toContain('folderWorkspace.delete')
const after = [fixture.local, fixture.remote].map((s) => projectHostTwinState(fixture, s))
expect(after.map((state, i) => changedHostTwinState(before[i], state))).toEqual([[], []])

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Compare the unstamped folder row directly.

For 'folder group local+ssh', projectHostTwinState excludes the folder row from both host snapshots because the row has no executionHostId. If deletion changes that row while returning false and making no API call, this assertion still passes. Snapshot folderWorkspaces before deletion and assert that it remains unchanged.

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