Skip to content

fix(native-chat): scope composer file drops to the pane that received them - #19328

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/Native-chat-has-2-images
Sep 7, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/Native-chat-has-2-images

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​417 $\color{#cf222e}{\Huge{\mathbf{−}}}$​143 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​274
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47

ELI5

Dropping an image into one Chat composer put that image into every open Chat composer. Background chat tabs stay loaded (just hidden), so they silently collected images you never dropped on them, and the images were still sitting there when you came back to the tab. Now a dropped image only lands in the composer you actually dropped it on.

What Changed

A native OS file drop that resolves to target: 'composer' now carries the identity of the composer that received it.

  • NativeChatComposerField publishes its pane key as data-composer-scope-key, on the same element that already carries data-native-file-drop-target="composer".
  • The preload harvests it during the existing composedPath() walk and stamps it onto the payload as scopeKey (src/shared/native-file-drop.ts, src/preload/preload-runtime-support.ts).
  • Each chat composer attaches only when payload.scopeKey matches its own (use-native-chat-file-attachment-actions.ts).
  • The workspace-creation composer's last-wins ownership stack now claims only payloads with no scopeKey, so the two composer families stop stealing each other's drops (composer-drop-listener.ts).

This mirrors what the terminal target already does — it carries tabId/paneLeafId and each pane discards payloads that aren't its own. scopeKey accumulates innermost-first exactly like terminalPaneLeafId. paneKey was already the pane's identity (it keys the draft and attachment caches), so nothing new was invented.

Why

The drop payload is broadcast window-wide (preload → main → every renderer subscriber). Every other target disambiguates itself; composer was { paths, target } with no identity, so all subscribers took it.

That mattered because StructuredAgentSessionPaneOverlayLayer mounts every agent-session tab and hides inactive ones with display: none. One drop therefore wrote into every mounted chat pane's attachment cache, which replays on mount — hence images reappearing in a tab that never received a drop.

Failure modes are safe: an unscoped payload routes to the workspace stack rather than a wrong pane, and the composer branch still sits after path-count/size validation so oversized drops keep rejecting.

Linked Issue

No GitHub issue exists — reported internally as a P0 in Slack with a reproduction script attached. That script is now a test (see below).

Fixes #

Visual Proof

Same Codex Chat tab in both shots — an untouched session ("Start a chat with Codex", never used) after an image was dropped into a different chat tab.

Before — two images the user never added:

orcaqa-before.png

After — composer is clean:

orcaqa-after.png

Testing

Verified end-to-end in the running app (macOS) on an isolated dev profile with two real Codex Chat tabs, using CDP Input.dispatchDragEvent with real on-disk PNGs so Chromium's actual drag machinery runs and webUtils.getPathForFile resolves genuine paths. A synthetic DOM drop cannot test this — getPathForFile returns '', the handler bails at paths.length === 0, and "nothing happened" looks identical to a pass.

Chip counts on the two panes, dropping into the visible one:

untouched pane pane that received the drop
Fix in place 0 2
Fix ablated 2 2
Fix restored 0 2

The ablated row is the pre-fix bug reproduced live. Both directions of the cross-surface leak are covered.

Automated: 6967 tests pass across native-chat, hooks, shared, preload, main/window and terminal-pane; tsc clean on web, node and cli; changed-code quality gate reports 0 new findings.

The repro script from the Slack thread landed on main as native-chat-cross-pane-image-drop-repro.test.tsx, asserting the pre-fix behavior. It is superseded here by native-chat-composer-drop-scope.test.tsx, which keeps its editor-target control case verbatim and adds: correct per-pane scoping, unscoped-composer drops reaching no chat pane, and a scope key published inside the drop-target marker. A separate test asserts the real component renders the scope key on the marker element itself — the walk stops there, so a key anywhere else would silently never reach the payload.

Platforms: exercised on macOS. The change is platform-neutral (no paths, no shell, no OS APIs); the web preload shim's onFileDrop is a no-op stub, and no mobile code constructs composer payloads.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Backwards compatibility: scopeKey is optional. A payload without one behaves as before for the workspace composer and is ignored by chat composers, so no drop can land in a wrong pane during a mixed state.
  • Security: the new field is validated as an optional string in main (isNativeFileDropPayload), and the relay is already gated to the window's own webContents. Length is uncapped, matching the existing tabId/paneLeafId posture.
  • Remote/SSH: untouched — scoping happens before the existing local-vs-SSH attachment upload path.
  • Performance: one extra string comparison per subscriber per drop; strictly fewer attachment writes than before.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Merge Sim added 3 commits September 7, 2026 11:07
… them

A native OS file drop resolving to `target: 'composer'` carried no pane
identity, so the window-wide payload was attached by every mounted composer.
Because inactive chat tabs stay mounted (hidden), one drop populated every
chat pane's attachment cache, and those chips replayed whenever the user
returned to a tab they never dropped into. The workspace-creation composer
and chat composers also leaked into each other, since neither could tell
which surface actually received the drop.

Composer drops now carry a `scopeKey` the way a terminal drop carries its
tab and pane leaf id: the composer publishes its pane key as
`data-composer-scope-key`, the preload harvests it during the composedPath
walk, and each composer attaches only its own. The workspace composer's
last-wins ownership stack now claims unscoped payloads only.
…oping test

The repro that landed on main asserts the pre-fix behavior (a drop reaching
every mounted composer), so it fails once drops are scoped to the pane that
received them. Its scoping cases now live in
native-chat-composer-drop-scope.test.tsx, which keeps its editor-target
control case verbatim and adds coverage for unscoped composers and a scope
key published inside the drop-target marker.
@coderabbitai

coderabbitai Bot commented Sep 7, 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: Team

Run ID: 2ff62084-5571-470f-9370-cc06386e23c9

📥 Commits

Reviewing files that changed from the base of the PR and between 423cd1a and e8bf3ea.

📒 Files selected for processing (3)
  • src/renderer/src/components/native-chat/native-chat-composer-drop-scope.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-external-attachments.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-external-attachments.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Native file-drop paths and payloads now carry an optional composer scope key. Native chat composers publish their pane key on the drop target and pass it to the attachment hook. The hook accepts drops only when the payload scope matches its composer. Local paths require authorization before attachment, while SSH paths bypass local authorization. Tests cover scope propagation, validation, pane isolation, attachment authorization, and SSH uploads.

Merge Risk: ⚪ Minimal · up to e8bf3

Native file drops are scoped to the receiving chat composer, while workspace drops remain unscoped and local attachment paths are authorized before use. Current coverage indicates the intended isolation and attachment behavior is ready to merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed and covers the change, motivation, testing, visual proof, security, compatibility, and checklist items. However, the required Linked Issue section is incomplete because it … Add the applicable GitHub issue number or URL to the Linked Issue section. If no issue exists, create or link the required tracking issue before merging.
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 12 files. 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 clearly and concisely describes the main change: scoping native chat file drops to the pane that received them.
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.
Full details: Description check

Explanation

The description is detailed and covers the change, motivation, testing, visual proof, security, compatibility, and checklist items. However, the required Linked Issue section is incomplete because it contains Fixes # without an issue reference, despite the template stating that an issue must always be linked.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

@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 minor coverage gap suggested inline.

Reviewed changes

  • Drop-path scoping — resolveNativeFileDropPath now carries the receiving composer's scopeKey, accumulated innermost-first like terminalPaneLeafId.
  • Payload plumbing — the composer variants of NativeDropResolution / NativeFileDropPayload gain an optional scopeKey; createNativeFileDropPayload forwards it and isNativeFileDropPayload validates it as an optional string.
  • Chat composer gating — NativeChatComposerField publishes paneKey as data-composer-scope-key on the drop-target marker; useNativeChatFileAttachmentActions attaches only when payload.scopeKey matches.
  • Workspace composer gating — useComposerDropListener now claims only unscoped composer payloads.
  • Tests — a full-pipeline scoping test supersedes the bug-asserting repro, plus unit coverage for resolution, payload creation, and payload validation.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA at 423cd1a1be74c704099410bdd24e42119d39a924 (production identical to launched ae2d3e6736ed4ee17409e3070eb82f0f1657ad6f; final commit adds a regression test).

Real filesystem PNG drops through CDP Input.dispatchDragEvent passed native path extraction and receiving-pane isolation in an isolated hidden macOS Electron instance:

  • A received two files; mounted hidden B stayed empty, confirmed after tab navigation.
  • B then received one different file; A retained only its original two.
  • Workspace modal received an unscoped drop; both native-chat attachment caches stayed unchanged.

Checked emitted paths/scope keys, native attachment caches, workspace attachment props, and full-context rendered screenshots. Limitations: screenshots show attachment tiles with placeholder icons; decoded thumbnails/full-size previews were not proven in this hidden run (preview showed unavailable despite readable PNG data). The workspace modal masks chat, so simultaneous chat-to-workspace listener isolation is regression-test coverage rather than a reachable native-drop route. Native file picker, agent submission, SSH and other platforms were not exercised.

A retains two attachments after reverse drop:
A two attachments

B remains clean after A receives files:
B clean

B receives only its own file:
B one attachment

Workspace drop context (quick-create does not render attachment previews):
Workspace modal

@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

  • Workspace-composer drop isolation test — native-chat-composer-drop-scope.test.tsx now mounts a WorkspaceComposerProbe against the real useComposerDropListener, asserting that a scoped native-chat drop is ignored by the workspace stack while an unscoped drop still reaches it.

This closes the one coverage gap from the prior review. The new test asserts exact behavior on both sides of the split (workspaceDrop not called for a scoped payload, called exactly once with the paths for an unscoped one), so it genuinely fails if either half of the fix regresses.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review session complete at 423cd1a1be74c704099410bdd24e42119d39a924.

The scoped review is clean after two review/fix rounds and an independent final gpt-6-astra high-effort review. START and END readiness audits found no proven remaining issues.

The existing infrastructure is the right fit: the composed-path resolver identifies the recipient, the validated single IPC batch preserves that identity, and each composer enforces ownership before attachment/cache/upload work. No production refactor was warranted. Pushed one focused regression improvement: a mounted workspace composer and sibling chat cannot consume the receiving chat's drop, while ordinary workspace drops still work.

Validation:

  • 74 focused tests, web/node typechecks, changed-code quality checks and commit hooks passed.
  • Removing either ownership guard caused the intended regression failures.
  • Hidden isolated macOS Electron, with verified worktree identity and real native CDP PNG drops: both chat directions and workspace-to-chat isolation passed. Folder-workspace behavior was exercised.
  • Four inspected full-context screenshots and detailed QA evidence.

Limits: the workspace modal prevents a real chat drop while it is open; simultaneous listener isolation is proven by the regression test. Attachment tiles and backing paths were verified, but thumbnail/full-size preview rendering was not established (valid PNGs displayed placeholders in the hidden session). Native picker, agent submission, and physical Windows/Linux/SSH/mobile runs were not exercised. Grok could not run because its weekly usage limit was exhausted; Codex performed Electron QA.

The latest commit's typecheck and static analysis are green; test shards and packaging are still running. Working tree is clean. No merge performed.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Follow-up fixed at e8bf3ea63e7f633ff88573d4a52b993c3fedd469: the manual test exposed why native dropped images showed placeholder icons while pasted screenshots displayed previews. Native chat skipped external-file authorization before preview reads; a screenshot in macOS TemporaryItems was rejected by fs:readFile. Clipboard previews already have in-memory image data.

Native chat now uses the existing selected-path authorization API before adding local attachments. Grants remain limited to supplied paths; no temporary-directory blanket grant or generic preview-reader bypass. SSH upload routing is unchanged.

80 focused tests, web typecheck, and changed-code quality gates passed. The regression fails against the original intake. Independent high-effort review and readiness/performance checks are clean.

Fresh isolated hidden Electron proof: an external PNG read was denied before the actual native CDP drop; afterward both thumbnails decoded at 96×96 and the full-size preview displayed real pixels. An undropped neighboring file stayed denied. Chat B stayed empty, and a reverse drop into B left A unchanged. This resolves the earlier preview-rendering caveat—it was an authorization bug, not a hidden-window limitation.

Decoded dropped-image thumbnails
Decoded full-size preview
Untouched sibling chat

No merge performed. User's manual instance was left running; automated instance was cleaned up. Native picker, submission, and live SSH/other-platform execution remain untested in this follow-up.

@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 since the prior pullfrog review at 423cd1a (e8bf3ea, the "authorize external attachment paths before preview" commit):

  • Local-path authorization before attach — useNativeChatExternalAttachments now authorizes each non-SSH path via window.api.fs.authorizeExternalPath before calling attachResolvedPaths, mirroring the workspace composer's applyLocalComposerDrop so out-of-roots dropped images can actually read into the preview.
  • Disabled-state recheck across the await — the authorize loop bails on disabledRef.current and a final check gates the attach, so a composer flipped disabled mid-authorization never receives attachments.
  • Integration + unit coverage — the drop-scope test now drives the real NativeChatImageAttachmentPreview (asserting authorize order/count and rejecting an un-authorized sibling read), and use-native-chat-external-attachments.test.tsx gains cases for skip-rejected, disabled-mid-authorization, and SSH no-local-authorization.

The change faithfully follows the existing workspace-composer pattern (authorizeExternalPath then skip unreadable paths on failure), the sequential loop preserves order, and the new tests would fail without the fix rather than assert tautologically.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Additional independent review completed at e8bf3ea63e7f633ff88573d4a52b993c3fedd469: no proven meaningful in-scope findings. The reviewer checked the full PR, preview authorization, lifecycle/performance, compatibility, and final readiness, and passed 100 tests across nine focused suites.

The fix reuses the existing drop pipeline and workspace-composer pattern: route to the receiving pane, authorize each selected local path through the existing filesystem API, then publish attachments for preview. No additional infrastructure or broader refactor is needed.

CI is now green: all eight test shards, typecheck, static analysis, macOS/Windows packaging, and the final verify gate passed. The first attempt failed in the unchanged skill-install lock concurrency test; that file passed all 11 tests locally, and the failed CI jobs passed on rerun without source changes. Run: https://github.com/stablyai/orca/actions/runs/34158533507

The existing Electron preview/isolation screenshots and validation remain in the previous status comment: #19328 (comment). This additional review did not repeat live platform UI QA. Working tree is clean; no further changes were needed and the PR has not been merged.

@brennanb2025
brennanb2025 merged commit 6a47d28 into main Sep 7, 2026
52 of 54 checks passed
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.

1 participant