Repository navigation
Fix remote-host file open denied during SSH hydration (#6648) - #6692
Conversation
Opening a file to edit on a remote SSH host could fail with
"Access denied: path resolves outside allowed directories" and stay
stuck. The renderer resolves the file's owning host from the store; right
after a session restore the SSH repo has not hydrated yet, so the lookup
returns `undefined` ("owner unknown"). The editor collapsed that with
`null` ("local") and read the remote path off the LOCAL filesystem, which
denies it. The retry gate excludes "access denied", so the error latched
permanently even after the SSH repo finished connecting.
Distinguish "owner not yet known" from "definitely local": when the
worktree's backing repo has not hydrated, fail with a retryable
owner-not-ready error instead of doing a local read, and keep retrying
until the SSH repo lands in the store. Hydrated local repos resolve to
`null` and are unaffected. The defect is platform-agnostic; Windows just
surfaces the race most often because SSH connects more slowly there.
- connection-context: add isWorktreeConnectionResolved()
- useEditorPanelContentState: guard the unresolved-owner read
- useEditorPanelFileLoadRetry: retry the owner-not-ready case persistently
- add reproduction harness + regression tests
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR adds worktree owner readiness detection and new owner-not-ready/owner-unreachable error constants. File loading now avoids premature reads while an SSH worktree is still hydrating, and retry logic handles that error with separate bounds and terminal behavior. Tests were added for the helper, content loading, retry handling, and a remote file open reproduction. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 76f274b5-fd73-4a59-b8d0-c99c47bd7c18
📒 Files selected for processing (7)
src/renderer/src/components/editor/editor-panel-content-types.tssrc/renderer/src/components/editor/useEditorPanelContentState.test.tsxsrc/renderer/src/components/editor/useEditorPanelContentState.tssrc/renderer/src/components/editor/useEditorPanelFileLoadRetry.tssrc/renderer/src/lib/connection-context.test.tssrc/renderer/src/lib/connection-context.tssrc/renderer/src/runtime/remote-host-file-open-repro.test.ts
- isWorktreeConnectionResolved now delegates to getConnectionId (getConnectionId(worktreeId) !== undefined) instead of duplicating the worktree -> repoId -> repo store traversal, so the two cannot drift. - Drop the 40-attempt cap on the owner-not-ready retry. That check is a pure local store read (it throws before any network call until the SSH repo hydrates), so retry it indefinitely at a steady 750ms cadence rather than latching a misleading "still connecting" message after a fixed budget — matching the documented intent.
Retrying indefinitely could poll a never-connecting remote host for the
lifetime of the tab. Cap the owner-not-ready retry at a generous budget
(~2 min: 160 × 750ms) that covers any realistic SSH connect, then swap
the transient "still connecting…" text for a truthful terminal message
("Couldn't reach the remote host. Check the connection, then retry.").
The terminal message is excluded from auto-retry; the existing Retry
button clears the attempt counter to start a fresh budget. A successful
read at any point during the budget still recovers immediately.
Adds a fake-timer unit test for the bounded -> terminal transition.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c562689b-9c2e-44c4-b90b-9a464c5be085
📒 Files selected for processing (4)
src/renderer/src/components/editor/editor-panel-content-types.tssrc/renderer/src/components/editor/useEditorPanelFileLoadRetry.test.tsxsrc/renderer/src/components/editor/useEditorPanelFileLoadRetry.tssrc/renderer/src/runtime/remote-host-file-open-repro.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/runtime/remote-host-file-open-repro.test.ts
- Recovery test now relies on the retry hook auto-reloading once the owner-not-ready error clears, instead of bumping fileContentReloadNonce (which bypassed the hook and could pass even if auto-retry never fired). - Fake setFileContents now replaces the map instead of merging, so a key the hook deletes actually disappears — otherwise a stale loadError could be masked.
Summary
Fixes #6648 — opening a file to edit on a remote SSH host could fail with
Access denied: path resolves outside allowed directoriesand stay stuck.That error message is produced only by the local filesystem resolver (
src/main/ipc/filesystem-auth.ts). It surfaces whenfs:readFileis invoked without aconnectionId— i.e. a remote POSIX path got routed to the local read path.Root cause
The editor resolves a file's owning host from the store via
getConnectionIdForFile→getConnectionId. That lookup has three results:null→ local (read from disk)undefined→ owner not known yet (the SSH repo hasn't hydrated intostate.repos)Right after a session restore, the SSH connection is still establishing, so the lookup briefly returns
undefined. The editor collapsedundefined/nulltogether (?? undefined) and did a local read of the remote path, which the local resolver denies (SSH repo roots are intentionally excluded from local allowed roots).Worse, the retry gate excludes
access deniedfrom retries (so genuine permission denials don't get hammered), so this transient hiccup latched permanently — even after the SSH repo finished connecting a moment later. Local files never hit this race, which is why they "worked."The defect is platform-agnostic. Nothing in the failing path is OS-specific; the reproduction runs on macOS. Windows just surfaces the race most often because SSH connection setup is slower there, widening the window.
Fix
Distinguish "owner not yet known" from "definitely local":
connection-context.ts— newisWorktreeConnectionResolved(worktreeId):falsewhile the backing repo hasn't hydrated (mirrorsgetConnectionId's repoId derivation);truefor null worktrees and folder workspaces.useEditorPanelContentState.ts— when the connection is unresolved (undefined), it isn't a runtime-environment read, and the owner isn't resolved yet, throw a retryableWORKTREE_OWNER_NOT_READY_ERRORinstead of doing the bad local read.useEditorPanelFileLoadRetry.ts— retry the owner-not-ready case persistently (40 × 750ms ≈ 30s) so it auto-recovers once the SSH repo lands in the store; genuineaccess deniedstays non-retryable.Hydrated local repos resolve to
null(notundefined), so they're unaffected.Reproduction harness
src/renderer/src/runtime/remote-host-file-open-repro.test.tsdrives the real renderer code path (store →getConnectionIdForFile→readRuntimeFileContent→ anfs.readFilestand-in mirroring the main resolver). It reproduces the exact error during hydration, then proves recovery once the SSH repo lands.Testing
connection-context.test.tsanduseEditorPanelContentState.test.tsx.Known follow-ups (out of scope)
loadDiffContent(changes/diff view),useLocalImageSrc,useEditorExternalWatch, andmobile-markdown-bridgeshare the same hydration race but lack retry infrastructure. The reported symptom is edit-mode, so this PR stays focused there rather than half-fixing those.Made with Orca 🐋