Repository navigation
fix(mobile): show attached images in native (rich) chat - #10135
Conversation
Attaching an image in the mobile native chat did nothing visible — it reused the terminal attach flow, which pastes a bracketed host path into the hidden terminal, so there was no composer preview and nothing in the transcript. Give native chat the desktop model instead: - pick + upload shows a removable thumbnail chip in the composer (no early paste) - on submit, images ride along: Ctrl+U clear -> bracketed paste(s) -> settle -> text + Enter (idempotent on retry) - the optimistic echo carries the local preview URIs and the message renderer draws image-ref blocks as real thumbnails when the URI is loadable, so the sent photo appears in the conversation immediately - image-only echoes reconcile by ordinal against user turns after their tail (ignores agent replies / paginated history / the 'unknown' ack-loss path) Terminal chat attach is unchanged (both flows consolidated behind useMobileSessionImageAttachments). Adds unit coverage for pick+upload, the ride-along byte order, chip render/remove, and echo reconciliation.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (15)
📝 WalkthroughWalkthroughAdds native chat image attachments for mobile sessions, including image picking, URI preservation, host temporary-file uploads, terminal bracketed-paste delivery, scoped pending attachment state, and retry handling. The composer displays removable thumbnails and permits image-only sends. Chat rendering supports loadable image references and optimistic image blocks. Draft reconciliation handles image-only and captioned transcript turns. Session integration routes the new attachment state through the native chat overlay and centralizes Create Tab busy-state handling. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ece89216-8570-43a9-9906-66e6c7eb87a2
⛔ Files ignored due to path filters (2)
mobile/docs/native-chat-image-attachment/composer-before-after.pngis excluded by!**/*.pngmobile/docs/native-chat-image-attachment/native-chat-image-proof.pngis excluded by!**/*.png
📒 Files selected for processing (25)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/docs/native-chat-image-attachment/README.mdmobile/src/session/MobileNativeChatComposer.test.tsmobile/src/session/MobileNativeChatComposer.tsxmobile/src/session/MobileNativeChatMessage.tsxmobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatView.tsxmobile/src/session/mobile-image-source-picker.test.tsmobile/src/session/mobile-image-source-picker.tsmobile/src/session/mobile-native-chat-draft-reconcile.tsmobile/src/session/mobile-native-chat-image-attachment.test.tsmobile/src/session/mobile-native-chat-image-attachment.tsmobile/src/session/mobile-native-chat-image-preview.test.tsmobile/src/session/mobile-native-chat-image-preview.tsmobile/src/session/mobile-native-chat-image-send.test.tsmobile/src/session/mobile-native-chat-image-send.tsmobile/src/session/mobile-native-chat-message-styles.tsmobile/src/session/mobile-native-chat-render-data.test.tsmobile/src/session/mobile-native-chat-render-data.tsmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-drafts.test.tsmobile/src/session/use-mobile-native-chat-drafts.tsmobile/src/session/use-mobile-native-chat-image-attachments.test.tsmobile/src/session/use-mobile-native-chat-image-attachments.tsmobile/src/session/use-mobile-session-image-attachments.ts
…driven) Replace the hand-fed component render with an interactive harness that mounts the real MobileNativeChatComposer/Message + useMobileNativeChatImageAttachments + drafts under react-native-web and drives the actual flow via clicks. Only the two OS boundaries are faked: the photo picker and the paired-host RPC socket. Screenshots (mobile/docs/native-chat-image-attachment/) are produced by real clicks, not props: - attach -> real upload pipeline -> chip appears, nothing pasted yet - send -> real ride-along emits Ctrl+U clear, bracketed image paste, text+Enter (shown in the live byte trace) and the sent bubble renders the photo thumbnail
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ac480274-0309-4366-8cef-e5c0afb24c4d
⛔ Files ignored due to path filters (3)
mobile/docs/native-chat-image-attachment/flow-1-initial.pngis excluded by!**/*.pngmobile/docs/native-chat-image-attachment/flow-2-attached.pngis excluded by!**/*.pngmobile/docs/native-chat-image-attachment/flow-3-sent.pngis excluded by!**/*.png
📒 Files selected for processing (10)
mobile/docs/native-chat-image-attachment/README.mdmobile/rnw-preview/.gitignoremobile/rnw-preview/expo-clipboard-stub.tsmobile/rnw-preview/fake-rpc.tsmobile/rnw-preview/index.htmlmobile/rnw-preview/lucide-stub.tsxmobile/rnw-preview/main.tsxmobile/rnw-preview/markdown-stub.tsxmobile/rnw-preview/picker-stub.tsmobile/rnw-preview/vite.config.ts
Images are now scoped to the tab that initiated the pick, so switching tabs during upload cannot ride an image into another terminal. Chips stay with their original tab, and only the active scope's images send with text. Improved error handling with user-facing toast messages for disconnection and send failures.
Add comprehensive test coverage for tab-scoped attachment behavior, error handling when transport fails or lease is gated, and edge cases like attaching images during an in-flight send. Extract baseArgs and update helpers to reduce boilerplate across test cases.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d582ef5f-1a53-4829-ade4-d4c6e61c9b6b
📒 Files selected for processing (8)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/docs/native-chat-image-attachment/README.mdmobile/rnw-preview/main.tsxmobile/src/session/MobileNativeChatView.tsxmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-image-attachments.test.tsmobile/src/session/use-mobile-native-chat-image-attachments.tsmobile/src/session/use-mobile-session-image-attachments.ts
🚧 Files skipped from review as they are similar to previous changes (6)
- mobile/src/session/use-mobile-session-image-attachments.ts
- mobile/docs/native-chat-image-attachment/README.md
- mobile/rnw-preview/main.tsx
- mobile/src/session/use-mobile-native-chat-controller.ts
- mobile/src/session/MobileNativeChatView.tsx
- mobile/app/h/[hostId]/session/[worktreeId].tsx
Images attached in the mobile native (rich) chat now display as: - Removable composer chips while composing - Thumbnails in the sent user bubble after sending (desktop parity) Implements proper image echo reconciliation by distinguishing image-source marker turns from text echoes, so an image send isn't cleared by an unrelated text echo. Adds scope isolation to prevent chips and drafts from leaking between tabs, and detects tab switches during the image-paste settle window to abort the send. Fixes Android tap-target positioning for the image removal badge and clears stale terminal input after failed pastes to avoid gluing fragments onto the next message.
This reverts commit 8f40ddf (#10179). Rebased on current main. The revert applied cleanly across the vast majority of the 1,626-file PR; the remaining work was preserving PRs that had been built on top of #10179 after it merged. All are preserved: - #9990 perf(terminal): cold-restore replay - #10213 fix(codex): TUI settings promotion - #10135 fix(mobile): images in native chat - #9387 fix(status-bar): Resource Manager badge + concurrent listSessions - #9853 fix(app): bound wake/quit paths (phone-session-ended freeze) - #10237 fix(claude-accounts): quote claude path for Windows (kept shell:false) Because those PRs were written against helper modules/APIs that #10179 introduced, the minimal, typecheck-verified closure they depend on is kept so the tree builds and every later-PR test passes: - bounded file/JSON readers used by #10213/#9990 (agent-state-file-reader, node-bounded-file-reader, json-text-structure-limit, terminal-history limits) - claimed-agent-pty-owner cap API + pty:listSessions admission (#9990/#9387) - the mobile-E2EE outbound-memory-budget subsystem #9853 builds on (e2ee-channel, mobile-e2ee-*, ws-outbound-backpressure-queue, remote-runtime-request-frames/-memory-limits, map-with-concurrency, e2ee-crypto) Everything else #10179 added (~555 files) is deleted; every file it modified elsewhere is restored to its pre-#10179 state. Verified: root typecheck (node+cli+web), mobile typecheck, full root test suite, full mobile test suite, oxlint, localization catalog + coverage, reliability gates, max-lines ratchet, and the CLI emit build all pass. Two checks fail only locally and fail identically on clean origin/main (this clone's git-tag namespace for verify:skill-bundle-manifest; an inherited GIT_CONFIG_* env for one relay test) — both pass on a clean CI environment. Co-authored-by: Orca <[email protected]>
* fix(mobile): show attached images in native (rich) chat Attaching an image in the mobile native chat did nothing visible — it reused the terminal attach flow, which pastes a bracketed host path into the hidden terminal, so there was no composer preview and nothing in the transcript. Give native chat the desktop model instead: - pick + upload shows a removable thumbnail chip in the composer (no early paste) - on submit, images ride along: Ctrl+U clear -> bracketed paste(s) -> settle -> text + Enter (idempotent on retry) - the optimistic echo carries the local preview URIs and the message renderer draws image-ref blocks as real thumbnails when the URI is loadable, so the sent photo appears in the conversation immediately - image-only echoes reconcile by ordinal against user turns after their tail (ignores agent replies / paginated history / the 'unknown' ack-loss path) Terminal chat attach is unchanged (both flows consolidated behind useMobileSessionImageAttachments). Adds unit coverage for pick+upload, the ride-along byte order, chip render/remove, and echo reconciliation. * test(mobile): interactive native-chat image proof (real hooks, click-driven) Replace the hand-fed component render with an interactive harness that mounts the real MobileNativeChatComposer/Message + useMobileNativeChatImageAttachments + drafts under react-native-web and drives the actual flow via clicks. Only the two OS boundaries are faked: the photo picker and the paired-host RPC socket. Screenshots (mobile/docs/native-chat-image-attachment/) are produced by real clicks, not props: - attach -> real upload pipeline -> chip appears, nothing pasted yet - send -> real ride-along emits Ctrl+U clear, bracketed image paste, text+Enter (shown in the live byte trace) and the sent bubble renders the photo thumbnail * fix(mobile): scope native-chat image attachments by active tab Images are now scoped to the tab that initiated the pick, so switching tabs during upload cannot ride an image into another terminal. Chips stay with their original tab, and only the active scope's images send with text. Improved error handling with user-facing toast messages for disconnection and send failures. * test(mobile): add image attachment tab-scoping and error tests Add comprehensive test coverage for tab-scoped attachment behavior, error handling when transport fails or lease is gated, and edge cases like attaching images during an in-flight send. Extract baseArgs and update helpers to reduce boilerplate across test cases. * fix(mobile): show attached images in native rich chat Images attached in the mobile native (rich) chat now display as: - Removable composer chips while composing - Thumbnails in the sent user bubble after sending (desktop parity) Implements proper image echo reconciliation by distinguishing image-source marker turns from text echoes, so an image send isn't cleared by an unrelated text echo. Adds scope isolation to prevent chips and drafts from leaking between tabs, and detects tab switches during the image-paste settle window to abort the send. Fixes Android tap-target positioning for the image removal badge and clears stale terminal input after failed pastes to avoid gluing fragments onto the next message. * rm stubs --------- Co-authored-by: Jinjing <[email protected]>
Problem
In the mobile native / rich chat (not the terminal chat), attaching an image did nothing visible — the photo never appeared while composing or after sending.
Root cause
The native chat reused the terminal attach flow, which uploads the image and immediately pastes a bracketed host file path into the terminal. That's correct for the terminal chat (the path shows in the visible input), but in native chat the terminal is hidden, so there was no composer preview and nothing in the transcript. The desktop rich chat instead holds images as composer chips and rides them along on submit — mobile was missing that model entirely.
Fix (desktop parity)
Ctrl+U clear -> bracketed image paste(s) (no Enter) -> 300 ms settle -> text + Enter(mirrors desktop'ssendNativeChatMessageWithImageAttachments); the leading clear keeps a retry idempotent.image-refblocks as real<Image>thumbnails when the URI is loadable, so the sent user bubble shows the photo. Image-only echoes reconcile by ordinal against the next user turn after their tail (ignores agent replies / paginated history / the rareunknownack-loss path).useMobileSessionImageAttachments).Proof — driven by real clicks, not hand-fed props
An interactive harness (
mobile/rnw-preview/, reproducible) mounts the real components + hooks (MobileNativeChatComposer,MobileNativeChatMessage,useMobileNativeChatImageAttachments,useMobileNativeChatDrafts) under react-native-web. The only faked things are the two OS boundaries a browser/CI can't reach: the native photo picker and the paired-host RPC socket. Every state below is produced by the real code reacting to clicks; the bottom panel prints the actual bytes the real send pipeline wrote to the (faked) socket.1 — initial: Send disabled,
terminal.send calls (0).2 — after clicking Attach: the real upload pipeline runs and a thumbnail chip appears, Send enables, and still
terminal.send calls (0)(image held, not pasted early).3 — after clicking Send: the sent bubble shows the photo thumbnail, the composer clears, and the trace shows the real ride-along the code emitted:
""(Ctrl+U clear),enter=false"[200~/host/tmp/orca-attach-42.png[201~"(bracketed image paste),enter=false"Here is the layout bug",enter=trueTests / checks
pnpm test— 2311 pass (2 pre-existing skips), incl. new coverage for pick+upload, the exact ride-along byte order (clear -> paste -> settle -> text/Enter), attachments-only submit, retry-keeps-chips on rejection, pending->image-ref echo blocks, image-only echo reconciliation (agent-reply / pagination / rapid-send), and the renderable-URI gate.pnpm typecheck,pnpm lint,pnpm format:check— clean.Honest limitation
A fully on-device run (real iOS/Android app + live agent transcript) can't be automated headlessly — the native photo-picker modal isn't drivable and the mock host lacks the upload RPCs. The iOS 26.1 simulator runtime was installed, but that path needs a paired desktop + live agent. The proof above therefore drives the real app logic end-to-end with only the OS boundary faked; the send/echo/reconciliation is additionally covered by unit tests.