Skip to content

fix(native-chat): keep every image chip when several images are dropped at once - #32022

Merged
AmoabaKelvin merged 2 commits into
mainfrom
chat-image-drop-numbering
Oct 22, 2026
Merged

AmoabaKelvin merged 2 commits into
mainfrom
chat-image-drop-numbering

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7

ELI5

If you dropped three images into a chat at once, all three thumbnails showed up but the prompt only got chips for #1 and #3. The middle one was erased right after it was added. Now every image you drop or paste together gets its own chip, numbered 1, 2, 3.

What Changed

The bug hit structured chats (OpenCode, OMP, Claude) whenever several images are attached in one go: a Finder/Explorer drop, or pasting several copied files. Every other chip went missing (#1, #3, #5…). Sending then gave the agent [Image #1] and [Image #3], though all the files were attached. Adding images one at a time worked.

Cause: each chip goes into the prompt editor in its own transaction. TipTap renders a chip's React node view with flushSync during that transaction, before the editor reports the change. The flushSync also flushes the composer's pending render. That render's draft is the text from before the newest chip, and NativeChatComposerField's draft→editor sync saw it differ from the editor, so it wrote the old draft back and deleted the chip it had just added.

Fix: the sync remembers the draft the editor last reported or was given. A render carrying that same draft is one the editor has already moved past, so it is not pushed back. Drafts set from outside the editor (send clearing, a message handed back, recall, picker completions, appends while the editor is gone) still differ from that value and reach the editor as before. The check also skips serializing the editor's document on every keystroke.

Why

The field's sync is where the wrong fact gets written, and fixing it there covers every path that inserts more than one chip in a row: drop, multi-file paste, and anything added later. Other options were weaker:

  • Batching the inserts would need a reshaped begin API, and the next caller that dispatches twice would hit the bug again.
  • Getting the editor to report before node views render would mean patching TipTap's dispatch internals.
  • Drawing chips without React would lose the row numbering they read from React context.

Mobile has no inline chips in its composer, so it isn't affected. Nothing goes over the wire.

Linked Issue

Linear: STA-11357 (no GitHub issue).

The report also mentions an oversized first drop that did nothing. This branch doesn't touch that: it's a separate size/limit path, and the numbering bug reproduces without it.

Visual Proof

Hidden dev build, OpenCode chat in a folder workspace, three PNGs dropped at once with a trusted CDP drag (Input.dispatchDragEvent).

BEFORE (main): thumbnails #1–#3, chips #1 and #3

(screenshot removed: contained real product data)

AFTER (this branch): thumbnails #1–#3, chips #1, #2, #3

(screenshot removed: contained real product data)

Testing

Each chip's node view renders the composer inside the editor's change, before
the editor reports it, so the draft sync wrote the older draft back over it.
@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 22, 2026 21:32
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The composer now tracks editor drafts and updates the textarea only when the incoming draft differs from both the tracked draft and the current textarea value. The file-drop tests now support multiple filenames and verify the image-reference chip labels for three dropped PNG files.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 7ad60

A narrow IME cancellation sequence can leave a later draft invisible in the composer; update the tracked editor draft during settlement before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: preserving all image chips when multiple images are dropped.
Description check Passed The description is comprehensive and covers the user impact, mechanism, rationale, linked issue reference, visual proof, testing, platform scope, and known out-of-scope behavior. Some template section…
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 comprehensive and covers the user impact, mechanism, rationale, linked issue reference, visual proof, testing, platform scope, and known out-of-scope behavior. Some template sections are not included, and the linked issue is identified as Linear STA-11357 without a direct link, but the core required information is present.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a91b2c91-3b32-45ec-8c97-6112bd901eec
📥 Commits

Reviewing files that changed from the base of the PR and between d053ff9 and 7ad6005.

📒 Files selected for processing: 2
  • src/renderer/src/components/native-chat/NativeChatComposerField.tsx
  • src/renderer/src/components/native-chat/native-chat-composer-ime-file-drop.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Comment on lines +201 to +204
if (draft !== editorDraftRef.current && textarea.value !== draft) {
textarea.value = draft
}
textarea.value = draft
editorDraftRef.current = draft

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -n "settleImeValue|imeComposedSegment|onImeSettled|isComposing|composition" src/renderer/src/components/native-chat/NativeChatComposerField.tsx src/renderer/src/components/native-chat/NativeChatComposer.tsx src/renderer/src/components/native-chat src/renderer/src -g '*.tsx' -g '*.ts' | head -240
sed -n '1,180p' src/renderer/src/components/native-chat/use-native-chat-ime-enter-gesture.ts 2>/dev/null || true

Repository: stablyai/orca

Length of output: 32818


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- NativeChatComposerField.tsx ---'
nl -ba src/renderer/src/components/native-chat/NativeChatComposerField.tsx | sed -n '90,235p'
nl -ba src/renderer/src/components/native-chat/NativeChatComposerField.tsx | sed -n '280,345p'
printf '%s\n' '--- NativeChatComposer.tsx parent settlement and field ---'
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '360,420p'
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '70,115p'
printf '%s\n' '--- draft/picker/send related source ---'
nl -ba src/renderer/src/components/native-chat/use-native-chat-draft.ts | sed -n '1,90p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-picker-state.ts | sed -n '145,195p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts | sed -n '105,145p'
printf '%s\n' '--- relevant tests ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsx | sed -n '80,330p'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | sed -n '1,230p'
printf '%s\n' '--- PR diff for field and related tests ---'
git diff --unified=80 d053ff97ab3613a3813eb76604de1435f02607ae 7ad600519138a3fe18a59eaf8cfc5282d9ab0d42 -- src/renderer/src/components/native-chat/NativeChatComposerField.tsx src/renderer/src/components/native-chat/NativeChatComposer.tsx src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsx src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx

Repository: stablyai/orca

Length of output: 42231


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- NativeChatComposer draft handlers and editor wiring ---'
rg -n -F -- 'handleDraftChange' src/renderer/src/components/native-chat/NativeChatComposer.tsx
rg -n -F -- 'NativeChatPromptEditor' src/renderer/src/components/native-chat src/renderer/src -g '*.tsx' -g '*.ts' | head -80
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '115,230p'
nl -ba src/renderer/src/components/native-chat/NativeChatComposer.tsx | sed -n '230,360p'
printf '%s\n' '--- Prompt editor implementation ---'
rg -n -F -- 'export function NativeChatPromptEditor' src/renderer/src
rg -n -F -- 'onChange' src/renderer/src/components/native-chat/NativeChatPromptEditor.tsx src/renderer/src/components/native-chat/native-chat-prompt-editor-store-value.test.tsx 2>/dev/null || true
nl -ba src/renderer/src/components/native-chat/NativeChatPromptEditor.tsx | sed -n '1,240p' 2>/dev/null || true
printf '%s\n' '--- complete composition tests around direct settlement and external changes ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsx | sed -n '88,335p'
printf '%s\n' '--- external draft write/call sites relevant to recall, picker, send clear ---'
rg -n -F -- 'setDraft(' src/renderer/src/components/native-chat -g '*.tsx' -g '*.ts' | grep -E 'recall|picker|structured|send|NativeChatComposer|setDraft' | head -180
rg -n -F -e 'handleDraftOrCaretChange' -e 'commitCompletion' -e 'setDraft(' src/renderer/src/components/native-chat/use-native-chat-composer-recall.ts src/renderer/src/components/native-chat/use-native-chat-picker-state.ts src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts src/renderer/src/components/native-chat/NativeChatComposer.tsx 2>/dev/null || true

Repository: stablyai/orca

Length of output: 42182


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- IME ownership implementation ---'
rg -n -F -- 'useImeEnterGestureOwnership' src/renderer/src
nl -ba src/renderer/src/lib/ime-composition-keyboard-event.ts | sed -n '1,240p' 2>/dev/null || true
printf '%s\n' '--- NativeChatPromptEditor update and value setter ---'
nl -ba src/renderer/src/components/native-chat/NativeChatPromptEditor.tsx | sed -n '90,220p'
printf '%s\n' '--- structured send clear path ---'
nl -ba src/renderer/src/components/native-chat/use-native-chat-structured-composer-send.ts | sed -n '105,140p'
printf '%s\n' '--- recall implementation and invocation ---'
rg -n -F -- 'useNativeChatComposerRecall' src/renderer/src/components/native-chat
nl -ba src/renderer/src/components/native-chat/use-native-chat-composer-recall.ts | sed -n '1,240p' 2>/dev/null || true
nl -ba src/renderer/src/components/native-chat/use-native-chat-composer-keydown.ts | sed -n '120,190p'
printf '%s\n' '--- settlement-related tests with cancellation/no-op composition ---'
rg -n -F -e 'cancel' -e 'compositionEnd' src/renderer/src/components/native-chat/native-chat-composer-ime-file-drop.test.tsx src/renderer/src/components/native-chat/native-chat-composer-composition.test.tsx

Repository: stablyai/orca

Length of output: 26194


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- draft-only external writers ---'
nl -ba src/renderer/src/components/native-chat/use-native-chat-typed-insertion.ts | sed -n '1,90p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-launch-draft-adoption.ts | sed -n '80,145p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-picker-state.ts | sed -n '164,225p'
nl -ba src/renderer/src/components/native-chat/use-native-chat-picker-command-dispatch.ts | sed -n '70,115p'
printf '%s\n' '--- shared draft store update semantics ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts | sed -n '1,220p'
nl -ba src/renderer/src/components/native-chat/native-chat-draft-cache.ts | sed -n '1,150p'
printf '%s\n' '--- tests with multiple composers or external draft propagation ---'
rg -n -F -e 'same scope' -e 'other composer' -e 'second' -e 'setDraft(' src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | head -100
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | sed -n '230,430p'

Repository: stablyai/orca

Length of output: 36707


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- settlement cleanup behavior ---'
rg -n -F -- 'flushPendingAttachments' src/renderer/src/components/native-chat
rg -n -F -- 'flushDraftAppends' src/renderer/src/components/native-chat
nl -ba src/renderer/src/components/native-chat/use-native-chat-composer-attachments.ts | sed -n '180,255p'
printf '%s\n' '--- same-scope draft propagation contract/test ---'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-store.ts | sed -n '90,105p'
nl -ba src/renderer/src/components/native-chat/native-chat-composer-draft-lifecycle.test.tsx | sed -n '362,395p'

Repository: stablyai/orca

Length of output: 10628


Update editorDraftRef after the settlement write.

When a structured send clears the draft during an active IME composition, a canceled composition can settle with no composed segment. settleImeValue then writes '', but NativeChatPromptEditor suppresses onUpdate, so editorDraftRef still contains the previous text. onImeSettled skips handleDraftChange because the settled value already equals the cleared draft.

A later draft-only update to that previous text can then satisfy draft === editorDraftRef.current while the editor is empty. The new guard skips the synchronization and leaves the editor out of sync with the draft.

Suggested fix
       element.value = imeComposedSegment(compositionBaseRef.current, element.value)
+      editorDraftRef.current = element.value

@AmoabaKelvin
AmoabaKelvin merged commit 6a6c9e5 into main Oct 22, 2026
58 checks passed
@AmoabaKelvin AmoabaKelvin self-assigned this Oct 22, 2026
@AmoabaKelvin
AmoabaKelvin deleted the chat-image-drop-numbering branch October 22, 2026 21:50
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