Skip to content

Fix remote-host file open denied during SSH hydration (#6648) - #6692

Merged
Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/issue-6648-remote-host-attempting
Jun 29, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
Jinwoo-H/issue-6648-remote-host-attempting

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #6648 — opening a file to edit on a remote SSH host could fail with Access denied: path resolves outside allowed directories and stay stuck.

That error message is produced only by the local filesystem resolver (src/main/ipc/filesystem-auth.ts). It surfaces when fs:readFile is invoked without a connectionId — 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:

  • a connection id → remote (read over SSH)
  • null → local (read from disk)
  • undefined → owner not known yet (the SSH repo hasn't hydrated into state.repos)

Right after a session restore, the SSH connection is still establishing, so the lookup briefly returns undefined. The editor collapsed undefined/null together (?? 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 denied from 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 — new isWorktreeConnectionResolved(worktreeId): false while the backing repo hasn't hydrated (mirrors getConnectionId's repoId derivation); true for 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 retryable WORKTREE_OWNER_NOT_READY_ERROR instead 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; genuine access denied stays non-retryable.

Hydrated local repos resolve to null (not undefined), so they're unaffected.

Reproduction harness

src/renderer/src/runtime/remote-host-file-open-repro.test.ts drives the real renderer code path (store → getConnectionIdForFile → readRuntimeFileContent → an fs.readFile stand-in mirroring the main resolver). It reproduces the exact error during hydration, then proves recovery once the SSH repo lands.

Testing

  • Reproduction harness: 4/4 pass (fails retryably during hydration, never does the local read, recovers after).
  • New regression tests in connection-context.test.ts and useEditorPanelContentState.test.tsx.
  • Editor + runtime + connection-context suites: 957/957 pass. Typecheck and lint clean.

Known follow-ups (out of scope)

loadDiffContent (changes/diff view), useLocalImageSrc, useEditorExternalWatch, and mobile-markdown-bridge share 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 🐋

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
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f767d27-19e2-45b0-8910-8ea9cd8e905d

📥 Commits

Reviewing files that changed from the base of the PR and between 9162bc3 and 93cd68f.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/useEditorPanelContentState.test.tsx
  • src/renderer/src/components/editor/useEditorPanelFileLoadRetry.test.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/editor/useEditorPanelFileLoadRetry.test.tsx
  • src/renderer/src/components/editor/useEditorPanelContentState.test.tsx

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning It includes Summary, Testing, and Notes-like context, but it omits required Screenshots, AI Review Report, Security Audit, and checklist-style testing items. Add the missing template sections: Screenshots, checklist Testing items, AI Review Report with cross-platform checks, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and matches the main change: preventing remote file-open failures during SSH hydration.
Linked Issues check ✅ Passed The changes address #6648 by distinguishing unresolved worktree owners, retrying the transient case, and avoiding the local access-denied path.
Out of Scope Changes check ✅ Passed All added code, tests, and the repro harness support the SSH-hydration file-open fix; no clearly unrelated changes are present.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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: Pro

Run ID: 76f274b5-fd73-4a59-b8d0-c99c47bd7c18

📥 Commits

Reviewing files that changed from the base of the PR and between 49c0917 and e92e34d.

📒 Files selected for processing (7)
  • src/renderer/src/components/editor/editor-panel-content-types.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.test.tsx
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/components/editor/useEditorPanelFileLoadRetry.ts
  • src/renderer/src/lib/connection-context.test.ts
  • src/renderer/src/lib/connection-context.ts
  • src/renderer/src/runtime/remote-host-file-open-repro.test.ts

Jinwoo-H added 2 commits June 28, 2026 23:12
- 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.

@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: Pro

Run ID: c562689b-9c2e-44c4-b90b-9a464c5be085

📥 Commits

Reviewing files that changed from the base of the PR and between 529b029 and 9162bc3.

📒 Files selected for processing (4)
  • src/renderer/src/components/editor/editor-panel-content-types.ts
  • src/renderer/src/components/editor/useEditorPanelFileLoadRetry.test.tsx
  • src/renderer/src/components/editor/useEditorPanelFileLoadRetry.ts
  • src/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.
@Jinwoo-H
Jinwoo-H merged commit 63c8a66 into main Jun 29, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/issue-6648-remote-host-attempting branch June 29, 2026 04:03
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.

[Bug]: Remote host attempting to view a file results in error

1 participant