Skip to content

Commit f726d1c

Browse files
PR Batch Testerclaude
andcommitted
fix(client): keep a subagent question live when a follow-up is queued behind it
A queued follow-up becomes the child's latest run, so `status` read as "queued" while the blocked run still waited on the answer. Check the activity run instead and fall back to `status` for older servers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a53e4a8 commit f726d1c

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎packages/client-runtime/src/state/threadShell.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ describe("v2 thread shell lists", () => {
112112
id: ThreadId.make("child"),
113113
creationSource: "mcp" as const,
114114
status: "running" as const,
115+
activityRunStatus: "running" as const,
115116
lineage: {
116117
...root.lineage,
117118
parentThreadId: root.id,
@@ -127,10 +128,23 @@ describe("v2 thread shell lists", () => {
127128
const dispose = registry.mount(inputs);
128129
registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, child] });
129130
expect(registry.get(inputs).map((thread) => thread.id)).toEqual([child.id]);
131+
// A follow-up queued behind the blocked run leaves the question live.
132+
registry.set(snapshotAtom(environmentId), {
133+
...v2ShellSnapshot,
134+
threads: [root, { ...child, status: "queued" as const }],
135+
});
136+
expect(registry.get(inputs).map((thread) => thread.id)).toEqual([child.id]);
130137
// An async question stays pending after the run that asked it completes.
131138
registry.set(snapshotAtom(environmentId), {
132139
...v2ShellSnapshot,
133-
threads: [root, { ...child, status: "completed" as const }],
140+
threads: [root, { ...child, status: "completed" as const, activityRunStatus: null }],
141+
});
142+
expect(registry.get(inputs)).toEqual([]);
143+
// Older servers omit the activity run, so the latest run's status decides.
144+
const { activityRunStatus: _omitted, ...legacyChild } = child;
145+
registry.set(snapshotAtom(environmentId), {
146+
...v2ShellSnapshot,
147+
threads: [root, { ...legacyChild, status: "completed" as const }],
134148
});
135149
expect(registry.get(inputs)).toEqual([]);
136150
dispose();

‎packages/client-runtime/src/state/threadShell.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ const EMPTY_THREAD_REFS_BY_PROJECT: ReadonlyMap<
3232

3333
// An async question outlives the subagent's run, but once that run ends the
3434
// parent is no longer waiting on the answer, so it stops counting as input.
35-
const isChildRunLive = (status: OrchestrationV2ThreadShell["status"]) =>
36-
status === "preparing" || status === "starting" || status === "running" || status === "waiting";
35+
// The activity run stays set when a follow-up is queued behind a blocked run;
36+
// older servers omit it, so fall back to the latest run's status.
37+
const isChildRunLive = (
38+
thread: Pick<OrchestrationV2ThreadShell, "activityRunStatus" | "status">,
39+
) =>
40+
thread.activityRunStatus !== undefined
41+
? thread.activityRunStatus !== null
42+
: thread.status === "preparing" ||
43+
thread.status === "starting" ||
44+
thread.status === "running" ||
45+
thread.status === "waiting";
3746

3847
export function createEnvironmentThreadShellAtoms(input: {
3948
readonly catalogValueAtom: Atom.Atom<EnvironmentCatalogState>;
@@ -168,7 +177,7 @@ export function createEnvironmentThreadShellAtoms(input: {
168177
pending.push(child.id);
169178
if (
170179
child.pendingRuntimeRequest?.kind === "user_input" &&
171-
isChildRunLive(child.status) &&
180+
isChildRunLive(child) &&
172181
!isProviderNativeSubagentThread(child)
173182
) {
174183
next.push(scopedThread(ref.environmentId, child));

0 commit comments

Comments
 (0)