Repository navigation
fix(renderer): host writes route only through the strict owner, and twin projections stay on their host (review-5 #2 #9 #11) - #30890
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e3fad371-100d-4dc9-bd42-e9148c06564c
📒 Files selected for processing: 19
config/id-only-store-write-baseline.txtconfig/scripts/check-id-only-store-write-ratchet.mjsconfig/scripts/check-id-only-store-write-ratchet.test.mjssrc/renderer/src/components/right-sidebar/file-explorer-operation-owner.test.tssrc/renderer/src/components/right-sidebar/file-explorer-operation-owner.tssrc/renderer/src/components/right-sidebar/useFileExplorerWatch.test.tssrc/renderer/src/lib/editor-file-operation-owner.tssrc/renderer/src/lib/resolve-owner.tssrc/renderer/src/lib/ssh-mutation-expectation.tssrc/renderer/src/lib/terminal-worktree-route.tssrc/renderer/src/lib/workspace-terminal-host-authority.tssrc/renderer/src/lib/worktree-operation-route.test.tssrc/renderer/src/lib/worktree-operation-route.tssrc/renderer/src/lib/worktree-row-open-in-owner.tssrc/renderer/src/store/slices/worktrees/host-scoped-row-merges.test.tssrc/renderer/src/store/slices/worktrees/listing/worktree-owner-target.tssrc/renderer/src/store/slices/worktrees/listing/worktree-slice-types.tssrc/renderer/src/store/slices/worktrees/metadata/worktree-lineage-actions.tssrc/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/ |
There was a problem hiding this comment.
🎯 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/ |
There was a problem hiding this comment.
🎯 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).
… destructured ids
…pos; editor focus fallback left for a follow-up
d76ce06 to
a1650f2
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3740b8cd-d0ea-4639-a865-85397162cbbb
📒 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.
| : { kind: 'unresolved' } | ||
| } | ||
| if (match.kind === 'resolved' && match.owner.endpoint.kind === 'environment') { | ||
| return operationOwnerFromAuthority(match.owner) | ||
| } | ||
| return thisAppFolderOwner(state, worktreeId) |
There was a problem hiding this comment.
🗄️ 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.tsRepository: 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.tsRepository: 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 1Repository: 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.tsRepository: 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.
| : { 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) |
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).
ssh:boxworkspace, and this desktop also connects toboxdirectly. 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 (resolveSelectedHostRouteinworktree-operation-route.ts) now returnsambiguousfor 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.resolveOwner's full {server, place} pair, so the write expectsssh:ton server E, which is what the server checks.worktreeMatchesHost).captureWorktreeSshMutationExpectation(editor file drops) now builds its expected host fromresolveOwner'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.findSetupRepomatches 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 insrc/main/persistencethat 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 byprojectId, andgetConnectionIdForWorktree. 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 flagsupdateProjectHostSetup.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 becauseresolveOwneralready 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.
worktreeLineageByIdandworkspaceLineageByChildKeyare 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?.findand destructured ids, fixed; (3) a server git worktree whose only SSH evidence is the repo row now expectsssh: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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)