@devries-cameron20 / t3code-1 / commits / 3e42e668c4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): reconnecting threads no longer open on "Failed to connect" (#26643)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Liam Warfield committed Oct 30, 2026 at 19:41 UTC 3e42e668c4cd9a1618266f24b7e8fbea4b65cdc4
4 files changed +36 -6
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+12 -1
@@ -346,6 +346,9 @@ const NO_RUN_STOP_ATOM = Atom.make<RunStopPresentation | null>(null).pipe(
346 Atom.withLabel("mobile-thread-run-stop:empty"),
347 );
348
349 +// Connection failures survive retries and app suspension.
350 +const RECONNECT_ERROR_DELAY_MS = 5_000;
351 +
352 // Anchors, the submitted message, follow state and pending scrolls belong to
353 // one thread, so the body remounts when the thread changes.
354 export function ThreadDetailScreen(props: ThreadDetailScreenProps) {
@@ -527,6 +530,14 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
530 }
531 })();
532 const threadSyncLabel = useDelayedStatus(selectedThreadKey, realThreadSyncLabel);
533 + const connectionRetrying =
534 + props.connectionStateLabel === "connecting" || props.connectionStateLabel === "reconnecting";
535 + const retryError = connectionRetrying ? props.connectionError : null;
536 + const retryConnectionError = useDelayedStatus(
537 + `${props.environmentId}:${retryError !== null}`,
538 + retryError,
539 + RECONNECT_ERROR_DELAY_MS,
540 + );
541 const interruptThreadTurn = useAtomCommand(threadEnvironment.interruptTurn, {
542 reportFailure: false,
543 });
@@ -661,7 +672,7 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
672 );
673 const floatingStatus = ((): FloatingWorkingStatus | null => {
674 const connectionStatus = connectionFloatingStatus({
664 - connectionError: props.connectionError,
675 + connectionError: connectionRetrying ? retryConnectionError : props.connectionError,
676 connectionState: props.connectionStateLabel,
677 environmentLabel: props.environmentLabel,
678 onReconnect: props.onReconnectEnvironment,
apps/mobile/src/lib/useDelayedStatus.ts
+3 -3
@@ -7,12 +7,12 @@ import { useState } from "react";
7
8 import { useDeadlinePassed } from "./clock";
9
10 -export function useDelayedStatus<A>(key: string, value: A | null): A | null {
10 +export function useDelayedStatus<A>(key: string, value: A | null, showDelayMs?: number): A | null {
11 const [state, setState] = useState(() =>
12 - stepDelayedStatus<A>(null, { key, value, deadlinePassed: false }, Date.now),
12 + stepDelayedStatus<A>(null, { key, value, deadlinePassed: false, showDelayMs }, Date.now),
13 );
14 const deadlinePassed = useDeadlinePassed(delayedStatusDeadline(state));
15 - const next = stepDelayedStatus(state, { key, value, deadlinePassed }, Date.now);
15 + const next = stepDelayedStatus(state, { key, value, deadlinePassed, showDelayMs }, Date.now);
16 if (next !== state) setState(next);
17 return shownDelayedStatus(next, key);
18 }
packages/client-runtime/src/delayedStatus.test.ts
+18
@@ -27,6 +27,15 @@ describe("stepDelayedStatus", () => {
27 expect(step(pending, "syncing", 399)).toBe(pending);
28 const shown = step(pending, "syncing", 400);
29 expect(shownDelayedStatus(shown, "thread-1")).toBe("syncing");
30 + const slow = stepDelayedStatus(
31 + null,
32 + { key: "thread-1", value: "failed", deadlinePassed: false, showDelayMs: 5_000 },
33 + () => 0,
34 + );
35 + expect(delayedStatusDeadline(slow)).toBe(5_000);
36 + expect(shownDelayedStatus(step(slow, "failed", 4_999), "thread-1")).toBeNull();
37 + expect(shownDelayedStatus(step(slow, "failed", 5_000), "thread-1")).toBe("failed");
38 + expect(step(slow, null, 200).phase).toBe("idle");
39 });
40
41 it("never shows a status that clears before the show delay", () => {
@@ -69,5 +78,14 @@ describe("stepDelayedStatus", () => {
78 const other = step(shown, "syncing", 500, "thread-2");
79 expect(shownDelayedStatus(other, "thread-2")).toBeNull();
80 expect(delayedStatusDeadline(other)).toBe(900);
81 + const cleared = step(shown, null, 500, "cleared");
82 + expect(shownDelayedStatus(cleared, "cleared")).toBeNull();
83 + const retry = stepDelayedStatus(
84 + cleared,
85 + { key: "thread-1", value: "failed", deadlinePassed: false, showDelayMs: 5_000 },
86 + () => 501,
87 + );
88 + expect(shownDelayedStatus(retry, "thread-1")).toBeNull();
89 + expect(delayedStatusDeadline(retry)).toBe(5_501);
90 });
91 });
packages/client-runtime/src/delayedStatus.ts
+3 -2
@@ -21,6 +21,7 @@ export interface DelayedStatusInput<A> {
21 /** Compared by identity, so use strings or other stable values. */
22 readonly value: A | null;
23 readonly deadlinePassed: boolean;
24 + readonly showDelayMs?: number | undefined;
25 }
26
27 /**
@@ -30,14 +31,14 @@ export interface DelayedStatusInput<A> {
31 */
32 export function stepDelayedStatus<A>(
33 state: DelayedStatusState<A> | null,
33 - { key, value, deadlinePassed }: DelayedStatusInput<A>,
34 + { key, value, deadlinePassed, showDelayMs = STATUS_SHOW_DELAY_MS }: DelayedStatusInput<A>,
35 now: () => number,
36 ): DelayedStatusState<A> {
37 const idle = (): DelayedStatusState<A> => ({ phase: "idle", key });
38 const pending = (): DelayedStatusState<A> => ({
39 phase: "pending",
40 key,
40 - showAt: now() + STATUS_SHOW_DELAY_MS,
41 + showAt: now() + showDelayMs,
42 });
43 const shown = (shownValue: A): DelayedStatusState<A> => ({
44 phase: "shown",