Skip to content

Commit 7973145

Browse files
committed
fix(fx): retain nested delegation steps in child threads
1 parent 45c9a52 commit 7973145

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎packages/provider-fx/src/server/subagents.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ describe("fx sub-agent hooks", () => {
150150
status: "success",
151151
}),
152152
},
153+
{
154+
hook: hook(CHILD, "tool.start", {
155+
call: call("call_nested", "subagent", '{"action":"run","task":"Check scripts"}'),
156+
}),
157+
},
158+
{
159+
hook: hook(CHILD, "tool.end", {
160+
call: call("call_nested", "subagent"),
161+
output: '{"ok":true,"result":"Scripts checked"}',
162+
status: "success",
163+
}),
164+
},
153165
{ hook: hook(CHILD, "model.start", { modelCallId: 2, purpose: "permission_review" }) },
154166
{ hook: hook(CHILD, "model.end", { modelCallId: 2, output: "allow", toolCalls: [{}] }) },
155167
{ hook: hook(CHILD, "model.start", { modelCallId: 3, purpose: "agent" }) },
@@ -168,10 +180,28 @@ describe("fx sub-agent hooks", () => {
168180
"tool_call call_read in_progress",
169181
"tool_call_update call_read completed",
170182
"tool_call_update call_read completed",
183+
"tool_call call_nested in_progress",
184+
"tool_call_update call_nested completed",
171185
`agent_message result: ${REPLY}`,
172186
]);
173187
const read = run.delivered[1]?.update;
174188
assert.deepInclude(read, { kind: "read", rawInput: { path: "package.json" } });
189+
let nested: AcpToolCallState | undefined;
190+
for (const notification of run.delivered.slice(4, 6)) {
191+
for (const event of parseSessionUpdateEvent(notification).events) {
192+
if (event._tag !== "ToolCallUpdated") continue;
193+
nested = mergeToolCallState(nested, event.toolCall);
194+
assert.isUndefined(extractFxSubagentUpdate(nested));
195+
}
196+
}
197+
assert.deepInclude(nested, {
198+
toolCallId: "call_nested",
199+
status: "completed",
200+
title: "subagent",
201+
});
202+
assert.deepInclude(nested?.data, {
203+
rawInput: { action: "run", task: "Check scripts" },
204+
});
175205
// fx completes the ACP call before it reports the whole result.
176206
assert.deepEqual(run.statuses, [
177207
"running",

‎packages/provider-fx/src/server/subagents.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ function childToolCall(call: typeof HookCall.Type) {
214214
const rawInput = Option.getOrUndefined(decodeArguments(call.argumentsJson));
215215
return {
216216
toolCallId: call.callId,
217-
name: call.name,
217+
// Nested delegations are child steps, not new top-level subagent tasks.
218+
...(call.name === FX_SUBAGENT_TOOL ? {} : { name: call.name }),
218219
title: call.name,
219220
kind: fxToolKind(call.name),
220221
...(rawInput === undefined ? {} : { rawInput }),

0 commit comments

Comments
 (0)