Skip to content

fix(mobile): show attached images in native (rich) chat - #10135

Merged
AmethystLiang merged 7 commits into
mainfrom
nwparker/mobile-fixes
Jul 23, 2026
Merged

AmethystLiang merged 7 commits into
mainfrom
nwparker/mobile-fixes

Conversation

@nwparker

@nwparker nwparker commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

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)

  • Compose: picking an image uploads it and shows a removable thumbnail chip in the composer (no early paste). Send is enabled with an attachment even with no text.
  • Submit: the ride-along is Ctrl+U clear -> bracketed image paste(s) (no Enter) -> 300 ms settle -> text + Enter (mirrors desktop's sendNativeChatMessageWithImageAttachments); the leading clear keeps a retry idempotent.
  • After sent: the optimistic echo carries the local preview URIs and the renderer draws image-ref blocks 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 rare unknown ack-loss path).
  • The terminal chat attach path is unchanged (both flows consolidated behind 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).

initial

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).

attached

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:

  1. "" (Ctrl+U clear), enter=false
  2. "[200~/host/tmp/orca-attach-42.png[201~" (bracketed image paste), enter=false
  3. "Here is the layout bug", enter=true

sent

Tests / 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.

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

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ffc1daab-c412-41c0-b3c7-87b81fded700

📥 Commits

Reviewing files that changed from the base of the PR and between 17b65ba and ce4aafe.

📒 Files selected for processing (15)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/MobileNativeChatComposer.tsx
  • mobile/src/session/MobileNativeChatMessage.test.ts
  • mobile/src/session/mobile-image-source-picker.test.ts
  • mobile/src/session/mobile-image-source-picker.ts
  • mobile/src/session/mobile-native-chat-draft-reconcile.ts
  • mobile/src/session/mobile-native-chat-image-transcript-markers.ts
  • mobile/src/session/mobile-native-chat-render-data.test.ts
  • mobile/src/session/mobile-native-chat-render-data.ts
  • mobile/src/session/mobile-native-chat-scope-key.ts
  • mobile/src/session/use-mobile-native-chat-controller.test.ts
  • mobile/src/session/use-mobile-native-chat-drafts.test.ts
  • mobile/src/session/use-mobile-native-chat-drafts.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.test.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts

📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is detailed but does not follow the required template and omits AI Review Report, Security Audit, and Notes sections. Reformat it to the repo template with Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 18.92% which is insufficient. The required threshold is 80.00%. 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 matches the main change: mobile native chat now shows attached images.
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.
✨ Finishing Touches
📝 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.

@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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ece89216-8570-43a9-9906-66e6c7eb87a2

📥 Commits

Reviewing files that changed from the base of the PR and between 1648251 and edfe3db.

⛔ Files ignored due to path filters (2)
  • mobile/docs/native-chat-image-attachment/composer-before-after.png is excluded by !**/*.png
  • mobile/docs/native-chat-image-attachment/native-chat-image-proof.png is excluded by !**/*.png
📒 Files selected for processing (25)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/docs/native-chat-image-attachment/README.md
  • mobile/src/session/MobileNativeChatComposer.test.ts
  • mobile/src/session/MobileNativeChatComposer.tsx
  • mobile/src/session/MobileNativeChatMessage.tsx
  • mobile/src/session/MobileNativeChatOverlay.tsx
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/mobile-image-source-picker.test.ts
  • mobile/src/session/mobile-image-source-picker.ts
  • mobile/src/session/mobile-native-chat-draft-reconcile.ts
  • mobile/src/session/mobile-native-chat-image-attachment.test.ts
  • mobile/src/session/mobile-native-chat-image-attachment.ts
  • mobile/src/session/mobile-native-chat-image-preview.test.ts
  • mobile/src/session/mobile-native-chat-image-preview.ts
  • mobile/src/session/mobile-native-chat-image-send.test.ts
  • mobile/src/session/mobile-native-chat-image-send.ts
  • mobile/src/session/mobile-native-chat-message-styles.ts
  • mobile/src/session/mobile-native-chat-render-data.test.ts
  • mobile/src/session/mobile-native-chat-render-data.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-drafts.test.ts
  • mobile/src/session/use-mobile-native-chat-drafts.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.test.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts
  • mobile/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

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ac480274-0309-4366-8cef-e5c0afb24c4d

📥 Commits

Reviewing files that changed from the base of the PR and between edfe3db and 1f303bb.

⛔ Files ignored due to path filters (3)
  • mobile/docs/native-chat-image-attachment/flow-1-initial.png is excluded by !**/*.png
  • mobile/docs/native-chat-image-attachment/flow-2-attached.png is excluded by !**/*.png
  • mobile/docs/native-chat-image-attachment/flow-3-sent.png is excluded by !**/*.png
📒 Files selected for processing (10)
  • mobile/docs/native-chat-image-attachment/README.md
  • mobile/rnw-preview/.gitignore
  • mobile/rnw-preview/expo-clipboard-stub.ts
  • mobile/rnw-preview/fake-rpc.ts
  • mobile/rnw-preview/index.html
  • mobile/rnw-preview/lucide-stub.tsx
  • mobile/rnw-preview/main.tsx
  • mobile/rnw-preview/markdown-stub.tsx
  • mobile/rnw-preview/picker-stub.ts
  • mobile/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.
@AmethystLiang
AmethystLiang self-requested a review July 23, 2026 19:44

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d582ef5f-1a53-4829-ade4-d4c6e61c9b6b

📥 Commits

Reviewing files that changed from the base of the PR and between 1f303bb and 17b65ba.

📒 Files selected for processing (8)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/docs/native-chat-image-attachment/README.md
  • mobile/rnw-preview/main.tsx
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.test.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts
  • mobile/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.
@AmethystLiang
AmethystLiang merged commit 9500ca7 into main Jul 23, 2026
2 checks passed
nwparker added a commit that referenced this pull request Jul 24, 2026
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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* 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]>
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.

2 participants