Skip to content

Fix remote File Explorer opening files via local fs:readFile (#6440) - #6562

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-6440
Jun 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-6440

Conversation

@nwparker

@nwparker nwparker commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

🧑‍🤝‍🧑 Impact & ELI5

1) What's broken today (ELI5). If you connect Orca to a remote machine (a "paired runtime" — for example a server you SSH into) and then click a file in that remote project's File Explorer, the editor often just shows "Unable to load file." Clicking "Retry" does nothing — it keeps failing the same way. Orca is mistakenly trying to read the file from your own laptop's disk instead of from the remote machine where the file actually lives, so it hits a permission wall ("Access denied: path resolves outside allowed directories"). This affects people working against remote/headless runtimes; it doesn't hit purely-local users. For those who do use remote runtimes, it's a hard blocker on a basic action — opening a file to look at it.

2) What this PR does (ELI5). Think of every open file as a package that needs a "return address" saying which machine it came from. The File Explorer was sending files off with the address left blank, so Orca guessed — and often guessed "the laptop," which was wrong for remote files. This PR makes the File Explorer write the correct return address (the remote runtime that owns the file) right on the package when you click it. Now the editor knows to fetch the file over the remote connection instead of the local disk. For files that really are local, it stamps an explicit "this one is genuinely local" flag so Orca won't accidentally re-route it to whatever remote machine happens to be focused. Oh, so it now reads remote files from the remote machine instead of silently looking on your laptop and failing.

3) Tradeoffs / regressions — honest answer. No regressions — nothing is disabled, no new setup, no behavior is lost. The change is one extra piece of information ("which machine owns this file") passed along an existing call; no GPU flag, fast path, or feature is turned off, and there are no new network calls, watchers, or polling. There is one subtle behavior correction worth naming honestly: for a local worktree, the old code would fall back to "whatever runtime is currently focused" when the owner was blank, which could route a local file's read to a focused remote runtime. This PR now marks local opens as explicitly local so they stay local. That is strictly the intended behavior (the old fallback was the bug), and it mirrors the already-shipped drag-and-drop and mobile file-open paths, so it's consistent rather than a new special case. Net: remote-runtime users gain a working file open/retry; local users are unaffected.


Summary

Fixes #6440.

Opening a file from the File Explorer of a remote-runtime-owned worktree created the editor tab without a runtimeEnvironmentId. In store.openFile, an absent owner falls back to the ambient settings.activeRuntimeEnvironmentId, which is fragile: a tab for a remote worktree could be created with no/incorrect owner. The editor read path (useEditorPanelContentState -> settingsForRuntimeOwner -> readRuntimeFileContent) then routed through local fs:readFile and failed with Access denied: path resolves outside allowed directories. Retry reloaded the same tab and repeated the identical local read.

This change passes the worktree-owned runtime owner (getRuntimeEnvironmentIdForWorktree) when opening files from File Explorer (row click/keyboard activation and inline file creation), mirroring the existing useGlobalFileDrop and mobile file-open patterns. Explicit local opens pass suppressActiveRuntimeFallback: true so they stay local and are not retargeted to a focused runtime. Editor tabs now route through runtime file RPC, and Retry reuses the same owner.

This PR supersedes community PR #6506 (the original author is credited via Co-authored-by). #6506 is left open for the maintainers to close.

Screenshots

No visual change. This is a renderer-only logic fix to file-open owner routing.

Testing

  • pnpm lint (oxlint on changed files — clean)
  • pnpm typecheck (tsgo -p config/tsconfig.tc.web.json — exit 0)
  • pnpm test — targeted suites pass: useFileExplorerHandlers.test.ts, file-explorer-drag-scroll-marker.test.tsx (9 tests), plus editor.test.ts + useEditorPanelContentState.test.tsx (166 tests) as regression coverage for the read path
  • pnpm build — not run locally; CI will verify
  • Added/updated high-quality tests: new useFileExplorerHandlers case asserts a local file open emits runtimeEnvironmentId: undefined with suppressActiveRuntimeFallback: true; the symlink case now asserts the owner is stamped and suppressActiveRuntimeFallback: false

Electron verification: A full UI repro requires pairing a real remote/headless runtime (orca://pair), which was infeasible in this environment (no runtime environments present; all repos are local). Instead I verified the exact store.openFile owner-stamping contract over CDP against the running app, proving the three cases the fix depends on (see PR comment for output): a stamped remote owner is preserved on the tab; an explicit local open with suppressActiveRuntimeFallback stays local; and the old no-owner path inherits the ambient focused runtime (the buggy behavior this fix avoids).

AI Review Report

Reviewed adversarially as an adopted community contribution (assumed the original author could be malicious) and against AGENTS.md.

  • Cross-platform (macOS / Linux / Windows): Renderer-only TypeScript in File Explorer open paths. No keyboard shortcuts, menu accelerators, shell spawning, or path-separator assumptions added or changed. Platform-neutral.
  • SSH / remote / local: This is the core of the fix. Remote-runtime-owned worktrees now propagate their owner; local worktrees pass runtimeEnvironmentId: null with suppressActiveRuntimeFallback: true, preserving explicit local reads and avoiding retarget to a merely focused runtime.
  • Git provider compatibility: No source-control/provider logic touched.
  • Performance: One extra argument on existing openFile calls; no new watchers, polling, or IPC.
  • Consistency: Mirrors the established useGlobalFileDrop runtime-owner propagation pattern (runtimeEnvironmentId ?? undefined + suppressActiveRuntimeFallback: runtimeEnvironmentId === null).

Security Audit

  • Dependencies: None added.
  • Path handling: No new path construction; uses existing tree node paths and the already-computed inline-create fullPath. No path-traversal surface introduced.
  • IPC / auth: Routes reads through the existing runtime file RPC when an owner is set instead of incorrectly hitting local fs:readFile. This narrows cross-boundary reads rather than widening access.
  • Input / execution / secrets: No eval, no shell, no secret access, no network. The runtimeEnvironmentId originates from trusted store-derived owner functions, not user input.

No follow-up security work identified.

Notes

Made with Orca 🐋

File Explorer row activation and inline file creation opened editor tabs
without a runtimeEnvironmentId. In store.openFile, an absent owner falls
back to the ambient settings.activeRuntimeEnvironmentId, so a tab for a
remote-runtime-owned worktree could be created with no/incorrect owner.
The editor read path then routed through local fs:readFile and failed
with "Access denied: path resolves outside allowed directories"; Retry
reloaded the same tab and repeated the identical local read.

Pass the worktree-owned runtime owner (getRuntimeEnvironmentIdForWorktree)
when opening from File Explorer, mirroring the existing useGlobalFileDrop
and mobile file-open patterns. Explicit local opens pass
suppressActiveRuntimeFallback so they are not retargeted to a focused
runtime. This fixes both the initial load and Retry.

Supersedes community PR #6506.

Fixes #6440

Co-authored-by: Utkarsh Parekh <145644114+utkarshparekh@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 15 minutes and 25 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 76f32a76-647e-4c12-9a27-57c9e8fd4db3

📥 Commits

Reviewing files that changed from the base of the PR and between 5712cf9 and 235a22e.

📒 Files selected for processing (5)
  • src/renderer/src/components/right-sidebar/FileExplorer.tsx
  • src/renderer/src/components/right-sidebar/file-explorer-drag-scroll-marker.test.tsx
  • src/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerHandlers.ts
  • src/renderer/src/components/right-sidebar/useFileExplorerInlineInput.ts

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.

@nwparker

Copy link
Copy Markdown
Contributor Author

Verification evidence

Unit tests (vitest)

./node_modules/.bin/vitest run --config config/vitest.config.ts src/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.ts src/renderer/src/components/right-sidebar/file-explorer-drag-scroll-marker.test.tsx

 Test Files  2 passed (2)
      Tests  9 passed (9)

Regression coverage for the read path:

./node_modules/.bin/vitest run --config config/vitest.config.ts src/renderer/src/store/slices/editor.test.ts src/renderer/src/components/editor/useEditorPanelContentState.test.tsx

 Test Files  2 passed (2)
      Tests  166 passed (166)

The new useFileExplorerHandlers test asserts the exact openFile arguments:

  • Local open (no runtime owner): runtimeEnvironmentId: undefined + { preview: true, suppressActiveRuntimeFallback: true }
  • Symlink/remote-owned open: runtimeEnvironmentId: 'runtime-env-1' + { preview: true, suppressActiveRuntimeFallback: false }

Lint / typecheck

  • oxlint on the 5 changed files: clean (no output)
  • tsgo --noEmit -p config/tsconfig.tc.web.json: exit 0

Store-level CDP proof of the fix contract

A full UI repro needs a paired remote runtime (orca://pair), which was not available in this environment. I instead drove the live store.openFile action over CDP to prove the owner-stamping contract that the File Explorer change feeds, with an ambient focused runtime (ambient-focused-runtime) set:

caseA_remoteOwner   -> "owner-runtime-A"          (remote owner stamped; routes via runtime RPC — the fix)
caseB_localSuppressed -> null                      (explicit local + suppressActiveRuntimeFallback; stays local)
caseC_oldBuggyFallback -> "ambient-focused-runtime" (no owner + no suppression; OLD behavior inheriting the ambient runtime — the bug)

Before the fix, File Explorer opens behaved like caseC: a remote-worktree file tab could be created with the wrong/ambient owner (or none), so the read fell back to local fs:readFile and failed with "Access denied: path resolves outside allowed directories"; Retry repeated it. After the fix, opens behave like caseA (remote worktree -> correct owner, runtime RPC) and caseB (local worktree -> stays local, not retargeted to a focused runtime).

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.

Remote runtime File Explorer open/retry can fall back to local fs:readFile

1 participant