Skip to content

Fix desktop image drops for chat attachments - #7982

Merged
danielhanchen merged 21 commits into
unslothai:mainfrom
Souravrajvi0:feat/desktop-image-drop-7963-c8fc
Aug 8, 2026
Merged

danielhanchen merged 21 commits into
unslothai:mainfrom
Souravrajvi0:feat/desktop-image-drop-7963-c8fc

Conversation

@Souravrajvi0

Copy link
Copy Markdown
Contributor

Fixes #7963.

Dragging a PNG/JPG onto the desktop window was rejected because drop-paths.ts derived its whitelist from RAG_UPLOAD_ACCEPT (documents only). The chat composer already accepts vision images via a separate IMAGE_ACCEPT list.

Fix

layer change
drop-paths.ts Add CHAT_IMAGE_DROP_ACCEPT (.jpg,.jpeg,.png,.webp,.gif) merged into the native drop classifier; update SUPPORTED_DROP_HINT
native_path_policy.rs Add IMAGE_ATTACHMENT_EXTS and allow them in classify_native_attachment_path without widening document/RAG ingest

RAG_UPLOAD_ACCEPT is unchanged, so the knowledge-base uploader still only accepts documents.

Testing

node --experimental-strip-types --test tests/native-drop-paths.test.ts
✔ 10 pass  ✖ 0 fail

Covers image-only drops, mixed doc+image batches, hint text, and frontend↔Rust extension parity for both document and image sets.

Not run here: Tauri desktop drag-drop smoke (needs a built app).

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Souravrajvi0
Souravrajvi0 force-pushed the feat/desktop-image-drop-7963-c8fc branch from 99ba5cc to aa0b16b Compare August 6, 2026 09:06
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@LeoBorcherding

LeoBorcherding commented Aug 7, 2026 •

Copy link
Copy Markdown
Collaborator

Looking great, thank you @Souravrajvi0! great work, will leave a review of the code as well if there is anything that needs to be cleaned up.
image

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Pushed three commits to this branch (thanks for leaving maintainer edits on) and re-merged main.

The red CI isn't your feature. The merge in e7cb908 resolved in favour of the branch across the board and reverted ~13k lines of main -- 160-odd files, including scripts/virustotal_scan.py, studio/src-tauri/src/linux_webkit.rs, most of commands.rs, and a lot of tests. Backend CI's InferenceStatusResponse() got multiple values for keyword argument 'chat_template_override' is main's own fix for that TypeError being reverted back out. I redid the merge taking main's side everywhere outside this PR, then merged current main on top. git diff upstream/main..HEAD is now exactly the 11 files this PR owns.

The two open P2s from the last review:

  • 1838f49 -- dictation: dictationSendBlocked only counted hasPendingAttachments, so a held send called requestSubmit(), handleSubmit bounced it on hasMaterializingImageAttachments, and the transcript was dropped. It waits on materializing drops now. Same commit: a drain for a target the composer has already left returns without clearing materializingDroppedImages, so a stale worker can't open the send gate under the live target. And the Rust read is bounded by take(MAX + 1) instead of trusting the stat.
  • 2953f76 -- VisionImageAdapter.add already toasts before it throws, and every rejection reachable on this path is chat-wide (no model loaded, or not multimodal), so requeueing the rest of the batch just re-read each image over IPC to reject it again: a 3-image drop onto a text-only model produced six toasts. It stops at the first failure now, matching how the document drop path reports a batch-wide refusal once.
  • 9e02650 -- a test for the second seam of the same shape as [Bug] Desktop: dropping an image onto the window is rejected, though chat accepts image attachments #7963: native_intents.rs stamps the File's MIME type and the composer routes to an adapter by MIME, with nothing tying the two lists together. Pinned.

Local: 798 frontend tests, 173 Rust tests, typecheck and build clean. The drag-drop itself still needs a desktop build to smoke.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Souravrajvi0 and others added 12 commits August 7, 2026 20:06
)

Give the native drop classifier its own image extension whitelist
matching the chat composer, without widening RAG_UPLOAD_ACCEPT.
Extend Rust native attachment intake so register_native_attachment_path
accepts the same image types end-to-end.
Classify image drops separately from RAG documents, queue them for the
composer, and read dropped image bytes through Tauri so vision
attachments no longer fail on the document upload path.
Verify the attachment target key before each addAttachment and re-queue
remaining intents when the user switches chats mid-import. Align the
desktop reliability contract with the 30px titlebar control size.
Re-queue remaining intents on composer unmount or target change, and
handle per-image failures without dropping later valid attachments.
Align the desktop reliability contract with the 30px New chat button.
Subscribe to the image queue instead of tying the drain worker to
hasPendingImageAttachments, return after requeueing failed suffixes,
block send/queue while images materialize, and allow image drops without
backend path leases.
… holes

- dictation: the recording bar's send now waits on materializing image drops
  instead of spending the held send on a submit that shouldBlockSend bounces
- drain: a drain for a target the composer has already left no longer clears
  the shared materializing flag out from under the live target
- rust: cap the attachment read itself, so a file that grows after the stat
  can't get past the 20 MiB limit
VisionImageAdapter.add already toasts before it throws, and every rejection
it can reach on this path is chat-wide (no model, or not multimodal) rather
than per-file, since Rust enforces the same 20 MiB cap. Requeueing the rest
of the batch just read each image over IPC to reject it again, so a 3-image
drop onto a text-only model produced six toasts. Stop at the first failure,
matching how the document drop path reports a batch-wide refusal once.
…seam

unslothai#7963 was two features sharing one list until it drifted. The image drop path
has a second seam of that shape: native_intents.rs stamps the File's MIME type
and the composer routes to an adapter by MIME, with nothing tying the two
together. Pin them, so a format added to one side can't silently stop being
droppable.
A send parked behind document indexing fired the moment indexing cleared,
without re-checking the gate it passed on the way in. Drop an image onto
that draft and the text goes out without it, and the image attaches to the
next draft instead.
- registration: the gate only saw the queue, which the intents don't reach
  until Rust has answered. An Enter in that window sent the text alone. The
  count is deliberately not keyed: until the intents land there is no settled
  target, since an implicit single chat re-keys the moment its thread exists.
- failure: a parked send fired when a dropped image failed to materialize,
  turning a failed drop into a send of the text without it. Cancel the parked
  send instead, so the user keeps their text and the toast explains why.
The update() path now wraps setup in _WindowsLauncherUpdateTransaction
instead of _release_self_exe_lock_windows. Align the ordering assertion
with the current studio.py structure.
provider.tsx now uses --studio-titlebar-navigation-offset-y 4px and
--studio-chat-header-padding-top 9px; update the desktop reliability
contract assertions to match.
@Souravrajvi0
Souravrajvi0 force-pushed the feat/desktop-image-drop-7963-c8fc branch from 2bd5619 to 4c741bd Compare August 7, 2026 20:07
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Registration failures, listener teardown and partial batches each lost a
dropped image or sent the text without it. Also binds the native read to
the fingerprint the token was validated against.

- store: imageDropFailures, bumped when a drop fails before it queues, so
  the composer can drop a parked send instead of sending the text alone.
- use-native-drop: register per path (allSettled) so one bad file no
  longer discards its siblings' leases, and enqueue registered intents
  even when the listener was disposed mid-flight.
- thread: requeue a drained batch under the key the same composer moved
  to, so a fresh chat persisting mid-batch no longer strands it; guard
  the parked send on pendingSendRef for a cancel in the same commit.
- native_intents: open with O_NOFOLLOW and recheck size and mtime against
  the entry, so a file swapped in after validation is not read.
- tests: extension to MIME arm parity, composer picker parity, doc/image
  disjointness, and four Rust tests for the read path.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed d19bb57. The feature itself is right, and I checked that it does not disturb anything that worked before: I ran main's classifier and this branch's over 48,203 generated drop payloads (Linux, macOS and Windows path shapes, case variants, dotfiles, double extensions, unicode, spaces, batches of 1 to 4) and there are zero behaviour changes for any payload that previously classified as a model or a document drop. Every change is unsupported becoming images or attach.

What I fixed, all of it in the failure and teardown paths rather than the happy path.

1. A failed registration released the send gate with no way to cancel a parked send.
use-native-drop.ts toasted and let the finally clear the counter. The drain has cancelQueuedSendRef for exactly this, but the hook cannot reach it. Park a send behind document indexing, drop an image, let registration fail, and the text went out on its own. Added imageDropFailures to the store; the composer watches it and cancels. The parked-send effect also had to check pendingSendRef.current, since a cancel earlier in the same commit leaves pendingSend reading true from that render.

2. Teardown mid-registration lost the images. if (disposed) return; sat inside the try, so intents were registered with Rust and then dropped on the floor, with no toast and the lease left to expire. Both callbacks only enqueue against a target key, so they are safe to run after the listener is gone.

3. A mixed drop was all-or-nothing. One failing document rejected the whole Promise.all and discarded images that had already registered. Now per path with allSettled: what registered gets attached, one toast covers the batch, and a failed image still cancels a parked send.

4. A re-key mid-batch stranded the batch. artifactViewKey flips from single:new to single:<threadId> the moment a fresh chat persists, and the drain requeued its unprocessed suffix under the old key, which nothing watches. Three images went in, nothing arrived, no toast. The requeue now follows the key when the composer identity is unchanged, using the same list-item-id distinction the dictation send already relies on. A real thread switch still leaves the batch with the chat that received the drop, which I pinned with a test.

5. The native read was not bound to the fingerprint it had just validated. path_for_operation proves size and mtime still match the registered ones, then the read opened the path again and checked only is_file() and the cap. I reproduced both windows against the real policy module: a rename() of any regular file over the path between the two steps returned the substituted bytes, and a symlink swapped in after validation was followed. Those bytes become a data: URL sent to the vision endpoint, so it is worth closing even though the attacker has to be a same-user local process. Now opens with O_NOFOLLOW and O_NONBLOCK, matching native_clipboard.rs, and rechecks size and mtime against the entry. Both cases are refused after the change.

Tests. The two parity tests never joined up: CHAT_IMAGE_DROP_ACCEPT to IMAGE_ATTACHMENT_EXTS, and the Rust MIME arms to VisionImageAdapter, with nothing tying the extension list to attachment_mime_type. Adding .bmp to both allow-lists with no MIME arm passed both tests and produced a drop that is accepted, queued, and only then refused by the reader, one toast per file. Added the missing scrape, a check against the composer's own IMAGE_ACCEPT (the constant drop-paths.ts names in its keep-in-sync comment), a doc/image disjointness assertion, and four Rust tests for the read path including the swap rejection.

Local: 897 frontend tests, typecheck, build and biome all clean, biome at the same error and warning counts as before the change.

Two things I left alone and would suggest as follow-ups rather than fold in here. read_native_attachment_file is a sync command, so per Tauri's rule it runs on the main thread while read_native_clipboard_files is async fn plus spawn_blocking; measured in Chromium, Firefox and WebKit, a 20 MiB image is a 26.7 MB base64 string costing roughly 82 to 114 ms to decode plus 41 to 102 ms to re-encode as a data: URL, and the drain is sequential. Related, there is no per-drop count or total-byte cap, where the clipboard path caps at 8 files and 20 MiB total.

One thing worth knowing rather than fixing: Tauri has open reports of drag-drop not firing on some Wayland setups and of garbled paths out of onDragDropEvent on Windows. Neither is caused by this PR, and a garbled path fails closed here because registration re-checks it against was_recently_dropped.

On the red CI: the four Backend CI failures in tests/test_research_runs_hardening.py and the three pip scan-packages jobs are failing on main itself at e96d020, 1b3c31e, 47df5b8 and 0ca37e5. Not this branch.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d19bb57356

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2162 to +2164
const registeringImageDrops = useNativeIntentStore(
(s) => s.registeringImageDrops > 0,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scope the image-registration gate to its target chat

When an image dropped in chat A is still registering and the user switches to chat B, this global counter keeps B's shouldBlockSend and queue gate closed even though the resulting intents remain bound to A. Registration can remain in flight noticeably for a large batch or paths on a slow or unavailable network filesystem, making the unrelated active chat unable to send until A's work settles; track registration by the captured attachment target rather than as a window-wide boolean.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct as stated, but I do not think keying it is an improvement. The counter exists precisely to cover the window before the intents reach a queue, and that window is where a fresh chat re-keys from single:new to single:. Keying the gate to the drop-time value re-opens the hole it was added for, in exchange for a Send that is blocked for the length of one registration round trip on a chat the user just switched to. The queued intents themselves are already bound to the right chat, and the per-chat signal that does matter, imageDropFailures, is keyed in e512022. Happy to revisit if you have a repro where the block is long enough to notice on a local disk.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Aug 8, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Aug 8, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Aug 8, 2026
@unslothai unslothai deleted a comment from oobabooga Aug 8, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Aug 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…nslothai#7982

- A read failure now carries on to the next image and reports once at the end
  of the drain, instead of one toast per file when a whole batch is unreadable.
- The addAttachment catch drops its toast: VisionImageAdapter.add already
  toasts before it throws, and its only other throw is the 20 MiB cap that
  Rust enforces first.
- Both cancels test composer identity, matching requeueKey, so a fresh chat
  rekeying mid-read still cancels its own parked send.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b8a9a547e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

isModelLoading: Boolean(loadingModel) || modelLoading,
onAutoLoad: handleNativeModelDropAutoLoad,
onAttach: handleNativeAttachmentDrop,
onAttachImages: handleNativeImageDrop,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Route native image drops into compare mode

In desktop compare mode this callback is attached only to useNativeModelDrop, whose enabled condition remains restricted to view.mode === "single". The compare SharedComposer also explicitly returns from its drag handlers when isTauri (lines 1883–1895), so PNG/JPEG drops in compare mode are ignored even though that composer supports the same image types through its picker. Add native image-drop routing for SharedComposer or otherwise enable an appropriate compare-mode listener.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct that compare mode ignores these drops, but that is not this PR. enabled: active && view.mode === "single" is on main today at chat-page.tsx:2602, so compare mode has never taken a native drop of any kind, documents included. Wiring SharedComposer up is a new capability rather than a fix for #7963, and it needs its own decisions: compare has two panes and a drop lands on the window, so something has to say which pane gets the image. Worth its own issue, and I would rather not widen this one.

…thai#7982

- cancelQueuedSend clears the dictation hold as well: a transcript held behind
  the same block otherwise submits itself once the block clears, without the
  image the drop failed to attach.
- The drag overlay claimed "Indexed for this chat" for images, which are never
  indexed. The attach state now carries its kind and the copy follows.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…hem for PR unslothai#7982

- A fresh chat persisting remounts Composer, so the outgoing instance cannot
  hand its queue to the new key: it tags the batch with its composer identity
  and the next instance with that identity claims it on mount.
- interceptSend parks the send while images materialize instead of swallowing
  the click, with wait-toast copy that names what it is waiting for.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…for PR unslothai#7982

- The replacement composer's claim ran once at mount, so a predecessor that
  requeued after that point left its batch stranded. The claim is reactive now,
  watching imageDropOwners for an entry tagged with this composer.
- handleSubmit has its own gate ahead of interceptSend, so the image park was
  unreachable from a click or Enter. Both gates call one parkIfWaitingOnImages.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 59327fc3d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 8261f27087

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit f8497dc into unslothai:main Aug 8, 2026
37 of 43 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.

[Bug] Desktop: dropping an image onto the window is rejected, though chat accepts image attachments

3 participants