Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(mobile): pick, share, and receive files in threads #8237

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 26 commits intomain fromrefs/pull/8237/headmerged by juliusmarminge View on GitHub

Mobile can attach photos today, but it cannot pick documents or retain files shared from other apps. This adds Photos and Files controls when the connected environment supports file uploads, plus native share targets for documents, audio, and video.

Files stay with drafts and queued messages until delivery. Uploads reuse verified pending references, rejected sends restore the draft, and cleanup waits until no draft, outbox message, or incoming share owns the file. Saved iOS attachments continue working when an app update moves the data container. Picker and open-in-place source documents are never deleted.

Received files download from the selected environment and open in the native save/share sheet with their filenames preserved. Leaving the thread cancels unfinished downloads. Files handed to another app remain cached long enough for the recipient to read them. Unknown attachment types remain visible as inert rows.

Validation: 210 focused mobile tests pass, along with mobile typechecking, targeted lint and formatting, and Expo native configuration introspection for iOS and Android.

The native share registration and Expo SDK 57 Android sharing patch require new iOS and Android builds. Device verification is still required for native sharing, file picking, and save/share behavior before shipping those builds. No simulator or device session was run for this update. The tolerant attachment contract from #8235 must ship to older mobile clients before they receive threads containing files.

Original work by Theo Browne with Claude Fable 5 in the Claude Code harness. Prior modernization by GPT-5.6 Sol in the Codex harness. This update by nathree in the Codex harness.


Note

Medium Risk Touches share ingestion, local file lifecycle, and server pending-upload paths with many edge cases (Android content URIs, iOS container moves); mistakes could leak files or block sends, but ownership checks and rollback paths mitigate the worst outcomes.

Overview Extends the mobile composer and thread experience from image-only attachments to generic files, gated on each server’s file-upload capabilities and size limits.

Attach and send: Drafts now use a DraftComposerAttachment union. The composer can pick documents via pickComposerFiles / persistComposerAttachmentFile (app-owned copies, enforced counts and byte limits), upload file bytes through new prepareTurnAttachments (reuse pending uploads, persist ids on drafts/outbox), and show non-image thumbnails in ComposerAttachmentStrip. New-task and thread composers offer Photos vs Files when the server supports files.

Share into the app: Native share registration accepts files on iOS/Android. Incoming shares ingest file/audio/video payloads without base64, persist copies, filter attachments by destination server config, and roll back persisted files if durable inbox writes fail. Temporary share cleanup only deletes URIs under app-owned roots so open-in-place shares cannot wipe the sender’s document.

Read in threads: The feed renders file attachments as tappable rows that resolve a signed URL and download + share via downloadAndShareAttachment; unknown attachment types render inert rows.

Supporting changes include stricter incoming-share storage loading (strict mode), unused attachment cleanup sweeps on import/cancel/send, and moving some outbox removal imports to thread-outbox-removal.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 85b91ca7cee11a36859f625841a32379c13d0843. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add file picking, sharing, and receiving to mobile threads

  • Broadens DraftComposerAttachment from image-only to a union of image and file types across composer drafts, outbox models, and incoming share drafts.
  • Refactors outbox drain to upload attachments before sending and adds per-message revision tracking in thread-outbox-manager.ts for compare-and-set updates, removals, and clears to protect against concurrent edits.
  • Adds pickComposerFiles for selecting files, downloadAndShareAttachment for downloading and sharing received files, and renders file attachments with icons in the composer strip and thread feed.
  • Updates incoming share processing to accept non-image files with size validation against server capabilities, persist them locally, and roll back on failure.
  • Patches expo-sharing on Android to support simultaneous text and file payloads and preserve original filenames from DISPLAY_NAME.
  • Risk: removeThreadOutboxMessage and clearThreadOutboxEnvironment exports are removed from thread-outbox.ts and moved to thread-outbox-removal.ts; out-of-tree callers importing from the old module will break.
Macroscope summarized 85b91ca.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: d51fc70d-16a6-428e-9201-57b6bba5e435

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Warning

      Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High sharing/incoming-share-model.ts:93

      isShareFileUriUnderOwnedRoots returns true for some paths outside ownedRootUris, allowing removeOwnedFile to delete a sender's open-in-place document. After decodeURIComponent, an encoded /../ segment remains in path, but the lexical startsWith check treats it as owned; canonicalize the decoded path and reject traversal before checking containment.

      -    return path.startsWith(root) && path.length > root.length;
      +    if (path.split("/").some((segment) => segment === "..")) {
      +      return false;
      +    }
      +    return path.startsWith(root) && path.length > root.length;
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/features/sharing/incoming-share-model.ts around line 93:
      
      `isShareFileUriUnderOwnedRoots` returns `true` for some paths outside `ownedRootUris`, allowing `removeOwnedFile` to delete a sender's open-in-place document. After `decodeURIComponent`, an encoded `/../` segment remains in `path`, but the lexical `startsWith` check treats it as owned; canonicalize the decoded path and reject traversal before checking containment.
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High state/use-composer-drafts.ts:245

      On a cold start, releaseUnusedComposerAttachmentFiles deletes files still referenced by persisted drafts, causing those drafts to hydrate with missing attachment data. The function scans composerDraftsAtom before waitForComposerDraftsLoaded() has hydrated it, so the atom appears empty; await hydration before flushing and scanning candidates.

      -  await flushComposerDrafts();
      +  await waitForComposerDraftsLoaded();
      +  await flushComposerDrafts();
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/state/use-composer-drafts.ts around line 245:
      
      On a cold start, `releaseUnusedComposerAttachmentFiles` deletes files still referenced by persisted drafts, causing those drafts to hydrate with missing attachment data. The function scans `composerDraftsAtom` before `waitForComposerDraftsLoaded()` has hydrated it, so the atom appears empty; await hydration before flushing and scanning candidates.
    5. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.3 KiB13.3 KiB+2 B (+0.0%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB−3 B (−0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.4 KiB6.4 KiB+5 B (+0.1%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.6 KiB55.6 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages11110 (0.0%)21✅
      ClaudeTotal thread wire13.4 KiB13.4 KiB+3 B (+0.0%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB+1 B (+0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.5 KiB+2 B (+0.0%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded56.4 KiB56.4 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages11110 (0.0%)21✅

      Baseline: 7880a6e · PR result: 85b91ca · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    6. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR adds a substantial mobile file workflow across native sharing, local persistence, uploads, queued delivery, and received-file sharing. It also changes native product defaults and requires new iOS/Android builds, so the scope and runtime impact warrant human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    7. Note

      🤖 Claude Fable 5 responding on behalf of Theo

      Fixed in 37945fefa. Confirmed the vector: an encoded separator survives URL parsing and decodeURIComponent recreates the ../ segment. Any decoded .. segment is now rejected before the containment check, with three traversal cases in the tests.

    8. Note

      🤖 Claude Fable 5 responding on behalf of Theo

      Fixed in 37945fefa. The sweep awaits waitForComposerDraftsLoaded() before flushing and scanning, so a cold start can no longer see an empty atom and delete referenced files.

    9. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/eb637e66d9e2124ab615907ddda1a47ba808a0d7/apps/mobile/src/state/thread-outbox-manager.ts#L112

      A failed same-ID enqueue is resurrected after restart because its payload remains persisted even though the enqueue was rolled back from memory. The compensating write at line 172 persists that optimistic winner before the enqueue's own write succeeds; ensure the enqueue failure path removes the disk entry (or otherwise restores the previously durable payload).

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/state/thread-outbox-manager.ts around line 112:
      
      A failed same-ID `enqueue` is resurrected after restart because its payload remains persisted even though the enqueue was rolled back from memory. The compensating write at line 172 persists that optimistic winner before the enqueue's own write succeeds; ensure the enqueue failure path removes the disk entry (or otherwise restores the previously durable payload).
    10. Note

      🤖 Claude Fable 5 responding on behalf of Theo

      Fixed in 9ae4de936. When a failed enqueue's rollback leaves no same-id message queued, the disk entry is removed too, so the compensating write from a racing update cannot resurrect the message after restart. Tested.

    11. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/959a32f3c1feb7f2c4bdd8c1aa507f0ce8fe1adb/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx#L550

      Cancelling a file-share import after consumeShare removes the inbox entry but loadDrafts() fails leaks the newly merged local files. The cancel path restores draftBackup, dropping those attachments, but never calls scheduleUnusedComposerAttachmentCleanup, so neither the inbox nor the draft references them; capture the current attachments before rollback and schedule their cleanup after restoring the backup.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/features/threads/NewTaskDraftScreen.tsx around line 550:
      
      Cancelling a file-share import after `consumeShare` removes the inbox entry but `loadDrafts()` fails leaks the newly merged local files. The cancel path restores `draftBackup`, dropping those attachments, but never calls `scheduleUnusedComposerAttachmentCleanup`, so neither the inbox nor the draft references them; capture the current attachments before rollback and schedule their cleanup after restoring the backup.
    12. Note

      🤖 Claude Fable 5 responding on behalf of Theo

      Fixed in 197413447. The cancel restore captures the pre-restore attachments and sweeps them after the snapshot restore, so files merged from a consumed share cannot leak.

    13. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/197413447cf0505a367158b00422c5a56384fd98/apps/mobile/src/features/threads/new-task-flow-provider.tsx#L978

      The unmount flush can overwrite a newer queued edit for the same message with the dismissed session’s stale payload, losing the newer edits. updateThreadOutboxMessage(message) omits expectedRevision, so the outbox manager cannot reject this stale asynchronous write; pass the revision captured before the flush.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/features/threads/new-task-flow-provider.tsx around line 978:
      
      The unmount flush can overwrite a newer queued edit for the same message with the dismissed session’s stale payload, losing the newer edits. `updateThreadOutboxMessage(message)` omits `expectedRevision`, so the outbox manager cannot reject this stale asynchronous write; pass the revision captured before the flush.
    14. t3dotgg(GitHub profile, opens in a new tab)commented

      Note

      🤖 Claude Fable 5 responding on behalf of Theo

      Fixed in ddb9befa8. The editor captures the outbox revision when it takes the task and the unmount flush passes it as the CAS, so a dismissed session cannot overwrite an edit accepted since.

    15. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High state/use-thread-outbox-drain.ts:162

      When a user opens the pending-task editor while startTurn is in flight, completeQueuedMessageDelivery removes the queued entry and the editor loses its unsaved edits after the stale payload is delivered. Because no queue update has yet changed the revision, the revision check succeeds; re-check editingQueuedMessageIdsAtom before removal and return "edited" when editing is active.

      -  try {
      +  if (appAtomRegistry.get(editingQueuedMessageIdsAtom)[queuedMessage.messageId]) {
      +    return "edited";
      +  }
      +  try {
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/state/use-thread-outbox-drain.ts around line 162:
      
      When a user opens the pending-task editor while `startTurn` is in flight, `completeQueuedMessageDelivery` removes the queued entry and the editor loses its unsaved edits after the stale payload is delivered. Because no queue update has yet changed the revision, the revision check succeeds; re-check `editingQueuedMessageIdsAtom` before removal and return `"edited"` when editing is active.
    16. Note

      🤖 Claude Fable 5 responding on behalf of Theo

      Fixed in 2aec93113. Delivery completion re-checks the editing lock and returns edited without removing. A creation in that state defers recovery until the editor saves, then the duplicate-creation removal hands the saved edits to the thread's composer instead of discarding them.

    17. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/2aec93113ff3e1929ffa451b55d1c55a0e8ca821/apps/mobile/src/state/use-thread-composer-state.ts#L329

      onPickDraftImages silently discards picked images when the live draft reaches the attachment cap while the picker is open. appendComposerDraftAttachments returns the rejected count, but this path ignores it, so unlike the Files path it shows no error; handle that count and report the rejected attachments.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/state/use-thread-composer-state.ts around line 329:
      
      `onPickDraftImages` silently discards picked images when the live draft reaches the attachment cap while the picker is open. `appendComposerDraftAttachments` returns the rejected count, but this path ignores it, so unlike the Files path it shows no error; handle that count and report the rejected attachments.

Sign in to join this conversation.