Skip to content

Commit b8aca54

Browse files
committed
fix(fx): keep late subagent results parseable after the turn ends
1 parent 2f7e6f8 commit b8aca54

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ describe("fx sub-agent hooks", () => {
274274
status: "cancelled",
275275
result: "cancelled",
276276
});
277+
278+
// After the parent turn ends, the adapter parses a late root update without prior tool state.
279+
const router = makeFxSubagentHookRouter();
280+
router.enrich(announce);
281+
router.route(delegation("dispatched"));
282+
const late = router.route(rootResult(WHOLE_RESULT)).at(-1);
283+
if (late === undefined) throw new Error("the whole result produced no root update");
284+
const alone = parseSessionUpdateEvent(late).events.flatMap((event) =>
285+
event._tag === "ToolCallUpdated" ? [extractFxSubagentUpdate(event.toolCall)] : [],
286+
);
287+
assert.deepInclude(alone[0], { status: "completed", result: REPLY });
277288
});
278289

279290
it("ignores hooks for calls fx never announced over ACP and for sessions it never dispatched", () => {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ interface RootSubagentCall {
232232
readonly sessionId: string;
233233
/** fx's ACP `tool_call` arrived, so a hook-made update cannot invent a tool. */
234234
announced: boolean;
235+
/** Repeated on hook-made updates: one landing after the turn is parsed alone. */
236+
rawInput?: unknown;
235237
state: FxSubagentHookState;
236238
}
237239

@@ -257,6 +259,8 @@ export function makeFxSubagentHookRouter() {
257259
update: {
258260
sessionUpdate: "tool_call_update",
259261
toolCallId: callId,
262+
name: FX_SUBAGENT_TOOL,
263+
rawInput: call.rawInput,
260264
_meta: { [HOOK_STATE_META_KEY]: call.state },
261265
},
262266
},
@@ -400,6 +404,7 @@ export function makeFxSubagentHookRouter() {
400404
calls.set(update.toolCallId, call);
401405
}
402406
call.announced = true;
407+
if (update.rawInput !== undefined) call.rawInput = update.rawInput;
403408
return {
404409
...notification,
405410
update: { ...update, _meta: { ...update._meta, [HOOK_STATE_META_KEY]: call.state } },

0 commit comments

Comments
 (0)