Repository navigation
Fix ownership for terminal and chat file drops (STA-6940, PR 1/6) - #25749
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughNative chat attachments now revalidate their destination before attachment and when queued paths are flushed after input-method composition. Terminal file drops now require pane or tab identity, resolve workspace paths using the receiving transport’s host and runtime environment, and check captured ownership before delivery. Tests cover destination changes, pane routing, host-specific path resolution, and drop behavior across local, runtime, and SSH contexts. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No actionable issue remains in the reviewed context; the change is ready to proceed through normal CI. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The changes strengthen destination isolation and reject obsolete drops instead of redirecting them. No introduced or worsened security issue was established in the inspected flows. Some reconnect, teardown and partial-upload behavior remains incompletely verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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 |
Review summaryThis PR went through an independent code review, a fix round, a second review of the fixes, and a rendered check in a real Orca window. The reviews were done by separate agents that did not write the code. Their reports are summarized here because they were kept off GitHub while the work was in progress. First review (head
|
Restructured native chat checkThe restructured native chat (native chat + structured native chat on, agent tabs opening in chat view) was exercised on this head (
The test machine's real Oddities seen, outside what this PR changes (not yet checked against
|
…-pr1-drop-ownership # Conflicts: # src/renderer/src/components/native-chat/use-native-chat-external-attachments.ts
…-pr1-drop-ownership
…er (#25146) * feat(native-chat): a paired server keeps a store for chat attachments A structured chat on a paired Orca server had nowhere to put a file the client attached. The server now keeps a per-chat attachment store under its userData, filled through agentSessionAttachment.uploadStart/Append/Commit/Abort and read back for previews through agentSessionAttachment.read, behind the structured session gate and advertised as agent-session.attachments.v1. Nothing records cleanup as owed: a sweep re-derives what may go from the host's chat records and journal (unfinished uploads after an hour, uploads for a chat that never existed or that its journal never mentions after a day). The clipboard RPC's in-flight bookkeeping moves into a shared ChunkedUploadRegistry both use. * feat(native-chat): upload attached files into a paired server's chat store Main streams dropped or picked files (fs:uploadPathsToAgentSessionAttachments) and pasted images (clipboard:saveImageAsTempFile with agentSessionAttachment) into the chat's store on its paired server, reusing the file-import slice streamer and pinning every call to the pairing revision and server process. The browser client's paste takes the same route. * feat(native-chat): attach files to a structured chat on a paired server Pasted images, files dropped from Finder/Explorer and the file picker no longer refuse with "Local attachments are not available for remote sessions." in a structured chat on a paired server: they upload into that server's chat store and the chat gets only the stored path. Dropped files show as pending chips at once so Send waits for them; every attached item carries the server, pairing and chat it was stored for, and a send to anywhere else drops it with the existing "changed hosts" notice. Chips and transcript images read stored files back through the server, never from this machine's disk. An older server gets an update notice instead of an upload. The terminal-backed chat keeps refusing. * test(native-chat): type the attachment test doubles without bare casts * refactor(native-chat): keep the clipboard RPC on its own upload bookkeeping The chunked upload registry stays for the chat attachment store only, beside it. * feat(native-chat): claim chat attachments when the host admits a message A message's references into the host's attachment store are claimed in the same journal transaction that makes it durable (a direct send, a queued draft, a /clear carry). The sweep deletes an upload only after marking it in that database while no claim exists, so a send and a sweep can never both win: a client's send that names an expired or foreign upload is refused whole with the new attachmentExpired reason, before anything is recorded. This replaces scanning chat transcripts for paths. The store is now <root>/<upload id>/<name>, refuses uploads for chats the host does not hold, caps stored names in UTF-8 bytes and avoids Windows device names. The preview read goes through the protected bounded read and the request's reply budget, so an image too large for one reply is refused instead of closing the connection. * feat(native-chat): let structured Claude read the host's chat attachment store Attached non-image files live outside the workspace; the store root is passed as an added directory so the agent reads them without asking, the common pattern. * fix(native-chat): skip a dropped folder before staging walks into it * fix(native-chat): pin the browser client's chat paste to its server Every upload call goes to the environment the paste was meant for and checks its pairing and server process, as the desktop upload does; a re-pair ends the upload instead of storing the image on another server. * refactor(native-chat): let the host's claim be the only attachment check The composer no longer records which server and pairing each attachment came from, and Send no longer strips attachments it judges foreign: the host refuses an expired or unknown stored path when it admits the message, which also covers retries, Stop-restores and queued edits the client check missed. Previews of stored files route through the chat's own server by path. Removing a file's chip while it uploads now keeps its @path out of the draft. A dropped or picked file shows its name and kind on its chip while it uploads, with no separate progress toast, and files that did not attach are named in one notice. A rich-text paste into a chat on an older server no longer shows the update notice beside the pasted text. * chore(native-chat): keep the claim hook beside the draft consume and fit the line budgets The submission's claim runs in the same append hook as a draft's consume, owned by the queued-message collaborator, so the journal store stays within its size limit. Formats the new files and regenerates the runtime-required English catalog. * test(native-chat): pin the attachment store grant in the Claude launch, restore upload result types * fix(native-chat): create the attachment store at install and claim only exact store paths Claude drops an added directory that does not exist when it starts, so the store root is created when the host installs it, best effort. A commit keeps its upload in flight until the rename lands, so a sweep never takes a slow upload's part file. Only a path under this host's exact store root is claimed and required; any other mention of a store path is plain text and never refuses the message. * refactor(native-chat): reuse the newer-Orca notice and drop leftover attach options An older server's refusal to store attachments uses the notice every other write it refuses already shows, so one string fewer in every catalog; the attach callbacks lose an options parameter no caller passes since the provenance check went. * fix(native-chat): give a message refused for an expired attachment back to the composer Sending the same message again can never bring the attachment back, so instead of a Retry that always fails the message's text and images return to the composer, as a Stop's withdrawn message does, and the notice says what to remove. * fix(native-chat): keep uploads across a prompt, say why a file did not attach An upload that finishes while a prompt card has replaced the composer lands in the scope's attachment and draft caches, which the composer reads back when it returns, instead of the unmounted composer. The single failure notice names the cause the files share, such as the size limit. Rich text pasted into a chat on an older server no longer flashes an image chip: the chip waits for the server to take the image. A picked command waits, as Send does, while an attachment is still uploading. * fix(native-chat): keep a paste's upload across a prompt; pin the Claude grant hand-off A paste uploading into a paired server's store keeps its chip live when a prompt card unmounts the composer, and its result is filed for the composer's return, as a drop's is. A failure cause ending in full-width punctuation gets no extra full stop. A runtime test pins that the store root reaches Claude's launch resolver through the adapter. * test(native-chat): type the grant hand-off captures without casts * test(native-chat): pin that the composer files a paste's upload across a prompt * fix(native-chat): retry a held rename at commit and keep cut names Windows-safe A commit renames the part file with the Windows retry the app uses elsewhere, so an antivirus or indexer holding it briefly no longer loses the upload. A name cut to the byte limit is stripped of trailing dots and spaces again. The upload pump's result cast states why it holds. * fix(native-chat): keep attachments still on their way in the pane's attachment cache A prompt card unmounts the composer, and an attachment still saving or uploading lived only in that composer: one that came back showed no pending chip, so Send went out without the file and the file then landed in the next draft. Pending chips now live in the pane's attachment cache beside settled ones and settle there whichever composer is showing, so Send waits for them after a remount too. A stored file's @path goes into the pane's draft cache, which keeps it through an input-method composition and a remount. A rich-text paste's image is registered as a hidden pending chip before the server is asked, so Send waits for it from the start, and it shows only once the server takes it. * test(native-chat): a dropped file still uploading stays pending across a remount * fix(native-chat): reveal a rich-text image in a composer that came back; keep caret inserts A rich-text paste's held image is revealed through the pane's attachment cache, so a composer a prompt card remounted during the server's answer shows it rather than holding Send on an invisible chip. A stored file's @path goes in at the caret while the composer is showing and not composing, as every other attach does; only mid-composition or after a remount does it go to the pane's draft. * fix(native-chat): never evict a pane's attachments while a composer shows them or one is on its way The pane attachment cache is now where chips live, so its 128-scope bound passes over a scope a mounted composer subscribes to or that still holds a pending attachment, and evicts the oldest scope nobody uses instead. Protected scopes are bounded by mounted composers and attachments in flight. * fix(native-chat): never evict the scope just written when every older one is in use * fix(native-chat): keep the attachment store out of the RPC method table's imports The method table is imported far and wide (the SSH relay's CLI included), and the attachment RPCs pulled in the store, whose preview read loads modules that read fs constants at load: any test that mocks fs/promises without them failed to import. The installed store now lives in a small registry module; only the host wiring loads the store itself. * refactor(native-chat): the submission hook gets its own module Merging main added the operation receipt to the queued-message insert, which put journal-queued-messages.ts over the 300-line limit. The submission hook only uses the queued-messages object's public methods, so it moves out. * refactor(native-chat): fit the attachment sweep and paste upload into main's line budgets After merging main, the record store and the clipboard handlers each ran a few lines over the 300-line budget. The sweep now asks the record store whether a chat is recorded through the two lookups it already has (readable or unreadable) instead of a new id-listing method, and the paired-server paste upload lives beside the other attachment uploads. No behavior changes. * fix(native-chat): pending chips sit beside main's saved draft, which keeps server-stored images Main now saves a composer's draft (text and settled images) in one store that survives a reload or quit. This branch kept every chip, settled or not, in its own pane cache. After the merge the saved draft owns settled images and the pane cache holds only chips still on their way: they come back pending in a composer a prompt card remounted, hold Send, settle into the saved draft whichever composer is showing, and are never saved themselves, so a restored draft cannot bring back an upload as if it were attached. An image a paired server stored for the chat is saved with the draft as the real image (a pasted one is no longer turned into a "Not kept" placeholder), and the restore check leaves it to that server, whose claim at Send refuses one it no longer holds, instead of asking this machine's disk for a path that only exists on the server. Also: previews and the pending subscription move into their own small hooks to fit the line budget, the "local attachments" notice moves to the composer-target module so the attachments hook no longer pulls in the upload module's imports, and tests follow main's new mocks. * test(native-chat): give the claims test main's provider handle and message source * fix(native-chat): a paste still uploading dies with its tab or workspace A pasted image still uploading to a paired server sits in the pending chip cache, which by design outlives the composer and its tab. Removing the workspace deleted its saved drafts but left those chips, so the upload finishing afterwards recreated and saved the deleted draft. With the workspace's tabs gone it had no owner either, so no later workspace cleanup could ever remove it. A pending chip now records the owner its draft would have, resolved the way the draft store resolves one when the chip is added. Workspace removal and a user's tab close drop pending chips by the same owner, conversation and tab matches they delete drafts by, and a chip that settles after its chat's tab closed writes its draft under the owner it was begun in. * fix(native-chat): the claim type uses the journal's own SQLite type * refactor(native-chat): read the pending-image handlers off the composer's attachments Main's multi-file picker (#23956) and this branch together took NativeChatComposer over the 400-line limit; reading the two pending-image handlers the way the neighbouring ones already are keeps it at the limit. * test(native-chat): pass the launch-args resolver main now requires in the attachment grant test * fix(native-chat): grant the attachment store beside folders the saved Claude Arguments add Main (#25721) now builds additionalDirectories from the user's --add-dir arguments; this branch's attachment-store grant replaced that list instead of adding to it. Both are granted now. Moves the Claude session-id derivation to its own module to keep the resolver under the line limit. * test(native-chat): run the attachment store's SQLite tests in the Node runtime project * test(native-chat): follow main's attach ownership recheck (#25749) in the attachment tests * test(native-chat): a named upload chip still shows when the agent takes no images * fix(native-chat): a paired-server image paste failure keeps its error apart, as main's notice card does * fix(native-chat): the attachment sweep reads the chat list directly now that records have no import still owed
ELI5
Dropping a file on one terminal split could paste it into the active split, and hovering a title changed which split was active. A file queued during input-method composition in native chat could also attach after the chat moved to another workspace or host. These paths trusted focus or checked the destination before the queued attachment was finally applied.
The independent review found two remaining failures: terminals on a connected runtime server used that server's own “local” host label to search the client's workspace list, so drops could be refused or select a same-ID local workspace; and one stale chat drop could discard a later valid retry queued during the same composition after an SSH reconnect.
This is PR 1 of 6 for STA-6940. Drops now stay with the identified terminal leaf and its captured runtime workspace. Each queued chat drop is checked separately: obsolete drops are refused, and current retries attach once.
What Changed
localand a separate runtime environment; creating a transport no longer rewrites workspace rows to match it.The existing preload → main → window subscriber delivery remains in place. PR 2 adds the path bridge, preparation request, owner hook, and reader guards; PRs 3–5 migrate chat/composers/feedback, terminals, and file/editor/sidebar surfaces; PR 6 removes the broadcast and legacy markers.
Why
Stable leaf identity and the receiving transport identify the destination without changing focus. The server's physical host and the client's workspace-list host name different things; deriving the latter from the captured runtime fixes lookup without changing the upload's execution-host checks. Reusing the existing workspace lookup and recorded-owner routing avoids choosing another host's same-ID workspace.
Keeping gesture boundaries lets a valid retry survive an earlier stale drop while rejecting each obsolete drop as a whole. Flattening only accepted batches preserves insertion order and applies them together, without moving the caret between gestures. A separate chat destination check preserves the distinction between where an attachment may land and whether its paths came from a verified workspace drag.
Differences from the common pattern:
Linked Issue
STA-6940
Visual Proof
A separate QA agent ran this branch (head
a0a5923c29a) as a hidden Orca dev window with an isolated profile and simulated OS file drops through the Chrome DevTools Protocol (Input.dispatchDragEvent). Terminal text was read from each pane's screen buffer and the active pane from app state. Screenshots are uncropped captures of that window. All five checks passed.1. File dropped on the left pane's title bar while the right pane is active. The path lands in the left pane only; app state shows the right pane is still the active pane (before this PR the title bar delivered to whichever pane was active).
2. Same file dropped on the left pane's body. A second copy of the path lands in the left pane; the right pane is unchanged and still active.
3. File dropped on the divider between the panes. Nothing is pasted anywhere and no error appears: a drop Orca cannot place now does nothing instead of going to the active pane.
4. A file name with a space. Pasted as one single-quoted shell argument.
5. File dropped on the floating terminal (a terminal with no project behind it). The path is pasted there, and the main panes are unchanged.
Restructured native chat (macOS, Claude)
A second hidden-window run on this head (
a0a5923c29a) with native chat and structured native chat on, and agent tabs opening in chat view. Both chats were proven to be the restructured kind before testing: their tabs are structured agent sessions, the app had zero terminal sessions, and Claude ran through the agent SDK under Orca's provider supervisor, not as a command-line session in a terminal. Chat A is the visible tab; chat B is open in the second tab.1. File dropped from the OS on chat A's composer. It attaches to A as a file reference, once. Chat B and the (non-existent) terminal get nothing.
2. Image dropped on chat A's transcript area, outside the composer. It attaches to A as one image.
3. Hidden chat isolation. A file dropped on chat B attached to B only; back on A, nothing from B appears.
4. Image pasted into chat B's composer (a real PNG on the system clipboard, pasted through the composer's paste handler). Exactly one image attaches to B, next to B's own dropped file; chat A gains nothing.
5. File dragged from Orca's file explorer into chat A. It attaches as a workspace file reference, once.
6. File dropped while an input method was mid-composition (this PR's new destination re-check). The file attached exactly once after composition ended; the composed text survived.
7. The attachment reaches the agent. With only the dropped image attached, a message was sent; Orca's session journal records the submission with exactly that image. Claude's reply never arrived in this isolated test profile (the turn stayed "Working…"), so the reply itself is not verified.
Not covered by this run: SSH, WSL and remote-runtime workspaces (covered by the unit fixtures listed below), Linux and Windows. There is no "before" capture; the before behaviour is pinned by the regression tests below, which fail against
main's code.Testing
On macOS, the following explicit 24-file Vitest command passed 215/215 tests:
Both follow-up regressions fail on the reviewed PR head
2dcc2a94273260d6b3aec5371c2934634ae7c553and pass after these fixes. With the final tests retained, I temporarily replaced the four changed production modules with that head's sources and ran:ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/terminal-drop-runtime-catalog-owner.test.ts src/renderer/src/components/native-chat/native-chat-external-attachments-destination.test.tsxThe reviewed head produced 11 behavioral assertion failures and 9 passes: 10 runtime ownership cases failed across OS and internal drops, and the stale-then-current SSH composition retry failed. After restoring the fixed sources, the identical command passed 20/20 tests. Runtime worktree, folder, and SSH fixtures keep a different runtime focused and include same-ID local records; the SSH fixture also includes a direct-client record and another runtime's same target. The chat test queues files and images on SSH generation 1, reconnects to generation 2, queues the retry, then flushes twice: only the retry attaches, exactly once, and the existing owner-change notice remains.
Initial PR validation temporarily replaced the nine changed existing source modules with
origin/mainat9756daeced4e, retaining the regression tests, then ran the title, pane resolution, workspace path, internal handler, global terminal subscriber, local-workspace, and external-attachment destination test files. 16 tests failed and 28 passed, covering all four title drag/drop combinations, missing/stale destinations, folder/host lookup, the dropped-path root fallback, missing terminal tab, and queued workspace/host/SSH-generation changes. Both native and internal floating-terminal tests passed against main and this branch. All source files were restored afterward.The two OS workspace-exemption guards already pass on main. Initial PR validation proved they catch the rejected implementation by temporarily changing the OS lane to pass its destination check as
targetOwnerIsCurrent: both immediate and queued guards failed. Restoring the separatedestinationIsCurrentcheck returned the entire suite to green.Also passed:
pnpm tc:web;pnpm run check:code-quality:changed; full-filepnpm exec oxlinton all 22 changed TypeScript files;pnpm run check:react-doctor:changed(no issues);pnpm run verify:localization-catalogs; formatting andgit diff --check.SSH, runtime, Windows/WSL, and folder cases were exercised through unit fixtures. No real SSH/WSL host, Linux/Windows machine, or packaged build was verified; the Electron check is under Visual Proof.
Review
Self-reviewed destination identity, source provenance, server host identity, workspace-list qualification, and queued drop settlement, and line budgets. The title overlay is net −1 effective line and the global-effects hook is net negative; full-file lint enforces their limits. No preload, main-process relay, editor options, sidebar readers, web entry files, or documentation changed.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Checklist
N/Awith reason (after screenshots above; the before behaviour is pinned by tests failing on main)pnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (focused checks passed above; full build and full lint left to CI)