Skip to content

feat(native-chat): local attachments in the composer on Remote Orca Server panes - #17797

Open
cmer wants to merge 7 commits into
stablyai:mainfrom
cmer:cmer/Allow-local-attachment-with-remote-server-and-or-ssh-session
Open

cmer wants to merge 7 commits into
stablyai:mainfrom
cmer:cmer/Allow-local-attachment-with-remote-server-and-or-ssh-session

Conversation

@cmer

@cmer cmer commented Sep 1, 2026

Copy link
Copy Markdown

Fixes #12572
Fixes #17410
Fixes #6889

Stacked on #17787 — the first two commits here belong to that PR (the nested clipboard routing fix this feature builds on). Review the last commit; this PR will shrink to it once #17787 merges.

Problem

On a runtime-owned (remote:) native chat pane, none of the composer's attach surfaces work: drag-and-drop and the file picker show "Local attachments are not available for remote sessions", and clipboard image paste is refused. Meanwhile the same pane's terminal view happily uploads a pasted image to the server, and mobile clients attach images to the very same sessions — the gap was specific to the desktop/web composer. Users fall back to scp/synced folders or pasting screenshots into GitHub comment boxes for the URL (#12572, #6889 comments).

What this does

All three composer attach surfaces now work on runtime-owned panes, producing the same end state the SSH composer path already produces — and it's wiring, not new transport:

  • Clipboard image paste calls the same saveClipboardImageAsTempFile({ runtimeEnvironmentId, connectionId }) terminal paste uses (chunked upload over the pairing channel, single-frame fallback for old servers). Nested worktrees on a server-owned SSH target work from day one (fix(clipboard): route runtime-owned image paste through the runtime for server-owned SSH targets #17787).
  • Drag-and-drop and the file picker upload through the existing importExternalPathsToRuntime into the worktree's .orca/drops (no-clobber), mirroring terminal drops — including the per-file skip/failure toasts and the capability assertion that surfaces "Remote file changes require a newer Orca server" against old servers.
  • The attachment owner resolver now returns a full runtime owner (environment id, worktree, server-owned connection id, host expectation), failing closed to not-ready while ownership is mid-flip. A stale-owner guard fails an in-flight upload if the pane's host changes underneath it.
  • The attach funnel's invariant changed, not disappeared: instead of blocking every remote pane, attachResolvedPaths receives owner-resolved host contexts. Client-local paths still can't reach a remote agent because every entry point resolves the owner and uploads first (the [Bug]: Remote host attempting to view a file results in error #6648 property, now enforced at the entries and pinned by tests).
  • Attachment chips carry their owning host: image previews read via the runtime for in-worktree files (dropped images get real thumbnails); pasted server-/tmp images fall back to the generic thumbnail, matching current SSH-paste behavior. A runtime chip never carries a connection id — that connection is server-owned and must not be dialed from the client.

No new wire methods, no capability negotiation needed. The send path is untouched (runtime image sends already existed for mobile). The paired web client shares the renderer, so it gets all three surfaces too; mobile already worked and is unchanged.

Testing

At the pre-agreed seams:

  • native-chat-attachment-upload.test.ts — resolver returns the enriched runtime owner (plain, nested-SSH, focused-host, not-ready), and the runtime upload flow: import args, .orca/drops destination, skip/failure toasts, stale-owner failure, error → null.
  • use-native-chat-composer-paste.test.tsx — runtime paste routes to the runtime save (plain + nested) and attaches the returned path; existing SSH/local/failure cases unchanged.
  • use-native-chat-external-attachments.test.tsx — runtime drop/picker uploads and attaches destination-side paths with the runtime host context; failed uploads attach nothing; SSH/local/not-ready/disabled cases unchanged.

Full pnpm test, pnpm tc, oxlint, and the localization verifies pass.

🤖 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
@cmer
cmer requested a review from brennanb2025 as a code owner September 1, 2026 03:21
@greptile-apps

greptile-apps Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR enables clipboard, drop, and picker attachments for runtime-owned native chat panes by routing uploads through the owning runtime and preserving host context for uploaded files. The clipboard path’s ownership fix remains incomplete because pasted chips still discard their captured host before submission.

  • Adds runtime-aware attachment-owner resolution and stale-owner fencing
  • Reuses runtime upload protocols for clipboard images and external paths
  • Adds runtime-backed image previews and localized upload feedback
  • Extends coverage for local, SSH, nested-runtime, and ownership-transition cases

Confidence Score: 4/5

The PR is not yet safe to merge because a pasted remote image can still be submitted to a different host than the one that created its temporary path.

The new post-save check prevents ownership changes during the clipboard save, but the accepted path is stored without its captured host and remains available across later pane-owner changes, allowing submission to the wrong execution host.

Files Needing Attention: src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts, src/renderer/src/components/native-chat/use-native-chat-composer-attachments.ts

Important Files Changed

Filename Overview
src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts Adds runtime clipboard routing and an in-flight stale-owner guard, but drops owner metadata when committing the pasted attachment.
src/renderer/src/components/native-chat/use-native-chat-composer-attachments.ts Extends attachment chips with host metadata, although pasted images do not provide that metadata.
src/renderer/src/components/native-chat/native-chat-attachment-upload.ts Adds enriched runtime ownership resolution, destination uploads, and host-transition fencing.
src/main/window/clipboard-runtime-image-upload.ts Consolidates runtime clipboard uploads through the shared chunking protocol and supports server-owned nested SSH connections.
src/renderer/src/components/native-chat/NativeChatImageAttachmentPreview.tsx Routes previews for runtime-owned worktree attachments through the runtime image-loading context.

Sequence Diagram

sequenceDiagram
  participant U as User
  participant C as Composer
  participant H1 as Original host
  participant H2 as Current host
  U->>C: Paste image
  C->>H1: Save temporary image
  H1-->>C: Return host-local path
  C->>C: Validate owner and store path without host
  U->>C: Change pane owner
  C->>H2: Submit stored path
  H2-->>C: Path unreadable or resolves incorrectly
Loading

Comments Outside Diff (1)

  1. src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts, line 129 (link)

    P1 Pasted attachment loses host ownership

    When a runtime or SSH owner changes after an image is attached but before submission, this call stores the temporary path without the captured owner, causing the current agent to receive a path belonging to the previous host where it is unreadable or can identify an unrelated file.

    Knowledge Base Used: Remote connectivity and execution

Reviews (4): Last reviewed commit: "fix(native-chat): share the catalog fall..." | Re-trigger Greptile

…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 and others added 2 commits August 31, 2026 22:31
… panes

Wire the composer's three attach surfaces - clipboard image paste, file
drag-and-drop, and the file picker - to the existing runtime transports,
so a client paired to a Remote Orca Server can attach local files and
screenshots the same way SSH panes already do.

- The attachment owner resolver returns a full runtime owner (environment
  id, worktree, server-owned SSH connection for nested topologies, and
  the host-change expectation), failing closed to not-ready mid-flip.
- Paste routes through saveClipboardImageAsTempFile with the runtime
  environment and server-owned connection, matching terminal paste.
- Drop/picker upload through importExternalPathsToRuntime into the
  worktree's .orca/drops (no-clobber), mirroring terminal drops including
  the per-file skip/failure toasts and a stale-owner guard.
- The attach funnel now keys on owner-resolved host contexts instead of
  blocking every remote pane; client-local paths still cannot reach a
  remote agent because every entry point resolves and uploads first.
- Attachment chips carry the owning host so image previews read via the
  runtime for in-worktree files; server-tmp pastes fall back to the
  generic thumbnail, matching SSH behavior.

Old servers degrade visibly: file uploads surface the existing
'requires a newer Orca server' capability message and small-image pastes
use the single-frame fallback. No new wire methods.

Fixes stablyai#12572
Fixes stablyai#17410
Fixes stablyai#6889

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019G22teMcYiNe9RmGQ4dKuK
…l closed on unresolved connections

Review follow-ups: extract the runtime .orca/drops upload flow into one
core used by terminal drops and the composer (they were statement-for-
statement duplicates), fail closed to not-ready when a runtime worktree's
server-owned connection has not hydrated (nested topology, stablyai#17679),
build the chip preview's runtime context without a settings-store
subscription, drop the dead attached-host helper, and delete the now-
unused local-attachment notice from all five locales.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019G22teMcYiNe9RmGQ4dKuK
@cmer
cmer force-pushed the cmer/Allow-local-attachment-with-remote-server-and-or-ssh-session branch from e3a6b57 to 1a12c0f Compare September 1, 2026 03:32
Drop and picker uploads already assert the owner is unchanged before
attaching; clipboard paste attached the saved temp path without
re-checking, so a pane re-pair or SSH generation bump during the async
save could hand the new agent a path minted on the old host (review
finding on stablyai#17797). Re-resolve the owner after the save and drop the
attachment with a visible notice when the host identity drifted, using
one shared owner-match helper for both fences.

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 Greptile's P1 (clipboard paste retains stale owner) in f5aad0f:

  • The gap was real: drop/picker uploads were fenced by assertCurrent, but clipboard paste attached the saved temp path without re-validating the owner after the async save — a pane re-pair, environment switch, or SSH generation bump mid-save could attach a path minted on the old host.
  • Fix: after the save resolves, both paste flows (handlePaste and the menu-driven pasteFromClipboard) re-resolve the owner and compare host identity via a new shared nativeChatAttachmentOwnersMatch helper — the same comparison the drop/picker fence now uses (assertNativeChatRuntimeOwnerCurrent was refactored onto it). On drift the attachment is dropped with a visible notice ("Attachment upload host changed; retry the attach."), never silently. not-ready deliberately never matches: an unverifiable host is a changed host.
  • Tests: field-level match semantics pinned in native-chat-attachment-upload.test.ts (identity match per owner kind, drift rejection incl. generation bumps and not-ready); the hook-level fence pinned in use-native-chat-composer-paste.test.tsx (owner changes mid-save → no attach + notice; unchanged owner still attaches).

Full native-chat suite (952 tests), typecheck, and lint pass.

@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 — one edge-case suggestion inline.

Reviewed changes

Reviewed the full four-commit stack (the two clipboard commits are from the stacked #17787, the native-chat commits are this feature), including the main-process clipboard routing, the shared upload driver, the web preload path, the attachment-owner resolver, and the terminal drop refactor.

  • Runtime paste routing — runtime-owned paste now saves over the pairing channel and forwards the server-owned nested-SSH connectionId, so a client-owned SSH provider is never dialed for a server-owned connection (#17679).
  • Shared upload protocol — the chunked clipboard-image upload driver is extracted to src/shared/clipboard-image-upload-protocol.ts and reused by the desktop main process and the web preload instead of two divergent copies.
  • Owner resolution — resolveNativeChatAttachmentOwnerForWorktree returns a full runtime owner (environment id, worktree, server-owned connection, host expectation) and fails closed to not-ready while ownership is mid-flip.
  • Drop/picker upload — runtime drop and file-picker attach upload client paths into .orca/drops through a shared runtime-drop-dir-upload core that the terminal drop path now also uses.
  • Host-aware chips — attachment chips carry their owning host: in-worktree runtime images get real previews via the runtime, pasted /tmp images fall back to the generic thumbnail.

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

@@ -139,3 +184,41 @@ export async function uploadNativeChatAttachmentPaths(
toast.dismiss(pending)
}
}

function assertNativeChatRuntimeOwnerCurrent(owner: NativeChatRuntimeAttachmentOwner): void {
const current = resolveNativeChatAttachmentOwnerForWorktree(

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.

This re-resolution drops the terminalTabId that the terminal-tab capture path used, so worktreePath comes only from getKnownWorktreeById while the captured owner's path may have come from resolveNativeChatFileLinkContext's worktreesByRepo fallback. In the hydration window that fallback exists for (catalog row present, known-worktree index not yet populated), the assert resolves not-ready and fails a legitimate attach with "Attachment upload host changed" even though nothing changed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 48ece5f. The asymmetry was real: the tab-path capture resolves the worktree path with the worktreesByRepo fallback, while the assert's tab-less re-resolution used only getKnownWorktreeById — so during index hydration the assert could resolve not-ready and spuriously fail a legitimate attach. The structured branch (which the assert re-resolves through) now uses the same fallback, pinned by a test that captures through an empty known-worktree index.

@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

Delta review of the two commits pushed since the prior pullfrog review (plus the rebased base commits): the blank-connection normalization inside the shared upload driver, and the mid-save owner fence added to clipboard paste.

  • Blank connection normalization — saveClipboardImageBase64ThroughRuntime now trims rawConnectionId to null inside the shared driver, so the web preload no longer forwards an empty string that the runtime schema rejects.
  • Paste owner fence — a shared nativeChatAttachmentOwnersMatch predicate compares the owner captured at paste time against a post-save re-resolution, and both handlePaste and pasteFromClipboard drop the temp path with the host-changed notice when the pane's host drifted mid-save.

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

…d re-resolution

The tab-path owner capture resolves the worktree path with a
worktreesByRepo fallback, but the stale-owner assert's tab-less
re-resolution used only the known-worktree index — during index
hydration a legitimate attach could spuriously fail as 'host changed'
(review finding on stablyai#17797). Use the same fallback in both branches.

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

Pullfrog's review is in (no critical issues, one inline edge-case) — addressed in 48ece5f:

  • Stale-owner assert vs. hydration window: the inline finding was correct — owner capture through the terminal-tab path resolves the worktree path with a worktreesByRepo catalog fallback, but the stale-owner assert re-resolved without the tab id and used only the known-worktree index, so a mid-upload assert during index hydration could fail a legitimate attach with "Attachment upload host changed." Both resolution branches now share the same fallback, so capture and re-resolution agree regardless of provenance. Pinned by a new resolver test (owner resolves via the catalog fallback with an empty known-worktree index).

Full native-chat suite (953 tests), typecheck, and lint pass. That closes out all bot findings on this PR: Greptile's P1 (paste fence, f5aad0f) and pullfrog's inline edge-case (48ece5f).

@BTForIT

BTForIT commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Hi @cmer, thanks for this PR. We run Orca as a headless orca serve on Linux with macOS and iOS clients paired to it, and the Chat-view attachment block from #12572 affects us daily.

Do you plan to rebase this? If so, we're happy to test the branch on that setup and post the results here.

If you'd rather keep it moving in smaller pieces, would you mind if we opened a narrow PR for clipboard image paste in Chat view only on paired-runtime panes? It would reuse saveClipboardImageAsTempFile with the runtime environment id, the same path terminal paste already uses. Drag-and-drop and the file picker would stay with your PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants