Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(mobile): sends respond instantly, thread opens stop freezing #4882

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/4882/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

On iOS, sending a message did nothing for 3+ seconds before showing "queued", opening a thread locked the app for ~1s before the transition, and starting a new thread froze before the composer appeared. A multi-agent investigation traced each symptom; this PR takes the highest-impact fixes that were safe to make small.

Send: feedback on the tap frame. The "queued" state waited on a durable JSON file write (with attachments inlined as base64) before anything changed on screen, and the draft only cleared after that resolved. The outbox atom now publishes synchronously with the write happening behind it (rolled back on failure, content restored to the draft), and the lock-screen Live Activity arms after the send instead of before. Sending now clears the composer and shows "queued" immediately; the file write and relay round trip happen behind that feedback.

Thread open: linear feed derivation. groupAdjacentActivities copied the accumulated group array per activity — O(k²) on long tool runs. It now appends into a mutable trailing group. Isolated benchmark: 2,000 activities in one turn drops 1.47ms → 0.009ms per pass (~160x); at 5,000 activities ~1.8ms → 0.03ms. This runs on every thread open and every streaming update, and pending approvals/user inputs re-sorted the full activity array twice more per update — now sorted once and shared.

New thread: keyboard no longer races the sheet. The native composer's autoFocus fired becomeFirstResponder the moment the view attached, forcing iOS keyboard bring-up (300ms+ cold) during the formSheet present animation. The existing InteractionManager-deferred focus takes over, so the sheet animates immediately and the keyboard rises after it settles.

Re-render hygiene. The v2 home thread list passed a fresh extraData object literal every render, forcing all visible FlatList rows to re-render on any HomeScreen render — now memoized. useThreadOutboxDrain (subscribed to all threads, projects, connections, and the outbox) ran directly in the root navigation layout, re-rendering every screen on each enqueue/shell/connection change — now hosted in a null-rendering leaf. The Android-only shortcuts hook also subscribed the iOS root to the active thread shell — now gated.

Estimated impact (release builds; ranked by user-visible effect):

  • Send: perceived latency drops from 3+ seconds to instantaneous queued feedback (the transport round trip still runs, but behind visible state).
  • Thread open: eliminates the quadratic + duplicate-sort share of the pre-transition freeze (up to ~2ms per pass per 2k activities, × N re-runs during catch-up replay) and stops whole-list row re-renders on the way out; the remaining mount cost (markdown expansion, schema decode) is follow-up work.
  • New thread: removes the main-thread keyboard stall from the present animation, which was the dominant visible beat.
  • Streaming/idle: outbox and shell updates no longer re-render the root tree, cutting steady-state render fan-out during active turns.

Deeper follow-ups identified but out of scope here: client-side event-stream batching, using the existing granular thread-detail slice atoms, skipping re-decode of warm snapshots, dropping the drain's redundant pre-flight settings RPCs, and file-referenced (not base64) attachments.

Written by Claude Fable 5 in Claude Code.

🤖 Generated with Claude Code


Note

Medium Risk Optimistic outbox + confirm-before-drain changes message delivery ordering and failure recovery; incorrect rollback or stale guard logic could drop or duplicate sends, though new tests cover write failure and same-id retry cases.

Overview Makes send feel immediate and cuts main-thread work and root re-renders that were freezing thread open and new task flows.

Thread outbox: Queued messages update the in-memory atom before the durable write finishes; the composer clears on the tap frame. Failed writes roll back the queue entry and merge text back into the draft (attachments via uncapped append). The drain calls confirmThreadOutboxMessageQueued and re-checks edit/busy state after that await so rolled-back or stale messages are never delivered.

Re-render isolation: useThreadOutboxDrain moves into a null ThreadOutboxDrainWorker so outbox/shell/connection churn does not re-render RootStackLayout. On iOS, launcher shortcut sync no longer subscribes to the active thread shell. Home v2 FlatList extraData is memoized.

Feed derivation: groupAdjacentActivities appends into a mutable trailing group (avoids quadratic copies). sortThreadActivities runs once and feeds both pending-approval and pending-user-input derivations.

UX timing: New-task composer autoFocus is off on iOS; focus stays deferred until after the sheet animation. Live Activity arms after onSendMessage completes.

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

Note

Make mobile send respond instantly and stop thread opens from freezing

  • Queued messages in thread-outbox-manager.ts are now published to state synchronously before the durable write, so the draft clears immediately on send; failed writes roll back the message and restore the draft with an error.
  • use-thread-outbox-drain.ts uses the new confirmQueued API to verify the durable write succeeded before dispatching, preventing dispatch of rolled-back or stale messages.
  • ThreadOutboxDrainWorker in Stack.tsx isolates outbox drain subscriptions to a leaf component, preventing outbox state updates from re-rendering RootStackLayout.
  • ComposerEditor in NewTaskDraftScreen.tsx defers auto-focus until after the iOS sheet presentation animation completes.
  • FlatList.extraData in HomeScreen.tsx is memoized to avoid unnecessary row re-renders, and useRecentThreadShortcutSync in useAppShortcuts.ts skips active thread subscription on iOS.
  • Behavioral Change: onSendMessage now resolves immediately with the new messageId without waiting for the durable write; callers previously relying on post-send resolution timing may see different behavior.
Macroscope summarized 1d87beb.
    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: aeb7de55-944c-4d9f-8f69-5f29340ccb5f

      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

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0b7c9d8cde0b22aa585d29fa936dabf217d2aa07. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR changes the timing and ordering semantics of message enqueueing with an optimistic publish + rollback pattern, and adds complex race condition handling in the drain logic. While performance-focused and well-tested, these architectural changes to message queuing behavior warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.