The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 23:30 UTC
fix: new threads move from draft to Working in one step (#33783)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 10, 2026 at 21:45 UTC
a0efdaeb89a75050612a82436432de4ebf526206
16 files changed
+315
-17
apps/mobile/src/features/home/HomeRouteScreen.tsx
+3
-4
@@ -16,7 +16,7 @@ import {
16
17
import { useProjects } from "../../state/entities";
18
import { environmentThreadShells } from "../../state/threads";
19
-import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
19
+import { useLaunchingThreads, usePendingNewTasks } from "../../state/use-pending-new-tasks";
20
import { useWorkspaceState } from "../../state/workspace";
21
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
22
import {
@@ -46,9 +46,8 @@ export function HomeRouteScreen() {
46
const projects = useProjects();
47
// Stop rebuilding the streaming thread list while Thread covers Home.
48
const visible = useHomeRouteVisible();
49
- const threads = useAtomValueWhileVisible(
50
- environmentThreadShells.navigationThreadShellsAtom,
51
- visible,
49
+ const threads = useLaunchingThreads(
50
+ useAtomValueWhileVisible(environmentThreadShells.navigationThreadShellsAtom, visible),
51
);
52
const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
53
const { savedConnectionsById } = useSavedRemoteConnections();
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+7
-2
@@ -32,7 +32,11 @@ import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-pref
32
import { useThreadListNow } from "./use-thread-list-now";
33
import { usePendingThreadOrder } from "../../state/thread-order";
34
import { threadListEnvironmentsAtom } from "../../state/presentation";
35
-import { usePendingNewTasks, type PendingNewTask } from "../../state/use-pending-new-tasks";
35
+import {
36
+ useLaunchingThreads,
37
+ usePendingNewTasks,
38
+ type PendingNewTask,
39
+} from "../../state/use-pending-new-tasks";
40
import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
41
import { useWorkspaceState } from "../../state/workspace";
42
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
@@ -136,6 +140,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
140
regenerateThreadTitle,
141
} = useThreadListActions();
142
const pendingTasks = usePendingNewTasks();
143
+ const launchingThreads = useLaunchingThreads(threads);
144
const activeNewTask = useActiveNewTask();
145
const queuedThreadKeys = useQueuedThreadKeys();
146
const selectDetail = useSelectWorkspaceDetail();
@@ -264,7 +269,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
269
contentOnlyThreadKeys,
270
olderSettledShelf,
271
} = useThreadListV2({
267
- threads,
272
+ threads: launchingThreads,
273
pendingTasks,
274
environmentId: options.selectedEnvironmentId,
275
projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
apps/mobile/src/state/composer-attachment-uploads.test.ts
+1
@@ -170,6 +170,7 @@ vi.mock("./use-thread-outbox", async () => {
170
dispatchingQueuedMessageIdAtom: Atom.make<Record<string, string>>({}).pipe(Atom.keepAlive),
171
useThreadOutboxMessages: () =>
172
appAtomRegistry.get(threadOutboxManager.queuedMessagesByThreadKeyAtom),
173
+ retryingQueuedMessageIdsAtom: Atom.make({}).pipe(Atom.keepAlive),
174
threadOutboxShellStatusesAtom: Atom.make(new Map()),
175
};
176
});
apps/mobile/src/state/pending-new-tasks-model.test.ts
+62
-1
@@ -1,11 +1,20 @@
1
-import { EnvironmentId, ProjectId } from "@t3tools/contracts";
1
+import {
2
+ CommandId,
3
+ EnvironmentId,
4
+ MessageId,
5
+ ProjectId,
6
+ ProviderInstanceId,
7
+ ThreadId,
8
+} from "@t3tools/contracts";
9
import { describe, expect, it } from "vite-plus/test";
10
11
import {
12
+ buildPendingNewTasks,
13
type PendingDraftProjectDefaults,
14
pendingDraftBranchNeedsRefs,
15
resolvePendingDraftBranch,
16
} from "./pending-new-tasks-model";
17
+import type { QueuedThreadMessage } from "./thread-outbox-model";
18
import type { ComposerDraft, ComposerDraftWorkspaceSelection } from "./use-composer-drafts";
19
20
const projectCwd = "/repo";
@@ -82,3 +91,55 @@ describe("resolvePendingDraftBranch", () => {
91
expect(resolve({ draft: chosen, branches, projectCwd })).toBe("release");
92
});
93
});
94
+
95
+function queuedCreation(environmentId: string): QueuedThreadMessage {
96
+ return {
97
+ environmentId: EnvironmentId.make(environmentId),
98
+ threadId: ThreadId.make(`thread-${environmentId}`),
99
+ messageId: MessageId.make(`message-${environmentId}`),
100
+ commandId: CommandId.make(`command-${environmentId}`),
101
+ text: "Test",
102
+ attachments: [],
103
+ modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
104
+ creation: {
105
+ projectId: ProjectId.make("project-1"),
106
+ workspaceMode: "local",
107
+ branch: null,
108
+ worktreePath: null,
109
+ },
110
+ createdAt: "2026-11-10T01:10:00.000Z",
111
+ };
112
+}
113
+
114
+describe("buildPendingNewTasks", () => {
115
+ it("lists only creations the outbox is not sending yet", () => {
116
+ const sending = EnvironmentId.make("sending");
117
+ const syncing = EnvironmentId.make("syncing");
118
+ const readOnly = EnvironmentId.make("read-only");
119
+ const retrying = EnvironmentId.make("retrying");
120
+ const { modelSelection: _model, ...modelless } = queuedCreation("sending");
121
+ const tasks = buildPendingNewTasks({
122
+ queuedMessages: [
123
+ ...["sending", "syncing", "read-only", "retrying", "offline"].map(queuedCreation),
124
+ { ...modelless, messageId: MessageId.make("message-modelless") },
125
+ ],
126
+ drafts: {},
127
+ sendGate: {
128
+ connectedEnvironmentIds: new Set([sending, syncing, readOnly, retrying]),
129
+ operableEnvironmentIds: new Set([sending, syncing, retrying]),
130
+ shellStatuses: new Map([
131
+ [sending, "live"],
132
+ [syncing, "synchronizing"],
133
+ [readOnly, "live"],
134
+ [retrying, "live"],
135
+ ]),
136
+ retryingMessageIds: { [MessageId.make("message-retrying")]: true },
137
+ },
138
+ });
139
+
140
+ expect(tasks).toHaveLength(5);
141
+ expect(new Set(tasks.map((task) => task.environmentId))).toEqual(
142
+ new Set(["syncing", "read-only", "retrying", "offline", "sending"]),
143
+ );
144
+ });
145
+});
apps/mobile/src/state/pending-new-tasks-model.ts
+37
-3
@@ -1,7 +1,13 @@
1
-import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
1
+import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell";
2
+import type { EnvironmentId, MessageId, ProjectId } from "@t3tools/contracts";
3
4
import { deriveThreadTitleFromPrompt } from "../lib/projectThreadStartTurn";
4
-import type { QueuedThreadCreation, QueuedThreadMessage } from "./thread-outbox-model";
5
+import {
6
+ isQueuedThreadCreationSendable,
7
+ resolveThreadOutboxDeliveryAction,
8
+ type QueuedThreadCreation,
9
+ type QueuedThreadMessage,
10
+} from "./thread-outbox-model";
11
import { isNewTaskDraftKey } from "./new-task-draft-key";
12
import type { ComposerDraft } from "./use-composer-drafts";
13
import { resolveNewTaskDraftWorkspace } from "../features/threads/new-task-context-presentation";
@@ -85,13 +91,41 @@ export function resolvePendingDraftBranch(input: {
91
}).branch;
92
}
93
94
+export interface ThreadOutboxSendGate {
95
+ readonly connectedEnvironmentIds: ReadonlySet<EnvironmentId>;
96
+ readonly operableEnvironmentIds: ReadonlySet<EnvironmentId>;
97
+ readonly shellStatuses: ReadonlyMap<EnvironmentId, EnvironmentShellStatus>;
98
+ readonly retryingMessageIds: Readonly<Partial<Record<MessageId, true>>>;
99
+}
100
+
101
+/** The outbox drain's gate for a creation: sendable, connected, shell live, operate granted, not backing off. */
102
+export function isQueuedCreationSending(
103
+ message: QueuedThreadMessage,
104
+ gate: ThreadOutboxSendGate,
105
+): boolean {
106
+ const environmentId = message.environmentId;
107
+ return (
108
+ isQueuedThreadCreationSendable(message) &&
109
+ gate.retryingMessageIds[message.messageId] !== true &&
110
+ gate.operableEnvironmentIds.has(environmentId) &&
111
+ resolveThreadOutboxDeliveryAction({
112
+ isCreation: true,
113
+ threadExists: false,
114
+ shellStatus: gate.shellStatuses.get(environmentId) ?? "empty",
115
+ environmentConnected: gate.connectedEnvironmentIds.has(environmentId),
116
+ }) === "send"
117
+ );
118
+}
119
+
120
export function buildPendingNewTasks(input: {
121
readonly queuedMessages: ReadonlyArray<QueuedThreadMessage>;
122
readonly drafts: Readonly<Record<string, ComposerDraft>>;
123
+ readonly sendGate: ThreadOutboxSendGate;
124
}): ReadonlyArray<PendingNewTask> {
125
const tasks: PendingNewTask[] = [];
126
for (const message of input.queuedMessages) {
94
- if (!message.creation) {
127
+ // Listing a creation already being sent would flash an "Unsent" row.
128
+ if (!message.creation || isQueuedCreationSending(message, input.sendGate)) {
129
continue;
130
}
131
tasks.push({
apps/mobile/src/state/pending-thread-creation.test.ts
+31
@@ -4,13 +4,17 @@ import {
4
MessageId,
5
ProjectId,
6
ProviderInstanceId,
7
+ RunId,
8
ThreadId,
9
} from "@t3tools/contracts";
10
+import { isThreadWorking } from "@t3tools/client-runtime/state/thread-inbox";
11
import { describe, expect, it } from "vite-plus/test";
12
13
import {
14
+ pendingThreadCreationShell,
15
resolvePendingThreadCreation,
16
selectThreadCreationDetail,
17
+ withLaunchingThreads,
18
type PendingThreadCreation,
19
} from "./pending-thread-creation";
20
import type { QueuedThreadMessage } from "./thread-outbox-model";
@@ -186,3 +190,30 @@ describe("selectThreadCreationDetail", () => {
190
).toEqual({ pendingCreation: null, detailRef: threadRef });
191
});
192
});
193
+
194
+describe("withLaunchingThreads", () => {
195
+ it("reads as working from Send until the thread's first run arrives", () => {
196
+ const launch = (threads: Parameters<typeof withLaunchingThreads>[0]["threads"]) =>
197
+ withLaunchingThreads({ threads, launches: [creation], hiddenThreadKeys: new Set() });
198
+ // Before the shell arrives, and after the server commits the thread without its run.
199
+ const created = { ...pendingThreadCreationShell(creation)!, title: "Server title" };
200
+ for (const threads of [launch([]), launch([created])]) {
201
+ expect(threads).toHaveLength(1);
202
+ expect(isThreadWorking(threads[0]!)).toBe(true);
203
+ }
204
+ expect(launch([created])[0]!.title).toBe("Server title");
205
+
206
+ const started = {
207
+ ...created,
208
+ latestRun: {
209
+ runId: RunId.make("run-1"),
210
+ status: "completed" as const,
211
+ requestedAt: null,
212
+ startedAt: null,
213
+ completedAt: null,
214
+ assistantMessageId: null,
215
+ },
216
+ };
217
+ expect(launch([started])[0]).toBe(started);
218
+ });
219
+});
apps/mobile/src/state/pending-thread-creation.ts
+29
@@ -4,6 +4,8 @@ import {
4
} from "@t3tools/client-runtime/state/shell";
5
import type { LocalThreadMessage } from "../lib/threadActivity";
6
import { DEFAULT_PROVIDER_INTERACTION_MODE, DEFAULT_RUNTIME_MODE } from "@t3tools/contracts";
7
+import { threadKey } from "@t3tools/client-runtime/state/entities";
8
+import { asLaunchingThread } from "@t3tools/client-runtime/state/thread-inbox";
9
import { Atom } from "effect/reactivity";
10
import * as DateTime from "effect/DateTime";
11
@@ -133,6 +135,33 @@ export function pendingThreadCreationMessage(message: QueuedThreadMessage): Loca
135
};
136
}
137
138
+/** Launches show as preparing from Send, before the server's shell exists, until their first run. */
139
+export function withLaunchingThreads(input: {
140
+ readonly threads: ReadonlyArray<EnvironmentThreadShell>;
141
+ readonly launches: ReadonlyArray<QueuedThreadMessage>;
142
+ readonly hiddenThreadKeys: ReadonlySet<string>;
143
+}): ReadonlyArray<EnvironmentThreadShell> {
144
+ if (input.launches.length === 0) return input.threads;
145
+ const launchByKey = new Map<string, QueuedThreadMessage>();
146
+ for (const message of input.launches) {
147
+ if (!message.creation || input.hiddenThreadKeys.has(threadKey(message))) continue;
148
+ launchByKey.set(scopedThreadKey(message.environmentId, message.threadId), message);
149
+ }
150
+ if (launchByKey.size === 0) return input.threads;
151
+ const threads = input.threads.map((thread) => {
152
+ const key = scopedThreadKey(thread.environmentId, thread.id);
153
+ const launch = launchByKey.get(key);
154
+ if (!launch) return thread;
155
+ launchByKey.delete(key);
156
+ return asLaunchingThread(thread);
157
+ });
158
+ for (const launch of launchByKey.values()) {
159
+ const shell = pendingThreadCreationShell(launch);
160
+ if (shell) threads.push(asLaunchingThread(shell));
161
+ }
162
+ return threads;
163
+}
164
+
165
export function pendingThreadCreationShell(
166
message: QueuedThreadMessage,
167
): EnvironmentThreadShell | null {
apps/mobile/src/state/threadOutboxDelivery.permissions.test.ts
+1
@@ -136,6 +136,7 @@ vi.mock("./use-thread-outbox", async () => {
136
return {
137
editingQueuedMessageIdsAtom: Atom.make({}).pipe(Atom.keepAlive),
138
dispatchingQueuedMessageIdAtom: Atom.make<MessageId | null>(null).pipe(Atom.keepAlive),
139
+ retryingQueuedMessageIdsAtom: Atom.make({}).pipe(Atom.keepAlive),
140
threadOutboxShellStatusesAtom: Atom.make(new Map([["secondary", "live"]])),
141
};
142
});
apps/mobile/src/state/threadOutboxDelivery.test.ts
+1
@@ -120,6 +120,7 @@ vi.mock("./use-thread-outbox", async () => {
120
return {
121
editingQueuedMessageIdsAtom: Atom.make<Record<string, boolean>>({}).pipe(Atom.keepAlive),
122
dispatchingQueuedMessageIdAtom: Atom.make(null).pipe(Atom.keepAlive),
123
+ retryingQueuedMessageIdsAtom: Atom.make({}).pipe(Atom.keepAlive),
124
threadOutboxShellStatusesAtom: Atom.make(new Map()),
125
};
126
});
apps/mobile/src/state/threadOutboxDelivery.ts
+17
@@ -87,6 +87,7 @@ import {
87
import {
88
dispatchingQueuedMessageIdAtom,
89
editingQueuedMessageIdsAtom,
90
+ retryingQueuedMessageIdsAtom,
91
threadOutboxShellStatusesAtom,
92
} from "./use-thread-outbox";
93
import { clearThreadComposerError, setThreadComposerError } from "./thread-composer-error";
@@ -155,7 +156,20 @@ function logThreadOutboxUploadFailure(queuedMessage: QueuedThreadMessage, error:
156
}
157
}
158
159
+function setQueuedMessageRetrying(queuedMessageId: MessageId, retrying: boolean): void {
160
+ const { [queuedMessageId]: current, ...others } = appAtomRegistry.get(
161
+ retryingQueuedMessageIdsAtom,
162
+ );
163
+ if ((current === true) === retrying) return;
164
+ appAtomRegistry.set(
165
+ retryingQueuedMessageIdsAtom,
166
+ retrying ? { ...others, [queuedMessageId]: true } : others,
167
+ );
168
+}
169
+
170
function beginDispatchingQueuedMessage(queuedMessageId: MessageId): void {
171
+ // An attempt in flight is sending, even while its retry count is kept.
172
+ setQueuedMessageRetrying(queuedMessageId, false);
173
appAtomRegistry.set(dispatchingQueuedMessageIdAtom, queuedMessageId);
174
}
175
@@ -701,6 +715,7 @@ export function createThreadOutboxDelivery(): {
715
notBefore: Date.now() + delayMs,
716
timer: setTimeout(drain, delayMs),
717
});
718
+ setQueuedMessageRetrying(messageId, true);
719
};
720
721
const clearRetry = (messageId: MessageId): void => {
@@ -708,6 +723,7 @@ export function createThreadOutboxDelivery(): {
723
if (retry === undefined) return;
724
clearTimeout(retry.timer);
725
retries.delete(messageId);
726
+ setQueuedMessageRetrying(messageId, false);
727
};
728
729
// A delivery that throws backs off like any failure. Releasing the slot
@@ -1412,6 +1428,7 @@ export function createThreadOutboxDelivery(): {
1428
stopCollectingOutcomes();
1429
for (const retry of retries.values()) clearTimeout(retry.timer);
1430
retries.clear();
1431
+ appAtomRegistry.set(retryingQueuedMessageIdsAtom, {});
1432
for (const blocked of blockedRecoveries.values()) blocked.unsubscribe();
1433
blockedRecoveries.clear();
1434
for (const release of familyMounts.values()) release();
apps/mobile/src/state/use-pending-new-tasks.ts
+64
-3
@@ -1,10 +1,26 @@
1
import { useAtomValue } from "@effect/atom-react";
2
+import { AuthOrchestrationOperateScope } from "@t3tools/contracts";
3
+import { Atom } from "effect/reactivity";
4
+import { useMemo } from "react";
5
import { threadKey } from "@t3tools/client-runtime/state/entities";
3
-import { buildPendingNewTasks, type PendingNewTask } from "./pending-new-tasks-model";
6
+import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
7
+import {
8
+ buildPendingNewTasks,
9
+ isQueuedCreationSending,
10
+ type PendingNewTask,
11
+ type ThreadOutboxSendGate,
12
+} from "./pending-new-tasks-model";
13
+import { pendingThreadCreationOutcomesAtom, withLaunchingThreads } from "./pending-thread-creation";
14
import { flattenQueuedThreadMessages } from "./thread-outbox-model";
15
import { environmentThreadShells } from "./threads";
16
import { newTaskComposerDraftsAtom } from "./use-composer-drafts";
7
-import { useThreadOutboxMessages } from "./use-thread-outbox";
17
+import {
18
+ retryingQueuedMessageIdsAtom,
19
+ threadOutboxShellStatusesAtom,
20
+ useThreadOutboxMessages,
21
+} from "./use-thread-outbox";
22
+import { environmentSession, sessionHasScope } from "./session";
23
+import { workspaceConnections } from "./workspace";
24
25
export type {
26
PendingDraftTask,
@@ -12,13 +28,58 @@ export type {
28
PendingQueuedTask,
29
} from "./pending-new-tasks-model";
30
31
+const threadOutboxSendGateAtom = Atom.make((get): ThreadOutboxSendGate => {
32
+ const connected = get(workspaceConnections.environmentsAtom).flatMap((environment) =>
33
+ environment.connectionState === "connected" ? [environment.environmentId] : [],
34
+ );
35
+ return {
36
+ connectedEnvironmentIds: new Set(connected),
37
+ operableEnvironmentIds: new Set(
38
+ connected.filter((environmentId) =>
39
+ sessionHasScope(
40
+ get(environmentSession.sessionStateAtom(environmentId)),
41
+ AuthOrchestrationOperateScope,
42
+ ),
43
+ ),
44
+ ),
45
+ shellStatuses: get(threadOutboxShellStatusesAtom),
46
+ retryingMessageIds: get(retryingQueuedMessageIdsAtom),
47
+ };
48
+}).pipe(Atom.withLabel("mobile:pending-new-tasks:send-gate"));
49
+
50
export function usePendingNewTasks(): ReadonlyArray<PendingNewTask> {
51
const queuedMessagesByThreadKey = useThreadOutboxMessages();
52
const drafts = useAtomValue(newTaskComposerDraftsAtom);
53
const hiddenKeys = useAtomValue(environmentThreadShells.hiddenThreadKeysAtom);
54
+ const sendGate = useAtomValue(threadOutboxSendGateAtom);
55
// A delivered creation can stay queued after its thread is live and hidden.
56
const queuedMessages = flattenQueuedThreadMessages(queuedMessagesByThreadKey).filter(
57
(message) => !hiddenKeys.has(threadKey(message)),
58
);
23
- return buildPendingNewTasks({ queuedMessages, drafts });
59
+ return buildPendingNewTasks({
60
+ queuedMessages,
61
+ drafts,
62
+ sendGate,
63
+ });
64
+}
65
+
66
+/** The list's threads, with creations the outbox is sending placed as working. */
67
+export function useLaunchingThreads(
68
+ threads: ReadonlyArray<EnvironmentThreadShell>,
69
+): ReadonlyArray<EnvironmentThreadShell> {
70
+ const queuedMessagesByThreadKey = useThreadOutboxMessages();
71
+ const outcomes = useAtomValue(pendingThreadCreationOutcomesAtom);
72
+ const hiddenThreadKeys = useAtomValue(environmentThreadShells.hiddenThreadKeysAtom);
73
+ const sendGate = useAtomValue(threadOutboxSendGateAtom);
74
+ return useMemo(() => {
75
+ const launches = [
76
+ ...flattenQueuedThreadMessages(queuedMessagesByThreadKey).filter((message) =>
77
+ isQueuedCreationSending(message, sendGate),
78
+ ),
79
+ ...Object.values(outcomes).flatMap((outcome) =>
80
+ outcome.kind === "delivered" ? [outcome.message] : [],
81
+ ),
82
+ ];
83
+ return withLaunchingThreads({ threads, launches, hiddenThreadKeys });
84
+ }, [threads, queuedMessagesByThreadKey, outcomes, hiddenThreadKeys, sendGate]);
85
}
apps/mobile/src/state/use-thread-outbox.ts
+5
@@ -31,6 +31,11 @@ export const dispatchingQueuedMessageIdAtom = Atom.make<MessageId | null>(null).
31
Atom.withLabel("mobile:thread-outbox:dispatching-message-id"),
32
);
33
34
+/** Messages waiting out a retry backoff, which can repeat for as long as the failure lasts. */
35
+export const retryingQueuedMessageIdsAtom = Atom.make<Readonly<Partial<Record<MessageId, true>>>>(
36
+ {},
37
+).pipe(Atom.keepAlive, Atom.withLabel("mobile:thread-outbox:retrying-message-ids"));
38
+
39
export function holdEditingQueuedMessage(messageId: MessageId): void {
40
const current = appAtomRegistry.get(editingQueuedMessageIdsAtom);
41
if (current[messageId]) {
apps/web/src/components/Sidebar.tsx
+17
-2
@@ -30,6 +30,7 @@ import {
30
threadWokeAt,
31
} from "@t3tools/client-runtime/state/thread-settled";
32
import {
33
+ asLaunchingThread,
34
createInboxReturnTracker,
35
isThreadWorking,
36
} from "@t3tools/client-runtime/state/thread-inbox";
@@ -248,7 +249,12 @@ import { SidebarContent, SidebarGroup, useSidebar } from "./ui/sidebar";
249
import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChrome";
250
import { SidebarHeaderIconButton, SidebarThreadHeader } from "./sidebar/SidebarThreadHeader";
251
import { TooltipProvider } from "./ui/tooltip";
251
-import { composerDraftHasUserContent, DraftId, useComposerDraftStore } from "../composerDraftStore";
252
+import {
253
+ composerDraftHasUserContent,
254
+ DraftId,
255
+ useComposerDraftStore,
256
+ usePromotingDraftThreadKeys,
257
+} from "../composerDraftStore";
258
import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
259
import {
260
SidebarSearchResultRow,
@@ -1095,6 +1101,15 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1101
),
1102
);
1103
const threads = useQuietThreadShells();
1104
+ const promotingDraftThreadKeys = usePromotingDraftThreadKeys();
1105
+ const listedThreads =
1106
+ promotingDraftThreadKeys.length === 0
1107
+ ? threads
1108
+ : threads.map((thread) =>
1109
+ promotingDraftThreadKeys.includes(threadShellKey(thread))
1110
+ ? asLaunchingThread(thread)
1111
+ : thread,
1112
+ );
1113
const routeRowThreadKey =
1114
routeThreadRef === null
1115
? null
@@ -1326,7 +1341,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1341
serverConfigs,
1342
connectedEnvironmentIds,
1343
optimisticDrop,
1329
- threads,
1344
+ threads: listedThreads,
1345
delegatedUnderParent,
1346
routeRowThreadKey,
1347
folderGroups: boringSidebarEnabled
apps/web/src/components/sidebar/SidebarThreadRow.tsx
+10
-2
@@ -1,4 +1,5 @@
1
import { useAtomMount } from "@effect/atom-react";
2
+import { asLaunchingThread } from "@t3tools/client-runtime/state/thread-inbox";
3
import { ThreadHoverCard, ThreadHoverCardPopup } from "../ThreadHoverCard";
4
import { ThreadTerminalStatusButton } from "../ThreadStatusIndicators";
5
import { discardComposerDraft } from "../../lib/discardComposerDraft";
@@ -477,9 +478,16 @@ export function SortableThreadRow(
478
};
479
// The sidebar arranges rows from quiet shells, which hold still while a
480
// thread streams; reading the live shell here re-renders only this row.
481
+ const liveThread = useThreadShell(
482
+ scopeThreadRef(rowProps.thread.environmentId, rowProps.thread.id),
483
+ );
484
+ // A runtime on the arranged copy but not the run-less live shell is the list's launch overlay.
485
const thread =
481
- useThreadShell(scopeThreadRef(rowProps.thread.environmentId, rowProps.thread.id)) ??
482
- rowProps.thread;
486
+ liveThread === null
487
+ ? rowProps.thread
488
+ : rowProps.thread.runtime !== null
489
+ ? asLaunchingThread(liveThread)
490
+ : liveThread;
491
// Keyed by variant so a card/slim switch remounts the row.
492
return <SidebarThreadRow key={rowProps.variant} {...rowProps} thread={thread} sortable={bag} />;
493
}
apps/web/src/composerDraftStore.ts
+11
@@ -4439,6 +4439,17 @@ export function useComposerDraftModelState(
4439
);
4440
}
4441
4442
+/** Threads a sent draft is launching into: from their shell's arrival until the server owns the send. */
4443
+export function usePromotingDraftThreadKeys(): ReadonlyArray<string> {
4444
+ return useComposerDraftStore(
4445
+ useShallow((state) =>
4446
+ Object.values(state.draftThreadsByThreadKey).flatMap((draft) =>
4447
+ draft.promotedTo ? [scopedThreadKey(draft.promotedTo)] : [],
4448
+ ),
4449
+ ),
4450
+ );
4451
+}
4452
+
4453
export function markPromotedDraftThreadByRef(threadRef: ScopedThreadRef): void {
4454
const draftStore = useComposerDraftStore.getState();
4455
for (const [draftId, draftThread] of Object.entries(draftStore.draftThreadsByThreadKey)) {
packages/client-runtime/src/state/threadInbox.ts
+19
@@ -30,6 +30,25 @@ export function isThreadWorking(thread: WorkingThreadInput): boolean {
30
return !(thread.interactionMode === "plan" && thread.hasActionableProposedPlan && runSettled);
31
}
32
33
+/**
34
+ * A thread its own client is launching reads as preparing until its first run lands.
35
+ * The server commits the thread before its run, so the list would otherwise place it twice.
36
+ */
37
+export function asLaunchingThread<T extends EnvironmentThreadShell>(thread: T): T {
38
+ if (thread.latestRun !== null || thread.runtime !== null) return thread;
39
+ return {
40
+ ...thread,
41
+ runtime: {
42
+ status: "preparing",
43
+ activeRunId: null,
44
+ providerInstanceId: thread.providerInstanceId,
45
+ providerName: null,
46
+ lastError: null,
47
+ updatedAt: thread.updatedAt,
48
+ },
49
+ };
50
+}
51
+
52
type InboxThreadInput = Pick<
53
EnvironmentThreadShell,
54
"id" | "environmentId" | "createdAt" | "unsettledAt" | "latestRun"