Skip to content

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

Open
juliusmarminge wants to merge 3 commits into
pingdotgg:mainfrom
juliusmarminge:codex/pr3910-reconnect-recovery
Open

fix(mobile): Recover thread state reliably after reconnects#4034
juliusmarminge wants to merge 3 commits into
pingdotgg:mainfrom
juliusmarminge:codex/pr3910-reconnect-recovery

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Jul 16, 2026

Copy link
Copy Markdown
Member

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 and shell state reliably after reconnects in mobile

  • Fixes makeEnvironmentShellState.setReady and makeEnvironmentThreadState.setReady to return to 'live' status when cached data exists after a reconnect, even if no new sync events arrive.
  • Adds retry logic in ThreadRouteScreen: when a thread detail stalls while connected, it retries at ~8s and ~12s, then surfaces a static error message if still unresolved.
  • Introduces useEnvironmentThreadQuery and useSelectedThreadDetailQuery hooks that expose refresh, isPending, and preserved-on-failure state.
  • Adds causeFailureMessage utility in client-runtime for consistent user-facing error extraction from Cause values, replacing ad-hoc Cause.squash calls.
  • Behavioral Change: shell and thread state now transitions back to 'live' on reconnect without waiting for new events; thread sync error message text may change for some failure shapes.

Macroscope summarized 9ff248f.


Note

Medium Risk
Changes reconnect state transitions in shared client-runtime shell/thread sync and add timed refresh logic on the thread route; behavior is covered by new tests but affects live sync UX after reconnects.

Overview
Shell and thread sync now go live on reconnect when cached snapshot/data already exists, instead of staying in synchronizing until new stream events arrive (setReady in shell.ts and threads.ts). Tests cover reconnect with no new events.

Mobile thread detail gains useEnvironmentThreadQuery / useSelectedThreadDetailQuery with refresh and isPending, plus environmentThreadStateFromAsyncResult so refresh failures keep prior data while surfacing errors.

ThreadRouteScreen adds a stall watchdog: while connected with no detail, it refreshes at 8s and 12s, then shows a user-facing load error if detail still never arrives.

causeFailureMessage in client-runtime centralizes Effect Cause message extraction for mobile queries and thread/shell error strings.

Reviewed by Cursor Bugbot for commit 9ff248f. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-authored-by: codex <codex@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

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: 2cd8e8fa-8969-4a8a-8004-b1ec9b3e402c

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.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jul 16, 2026
@juliusmarminge juliusmarminge marked this pull request as ready for review July 16, 2026 09:25
Comment thread apps/mobile/src/features/threads/ThreadRouteScreen.tsx
@macroscopeapp

macroscopeapp Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Bug fix for reconnection handling with limited scope. The core change restores 'live' status when cached data exists after reconnect, adds automatic retry logic with timeouts, and includes comprehensive test coverage. Author is the primary contributor to these files.

You can customize Macroscope's approvability policy. Learn more.

Co-authored-by: codex <codex@users.noreply.github.com>
Comment thread apps/mobile/src/features/threads/ThreadRouteScreen.tsx Outdated

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

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 for commit 2f86672. Configure here.

Comment thread apps/mobile/src/features/threads/ThreadRouteScreen.tsx Outdated
Co-authored-by: codex <codex@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant