Skip to content

feat(mobile): show attached images as removable thumbnails in native chat - #9981

Closed
brennanb2025 wants to merge 13 commits into
mainfrom
brennanb2025/mobile-add-picture-attachment
Closed

brennanb2025 wants to merge 13 commits into
mainfrom
brennanb2025/mobile-add-picture-attachment

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Attaching a picture in mobile native chat gave no visible feedback. The image uploaded to the host and its file path was pasted straight into the hidden PTY (mobile-image-attachment.ts), so beyond a brief spinner on the attach button, nothing on screen ever indicated an image was attached — it looked like the button did nothing.

Change

Native chat now defers the TUI paste to send time and shows picked images as a thumbnail tray above the input, matching the desktop composer-attachment model (chips held in composer state, images "ride along" on submit):

  • use-mobile-native-chat-pending-images.ts — pending-image state. Picking still uploads to the host eagerly (same chunked upload RPC); the entry renders as an 88px thumbnail with a spinner overlay while uploading and a circular ✕ once ready. Thumbnails use the picker's local file URI so no second base64 copy is held in JS memory. Pending images are scoped to the chat target and RPC client, and target switches/removal/unmount cancel remaining upload chunks.
  • use-mobile-native-chat-image-send.ts — send wrapper. Pastes each ready image's host path bracketed (enter:false, the same payload as a desktop image paste) right before the message text. Accepted path writes remain as non-removable pasted entries until the caption/Enter is accepted, so rejected and delivery-unknown retries never paste the same path twice. Image-only sends submit with a bare Enter and can retry only that Enter after rejection. Newly pasted paths use the same 300 ms image-settle and 500 ms submit cadence as desktop so caption or Enter bytes cannot overtake TUI image-chip processing.
  • MobileNativeChatComposer.tsx — attachment tray UI; send is allowed with images and no text, blocked while an upload is in flight, and uses the native-chat upload state rather than the unrelated terminal-mode spinner.
  • PickedMobileImage now carries the picker's file uri; the attach-failure toast copy is extracted to mobileImageAttachToastMessage and shared by both flows.

Deferring the paste is what makes ✕ possible: removing a ready thumbnail needs no TUI un-paste. Once a path has reached the hidden TUI, its retained non-removable thumbnail keeps composer state aligned with that input until submission settles.

The terminal live-input surface intentionally keeps the immediate paste — there the agent TUI's own input line is the visible feedback.

Follow-up review also closes asynchronous target-lifetime races: picker/upload completion is ignored after a terminal/client switch, removal, or unmount; multi-image delivery stops if the active terminal/client/lease changes; and a caption can no longer be sent to a different terminal than the one that received the image paths. The native-chat controller owns this coordination, keeping the already-dense session route below its max-lines ratchet without a lint bypass.

Out of scope (follow-ups)

  • The mobile chat transcript has no image-block rendering, so a sent image still surfaces via the agent's raw text markers; porting the desktop transcript normalization is a separate change.
  • The attachment lease-gate's silent-drop paths (use-mobile-attachment-input-lease-gate.ts) still read as picker-cancel.

Testing

  • 26 new unit tests, including upload lifecycle/cancellation, picker cancel/failure, ready/pasted/remove/consume transitions, handle/client-switch clearing, picker-open and mid-send terminal switches, removal/unmount during upload, accepted/rejected/ACK-lost paste sequencing, retry call counts, image-only submit/Enter retry, composer readiness, and lease guards.
  • Full mobile suite on the latest main merge: 316 files passed; 2,296 tests passed and 2 skipped.
  • Focused post-merge attachment gate: 4 files and 44 tests passed.
  • Electron RPC boundary suites: 41 tests passed across clipboard upload and terminal send.
  • Mobile tsc --noEmit, full oxlint, oxfmt, the repository max-lines ratchet, and reliability-manifest validation passed.

Reliability contract

  • Invariant (mobile-relay.terminal-input-delivery): an attachment remains bound to its originating chat target; retry never duplicates a path already accepted or possibly delivered by terminal.send; a rejected final submit remains retryable; caption and image-only submit writes preserve the desktop-proven TUI settle cadence.
  • Failure source: the original hidden-PTY feedback bug plus plausible relay ACK loss, tab/client switches, and removal/unmount during a large upload.
  • Oracle: deterministic tests count exact terminal.send calls across accepted, rejected, target-switch, and delivery-unknown outcomes; cancellation asserts start → first chunk → abort with no later chunk or commit.
  • Gate: accepted gap — no dedicated entry currently exists in config/reliability-gates.jsonc; the focused mobile tests are the deterministic gate for this PR.
  • Provider/platform coverage: mobile/relay behavior is covered at the RPC/state-machine layer; path handling stays opaque for local and SSH hosts. Existing manual iOS validation covers the happy path. Live Android, live SSH failure injection, WSL, Windows, and relay-partition runs remain unproved; no provider-specific path/process behavior changed.
  • Performance budget: no polling, inventory scans, subprocesses, or persistent listeners were added; the send path adds only one bounded 300 ms or 500 ms TUI-settle timer when it writes a new image path. Cancellation stops future 512 KiB upload chunks and releases server upload state; retries issue zero duplicate image-path RPCs.
  • Diagnostics: rejected sends retain the inline failure state; ambiguous image delivery surfaces a specific “check terminal before retrying” toast instead of claiming failure.
  • Residual gap: an ACK-lost non-submitting image-path write cannot be proven delivered from the native transcript. The implementation preserves it as pasted and avoids duplication; the user must inspect the terminal before retrying, as the toast states.

Manual validation

Validated on an iPhone 17 Pro simulator (iOS 26.5) paired to an isolated desktop runtime: selecting a photo shows a ready thumbnail, ✕ removes it without touching the TUI input, and an image-only send delivers the image then clears the tray.

Ready to send Removed
Native chat composer showing a ready image thumbnail Native chat composer after removing the pending image

…chat

Attaching a picture in mobile native chat gave no visible feedback: the
image uploaded to the host and its path was pasted into the hidden PTY, so
nothing on screen ever showed it was attached.

Defer the TUI paste to send time and hold picked images in composer state,
rendered as a thumbnail tray above the input (spinner while uploading, X
to remove, image-only sends allowed). On send, each ready image's path is
pasted bracketed into the agent TUI right before the message text, matching
the desktop composer-attachment model. The terminal live-input surface keeps
the immediate paste, where the TUI's own input line is the feedback.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b06b3233-81a6-43bd-acb8-ffda9c2152ce

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad54c0 and cb02067.

📒 Files selected for processing (8)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/mobile-image-source-picker.test.ts
  • mobile/src/session/mobile-image-source-picker.ts
  • mobile/src/session/mobile-native-chat-image-scope-cache.test.ts
  • mobile/src/session/mobile-native-chat-image-scope-cache.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.test.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.ts
  • mobile/src/session/use-mobile-worktree-connection-id.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • mobile/src/session/mobile-image-source-picker.test.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.ts

📝 Walkthrough

Walkthrough

Native chat now supports queued image attachments. Picked images retain local URIs, remain visible while uploading, and transition to ready entries with removable and consumable state. A new sender pastes ready images into the active terminal before sending text or submitting image-only messages, with checks for upload readiness, disconnection, and terminal changes. The composer renders attachment thumbnails and upload status, while the session overlay wires the new hooks and callbacks. Tests cover picker output, lifecycle races, rendering behavior, and send sequencing.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has useful detail, but it does not follow the required template and is missing the Summary, Screenshots, AI Review Report, Security Audit, and Notes sections. Reformat the PR description to match the template and add the missing Summary, Screenshots, AI Review Report, Security Audit, and Notes sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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 is concise and accurately describes the main change: removable image thumbnails in the mobile native chat composer.
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mobile/app/h/[hostId]/session/[worktreeId].tsx (1)

3629-3672: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Wrong isAttaching source wired into the native-chat composer.

onAttachImage on MobileNativeChatOverlay now calls the new attachPendingChatImage (chat-scoped upload), but the isAttaching prop passed alongside it is still isAttaching from useMobileImageAttachment — the terminal live-input attach flow, which is unrelated and (since the terminal command dock is unmounted while chat is shown) effectively always false here. The chat composer's "Attach image" button therefore never shows its upload spinner/disabled state for a chat-image upload, and the !isAttaching clause in MobileNativeChatComposer's canSend is inert for this surface.

🛡️ Proposed fix
+  const isChatImageUploading = pendingChatImages.some((image) => image.status === 'uploading')
+
   <MobileNativeChatOverlay
     controller={nativeChatController}
     onAttachImage={() => void attachPendingChatImage('library')}
-    isAttaching={isAttaching}
+    isAttaching={isChatImageUploading}
     onSend={sendNativeChatWithImages}
     pendingImages={pendingChatImages}
     onRemovePendingImage={removePendingChatImage}

Also applies to: 4721-4727


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 17d88c7d-e751-4911-a09e-189767557f5d

📥 Commits

Reviewing files that changed from the base of the PR and between 0121f57 and ac34bda.

📒 Files selected for processing (12)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/MobileNativeChatComposer.test.ts
  • mobile/src/session/MobileNativeChatComposer.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/use-mobile-image-attachment.ts
  • mobile/src/session/use-mobile-native-chat-image-send.test.ts
  • mobile/src/session/use-mobile-native-chat-image-send.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.test.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.ts

@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

Run ID: 90ac42ba-a3d2-4f45-b347-25b3e16d212d

📥 Commits

Reviewing files that changed from the base of the PR and between ac34bda and cbcc20a.

📒 Files selected for processing (4)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/MobileNativeChatOverlay.tsx
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts

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

🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-pending-images.ts (1)

66-87: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate upload-abort cleanup across two effects.

Both effects abort and clear uploadControllersRef on cleanup. The [client, attachmentScopeKey]-effect's cleanup already runs on unmount (in addition to dependency changes), so the abort loop inside the empty-deps effect's cleanup (lines 70-73) is fully subsumed by the second effect. Keeping two copies of this loop risks drift if one is edited without the other.

♻️ Extract a shared helper to avoid duplicating the abort loop
+  const abortAllUploads = useCallback(() => {
+    for (const controller of uploadControllersRef.current.values()) {
+      controller.abort()
+    }
+    uploadControllersRef.current.clear()
+  }, [])
+
   useEffect(() => {
     mountedRef.current = true
     return () => {
       mountedRef.current = false
-      for (const controller of uploadControllersRef.current.values()) {
-        controller.abort()
-      }
-      uploadControllersRef.current.clear()
+      abortAllUploads()
       // Why: release thumbnail data captured by in-flight uploads instead of retaining it until RPC timeout.
       entriesRef.current = []
     }
-  }, [])
+  }, [abortAllUploads])

   useEffect(
-    () => () => {
-      for (const controller of uploadControllersRef.current.values()) {
-        controller.abort()
-      }
-      uploadControllersRef.current.clear()
-    },
-    [client, attachmentScopeKey]
+    () => abortAllUploads,
+    [client, attachmentScopeKey, abortAllUploads]
   )

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3aaad746-c4e8-4c50-acd0-e13e60349df7

📥 Commits

Reviewing files that changed from the base of the PR and between cbcc20a and a5367c5.

📒 Files selected for processing (13)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/MobileNativeChatComposer.test.ts
  • mobile/src/session/MobileNativeChatComposer.tsx
  • mobile/src/session/MobileNativeChatOverlay.tsx
  • mobile/src/session/mobile-clipboard-image.test.ts
  • mobile/src/session/mobile-clipboard-image.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts
  • mobile/src/session/use-mobile-native-chat-image-send.test.ts
  • mobile/src/session/use-mobile-native-chat-image-send.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.test.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.ts
  • mobile/src/theme/mobile-theme.ts
💤 Files with no reviewable changes (1)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
🚧 Files skipped from review as they are similar to previous changes (6)
  • mobile/src/session/MobileNativeChatComposer.test.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts
  • mobile/src/session/use-mobile-native-chat-pending-images.test.ts
  • mobile/src/session/MobileNativeChatComposer.tsx
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/MobileNativeChatOverlay.tsx

…dd-picture-attachment

# Conflicts:
#	resources/skills/release-mapping.json
…dd-picture-attachment

# Conflicts:
#	mobile/src/session/mobile-image-source-picker.test.ts
#	mobile/src/session/mobile-image-source-picker.ts
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded by merged #10135. The retry-safety follow-up from the Sol-high review is in #10228.

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