Skip to content

fix(ssh): open external host images from terminal links - #10323

Merged
Jinwoo-H merged 3 commits into
mainfrom
loading-images-ssh-host
Jul 24, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
loading-images-ssh-host

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Open absolute image/file paths outside an SSH worktree from terminal links on the owning host.
  • Persist the SSH target across workspace restore and fail closed if the workspace moves to another host.
  • Apply the same ownership check to editor reads, embedded markdown images, mobile markdown, external-change flows, conflict scans, and mutations.

Root Cause

PR #1878 changed external SSH reads from readFile({ connectionId }) to unconditional rejection whenever a connection existed. PR #1924 later moved that logic without introducing the regression. External SSH paths use the absolute path as both filePath and relativePath, so the editor misclassified them as restored client-local files before the healthy SSH read/image path could run.

Screenshots

No visual design change. The Docker-backed Electron E2E captures the rendered remote image as test evidence.

Testing

  • pnpm lint — touched-file oxlint and React Doctor pre-commit lint passed; full repository lint was not run.
  • pnpm typecheck
  • pnpm test — 531 focused Vitest tests passed across terminal routing, editor ownership/loading/restore, markdown image loaders, session persistence, runtime file routing, and relay filesystem handling.
  • pnpm build — Electron E2E build and all-platform relay build passed.
  • Added or updated high-quality regression tests, including red/green ownership oracles and a Docker-backed Electron test that renders the exact remote 2×2 PNG bytes from outside the worktree.

Additional gates:

  • pnpm run typecheck:node
  • pnpm run build:relay
  • pnpm run check:max-lines-ratchet
  • pnpm run check:reliability-gates
  • git diff --check
  • ORCA_E2E_SSH_DOCKER=1 ... ssh-external-image-preview.spec.ts (1 passed)

AI Review Report

Completed four internal review/fix rounds, including repeated elegance and performance audits. The review covered macOS/Linux/Windows path forms (including WSL UNC aliases), direct SSH vs remote-runtime routing, host replacement/reconnect behavior, restart persistence, secondary reads, detached markdown previews, mutation provenance, mobile reads, and relay behavior.

Issues found and fixed during review:

  • Runtime-owned WSL paths could be incorrectly stamped with the worktree SSH target.
  • Zod session parsing stripped externalSshTargetId on restart.
  • Secondary editor/markdown/mobile reads could follow a replacement host.
  • Reopening an existing tab could update its read owner without refreshing mutation provenance.
  • A detached markdown preview could lose the source tab's SSH ownership.

The final round found no remaining in-scope issues. The docstring warning is not actionable under this repository's policy favoring concise, non-obvious comments.

Security Audit

Reviewed path authorization, IPC boundaries, SSH provider selection, remote-runtime separation, persistence, and mutation ownership. Remote absolute paths remain behind the SSH/runtime filesystem providers; client-local authorization is not granted for SSH paths. Reads and writes reject when the persisted external owner no longer matches the current target, and runtime-owned paths cannot inherit direct-SSH ownership. No secrets, auth changes, new dependencies, or new command construction were introduced.

Notes

  • Intentional fail-closed behavior: after switching hosts, an external SSH tab must be reopened from the new host before it can load or save.
  • Sessions created before this field existed cannot infer the old external SSH owner and may require reopening those tabs once after upgrade.
  • The added work is constant-time string comparison plus one optional persisted scalar; no polling, extra IPC fanout, or render loop was added.

@coderabbitai

coderabbitai Bot commented Jul 24, 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 Plus

Run ID: 402bcf5f-c547-4567-8e0e-16f07c7e2319

📥 Commits

Reviewing files that changed from the base of the PR and between 2dfe857 and 19dc596.

📒 Files selected for processing (2)
  • src/shared/workspace-session-schema.test.ts
  • src/shared/workspace-session-schema.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shared/workspace-session-schema.ts

📝 Walkthrough

Walkthrough

Adds externalSshTargetId tracking to editor files and persisted workspace sessions. Terminal links attach the SSH target to external paths, while restored-file loading, file operations, and conflict scanning validate that the current SSH connection still owns the file. New unit and integration coverage verifies persistence, ownership replacement handling, deferred conflict checks, and remote image previews opened from terminal links.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main user-visible change: opening external SSH host images from terminal links.
Description check ✅ Passed The description follows the required template and includes summary, screenshots, testing, AI review, security audit, and notes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 78a26df8-1ec7-4725-b665-7b143f0aefbb

📥 Commits

Reviewing files that changed from the base of the PR and between 20ce29a and 9671d69.

📒 Files selected for processing (14)
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.test.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.test.tsx
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/components/terminal-pane/terminal-file-open-routing.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts
  • src/renderer/src/lib/editor-file-operation-owner.test.ts
  • src/renderer/src/lib/editor-file-operation-owner.ts
  • src/renderer/src/lib/workspace-session-editor-drafts.test.ts
  • src/renderer/src/lib/workspace-session.ts
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts
  • src/shared/types.ts
  • tests/e2e/ssh-external-image-preview.spec.ts

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

Run ID: 086617f2-3381-422b-bf59-f9a38c98b070

📥 Commits

Reviewing files that changed from the base of the PR and between 9671d69 and 2dfe857.

📒 Files selected for processing (24)
  • src/renderer/src/components/editor/EditorContent.tsx
  • src/renderer/src/components/editor/ExternalFileChangeBanner.tsx
  • src/renderer/src/components/editor/ExternalFileChangeCompareDialog.tsx
  • src/renderer/src/components/editor/MarkdownPreview.tsx
  • src/renderer/src/components/editor/RichMarkdownEditor.tsx
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.ts
  • src/renderer/src/components/editor/rich-markdown-editor-config.ts
  • src/renderer/src/components/editor/rich-markdown-image-context.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.test.tsx
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/components/editor/useLocalImageSrc.test.ts
  • src/renderer/src/components/editor/useLocalImageSrc.ts
  • src/renderer/src/components/editor/useRichMarkdownProgrammaticSync.ts
  • src/renderer/src/components/editor/useRichMarkdownReconcileRoundTrip.ts
  • src/renderer/src/components/terminal-pane/terminal-file-open-routing.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts
  • src/renderer/src/hooks/useEditorExternalWatch.ts
  • src/renderer/src/runtime/mobile-markdown-bridge.ts
  • src/renderer/src/runtime/runtime-file-client.test.ts
  • src/renderer/src/runtime/runtime-file-client.ts
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts
  • src/shared/workspace-session-schema.test.ts
  • src/shared/workspace-session-schema.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/renderer/src/components/terminal-pane/terminal-file-open-routing.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.ts
  • src/renderer/src/store/slices/editor.ts

Comment thread src/shared/workspace-session-schema.ts Resolved
@Jinwoo-H
Jinwoo-H merged commit 01929fd into main Jul 24, 2026
3 checks passed
AmethystLiang added a commit that referenced this pull request Jul 24, 2026
Main's SSH external-image wiring (#10323) pushed RichMarkdownEditor.tsx over
the 400-line tsx budget, failing PR Checks lint on every merge into main.
Move the props type into a sibling module so the component stays under the
limit without disabling max-lines.
AmethystLiang added a commit that referenced this pull request Jul 24, 2026
…10429)

* Fix fork PR/MR worktree creation race via durable review-head refs

When creating a fork PR/MR worktree, concurrent `git fetch origin` operations
clobber the shared FETCH_HEAD, causing the wrong commit to be checked out.
Fetch PR/MR heads into dedicated per-review refs (`refs/orca/pull/<N>`,
`refs/orca/merge-requests/<N>`) that persist and isolate each head from other
fetches. Gracefully keep the compare-base when the fetch fails but the local
ref already exists, avoiding silent fallback to the wrong branch on transient
network errors.

* Bound PR/MR head fetches with 60s timeout

Prevent PR/MR creation from hanging when a remote is stalled or
unreachable. Both GitHub and GitLab head fetches now enforce a
60-second timeout, matching the bound used in the create-path
fetch. Durable refs (refs/orca/pull/*, refs/orca/merge-requests/*)
decouple the ref from FETCH_HEAD, preserving legacy client semantics.

* test: align CI expectations with main PowerShell/sparse regressions

PR checks merge into main, which recently changed PowerShell launch args
(cwd restore after profiles) and sparse-checkout detection (require
core.sparseCheckout). Derive PowerShell spawn args from the production
resolver, mock the sparse config flag, reset shared worktree list scan
cache between tests, and stop requiring floating polls to avoid getRepos
hydration.

* Address review follow-ups on durable review-head refs

- Unify PR review-head remote selection: local and SSH GitHub paths share
  resolveGitHubReviewHeadRemote, which prefers the remote mapping to the
  hosting GitHub project (upstream before origin, matching work-item/API
  candidate order) so contributor clones fetch refs/pull from the repo
  that actually hosts the PR.
- Soft-keep durable review heads: when the PR/MR head fetch fails but
  refs/orca/pull/<N> / refs/orca/merge-requests/<iid> still resolves,
  keep the pinned SHA (warn) instead of failing resolve, mirroring the
  compare-base fallback. Extracted shared compare-base soft-keep into
  compare-base-ref-fetch.ts.
- Extract fetchGitLabMergeRequestHeadRef (local + SSH) parallel to the
  GitHub helper; bound its local fetch with the shared 60s timeout.
- Share relay-style fetch validation (positive safe-integer id, remote
  not starting with "-") between relay and local helpers via
  review-head-tracking-ref.ts; move REVIEW_HEAD_FETCH_TIMEOUT_MS there.
- Drop the githubPullRequestHeadLocalRef re-export; resolve head SHAs via
  rev-parse --verify <ref>^{commit}.
- Add GitLab anti-FETCH_HEAD regression test plus durable-head soft-keep
  and remote-selection unit tests.

Co-authored-by: Orca <[email protected]>

* test: supply live getRepos for terminal-retirement hydrates

Main's headless tab hydrate (#9343) skips worktree keys whose repo is not
in getRepos. Retirement tests that rebuild mobile tabs from a persisted
session now advertise the fixture repo as live so PR Checks merge stays green.

* fix(editor): extract RichMarkdownEditor props to stay under max-lines

Main's SSH external-image wiring (#10323) pushed RichMarkdownEditor.tsx over
the 400-line tsx budget, failing PR Checks lint on every merge into main.
Move the props type into a sibling module so the component stays under the
limit without disabling max-lines.

* Make durable review-head refs remote-identity scoped

Embed remote name + URL hash into refs/orca/pull|merge-requests refs to prevent soft-keep from serving wrong project's PR/MR when FETCH_HEAD is clobbered by concurrent fetch. Fetch functions now return the written ref path (writer-authoritative) so callers rev-parse exactly what was fetched, not re-derive identity. Soft-keep only applies to transient errors (timeout, network); fails hard on missing refs, auth failures, and stale relay. Relay returns localRef so client avoids re-hashing (URL normalization can disagree).

---------

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(ssh): open external host images from terminal links

* fix(ssh): keep external file ownership host-scoped

* fix(ssh): reject blank external file owners

---------

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#10429)

* Fix fork PR/MR worktree creation race via durable review-head refs

When creating a fork PR/MR worktree, concurrent `git fetch origin` operations
clobber the shared FETCH_HEAD, causing the wrong commit to be checked out.
Fetch PR/MR heads into dedicated per-review refs (`refs/orca/pull/<N>`,
`refs/orca/merge-requests/<N>`) that persist and isolate each head from other
fetches. Gracefully keep the compare-base when the fetch fails but the local
ref already exists, avoiding silent fallback to the wrong branch on transient
network errors.

* Bound PR/MR head fetches with 60s timeout

Prevent PR/MR creation from hanging when a remote is stalled or
unreachable. Both GitHub and GitLab head fetches now enforce a
60-second timeout, matching the bound used in the create-path
fetch. Durable refs (refs/orca/pull/*, refs/orca/merge-requests/*)
decouple the ref from FETCH_HEAD, preserving legacy client semantics.

* test: align CI expectations with main PowerShell/sparse regressions

PR checks merge into main, which recently changed PowerShell launch args
(cwd restore after profiles) and sparse-checkout detection (require
core.sparseCheckout). Derive PowerShell spawn args from the production
resolver, mock the sparse config flag, reset shared worktree list scan
cache between tests, and stop requiring floating polls to avoid getRepos
hydration.

* Address review follow-ups on durable review-head refs

- Unify PR review-head remote selection: local and SSH GitHub paths share
  resolveGitHubReviewHeadRemote, which prefers the remote mapping to the
  hosting GitHub project (upstream before origin, matching work-item/API
  candidate order) so contributor clones fetch refs/pull from the repo
  that actually hosts the PR.
- Soft-keep durable review heads: when the PR/MR head fetch fails but
  refs/orca/pull/<N> / refs/orca/merge-requests/<iid> still resolves,
  keep the pinned SHA (warn) instead of failing resolve, mirroring the
  compare-base fallback. Extracted shared compare-base soft-keep into
  compare-base-ref-fetch.ts.
- Extract fetchGitLabMergeRequestHeadRef (local + SSH) parallel to the
  GitHub helper; bound its local fetch with the shared 60s timeout.
- Share relay-style fetch validation (positive safe-integer id, remote
  not starting with "-") between relay and local helpers via
  review-head-tracking-ref.ts; move REVIEW_HEAD_FETCH_TIMEOUT_MS there.
- Drop the githubPullRequestHeadLocalRef re-export; resolve head SHAs via
  rev-parse --verify <ref>^{commit}.
- Add GitLab anti-FETCH_HEAD regression test plus durable-head soft-keep
  and remote-selection unit tests.

Co-authored-by: Orca <[email protected]>

* test: supply live getRepos for terminal-retirement hydrates

Main's headless tab hydrate (stablyai#9343) skips worktree keys whose repo is not
in getRepos. Retirement tests that rebuild mobile tabs from a persisted
session now advertise the fixture repo as live so PR Checks merge stays green.

* fix(editor): extract RichMarkdownEditor props to stay under max-lines

Main's SSH external-image wiring (stablyai#10323) pushed RichMarkdownEditor.tsx over
the 400-line tsx budget, failing PR Checks lint on every merge into main.
Move the props type into a sibling module so the component stays under the
limit without disabling max-lines.

* Make durable review-head refs remote-identity scoped

Embed remote name + URL hash into refs/orca/pull|merge-requests refs to prevent soft-keep from serving wrong project's PR/MR when FETCH_HEAD is clobbered by concurrent fetch. Fetch functions now return the written ref path (writer-authoritative) so callers rev-parse exactly what was fetched, not re-derive identity. Soft-keep only applies to transient errors (timeout, network); fails hard on missing refs, auth failures, and stale relay. Relay returns localRef so client avoids re-hashing (URL normalization can disagree).

---------

Co-authored-by: Orca <[email protected]>
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.

2 participants