Repository navigation
refactor(files): file reads and edits route by the file's owner - #27278
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to In the inspected paths, file operations use the file’s owner rather than the focused server, and unresolved image ownership does not trigger a local read. No actionable PR-introduced risk remains in the reviewed evidence; normal checks still apply. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
341ca995-e0ae-4c59-b18d-97e94db1d56c
📥 Commits
Reviewing files that changed from the base of the PR and between 5c7c493 and 6a6e097312cd0df6b99fba5d7ce19dc517fcc4f9.
📒 Files selected for processing (157)
config/focus-setting-read-baseline.txtconfig/owner-routing-baseline.txtconfig/scripts/check-owner-routing-ratchet.mjsconfig/scripts/check-owner-routing-ratchet.test.mjssrc/renderer/src/components/browser-pane/navigate/navigate-browser-page-url.tssrc/renderer/src/components/browser-pane/workspace-doc/doc-preview-document-actions.test.tssrc/renderer/src/components/editor/EditorPanel.tsxsrc/renderer/src/components/editor/ExternalFileChangeBanner.tsxsrc/renderer/src/components/editor/ExternalFileChangeCompareDialog.tsxsrc/renderer/src/components/editor/MarkdownPreview.image-access.test.tsxsrc/renderer/src/components/editor/MarkdownPreview.link-routing.interaction.test.tsxsrc/renderer/src/components/editor/MarkdownPreview.toc-visibility-gate.test.tsxsrc/renderer/src/components/editor/RichMarkdownEditor.tsxsrc/renderer/src/components/editor/csv/CsvPagedViewer.tsxsrc/renderer/src/components/editor/csv/csv-paged-preview.test.tssrc/renderer/src/components/editor/csv/useCsvPagedPreview.test.tsxsrc/renderer/src/components/editor/editor-dropped-file-open.escaping-link.test.tssrc/renderer/src/components/editor/editor-dropped-file-open.test.tssrc/renderer/src/components/editor/editor-dropped-file-open.tssrc/renderer/src/components/editor/editor-restored-tab-conflict-scan.tssrc/renderer/src/components/editor/markdown-document-list-request.test.tssrc/renderer/src/components/editor/markdown-document-list-request.tssrc/renderer/src/components/editor/markdown-preview-link-actions.tssrc/renderer/src/components/editor/markdown-preview-local-images.test.tssrc/renderer/src/components/editor/restored-editor-workspace-runtime-owner.test.tsxsrc/renderer/src/components/editor/rich-markdown-async-image-paste.test.tssrc/renderer/src/components/editor/rich-markdown-editor-click-routing.tssrc/renderer/src/components/editor/rich-markdown-editor-config.test.tssrc/renderer/src/components/editor/rich-markdown-editor-config.tssrc/renderer/src/components/editor/rich-markdown-image-context.tssrc/renderer/src/components/editor/rich-markdown-image-insert.tssrc/renderer/src/components/editor/rich-markdown-large-text-paste.selection.test.tssrc/renderer/src/components/editor/rich-markdown-paste-image.tssrc/renderer/src/components/editor/use-editor-group-file-drop-owner.remote.test.tsxsrc/renderer/src/components/editor/use-editor-group-file-drop-owner.test.tsxsrc/renderer/src/components/editor/use-markdown-preview-source-foundation.tssrc/renderer/src/components/editor/useEditorPanelContentState.test.tsxsrc/renderer/src/components/editor/useEditorPanelFileContentLoader.tssrc/renderer/src/components/editor/useEditorPanelRemoteSiblingContentState.test.tsxsrc/renderer/src/components/editor/useLocalImageSrc.test.tssrc/renderer/src/components/editor/useLocalImageSrc.tssrc/renderer/src/components/editor/useMarkdownDocuments.navigation.test.tssrc/renderer/src/components/editor/useMarkdownDocuments.ownership.test.tsxsrc/renderer/src/components/editor/useMarkdownDocuments.tssrc/renderer/src/components/editor/useMarkdownDocuments.watch.test.tssrc/renderer/src/components/editor/useRichMarkdownEditorInstance.test.tsxsrc/renderer/src/components/editor/useRichMarkdownProgrammaticSync.test.tssrc/renderer/src/components/editor/useRichMarkdownProgrammaticSync.tssrc/renderer/src/components/editor/useRichMarkdownReconcileRoundTrip.tssrc/renderer/src/components/floating-terminal/FloatingTerminalPanel.bounds.test.tsxsrc/renderer/src/components/floating-terminal/use-floating-terminal-create-actions.tssrc/renderer/src/components/native-chat/NativeChatAgentMessageRow.test.tsxsrc/renderer/src/components/native-chat/NativeChatImageAttachmentPreview.test.tsxsrc/renderer/src/components/native-chat/NativeChatImageAttachmentPreview.tsxsrc/renderer/src/components/native-chat/NativeChatTranscriptChrome.test.tsxsrc/renderer/src/components/native-chat/native-chat-file-link-existence.test.tssrc/renderer/src/components/native-chat/native-chat-file-link-existence.tssrc/renderer/src/components/native-chat/native-chat-image-runtime-context.test.tssrc/renderer/src/components/native-chat/native-chat-image-runtime-context.tssrc/renderer/src/components/quick-open-file-list-remote-catalog.react.test.tsxsrc/renderer/src/components/quick-open-file-list.react.test.tsxsrc/renderer/src/components/quick-open-file-list.tssrc/renderer/src/components/quick-open-file-navigation.test.tssrc/renderer/src/components/quick-open-file-navigation.tssrc/renderer/src/components/quick-open-recent-validation.test.tssrc/renderer/src/components/right-sidebar/FileExplorerRow.actions.test.tsxsrc/renderer/src/components/right-sidebar/file-explorer-deletion-editors.tssrc/renderer/src/components/right-sidebar/file-explorer-directory-listing.tssrc/renderer/src/components/right-sidebar/file-explorer-instant-dir-toggle.test.tssrc/renderer/src/components/right-sidebar/file-explorer-operation-generation.test.tssrc/renderer/src/components/right-sidebar/file-explorer-operation-owner.tssrc/renderer/src/components/right-sidebar/use-file-explorer-tree-pane-state.tssrc/renderer/src/components/right-sidebar/useFileDeletion.tssrc/renderer/src/components/right-sidebar/useFileDuplicate.tssrc/renderer/src/components/right-sidebar/useFileExplorerHandlers.tssrc/renderer/src/components/right-sidebar/useFileExplorerImport.remote.test.tsxsrc/renderer/src/components/right-sidebar/useFileExplorerImport.tssrc/renderer/src/components/right-sidebar/useFileExplorerInlineInput.tssrc/renderer/src/components/right-sidebar/useFileExplorerMoveDrop.tssrc/renderer/src/components/right-sidebar/useFileExplorerTree.tssrc/renderer/src/components/right-sidebar/useFileSearchPanel.lifecycle.test.tsxsrc/renderer/src/components/right-sidebar/useFileSearchRunner.test.tsxsrc/renderer/src/components/right-sidebar/useFileSearchRunner.tssrc/renderer/src/components/settings/McpConfigSection.host-owner.test.tsxsrc/renderer/src/components/settings/McpConfigSection.tsxsrc/renderer/src/components/settings/mcp-config-inspection.tssrc/renderer/src/components/tab-bar/tab-create-entry-action.test.tssrc/renderer/src/components/tab-bar/tab-create-entry-local-path.tssrc/renderer/src/components/terminal-pane/terminal-drop-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-runtime-catalog-owner.test.tssrc/renderer/src/components/terminal-pane/terminal-file-link-target.test.tssrc/renderer/src/components/terminal-pane/terminal-file-open-routing.tssrc/renderer/src/components/terminal-pane/terminal-file-path-mapping.tssrc/renderer/src/components/terminal-pane/terminal-host-workspace-file.tssrc/renderer/src/components/terminal-pane/terminal-link-remote-runtime-ssh-open.test.tssrc/renderer/src/components/terminal-pane/terminal-native-file-drop-destination.tssrc/renderer/src/components/terminal-pane/terminal-native-file-drop.tssrc/renderer/src/components/terminal-pane/terminal-pane-element-file-drop.test.tsxsrc/renderer/src/components/terminal-pane/terminal-path-existence-batch.test.tssrc/renderer/src/components/terminal-pane/terminal-path-existence-batch.tssrc/renderer/src/components/terminal-pane/terminal-worktree-path-link.test.tssrc/renderer/src/components/terminal-pane/terminal-worktree-path-link.tssrc/renderer/src/hooks/composer-state/attachment-drop-state.tssrc/renderer/src/hooks/editor-external-watch-disk-verification.tssrc/renderer/src/hooks/editor-runtime-file-watch.test.tssrc/renderer/src/hooks/editor-runtime-file-watch.tssrc/renderer/src/lib/create-untitled-markdown.test.tssrc/renderer/src/lib/create-untitled-markdown.tssrc/renderer/src/lib/default-creation-host.test.tssrc/renderer/src/lib/default-creation-host.tssrc/renderer/src/lib/editor-file-operation-owner.test.tssrc/renderer/src/lib/editor-file-operation-owner.tssrc/renderer/src/lib/execute-open-editor-path-move.test.tssrc/renderer/src/lib/file-search-result-owner.test.tssrc/renderer/src/lib/file-search-result-owner.tssrc/renderer/src/lib/floating-workspace-tab-creation.tssrc/renderer/src/lib/floating-workspace-terminal-actions.test.tssrc/renderer/src/lib/local-file-access.tssrc/renderer/src/lib/markdown-document-templates.test.tssrc/renderer/src/lib/markdown-document-templates.tssrc/renderer/src/lib/rename-file.tssrc/renderer/src/lib/resolve-owner.test.tssrc/renderer/src/lib/resolve-owner.tssrc/renderer/src/lib/user-opened-local-path.test.tssrc/renderer/src/lib/workspace-file-host-routing.tssrc/renderer/src/lib/worktree-runtime-owner.test.tssrc/renderer/src/lib/worktree-runtime-owner.tssrc/renderer/src/runtime/mobile-markdown-bridge.tssrc/renderer/src/runtime/remote-host-file-open-repro.test.tssrc/renderer/src/runtime/runtime-client-target.test.tssrc/renderer/src/runtime/runtime-client-target.tssrc/renderer/src/runtime/runtime-file-client-download.test.tssrc/renderer/src/runtime/runtime-file-client-external-import.test.tssrc/renderer/src/runtime/runtime-file-client-mutation-ownership.test.tssrc/renderer/src/runtime/runtime-file-client-search-listing.test.tssrc/renderer/src/runtime/runtime-file-client-types.tssrc/renderer/src/runtime/runtime-file-client-watch.test.tssrc/renderer/src/runtime/runtime-file-client.test.tssrc/renderer/src/runtime/runtime-file-import-client.tssrc/renderer/src/runtime/runtime-file-import-pairing-revision.test.tssrc/renderer/src/runtime/runtime-file-metadata-client.tssrc/renderer/src/runtime/runtime-file-mutation-client.tssrc/renderer/src/runtime/runtime-file-range-client.test.tssrc/renderer/src/runtime/runtime-file-range-client.tssrc/renderer/src/runtime/runtime-file-read-client.tssrc/renderer/src/runtime/runtime-file-routing.tssrc/renderer/src/runtime/runtime-file-search-client.tssrc/renderer/src/runtime/runtime-file-watch-client.tssrc/renderer/src/runtime/runtime-legacy-recent-freshness.test.tssrc/renderer/src/runtime/runtime-path-existence-batch.test.tssrc/renderer/src/runtime/runtime-path-existence-error-parity.test.tssrc/renderer/src/runtime/runtime-path-existence-pairing.test.tssrc/renderer/src/runtime/runtime-path-existence-queue-pairing.test.tssrc/renderer/src/runtime/runtime-quick-open-version-compatibility.test.tssrc/renderer/src/runtime/use-worktree-runtime-target.tssrc/renderer/src/store/slices/editor/actions/markdown-link-action.tssrc/renderer/src/store/slices/editor/actions/markdown-preview-actions.ts
💤 Files with no reviewable changes (3)
- src/renderer/src/components/editor/rich-markdown-editor-click-routing.ts
- config/owner-routing-baseline.txt
- src/renderer/src/components/terminal-pane/terminal-native-file-drop-destination.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.
| const SETTING_MEMBER_READ = | ||
| /\??\.\s*activeRuntimeEnvironmentId\b|(?<!(?:\b[A-Z][\w$]*|>)\s*)\[\s*['"]activeRuntimeEnvironmentId['"]\s*\]/g |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Exclude plain setting assignments from read counts.
If code assigns settings.activeRuntimeEnvironmentId = id, SETTING_MEMBER_READ counts the assignment as a read. A new setting write can therefore fail the focus-setting ratchet without adding a focus read. Exclude plain = assignments for both member and element access, while retaining compound assignments that read the old value.
| const SETTING_DESTRUCTURE_READ = | ||
| /\{[^{}]*\bactiveRuntimeEnvironmentId\b[^{}]*\}(?:\s*\})*\s*(?::[^=;{}]*)?=(?![=>])/g |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Count parenthesized destructuring assignments.
If code uses ({ activeRuntimeEnvironmentId } = settings), the ) between } and = prevents a match. The ratchet then accepts a new setting read without counting it. Cover this assignment form and add a matching test.
| for (const { name, exported, text: body } of topLevelDeclarations( | ||
| text.replace(IMPORT_EXPORT_LIST, '') | ||
| )) { | ||
| seedUse.lastIndex = 0 | ||
| if (exported && (countSettingReads(body) > 0 || seedUse.test(body))) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Discover readers exported in a separate statement.
If a file declares function selectHost(settings) { return settings.activeRuntimeEnvironmentId } and later uses export { selectHost }, exported remains false. Calls to selectHost in other renderer files then contribute zero to their focus-setting counts. Resolve local export lists when building the reader set, and test a separately exported reader.
f3d000a to
283c2aa
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:
493aad20-fa59-4595-ae8f-9c7601213099
📥 Commits
Reviewing files that changed from the base of the PR and between 6a6e097312cd0df6b99fba5d7ce19dc517fcc4f9 and 283c2aafd3c8378c0cea6a6a1ba88ed00fe88329.
📒 Files selected for processing (38)
config/focus-setting-read-baseline.txtsrc/renderer/src/components/browser-pane/navigate/navigate-browser-page-url.tssrc/renderer/src/components/browser-pane/workspace-doc/doc-preview-document-actions.test.tssrc/renderer/src/components/editor/EditorPanel.tsxsrc/renderer/src/components/editor/ExternalFileChangeBanner.tsxsrc/renderer/src/components/editor/ExternalFileChangeCompareDialog.tsxsrc/renderer/src/components/editor/MarkdownPreview.image-access.test.tsxsrc/renderer/src/components/editor/MarkdownPreview.link-routing.interaction.test.tsxsrc/renderer/src/components/editor/MarkdownPreview.toc-visibility-gate.test.tsxsrc/renderer/src/components/editor/editor-dropped-file-open.escaping-link.test.tssrc/renderer/src/components/editor/editor-dropped-file-open.test.tssrc/renderer/src/components/editor/editor-dropped-file-open.tssrc/renderer/src/components/editor/editor-restored-tab-conflict-scan.tssrc/renderer/src/components/editor/markdown-preview-link-actions.tssrc/renderer/src/components/editor/markdown-preview-local-images.tssrc/renderer/src/components/editor/rich-markdown-editor-config.tssrc/renderer/src/components/editor/rich-markdown-extensions.tssrc/renderer/src/components/editor/rich-markdown-image-context.test.tssrc/renderer/src/components/editor/rich-markdown-image-context.tssrc/renderer/src/components/editor/rich-markdown-image-insert.tssrc/renderer/src/components/editor/rich-markdown-paste-image.tssrc/renderer/src/components/editor/use-editor-group-file-drop-owner.test.tsxsrc/renderer/src/components/editor/use-markdown-preview-source-foundation.tssrc/renderer/src/components/editor/useEditorPanelContentState.test.tsxsrc/renderer/src/components/editor/useEditorPanelFileContentLoader.tssrc/renderer/src/components/editor/useEditorPanelRemoteSiblingContentState.test.tsxsrc/renderer/src/components/editor/useMarkdownDocuments.navigation.test.tssrc/renderer/src/components/editor/useMarkdownDocuments.tssrc/renderer/src/components/editor/useMarkdownDocuments.watch.test.tssrc/renderer/src/components/editor/useRichMarkdownProgrammaticSync.tssrc/renderer/src/components/terminal-pane/terminal-file-path-mapping.tssrc/renderer/src/lib/file-owner-runtime-target.test.tssrc/renderer/src/lib/file-owner-runtime-target.tssrc/renderer/src/lib/local-file-access.tssrc/renderer/src/lib/workspace-file-host-routing.tssrc/renderer/src/runtime/mobile-markdown-bridge.tssrc/renderer/src/runtime/runtime-client-target.tssrc/renderer/src/runtime/use-worktree-runtime-target.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The runtime file clients took a settings object and turned its Active Server field into a connection, so any caller that passed raw settings silently read or wrote on the focused server. They now take `target: RuntimeClientTarget`, and every caller derives it from the owner: the tab's stamped owner, else its worktree's owner (getRuntimeTargetForFileOwner / getRuntimeTargetForWorktreeOwner), the file-explorer operation owner, or an already captured owner id. Behavior: single-host (local-only) users see no change. An editor tab opened without an owner stamp, a terminal link with no PTY owner, an OS file drop and a notebook link now go to the workspace's owner instead of whichever server is focused when the read happens. Removes getEditorFileDropSettingsForWorktree and the native-chat settings clone cache; settingsForWorktreeOperationRoute loses its editor caller.
…server getRuntimeTargetForWorktreeOwner/getRuntimeTargetForFileOwner move to lib/file-owner-runtime-target.ts and resolve through the focus-free resolveOwner. A workspace with no row yet stays on this app (tabs and drops stamp a server owner when one exists); rows that disagree return null, and callers with an error path refuse via requireRuntimeTargetForFileOwner.
A null owner target became runtimeContext undefined, which image readers take as a plain local file, so a server-owned document's images were read from this machine. It is now runtimeContext null, the readers' do-not-load sentinel, in the rich editor and the preview, and prewarm skips it.
edfb648 to
7a7daa9
Compare
ELI5
When Orca reads, saves, lists or searches a file on a remote server, it has to pick which machine to ask. Until now the file code asked the machine named by the "Active Server" setting, and trusted each caller to swap in the right one first. Most callers did, but some didn't. Now the file code is given the machine that owns the file, and it can no longer be handed the setting by mistake.
Builds on #27275 (merged), which added the shared helpers and the focus-read lint counter.
What Changed
Before (user): if you had more than one host, a few file paths followed whichever server was focused when the action ran, not the workspace the file belongs to:
Switching the Active Server could make those read the same path on the wrong machine.
After (user): each of these goes to the file's own host: the owner stamped on the tab, or else the workspace's owner, worked out from the rows alone. A row from before owner stamping now counts as this computer, even while a single saved server is focused. If the rows disagree about the owner, the action refuses with "Couldn't verify which host owns this file" instead of guessing. Single-host (local-only) users see no change.
Mechanism:
RuntimeFileReadArgsandRuntimeFileOperationArgsreplacesettingswithtarget: RuntimeClientTarget. The read, range, search, watch, metadata, import and mutation clients, andruntime-file-routing, readcontext.targetdirectly.getRuntimeFileReadScopetakes a target, so cache and dedupe keys keep the same strings.lib/file-owner-runtime-target.tswithgetRuntimeTargetForWorktreeOwner,getRuntimeTargetForFileOwnerandrequireRuntimeTargetForFileOwner. They read the tab's stamped owner first, else the foundation's focus-freeruntimeTargetForWorkspaceOwner(resolveOwner). The cases are:null. Callers with an error path refuse. Render paths treat it as "not this computer": editor and preview images get the readers' do-not-load context (runtimeContext: null, neverundefined, which would read the image from this machine), and the rename folder picker and client-side file checks are turned off.useFileOwnerRuntimeTargetis the hook version, with a value that stays stable across renders.getEditorFileOperationContext, native-chat image contexts, quick-open, MCP config, terminal drops, and the composer attachment upload.runtimeTargetin place of the whole settings object.getEditorFileDropSettingsForWorktreeand the native-chat "settings clone" cache.createFileSearchResultOwnernow takes the owner id.createUntitledMarkdownFiletakes a target.Why
Requiring a target means a raw settings object no longer compiles at a file call site. This is why the remaining wrong-host paths came to light; they would have stayed hidden otherwise.
Alternatives considered:
worktreeIditself. Worktree ids can repeat across hosts, and callers often already hold the exact owner, so this would sometimes pick a different host than the caller meant.This PR changes about 1,450 lines; I kept it as one PR on purpose. Changing the type forces every caller to change at the same time, so it cannot be split into PRs that each still compile. About 690 of those lines are tests, almost all one-for-one
settings: {...}→target: {...}swaps.Linked Issue
None. This is part of the host-ownership routing stack (D4 G1, files area).
Visual Proof
N/A. Routing only; nothing on screen changes. The machine is load-capped, so the app wasn't launched.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
file-owner-runtime-target.test.ts:getRuntimeEnvironmentIdForWorktreeanswersfocused-envfor that same state.null, andrequireRuntimeTargetForFileOwnerthrows.rich-markdown-image-context.test.ts: when the document's owner can't be resolved, image loading and preloading never callwindow.api.fs.readFile.terminal-link-remote-runtime-ssh-open.test.ts: the test that expected a terminal link to follow the focused server now gives the workspace an owner (env-1) and focuses a different server (env-2). The link is read fromenv-1.editor-dropped-file-open.test.ts: drops follow the worktree owner, not focus.All other test edits update fixtures and assertions from
settingstotarget, with no change in what they check.Ran:
pnpm tc:web,oxlint,oxfmt,pnpm run check:code-quality:changed, andpnpm check:owner-routing-ratchet(both OK). Also ranpnpm testover editor, right-sidebar, terminal-pane, runtime, native-chat, tab-bar, hooks, editor slice, browser-pane, floating-terminal, lib, settings, quick-open, store, sidebar, automations, agent, status-bar and web: about 36,600 tests pass. The one failure isai-vault-session-worktree-map"builds the map at scale", a timing bound (208ms vs 150ms) that broke because the machine was loaded. It passes when run alone.Review
Agent skill upstream boundary
Notes
No wire change; renderer only. Direct SSH still goes through this app with
connectionId. Folder workspaces resolve through the same owner resolver as before (getRuntimeEnvironmentIdForWorktreehandlesfolder:keys). Windows path handling is unchanged.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)