Skip to content

fix(renderer): host writes route only through the strict owner, and twin projections stay on their host (review-5 #2 #9 #11) - #30890

Merged
nwparker merged 4 commits into
mainfrom
nwparker/review5-owner-routes
Oct 20, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/review5-owner-routes

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​127 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​120
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​216 $\color{#cf222e}{\Huge{\mathbf{−}}}$​160 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​56

ELI5

The same workspace can show up from more than one machine at once: on this computer, on a paired Orca server, or on an SSH machine that a server reaches for you. Some actions picked which machine to act on by the workspace's name alone, or by an older, looser lookup. When two machines shared a name, the action could land on the wrong one. Now every write asks one strict question, "which machine owns this, for certain?", and refuses when the answer isn't certain.

What Changed

Codex review 5, items #2, #9, #11 (and #10's bug shape, now blocked by a lint ratchet).

  • Fix Ctrl+Backspace not deleting word in terminal #2 (P1) File Explorer could delete through the wrong SSH connection. Before: two paired servers both publish the same ssh:box workspace, and this desktop also connects to box directly. File Explorer saw "two servers, can't tell which", dropped the server part of the route, and sent the delete over the desktop's own direct SSH connection. After: the delete refuses with "Couldn't determine which host owns this workspace". Mechanism: the one function that resolves a selected host (resolveSelectedHostRoute in worktree-operation-route.ts) now returns ambiguous for rival servers instead of a route with no server. The separate "strict" copy of that function is gone: every caller (file operations, deletes, terminals, open-in-owner) now gets the same strict answer.
  • Fix useEffect anti-patterns across renderer #9 (P2) File Explorer writes failed in a server folder that lives on an SSH machine. Before: the owner "server E, SSH machine t" was reduced to "server E, local", so create, rename and delete failed with "Workspace host changed". After: File Explorer builds its owner from resolveOwner's full {server, place} pair, so the write expects ssh:t on server E, which is what the server checks.
  • Capitalize app name to Orca for desktop installs #11 (P2) Changing a local workspace's parent also changed its twin on a server. Before: the local update rewrote every row with that id, including the server copy's parent and its parent's child list. After: the update carries the host it was written on and touches only rows on that host (worktreeMatchesHost).
  • SSH write expectations come from the same owner. captureWorktreeSshMutationExpectation (editor file drops) now builds its expected host from resolveOwner's pair, not from the looser route plus a host-blind connection lookup. A folder this app owns still reads its host from its repos (the rule main shares), exactly as before.
  • Add card gap and quick-create in worktree dialog #10 (P2) is already fixed on main by fix(projects): setup edits and removals name the host, so the twin on another host is never touched #30664 (findSetupRepo matches id AND host). This PR adds a guard so the bug can't come back: the existing id-only-store-write ratchet now also flags repo-row lookups in src/main/persistence that match by id alone (repos.find((r) => r.id === x) with no host in the predicate). Four existing lookups are recorded in the baseline: getRepo, automation create/update by projectId, and getConnectionIdForWorktree. Entries can only be removed. Against the pre-fix(projects): setup edits and removals name the host, so the twin on another host is never touched #30664 file, the ratchet flags updateProjectHostSetup.

Why

The review found one bug class: a write chooses its target from a lenient route. Patching each call site would leave the lenient route available for the next one. This change makes the strict answer the only one: the selected-host resolver can no longer give a route without a server for a contested host, and File Explorer and SSH expectations read resolveOwner, which already returns the full pair. Alternatives considered: (1) a strict check added only in File Explorer, rejected because deletes and terminals kept the lenient path; (2) a new write-route resolver, rejected because resolveOwner already exists and the task forbids adding a parallel system.

Known limits and follow-ups: the editor's file-owner provenance still uses the looser route (including server focus for rows with no host); several editor tests depend on it, so it is left for a separate change. worktreeLineageById and workspaceLineageByChildKey are keyed by id, so a local lineage write still replaces that id's map entry; the per-host lineage refresh reconciles it. Worktree removal with no named host still uses the owner resolver that falls back to server focus for unstamped rows.

Linked Issue

Codex review 5 items #2, #9, #10, #11 (no GitHub issue).

Visual Proof

N/A: routing and refusal logic only. The only visible effect is an existing error toast in a twin-host setup.

Testing

  • New tests fail on main and pass here: file-explorer-operation-owner.test.ts (Fix Ctrl+Backspace not deleting word in terminal #2, Fix useEffect anti-patterns across renderer #9), host-scoped-row-merges.test.ts (Capitalize app name to Orca for desktop installs #11), check-id-only-store-write-ratchet.test.mjs (lookup ratchet).

  • Updated two tests that encoded the old behavior: "drops the HUB transport" now expects ambiguous, and "uses the active runtime for legacy unowned active worktrees" now expects no focus routing.

  • Run locally, single worker: src/renderer/src/{store,components,lib,hooks,runtime} (43,766 tests passed), pnpm tc, pnpm lint (includes every ratchet), pnpm run check:code-quality:changed, the type-aware oxlint, and the Zustand fan-out check.

  • Verified only in tests: no live two-server SSH setup was run.

  • I manually tested these changes locally

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

AI Disclosure

Review

Codex (gpt-6.1-sol, high) on the final head: no findings. Independent Opus review: no P0-P2 findings. Its P3 notes: (1) a stale comment, fixed; (2) the ratchet missed repos?.find and destructured ids, fixed; (3) a server git worktree whose only SSH evidence is the repo row now expects ssh:X, and writes need that server's SSH state for X. Kept deliberately: the server checks the expectation, so the write still refuses rather than landing on the wrong host. (4) Removing a row that two servers publish on the same SSH target now refuses. That is correct, but the UI has no way to pick one server's copy (follow-up). The wider local run found two regressions in the first revision: inferred-SSH folders, and editor tests that relied on server focus. Both were fixed or reverted before review.

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

SSH: every change makes a contested host refuse rather than guess. Nothing changes on the wire. Folder workspaces are covered (#9). Cross-platform: no platform code.

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 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The persistence ratchet now detects repo-row lookups that compare IDs without matching a host. Worktree routing can preserve ambiguous and missing results, and owner resolution uses host-aware routes. Lineage update results carry a host ID, which scopes local row projection and remote replacement.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to a1650

A file operation selected for the local host can instead run on a remote host. Correct that routing before merging; the persistence lookup check also has two unresolved coverage gaps.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 18 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 identifies the main changes: strict host-owner routing for renderer writes and host-scoped twin projections. The review references add noise but do not make the title unclear.
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.
Description check Passed The description follows the required structure and clearly explains the user impact, implementation, rationale, testing, known limits, and checklist status. The Linked Issue section does not provide a…
Full details: Description check

Explanation

The description follows the required structure and clearly explains the user impact, implementation, rationale, testing, known limits, and checklist status. The Linked Issue section does not provide an actual issue reference, but the rest of the description is complete and directly relevant.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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: e3fad371-100d-4dc9-bd42-e9148c06564c
📥 Commits

Reviewing files that changed from the base of the PR and between a201eac and d76ce06.

📒 Files selected for processing: 19
  • config/id-only-store-write-baseline.txt
  • config/scripts/check-id-only-store-write-ratchet.mjs
  • config/scripts/check-id-only-store-write-ratchet.test.mjs
  • src/renderer/src/components/right-sidebar/file-explorer-operation-owner.test.ts
  • src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerWatch.test.ts
  • src/renderer/src/lib/editor-file-operation-owner.ts
  • src/renderer/src/lib/resolve-owner.ts
  • src/renderer/src/lib/ssh-mutation-expectation.ts
  • src/renderer/src/lib/terminal-worktree-route.ts
  • src/renderer/src/lib/workspace-terminal-host-authority.ts
  • src/renderer/src/lib/worktree-operation-route.test.ts
  • src/renderer/src/lib/worktree-operation-route.ts
  • src/renderer/src/lib/worktree-row-open-in-owner.ts
  • src/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.ts
  • src/renderer/src/store/slices/worktrees/listing/worktree-owner-target.ts
  • src/renderer/src/store/slices/worktrees/listing/worktree-slice-types.ts
  • src/renderer/src/store/slices/worktrees/metadata/worktree-lineage-actions.ts
  • src/renderer/src/store/slices/worktrees/metadata/worktree-lineage-refresh.ts

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

const LOOKUP_ROOT = 'src/main/persistence/'
const REPO_ROW_LOOKUP = /\brepos\s*\??\.\s*(?:find|findIndex|findLast|findLastIndex)\s*\(/g
// A predicate that names a host (or compares whole rows' host ids) is host-scoped.
const HOST_SCOPED_PREDICATE = /host|Host|connectionId/

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

Require a host comparison before excluding a lookup.

If a predicate is repo.id === hostTarget.repoId, HOST_SCOPED_PREDICATE matches hostTarget. The detector then accepts the lookup even though it never compares the row’s host. Check for a comparison involving the row’s host instead of checking for host-related text anywhere in the predicate.

const REPO_ROW_LOOKUP = /\brepos\s*\??\.\s*(?:find|findIndex|findLast|findLastIndex)\s*\(/g
// A predicate that names a host (or compares whole rows' host ids) is host-scoped.
const HOST_SCOPED_PREDICATE = /host|Host|connectionId/
const ID_COMPARISON = /\bid\s*===|===\s*(?:[\w.]*\.)?id\b/

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

Detect aliases of destructured row IDs.

If a lookup uses repos.find(({ id: candidateId }) => candidateId === repoId), ID_COMPARISON finds no id comparison. The ratchet silently accepts this ID-only lookup. Resolve an id alias in the predicate before testing the comparison, and add that form to the fixture.

…win projections stay on their host (review-5 #2 #9 #11)

A selected ssh: host that two paired servers proxy now resolves ambiguous at the one
selected-host resolver, so no caller can fall back to this app's own SSH connection.
File Explorer and SSH mutation expectations derive the full {endpoint, place} pair from
resolveOwner, so a server folder's nested SSH target stays the write's host. A local
lineage write projects onto its own host's rows only. The id-only store-write ratchet
now also covers persistence repo-row lookups by id alone (review-5 #10's shape).
…pos; editor focus fallback left for a follow-up
@nwparker
nwparker force-pushed the nwparker/review5-owner-routes branch from d76ce06 to a1650f2 Compare October 19, 2026 22:45

@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: Advanced
  • Run ID: 3740b8cd-d0ea-4639-a865-85397162cbbb
📥 Commits

Reviewing files that changed from the base of the PR and between d76ce06 and a1650f2.

📒 Files selected for processing: 1
  • src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts

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

Comment on lines +64 to +69
: { kind: 'unresolved' }
}
if (match.kind === 'resolved' && match.owner.endpoint.kind === 'environment') {
return operationOwnerFromAuthority(match.owner)
}
return thisAppFolderOwner(state, worktreeId)

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '42,120p' src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts
sed -n '130,225p' src/renderer/src/components/right-sidebar/file-explorer-operation-owner.test.ts
rg -n 'getFileExplorerOperationOwnerFromState|selectedHost|hostId|thisAppFolderOwner' src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts src/renderer/src/components/right-sidebar/file-explorer-operation-owner.test.ts src/renderer/src/lib/resolve-owner.ts

Repository: stablyai/orca

Length of output: 6573


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- owner callers and mutation routes ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'getFileExplorerOperationOwner(' -e 'getFileExplorerOperationRoute(' -e 'getFileExplorerOperationOwnerFromState(' -e 'activeWorktreeId' -e 'folderWorkspaces' src/renderer/src | head -n 240
printf '%s\n' '--- folder selection/state producers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'setActiveWorktree' -e 'setActiveWorkspace' -e 'activeWorkspaceId' -e 'folderWorkspace' -e 'FolderWorkspace' src/renderer/src src/shared | head -n 300
printf '%s\n' '--- relevant tests and helpers ---'
sed -n '1,180p' src/renderer/src/components/right-sidebar/file-explorer-operation-owner.test.ts
printf '%s\n' '--- changed diff ---'
git diff --no-ext-diff --unified=35 209e468a7cc4265e6c5b8f122a1952877551a7de a1650f24feca6642f14575950609efff5f4d2af6 -- src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts src/renderer/src/components/right-sidebar/file-explorer-operation-owner.test.ts

Repository: stablyai/orca

Length of output: 42137


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- resolveOwner host selection ---'
sed -n '80,165p' src/renderer/src/lib/resolve-owner.ts
sed -n '200,245p' src/renderer/src/lib/resolve-owner.ts
printf '%s\n' '--- folder catalog merge and active selection handling ---'
sed -n '120,255p' src/renderer/src/store/folder-workspaces/folder-workspace-catalog.ts
sed -n '1,155p' src/renderer/src/store/folder-workspaces/folder-workspace-catalog-actions.ts
sed -n '100,155p' src/renderer/src/store/folder-workspaces/folder-workspace-mutations.ts
printf '%s\n' '--- exact File Explorer operation consumers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'getFileExplorerOperationOwner' -e 'getFileExplorerOperationRoute' -e 'getFileExplorerOperationExecutionHostId' -e 'getFileExplorerOperationGuard' src/renderer/src --glob '!**/*test*' || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 22402


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- folder route resolution for a named host ---'
rg -n -F -e 'resolveWorktreeOperationRouteResultForHost' -e 'function resolveWorktreeOperationRouteResultForHost' src/renderer/src/lib/worktree-operation-route.ts
sed -n '150,235p' src/renderer/src/lib/worktree-operation-route.ts
sed -n '330,410p' src/renderer/src/lib/worktree-operation-route.ts
printf '%s\n' '--- representative File Explorer mutation consumer ---'
sed -n '1,125p' src/renderer/src/lib/rename-file.ts
sed -n '1,90p' src/renderer/src/components/right-sidebar/file-explorer-directory-listing.ts
sed -n '65,105p' src/renderer/src/components/right-sidebar/useFileExplorerInlineInput.ts

Repository: stablyai/orca

Length of output: 13462


Use the resolved self/local owner for folder workspaces.

When the active selection names local, resolveOwner can return resolved self/local without a local catalog row. If only a remote folder row remains, the current branch calls thisAppFolderOwner, which can read that row's SSH connection and return an SSH owner. renameFileOnDisk then sends the mutation through that SSH route.

Suggested fix
-  if (match.kind === 'resolved' && match.owner.endpoint.kind === 'environment') {
+  if (match.kind === 'resolved') {
     return operationOwnerFromAuthority(match.owner)
   }
   return thisAppFolderOwner(state, worktreeId)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
: { kind: 'unresolved' }
}
if (match.kind === 'resolved' && match.owner.endpoint.kind === 'environment') {
return operationOwnerFromAuthority(match.owner)
}
return thisAppFolderOwner(state, worktreeId)
: { kind: 'unresolved' }
}
if (match.kind === 'resolved') {
return operationOwnerFromAuthority(match.owner)
}
return thisAppFolderOwner(state, worktreeId)

@nwparker
nwparker merged commit d42e6e0 into main Oct 20, 2026
93 of 95 checks passed
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