@devries-cameron20 / t3code-1 / commits / d09a9eadf4
Fork 0

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

fix(mobile): new threads no longer get stuck on Starting (#15870)

nekohasekai committed Oct 16, 2026 at 00:40 UTC d09a9eadf45b31f5a581f0a1ebd0da03b43abab8
7 files changed +43 -24
apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
+11 -2
@@ -9,6 +9,7 @@ import {
9 import { deriveSubagentElapsedMs, formatDuration } from "@t3tools/shared/orchestrationTiming";
10 import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
11 import * as DateTime from "effect/DateTime";
12 +import { Atom } from "effect/reactivity";
13 import * as Haptics from "expo-haptics";
14 import { useEffect, useState } from "react";
15 import { Platform, Pressable, ScrollView, View } from "react-native";
@@ -28,8 +29,16 @@ const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Pl
29
30 type AgentsTarget = { readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
31
31 -export function useThreadTurnSubagents(target: AgentsTarget): ThreadTurnSubagents | null {
32 - return useAtomValue(environmentThreadDetails.turnSubagentsAtom(target));
32 +const EMPTY_TURN_SUBAGENTS_ATOM = Atom.make<ThreadTurnSubagents | null>(null).pipe(
33 + Atom.withLabel("mobile-thread-turn-subagents:empty"),
34 +);
35 +
36 +export function useThreadTurnSubagents(target: AgentsTarget | null): ThreadTurnSubagents | null {
37 + return useAtomValue(
38 + target === null
39 + ? EMPTY_TURN_SUBAGENTS_ATOM
40 + : environmentThreadDetails.turnSubagentsAtom(target),
41 + );
42 }
43
44 export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+9 -12
@@ -26,6 +26,7 @@ import type {
26 ProviderInteractionMode,
27 RuntimeMode,
28 RuntimeRequestId,
29 + ScopedThreadRef,
30 ServerConfig as T3ServerConfig,
31 ThreadId,
32 UsageLimitsReport,
@@ -157,6 +158,11 @@ export interface ThreadDetailScreenProps {
158 readonly setupWorkingStartedAt?: string | null;
159 readonly canOperateThread: boolean;
160 readonly selectedThread: EnvironmentThreadShell;
161 + /**
162 + * Read thread details through this, not `selectedThread.id`: it stays null until
163 + * a queued creation reaches the server; see `useThreadSelection`.
164 + */
165 + readonly selectedThreadDetailRef: ScopedThreadRef | null;
166 readonly contentPresentation: ThreadContentPresentation;
167 readonly screenTone: StatusTone;
168 readonly connectionError: string | null;
@@ -333,10 +339,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
339 const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
340 const navigation = useNavigation();
341 const { session: voiceInputSession } = useGlobalVoiceInput();
336 - const reportedModelSelection = useThreadReportedModelSelection({
337 - environmentId: props.environmentId,
338 - threadId: props.selectedThread.id,
339 - });
342 + const reportedModelSelection = useThreadReportedModelSelection(props.selectedThreadDetailRef);
343 const deviceState = useEnvironmentQuery(
344 deviceEnvironment.state({ environmentId: props.environmentId, input: {} }),
345 );
@@ -414,14 +417,8 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
417 threadId: props.selectedThread.id,
418 });
419 const composerError = useAtomValue(threadComposerErrorsAtom)[selectedThreadKey]?.message ?? null;
417 - const queuedCount = useThreadQueuedCount({
418 - environmentId: props.environmentId,
419 - threadId: props.selectedThread.id,
420 - });
421 - const turnSubagents = useThreadTurnSubagents({
422 - environmentId: props.environmentId,
423 - threadId: props.selectedThread.id,
424 - });
420 + const queuedCount = useThreadQueuedCount(props.selectedThreadDetailRef);
421 + const turnSubagents = useThreadTurnSubagents(props.selectedThreadDetailRef);
422 const agentsSegment = resolveSubagentPillSegment(turnSubagents);
423 const composerEditorRef = useRef<ComposerEditorHandle>(null);
424 // A provider-native subagent shows status instead of a composer.
apps/mobile/src/features/threads/ThreadQueueControl.tsx
+8 -2
@@ -1,6 +1,7 @@
1 import { type StaticScreenProps, useNavigation } from "@react-navigation/native";
2 import { useAtomValue } from "@effect/atom-react";
3 import type { ChatAttachment, EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
4 +import { Atom } from "effect/reactivity";
5 import { Image } from "expo-image";
6 import * as Haptics from "expo-haptics";
7 import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
@@ -40,6 +41,9 @@ import { threadDragGapOffset } from "./threadDragGap";
41 const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
42 const REMOVE_ACTION_WIDTH = 76;
43 const THUMBNAIL_LIMIT = 3;
44 +const EMPTY_QUEUED_COUNT_ATOM = Atom.make(0).pipe(
45 + Atom.withLabel("mobile-thread-queue-count:empty"),
46 +);
47
48 type QueueTarget = { readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
49 type QueueAction = "steer" | "edit" | "up" | "down" | "remove";
@@ -49,8 +53,10 @@ export function useThreadQueueWorkflow(target: QueueTarget) {
53 return useAtomValue(environmentThreadDetails.queueWorkflowAtom(target));
54 }
55
52 -export function useThreadQueuedCount(target: QueueTarget) {
53 - return useAtomValue(environmentThreadDetails.queuedCountAtom(target));
56 +export function useThreadQueuedCount(target: QueueTarget | null) {
57 + return useAtomValue(
58 + target === null ? EMPTY_QUEUED_COUNT_ATOM : environmentThreadDetails.queuedCountAtom(target),
59 + );
60 }
61
62 export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+2
@@ -274,6 +274,7 @@ function ThreadRouteContent(
274 const {
275 selectedThread,
276 selectedThreadCreation,
277 + selectedThreadDetailRef,
278 selectedThreadProject,
279 selectedEnvironmentConnection,
280 } = useThreadSelection();
@@ -988,6 +989,7 @@ function ThreadRouteContent(
989 <ThreadDetailScreen
990 canOperateThread={canOperateThread}
991 selectedThread={selectedThreadWithDraftSettings ?? selectedThread}
992 + selectedThreadDetailRef={selectedThreadDetailRef}
993 contentPresentation={contentPresentation}
994 screenTone={connectionTone(routeConnectionState)}
995 connectionError={routeConnectionError}
apps/mobile/src/state/entities.ts
+8 -2
@@ -31,6 +31,9 @@ const EMPTY_THREAD_SHELL_ATOM = Atom.make<EnvironmentThreadShell | null>(null).p
31 const EMPTY_SERVER_CONFIG_ATOM = Atom.make<ServerConfig | null>(null).pipe(
32 Atom.withLabel("mobile-server-config:empty"),
33 );
34 +const EMPTY_THREAD_ATOM = Atom.make<EnvironmentThread | null>(null).pipe(
35 + Atom.withLabel("mobile-thread:empty"),
36 +);
37 const EMPTY_THREAD_TITLES: ReadonlyMap<ThreadId, string> = new Map();
38 const EMPTY_THREAD_TITLES_ATOM = Atom.make(EMPTY_THREAD_TITLES).pipe(
39 Atom.withLabel("mobile-thread-titles:empty"),
@@ -133,6 +136,9 @@ export function useServerConfigs(): ReadonlyMap<EnvironmentId, ServerConfig> {
136 const selectReportedModelSelection = (thread: EnvironmentThread | null) =>
137 thread === null ? null : deriveReportedModelSelection(thread.projection);
138
136 -export function useThreadReportedModelSelection(ref: ScopedThreadRef) {
137 - return useAtomValue(environmentThreadDetails.threadAtom(ref), selectReportedModelSelection);
139 +export function useThreadReportedModelSelection(ref: ScopedThreadRef | null) {
140 + return useAtomValue(
141 + ref === null ? EMPTY_THREAD_ATOM : environmentThreadDetails.threadAtom(ref),
142 + selectReportedModelSelection,
143 + );
144 }
apps/mobile/src/state/use-thread-composer-state.ts
+3 -5
@@ -184,6 +184,7 @@ export function useThreadComposerState() {
184 const {
185 selectedThread: selectedThreadShell,
186 selectedThreadCreation,
187 + selectedThreadDetailRef,
188 selectedEnvironmentRuntime,
189 } = useThreadSelection();
190 const selectedThreadProjection = useSelectedThreadProjection();
@@ -311,12 +312,9 @@ export function useThreadComposerState() {
312 // Steering needs a live provider turn the adapter can interrupt; the queue
313 // workflow already derives that from the session's capabilities.
314 const queueWorkflow = useAtomValue(
314 - selectedThreadShell === null
315 + selectedThreadDetailRef === null
316 ? EMPTY_QUEUE_WORKFLOW_ATOM
316 - : environmentThreadDetails.queueWorkflowAtom({
317 - environmentId: selectedThreadShell.environmentId,
318 - threadId: selectedThreadShell.id,
319 - }),
317 + : environmentThreadDetails.queueWorkflowAtom(selectedThreadDetailRef),
318 );
319 const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true;
320 const queuedRunEdit = useQueuedRunEdit(selectedThreadKey);
apps/mobile/src/state/use-thread-selection.ts
+2 -1
@@ -158,7 +158,8 @@ function useResolvedThreadSelection(params: ThreadSelectionRouteParams | undefin
158 return message === null ? null : { message, outcome };
159 }, [creationOutcome, queuedMessagesByThreadKey, selectedThreadKey]);
160 // Until the creation is delivered the server has no thread to subscribe
161 - // to; subscribing anyway would retry "not found" for the whole setup.
161 + // to. Every detail reader must use this ref, not the route id: an earlier
162 + // read gets a definitive not-found, which the thread state keeps as deleted.
163 const selectedThreadDetailRef =
164 selectedThreadShell !== null ||
165 pendingCreation === null ||