Skip to content

fix(clipboard): route runtime-owned image paste through the runtime for server-owned SSH targets - #17787

Closed
cmer wants to merge 3 commits into
stablyai:mainfrom
cmer:cmer/runtime-clipboard-nested-ssh-routing
Closed

cmer wants to merge 3 commits into
stablyai:mainfrom
cmer:cmer/runtime-clipboard-nested-ssh-routing

Conversation

@cmer

@cmer cmer commented Sep 1, 2026

Copy link
Copy Markdown

Fixes #17679

Problem

In a nested topology — desktop client → Remote Orca Server → server-owned SSH target — pasting a clipboard image fails with Remote connection dropped. Click Reconnect on the SSH target before retrying, and reconnecting never helps.

The routing in saveClipboardImageBufferForTarget only chose the runtime transport when no connectionId was present. A nested worktree carries both a runtimeEnvironmentId and the server's SSH connectionId, so the client fell into its own SSH SFTP path with a connection id it has no connection for — the exact error reported, on both Windows and macOS clients.

Fix

  • Route to the runtime whenever a runtime environment id is present. A connectionId alongside a runtime owner names a server-owned connection: the runtime forwards the file over its own SFTP, exactly as the paired web client already does.
  • Thread the connection id through the chunked upload start and the small-image single-frame fallback (both previously hardcoded null, which would have landed the file on the server instead of the SSH target).
  • No wire change: clipboard.startImageUpload / clipboard.saveImageAsTempFile have accepted the optional nullable connectionId since they were introduced, so older servers honor it (per docs/reference/remote-wire-compatibility.md, no capability negotiation needed).

Review follow-ups included

  • Extracted the chunked-upload / fallback / abort protocol into src/shared/clipboard-image-upload-protocol.ts, now driven by both the desktop main process and the web preload. The two hand-rolled copies are how the connectionId divergence happened in the first place. (The mobile client still has its own copy — possible follow-up, it's a separate package.)
  • Normalize an empty-string connectionId to null before forwarding (the old guard treated '' as absent; the RPC schema rejects it).
  • Test at the IPC seam that a failed runtime upload rejects instead of falling back to a client-reachable host — a wrong-host fallback is precisely the bug this PR fixes.

Known narrow edge (not addressed here)

getConnectionId resolution is host-blind over duplicate repo rows (one runtime-stamped, one client-SSH): in that state a client-owned connection id could be forwarded to a runtime that doesn't know it, failing the paste. The trigger requires duplicate repo ids with only the runtime row's worktree hydrated; fixing it means host-aware connection resolution in the renderer and is left as a follow-up.

Testing

  • clipboard-ipc-handlers.test.ts: routing matrix at the IPC seam — runtime-only, runtime+server-owned-connection (asserts the client SSH stack is never consulted), failure rejection, plus the untouched SSH-only/local cases.
  • clipboard-runtime-image-upload.test.ts (new): protocol mechanics through the shared driver — connection threading in start and fallback, chunking, abort-on-chunk-failure.
  • Web preload clipboard tests now exercise the same shared driver unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_019G22teMcYiNe9RmGQ4dKuK

cmer and others added 2 commits August 31, 2026 21:43
…or server-owned SSH targets

A clipboard image pasted into a runtime-owned pane whose worktree lives on
a server-owned SSH target (client -> orca serve -> SSH) was routed to the
client's own SSH stack, which has no such connection, failing with
'Remote connection dropped. Click Reconnect on the SSH target'.

Route to the runtime whenever a runtime environment id is present and
thread the server-owned connection id into the chunked upload start and
the small-image single-frame fallback, so the server forwards the file
over its own SFTP connection - matching the paired web client, which
already passes the connection through. No wire change: the RPCs have
accepted the optional connection id since introduction.

Fixes stablyai#17679

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019G22teMcYiNe9RmGQ4dKuK
…nd harden runtime routing

Review follow-ups: extract the chunked upload / single-frame fallback /
abort protocol into one shared driver used by both the desktop main
process and the web preload (their fork is what let connectionId handling
diverge), normalize an empty connectionId to null before forwarding, and
pin at the IPC seam that a failed runtime upload rejects rather than
falling back to a client-reachable host.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019G22teMcYiNe9RmGQ4dKuK
@greptile-apps

greptile-apps Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR routes runtime-owned clipboard-image pastes through the owning runtime even when a server-owned SSH connection is present.

  • Threads the normalized connection ID through chunked-upload initialization and the legacy single-frame fallback.
  • Consolidates desktop and web upload, fallback, and abort behavior into one shared protocol driver.
  • Adds IPC routing and protocol tests covering nested SSH targets, failure propagation, connection forwarding, and upload cleanup.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/main/window/clipboard-ipc-handlers.ts Routes image saves by runtime ownership first and normalizes the forwarded SSH connection identifier.
src/main/window/clipboard-runtime-image-upload.ts Delegates desktop runtime uploads to the shared protocol while preserving byte-limit enforcement.
src/shared/clipboard-image-upload-protocol.ts Centralizes bounded chunking, compatibility fallback, response validation, connection forwarding, and best-effort abort behavior.
src/renderer/src/web/preload-api/web-clipboard-api.ts Replaces the web-specific upload implementation with the shared protocol driver without changing its runtime adapter.
src/main/runtime/rpc/methods/clipboard.ts Re-exports the shared chunk-size constant so runtime validation and clients use the same protocol limit.

Sequence Diagram

sequenceDiagram
    participant UI as Desktop renderer
    participant IPC as Main clipboard IPC
    participant RT as Remote Orca runtime
    participant SSH as Server-owned SSH target
    UI->>IPC: save image(runtimeEnvironmentId, connectionId)
    IPC->>RT: startImageUpload(connectionId)
    loop bounded base64 chunks
        IPC->>RT: appendImageUploadChunk
    end
    IPC->>RT: commitImageUpload
    RT->>SSH: save temporary image over SFTP
    SSH-->>RT: target path
    RT-->>IPC: target path
    IPC-->>UI: target path
Loading

Reviews (2): Last reviewed commit: "fix(clipboard): normalize blank connecti..." | Re-trigger Greptile

@pullfrog pullfrog 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.

ℹ️ No critical issues — solid, well-tested fix. One nitpick inline and one follow-up worth tracking.

Reviewed changes

  • Runtime routing fix — saveClipboardImageBufferForTarget now routes to the runtime whenever a runtime owner is present, threading the server-owned SSH connectionId into the upload start and the single-frame fallback.
  • Shared protocol driver — extracted the chunk/fallback/abort logic into src/shared/clipboard-image-upload-protocol.ts, now driven by both the desktop main process and the web preload, removing the two duplicated copies whose divergence caused #17679.
  • Test coverage — a routing matrix at the IPC seam (including a wrong-host-fallback rejection test) plus a new protocol-mechanics suite; the web preload clipboard tests now exercise the same shared driver.

ℹ️ Known edge is a real behavior change — file a tracking issue

The routing change makes a previously-working (if narrow) path regress: when getRuntimeEnvironmentIdForWorktree resolves a runtime owner while getConnectionId (host-blind, in connection-owner-resolution.ts) returns a client-owned connection id for the same repo, the old !connectionId guard routed to the client's SSH stack — which owns that connection — and worked. The new code forwards that client-owned id to a runtime that has no such connection, failing the paste. The trigger is documented, but it is a silent regression of a path that used to work and should be tracked as an issue rather than left as a PR-body footnote.

Technical details
# Track duplicate-repo-rows routing regression

## Affected sites
- src/main/window/clipboard-ipc-handlers.ts:56 — unconditional runtime routing when `runtimeEnvironmentId` is set (removes the `!connectionId` guard)
- src/renderer/src/lib/connection-owner-resolution.ts:50 — `getConnectionIdFromState` returns `repo.connectionId ?? null` with no host awareness
- src/renderer/src/lib/worktree-runtime-owner.ts:58 — `getRuntimeEnvironmentIdForWorktree` can resolve a runtime owner from a different row than `getConnectionId`

## Required outcome
- A GitHub issue tracking the duplicate-repo-rows case so the regression is not lost.

## Open questions for the human
- Should the renderer resolve `connectionId` host-aware (only forward a connection the runtime actually owns), or should the main process guard against forwarding an unknown connection id?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…ad driver

A blank connectionId reached the runtime schema ('' fails min(1)) from
callers that pass it through raw — the web preload used '?? null'. Trim
inside the driver so every transport treats blank as 'no connection'.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019G22teMcYiNe9RmGQ4dKuK
@cmer

cmer commented Sep 1, 2026

Copy link
Copy Markdown
Author

Addressed the bot reviews:

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Blank connectionId normalization centralized — saveClipboardImageBase64ThroughRuntime now normalizes an empty/whitespace id to null inside the shared driver (rawConnectionId?.trim() || null), so both the desktop main process and the web preload treat a blank id as "no connection" instead of forwarding it into the runtime's z.string().min(1) schema. Pinned by a new driver test.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

@nwparker

Copy link
Copy Markdown
Contributor

Closing since the minimal in-repo version of this routing fix landed via #19352, which notes: "#17787 (community fork) targets the same issue with the same core routing change… This PR is the minimal, in-repo version of the routing fix only… Either can land; if #17787 is preferred, this one should be closed." Thanks for the community contribution — please reopen if your branch carries anything beyond #19352.

@nwparker nwparker closed this Sep 14, 2026
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]: Clipboard image paste fails in nested Remote Server → SSH session with "Remote connection dropped"

4 participants