Skip to content
TypeScript

fix(client-runtime): keep subagent questions off parent threads (#26367)

Yash Singh975b3dc56850
diff --git a/packages/client-runtime/src/state/threadShell.test.ts b/packages/client-runtime/src/state/threadShell.test.ts
index ec40d5f679e..fda1054064f 100644
--- a/packages/client-runtime/src/state/threadShell.test.ts
+++ b/packages/client-runtime/src/state/threadShell.test.ts
@@ -108,7 +108,7 @@ describe("v2 thread shell lists", () => {
registry.dispose();
});
- it("counts a subagent question on its parent only while the subagent runs", () => {
+ it("keeps a live subagent question inside the parent without flagging its thread", () => {
const { registry, threads, snapshotAtom } = makeHarness();
const root = v2ThreadShell;
const child = {
@@ -132,6 +132,10 @@ describe("v2 thread shell lists", () => {
const dispose = registry.mount(inputs);
registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, child] });
expect(registry.get(inputs).map((thread) => thread.id)).toEqual([child.id]);
+ expect(
+ registry.get(threads.threadShellAtom({ environmentId, threadId: root.id }))
+ ?.pendingSubagentRequest,
+ ).toBeNull();
registry.set(snapshotAtom(environmentId), {
...v2ShellSnapshot,
threads: [root, { ...child, status: "queued" as const }],
@@ -272,6 +276,16 @@ describe("v2 thread shell lists", () => {
`${remoteEnvironmentId}/${helper.id}`,
]);
+ registry.set(snapshotAtom(remoteEnvironmentId), {
+ ...v2ShellSnapshot,
+ threads: [
+ task,
+ { ...helper, pendingRuntimeRequest: { ...approval, kind: "user_input" as const } },
+ ],
+ });
+ expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBeNull();
+ expect(registry.get(inputs).map((thread) => thread.id)).toEqual([helper.id]);
+
// A task whose parent is gone there is listed on its own, as is one whose
// parent's environment is switched off.
registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [] });
diff --git a/packages/client-runtime/src/state/threadShell.ts b/packages/client-runtime/src/state/threadShell.ts
index 69df72418c2..15718da1eca 100644
--- a/packages/client-runtime/src/state/threadShell.ts
+++ b/packages/client-runtime/src/state/threadShell.ts
@@ -76,7 +76,7 @@ function subagentRequest(thread: OrchestrationV2ThreadShell): PendingSubagentReq
}
/**
- * The threads to flag for a subagent's live question or approval, up its
+ * The threads to flag for a subagent's live approval, up its
* subagent chain. `delegated` are tasks this environment's threads delegated
* to linked environments, with what each one, or its own subagents, asks.
*/
@@ -94,6 +94,8 @@ function pendingSubagentRequestsByThread(
request: PendingSubagentRequest,
seen: Set<ThreadId>,
) => {
+ // The coordinator answers child questions; only approvals need user attention.
+ if (request === "user_input") return;
byId ??= new Map(threads.map((thread) => [thread.id, thread] as const));
let parentId = firstParentId;
while (parentId !== null && !seen.has(parentId)) {