Skip to content

Commit a53e4a8

Browse files
PR Batch Testerclaude
andcommitted
fix(client): "Subagent needs input" no longer sticks after the subagent finishes
A subagent's async question stays pending after its run ends, so the parent kept showing the badge forever. Only count a subagent question while that subagent's run is still live. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6524a8d commit a53e4a8

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
EnvironmentId,
33
ProjectId,
4+
RuntimeRequestId,
45
ThreadId,
56
type OrchestrationV2ShellSnapshot,
67
} from "@t3tools/contracts";
@@ -9,7 +10,7 @@ import { Atom, AtomRegistry } from "effect/reactivity";
910
import { describe, expect, it } from "vite-plus/test";
1011

1112
import { PrimaryConnectionTarget } from "../connection/model.ts";
12-
import { v2ShellSnapshot, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
13+
import { v2Now, v2ShellSnapshot, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
1314
import { applyShellStreamEvent } from "./shellReducer.ts";
1415
import { createEnvironmentThreadShellAtoms } from "./threadShell.ts";
1516

@@ -103,6 +104,39 @@ describe("v2 thread shell lists", () => {
103104
registry.dispose();
104105
});
105106

107+
it("counts a subagent question on its parent only while the subagent runs", () => {
108+
const { registry, threads, snapshotAtom } = makeHarness();
109+
const root = v2ThreadShell;
110+
const child = {
111+
...root,
112+
id: ThreadId.make("child"),
113+
creationSource: "mcp" as const,
114+
status: "running" as const,
115+
lineage: {
116+
...root.lineage,
117+
parentThreadId: root.id,
118+
relationshipToParent: "subagent" as const,
119+
},
120+
pendingRuntimeRequest: {
121+
id: RuntimeRequestId.make("question"),
122+
kind: "user_input" as const,
123+
createdAt: v2Now,
124+
},
125+
};
126+
const inputs = threads.childThreadInputsAtom({ environmentId, threadId: root.id });
127+
const dispose = registry.mount(inputs);
128+
registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, child] });
129+
expect(registry.get(inputs).map((thread) => thread.id)).toEqual([child.id]);
130+
// An async question stays pending after the run that asked it completes.
131+
registry.set(snapshotAtom(environmentId), {
132+
...v2ShellSnapshot,
133+
threads: [root, { ...child, status: "completed" as const }],
134+
});
135+
expect(registry.get(inputs)).toEqual([]);
136+
dispose();
137+
registry.dispose();
138+
});
139+
106140
it("leaves switched-off environments out of navigation", () => {
107141
const { registry, threads, catalogValueAtom } = makeHarness([
108142
environmentId,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const EMPTY_THREAD_REFS_BY_PROJECT: ReadonlyMap<
3030
ReadonlyArray<ScopedThreadRef>
3131
> = new Map();
3232

33+
// An async question outlives the subagent's run, but once that run ends the
34+
// 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";
37+
3338
export function createEnvironmentThreadShellAtoms(input: {
3439
readonly catalogValueAtom: Atom.Atom<EnvironmentCatalogState>;
3540
readonly snapshotAtom: (
@@ -163,6 +168,7 @@ export function createEnvironmentThreadShellAtoms(input: {
163168
pending.push(child.id);
164169
if (
165170
child.pendingRuntimeRequest?.kind === "user_input" &&
171+
isChildRunLive(child.status) &&
166172
!isProviderNativeSubagentThread(child)
167173
) {
168174
next.push(scopedThread(ref.environmentId, child));

0 commit comments

Comments
 (0)