Skip to content

Commit 975b3dc

Browse files
authored
fix(client-runtime): keep subagent questions off parent threads (#26367)
1 parent cb4fe60 commit 975b3dc

2 files changed

Lines changed: 18 additions & 2 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
@@ -108,7 +108,7 @@ describe("v2 thread shell lists", () => {
108108
registry.dispose();
109109
});
110110

111-
it("counts a subagent question on its parent only while the subagent runs", () => {
111+
it("keeps a live subagent question inside the parent without flagging its thread", () => {
112112
const { registry, threads, snapshotAtom } = makeHarness();
113113
const root = v2ThreadShell;
114114
const child = {
@@ -132,6 +132,10 @@ describe("v2 thread shell lists", () => {
132132
const dispose = registry.mount(inputs);
133133
registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, child] });
134134
expect(registry.get(inputs).map((thread) => thread.id)).toEqual([child.id]);
135+
expect(
136+
registry.get(threads.threadShellAtom({ environmentId, threadId: root.id }))
137+
?.pendingSubagentRequest,
138+
).toBeNull();
135139
registry.set(snapshotAtom(environmentId), {
136140
...v2ShellSnapshot,
137141
threads: [root, { ...child, status: "queued" as const }],
@@ -272,6 +276,16 @@ describe("v2 thread shell lists", () => {
272276
`${remoteEnvironmentId}/${helper.id}`,
273277
]);
274278

279+
registry.set(snapshotAtom(remoteEnvironmentId), {
280+
...v2ShellSnapshot,
281+
threads: [
282+
task,
283+
{ ...helper, pendingRuntimeRequest: { ...approval, kind: "user_input" as const } },
284+
],
285+
});
286+
expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBeNull();
287+
expect(registry.get(inputs).map((thread) => thread.id)).toEqual([helper.id]);
288+
275289
// A task whose parent is gone there is listed on its own, as is one whose
276290
// parent's environment is switched off.
277291
registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [] });

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function subagentRequest(thread: OrchestrationV2ThreadShell): PendingSubagentReq
7676
}
7777

7878
/**
79-
* The threads to flag for a subagent's live question or approval, up its
79+
* The threads to flag for a subagent's live approval, up its
8080
* subagent chain. `delegated` are tasks this environment's threads delegated
8181
* to linked environments, with what each one, or its own subagents, asks.
8282
*/
@@ -94,6 +94,8 @@ function pendingSubagentRequestsByThread(
9494
request: PendingSubagentRequest,
9595
seen: Set<ThreadId>,
9696
) => {
97+
// The coordinator answers child questions; only approvals need user attention.
98+
if (request === "user_input") return;
9799
byId ??= new Map(threads.map((thread) => [thread.id, thread] as const));
98100
let parentId = firstParentId;
99101
while (parentId !== null && !seen.has(parentId)) {

0 commit comments

Comments
 (0)