Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): Recover thread state reliably after reconnects #4034

Closedjuliusmarmingewants to merge 4 commits intot3code/audit-mobile-thread-sync fromrefs/pull/4034/headopened View on GitHub

juliusmarmingecommented

Extracted from #3910.

Makes cached shell and thread state recover predictably after reconnects, preserves actionable error causes, retries stalled detail loading, and adds focused shell/thread synchronization coverage.

Validation inherited from #3910: vp check and mobile native lint passed before the split. The full typecheck is currently blocked in this workspace by unavailable mobile dependencies (expo-blur, expo-quick-actions, and @tabler/icons-react-native).

Note

Recover thread state reliably after reconnects using synchronized completion markers

  • Adds a synchronized marker item to shell and thread subscription streams so clients know exactly when catch-up is complete after a reconnect, keeping state as synchronizing until the marker arrives.
  • Server advertises support via new shellResumeCompletionMarker and threadResumeCompletionMarker fields in ServerConfig; clients request the marker via requestCompletionMarker on subscription input.
  • Shell and thread state effects in shell.ts and threads.ts are reworked to buffer live events during snapshot load, resume via afterSequence, and refresh on app foreground via a new subscribeDynamic helper.
  • On mobile, ThreadRouteScreen adds stall detection: if thread detail doesn't arrive despite an active connection, it retries at 8s and 12s intervals and surfaces an inline error asking the user to reopen the thread.
  • The WorkspaceConnectionStatus pill now shows during shell snapshot catch-up (hasPendingShellSnapshot) with distinct labels for initial load vs. cached catch-up.
  • Behavioral Change: shell warm caches are replaced by authoritative HTTP snapshots on reconnect; clients that do not send requestCompletionMarker see no change in behavior.
Macroscope summarized 4a5a299.

Note

Medium Risk Changes WebSocket subscription semantics and client sync state machines for shell and thread data—areas that affect reconnect correctness and what users see as “live” vs “syncing.” Server-side event buffering on shell snapshot load adds concurrency risk if mis-ordered.

Overview Adds an opt-in synchronized completion marker on shell and thread WebSocket subscriptions so clients can tell when initial snapshot or catch-up replay is finished before live events. The server advertises this via shellResumeCompletionMarker / threadResumeCompletionMarker in config, emits the marker after replay or snapshot (including empty catch-up), and buffers live shell events while a full snapshot loads on the fallback path so nothing is missed.

Client-runtime shell and thread state machines now load an authoritative HTTP snapshot on each subscribe (replacing warm-cache-only resume), request the completion marker when supported, and stay synchronizing until synchronized arrives. Shell sync also resubscribes on app foreground via subscribeDynamic. Shared causeFailureMessage normalizes Effect failure text; thread refresh failures keep prior data while surfacing the error.

Mobile exposes useEnvironmentThreadQuery / useSelectedThreadDetailQuery with refresh and isPending, retries stalled thread detail loads on a timer, and shows “Loading/Syncing threads…” connection status when hasPendingShellSnapshot is set (including in the home empty state on iOS).

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4a5a299890992069db6743eaf0ef8ad4eb245e7c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    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

      Run ID: 9e832643-4f74-4f60-a2cf-63faef79e6cb

      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
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved

      This is a straightforward bug fix that adds retry logic for recovering thread state after reconnects on mobile. The scope is limited, the retry pattern is standard with clear delays, new helpers are tested, and the author is the primary maintainer of the affected code.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. apps/mobile/src/features/threads/ThreadRouteScreen.tsx line 193OutdatedResolvedby juliusmarminge
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit acfb78a0e2b1cf9e43a3da2dc0587a945ae34eba. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. juliusmarminge closed this

Sign in to join this conversation.