Skip to content

Commit b3d700d

Browse files
fix(mobile): a new thread's first send no longer sticks on Starting
ThreadFeed read the workflow opening and guest share by the route thread id. While a new thread's creation is still queued, that subscribed to its detail before the server knew it; a not-found answer was cached as a deleted thread, so the screen stayed on Pending/Starting and reopening showed Thread unavailable. Both now read through the thread selection's guarded detail ref, like every other detail reader. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0712398 commit b3d700d

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
12901290
<ThreadFeed
12911291
environmentId={props.environmentId}
12921292
threadId={props.selectedThread.id}
1293+
detailRef={props.selectedThreadDetailRef}
12931294
workspaceRoot={props.threadCwd}
12941295
feed={props.selectedThreadFeed}
12951296
pendingHandoff={props.pendingHandoff}

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
type OrchestrationV2ProjectedTurnItem,
5252
type RunId,
5353
type ScheduledTaskId,
54+
type ScopedThreadRef,
5455
} from "@t3tools/contracts";
5556
import { renderAssistantCitationsAsText } from "@t3tools/shared/assistantCitations";
5657
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
@@ -332,6 +333,8 @@ export interface ThreadFeedProps {
332333
readonly onEditPendingMessage: ((message: QueuedThreadMessage) => void) | null;
333334
readonly environmentId: EnvironmentId;
334335
readonly threadId: ThreadId;
336+
/** Null while the thread's creation is queued: reading detail then caches a not-found as deleted. */
337+
readonly detailRef: ScopedThreadRef | null;
335338
readonly threadTitle: string;
336339
readonly workspaceRoot?: string | null;
337340
readonly feed: ReadonlyArray<ThreadFeedEntry>;
@@ -2098,12 +2101,8 @@ export const ThreadFeed = memo(function ThreadFeed({
20982101
...props
20992102
}: ThreadFeedProps & { readonly ref?: Ref<ThreadFeedHandle> }) {
21002103
const { listRef, onEndFollowEnabledChange, onHeaderMaterialVisibilityChange } = props;
2101-
const workflowOpening = useWorkflowOpening(props.environmentId, props.threadId);
2102-
const guestThreadRef = useMemo(
2103-
() => scopeThreadRef(props.environmentId, props.threadId),
2104-
[props.environmentId, props.threadId],
2105-
);
2106-
const guestShare = useThreadGuestShare(guestThreadRef);
2104+
const workflowOpening = useWorkflowOpening(props.detailRef);
2105+
const guestShare = useThreadGuestShare(props.detailRef);
21072106
const deviceType = useDeviceType();
21082107
const duoColumns = useNativeWorkspaceColumnsSupported() && isDuoDevice(deviceType);
21092108
const openPullRequest = useOpenPullRequest();

‎apps/mobile/src/features/threads/thread-workflow-opening.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
workflowOpeningParentThreadId,
77
type RuntimeSubagent,
88
} from "@t3tools/client-runtime/state/subagentRuntime";
9-
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
9+
import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
10+
import type { EnvironmentThread } from "@t3tools/client-runtime/state/shell";
11+
import { Atom } from "effect/reactivity";
1012
import { useState } from "react";
1113
import { Pressable, View } from "react-native";
1214

@@ -20,8 +22,10 @@ import { useOpenLinkedThread } from "./useOpenLinkedThread";
2022

2123
const FOLDED_SCRIPT_LINES = 10;
2224

23-
export function useWorkflowOpening(environmentId: EnvironmentId, threadId: ThreadId) {
24-
const threadAtom = environmentThreadDetails.threadAtom(scopeThreadRef(environmentId, threadId));
25+
const NO_THREAD_ATOM = Atom.make<EnvironmentThread | null>(null);
26+
27+
export function useWorkflowOpening(ref: ScopedThreadRef | null) {
28+
const threadAtom = ref === null ? NO_THREAD_ATOM : environmentThreadDetails.threadAtom(ref);
2529
// Selected as a primitive so an ordinary thread's updates never change the result.
2630
const parentId = useAtomValue(threadAtom, (thread) =>
2731
thread === null
@@ -35,7 +39,9 @@ export function useWorkflowOpening(environmentId: EnvironmentId, threadId: Threa
3539
parentId === null ? null : (thread?.projection ?? null),
3640
);
3741
const parentSubagents = useAtomValue(
38-
environmentThreadDetails.threadAtom(scopeThreadRef(environmentId, parentId ?? threadId)),
42+
ref === null || parentId === null
43+
? NO_THREAD_ATOM
44+
: environmentThreadDetails.threadAtom(scopeThreadRef(ref.environmentId, parentId)),
3945
(parent) => (parentId === null ? null : (parent?.projection.subagents ?? null)),
4046
);
4147
return projection === null

‎apps/mobile/src/lib/filePreview.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ describe("ThreadInlineFilePreview playback", () => {
435435
createElement(ThreadFeed, {
436436
environmentId,
437437
threadId,
438+
detailRef: null,
438439
threadTitle: "preview",
439440
workspaceRoot: "/repo",
440441
feed,
@@ -1374,6 +1375,7 @@ describe("ThreadFeed previews", () => {
13741375
createElement(ThreadFeed, {
13751376
environmentId,
13761377
threadId,
1378+
detailRef: null,
13771379
threadTitle: "preview",
13781380
workspaceRoot: "/repo",
13791381
feed: feedFor(threadId),

0 commit comments

Comments
 (0)