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

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

fix(client-runtime): imported threads that never ran no longer sit in Working as Waiting (#33042)

Julius Marminge committed Nov 12, 2026 at 23:52 UTC fb2e5a0128b8c688dd632b4aba35bbe513bd2f47
7 files changed +66 -12
apps/web/src/components/ChatView.logic.test.ts
+25 -1
@@ -9,7 +9,11 @@ import {
9 deriveAvailableRevertTurnCounts,
10 deriveThreadPendingBackgroundTasks,
11 } from "./ChatView.logic";
12 -import { recallCheckoutIsRepo, rememberCheckoutIsRepo } from "./ChatView.logic";
12 +import {
13 + isThreadEnvironmentLocked,
14 + recallCheckoutIsRepo,
15 + rememberCheckoutIsRepo,
16 +} from "./ChatView.logic";
17 import { ProviderDriverKind, type ServerProvider } from "@t3tools/contracts";
18 import { deriveProviderInstanceEntries } from "../providerInstances";
19 import { ensureInlineContextReferences } from "../lib/composerContextReferences";
@@ -133,6 +137,26 @@ describe("deriveComposerSendState", () => {
137 });
138 });
139
140 +describe("isThreadEnvironmentLocked", () => {
141 + it.each([
142 + { name: "an empty unbound thread", providerThread: null, expected: false },
143 + {
144 + name: "an imported session bound before its first run",
145 + providerThread: "imported",
146 + expected: true,
147 + },
148 + ])("locks $name: $expected", ({ providerThread, expected }) => {
149 + expect(
150 + isThreadEnvironmentLocked({
151 + messageCount: 0,
152 + hasRuntime: false,
153 + activeProviderThreadId:
154 + providerThread === null ? null : ProviderThreadId.make(providerThread),
155 + }),
156 + ).toBe(expected);
157 + });
158 +});
159 +
160 describe("buildExpiredTerminalContextToastCopy", () => {
161 it("refers to several expired contexts as them", () => {
162 expect(buildExpiredTerminalContextToastCopy(2, "empty")).toEqual({
apps/web/src/components/ChatView.logic.ts
+10
@@ -32,6 +32,7 @@ import {
32 type PreviewAnnotationPayload,
33 ProviderDriverKind,
34 type ProviderInstanceId,
35 + type ProviderThreadId,
36 type ServerProvider,
37 type ScopedProjectRef,
38 type ScopedThreadRef,
@@ -1541,3 +1542,12 @@ export function deriveAvailableRevertTurnCounts(projection: ThreadStructure | nu
1542 }
1543 return available;
1544 }
1545 +
1546 +/** An imported native session is bound before it has messages or runs, and its cwd is fixed. */
1547 +export function isThreadEnvironmentLocked(input: {
1548 + readonly messageCount: number;
1549 + readonly hasRuntime: boolean;
1550 + readonly activeProviderThreadId: ProviderThreadId | null;
1551 +}): boolean {
1552 + return input.messageCount > 0 || input.hasRuntime || input.activeProviderThreadId !== null;
1553 +}
apps/web/src/components/ChatView.tsx
+8 -2
@@ -37,7 +37,7 @@ import { ThreadFind, ThreadFindCanvas } from "./chat/ThreadFindProvider";
37 import { closeThreadFind, openThreadFind, useThreadFindOpen } from "./chat/threadFindStore";
38 import { THREAD_FIND_BAR_RESERVED_HEIGHT } from "./chat/ThreadFindBar";
39 import { usageLimitRecoveryBannerItem } from "./chat/UsageLimitRecoveryBanner";
40 -import { resolveDraftHeroState } from "./ChatView.logic";
40 +import { isThreadEnvironmentLocked, resolveDraftHeroState } from "./ChatView.logic";
41 import { useQueuedRunEdit } from "./chat/useQueuedRunEdit";
42 import { recallCheckoutIsRepo, rememberCheckoutIsRepo } from "./ChatView.logic";
43 import { useLogicalProjectEnvironments } from "../hooks/useLogicalProjectEnvironments";
@@ -1281,7 +1281,13 @@ export default function ChatView(props: ChatViewProps) {
1281 advertisedFileAttachmentBytes === null
1282 ? null
1283 : clampFileAttachmentUploadBytes(advertisedFileAttachmentBytes);
1284 - const envLocked = Boolean(activeThread && (activeMessageCount > 0 || activeRuntime !== null));
1284 + const envLocked =
1285 + Boolean(activeThread) &&
1286 + isThreadEnvironmentLocked({
1287 + messageCount: activeMessageCount,
1288 + hasRuntime: activeRuntime !== null,
1289 + activeProviderThreadId: serverThread?.activeProviderThreadId ?? null,
1290 + });
1291 // onEnvironmentChange only retargets an unsent draft. envLocked alone does not
1292 // rule out a started thread: one whose machine is offline never loads its
1293 // messages, so it would otherwise be offered a machine picker that does nothing.
packages/client-runtime/src/state/entities.test.ts
+13
@@ -98,6 +98,19 @@ describe("V2 client presentation", () => {
98 ).toBeNull();
99 });
100
101 + it("keeps an imported thread that never ran out of Working", () => {
102 + const imported = presentThreadShell(environmentId, {
103 + ...v2ThreadShell,
104 + historyOrigin: "v1_import",
105 + activeProviderThreadId: ProviderThreadId.make("provider-thread-imported"),
106 + latestRunId: null,
107 + activeRunId: null,
108 + status: "idle",
109 + pendingBackgroundTasks: [],
110 + });
111 + expect(isThreadWorking(imported)).toBe(false);
112 + });
113 +
114 it.each([
115 { kinds: ["command"], expected: "completed" },
116 { kinds: ["command", "subagent"], expected: "idle" },
packages/client-runtime/src/state/models.ts
+1 -1
@@ -231,7 +231,7 @@ function shellRuntime(thread: OrchestrationV2ThreadShell): ThreadRuntimeSummary
231 const parkAtIdle =
232 backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? []) &&
233 thread.status !== "failed";
234 - if (thread.latestRunId === null && thread.activeProviderThreadId === null && !parkAtIdle) {
234 + if (thread.latestRunId === null && !parkAtIdle) {
235 return null;
236 }
237 const status = parkAtIdle ? "idle" : (thread.activityRunStatus ?? thread.status);
packages/client-runtime/src/state/threadExecution.test.ts
+8 -1
@@ -553,7 +553,14 @@ describe("deriveRunlessWorkStartedAt", () => {
553 };
554
555 it("times a provider-native subagent from its runless root turn while it works", () => {
556 - const projection = { ...nativeChild, nodes: [rootTurn("running", later)] };
556 + const projection = {
557 + ...nativeChild,
558 + thread: {
559 + ...nativeChild.thread,
560 + activeProviderThreadId: ProviderThreadId.make("native-child"),
561 + },
562 + nodes: [rootTurn("running", later)],
563 + };
564 expect(deriveRunlessWorkStartedAt(projection)).toBe("2026-07-28T10:05:00.000Z");
565 expect(deriveThreadRuntime(projection)).toBeNull();
566 });
packages/client-runtime/src/state/threadExecution.ts
+1 -7
@@ -366,13 +366,7 @@ export function deriveThreadStructureRuntime(
366 }),
367 );
368 // A pull request watch can hold a thread that never ran.
369 - if (
370 - latestRun === null &&
371 - projection.thread.activeProviderThreadId === null &&
372 - !backgroundWorkHoldsRun
373 - ) {
374 - return null;
375 - }
369 + if (latestRun === null && !backgroundWorkHoldsRun) return null;
370 const activeRunId =
371 latestMatchingRun(projection, (run) => INTERRUPTIBLE_RUN_STATUSES.has(run.status))?.id ?? null;
372 return {