Skip to content

Commit 64bb64b

Browse files
committed
fix(fx): retain full results after child settlement
1 parent 7973145 commit 64bb64b

4 files changed

Lines changed: 76 additions & 5 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/FxAdapterV2.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,72 @@ describe("FxAdapterV2", () => {
433433
],
434434
}).pipe(Effect.provide(testLayer), Effect.scoped),
435435
);
436+
it.effect("retains full replies arriving after failed or cancelled children settle", () =>
437+
Effect.gen(function* () {
438+
for (const phase of ["failed", "cancelled"] as const) {
439+
for (const withPreview of [false, true]) {
440+
const reply = `Child ${phase}: ${"The complete diagnostic. ".repeat(20)}`;
441+
const childSessionId = "fx-session-child";
442+
const events = yield* openFxSession({
443+
scenario: `late-${phase}-${withPreview}`,
444+
runtimeMode: "approval-required",
445+
turnModel: "default",
446+
frames: [
447+
...initialize,
448+
outbound("session/new"),
449+
answer("session/new", {
450+
...fxSession({ model: FX_DEFAULT_MODEL, modes: FX_MAIN_MODES }),
451+
_meta: { fx: { hooksVersion: 1 } },
452+
}),
453+
...setConfig(
454+
"mode",
455+
"ask",
456+
fxConfig({ model: FX_DEFAULT_MODEL, modes: FX_MAIN_MODES }),
457+
),
458+
outbound("session/prompt"),
459+
subagentCall("call_child", "Read package.json"),
460+
hook(SESSION_ID, "delegation", {
461+
callId: "call_child",
462+
childSessionId,
463+
phase: "dispatched",
464+
}),
465+
...(withPreview ? [subagentPreview("call_child", reply)] : []),
466+
hook(SESSION_ID, "delegation", {
467+
callId: "call_child",
468+
childSessionId,
469+
phase,
470+
}),
471+
hook(SESSION_ID, "tool.end", {
472+
call: { callId: "call_child", name: "subagent", provenance: "model" },
473+
output: JSON.stringify({ ok: false, result: reply, error_code: null }),
474+
status: "success",
475+
}),
476+
answer("session/prompt", { stopReason: "end_turn" }),
477+
],
478+
});
479+
const subagents = events.flatMap((event) =>
480+
event.type === "subagent.updated" ? [event.subagent] : [],
481+
);
482+
const terminal = subagents.filter((subagent) => subagent.status === phase);
483+
assert.isAtLeast(terminal.length, 2);
484+
assert.notEqual(terminal[0]?.result, reply);
485+
const settled = terminal.at(-1);
486+
assert.equal(settled?.result, reply);
487+
assert.equal(settled?.completedAt, terminal[0]?.completedAt);
488+
assert.isTrue(
489+
events.some(
490+
(event) =>
491+
event.type === "turn_item.updated" &&
492+
event.turnItem.type === "subagent" &&
493+
event.turnItem.status === phase &&
494+
event.turnItem.result === reply,
495+
),
496+
);
497+
}
498+
}
499+
}).pipe(Effect.provide(testLayer), Effect.scoped),
500+
);
501+
436502
// A restart reloads the session: fx replays the finished call from history
437503
// with its 200-byte preview and none of the child's steps, which T3 already
438504
// holds. The reload confirms hooks, so the next sub-agent shows its steps.

‎docs/user/providers-fx.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ A message steered into a running turn stops that turn, and fx answers the new me
4646

4747
When fx hands work to a sub-agent, it opens in its own thread under the parent. That thread shows the sub-agent's task, each tool it runs and what it says between them, and its full reply. A reply longer than 64 KiB is cut off with a note. Steps from a sub-agent's own sub-agents aren't shown.
4848

49-
fx versions before 0.0.14 don't report sub-agent steps, so there the thread shows only the task and a reply shortened to a couple of lines.
49+
When fx does not confirm hook support, the thread shows only the task and a reply shortened to a couple of lines.
5050

5151
fx doesn't pass on a sub-agent's permission requests, so a sub-agent that needs one waits until you press **Stop**. This mostly happens in **Supervised**. In **Auto**, sub-agents can finish routine work by themselves.
5252

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,7 +2878,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
28782878
existing !== undefined &&
28792879
existing.task.status === update.status &&
28802880
updateIsTerminal &&
2881-
existing.terminalStatusProjected
2881+
existing.terminalStatusProjected &&
2882+
(update.result === null || update.result === existing.task.result)
28822883
) {
28832884
return;
28842885
}
@@ -2931,7 +2932,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
29312932
model: update.model?.trim() || existing?.task.model || null,
29322933
status: taskStatus,
29332934
result: update.result ?? existing?.task.result ?? null,
2934-
completedAt: acpSubagentStatusIsTerminal(taskStatus) ? now : null,
2935+
completedAt: acpSubagentStatusIsTerminal(taskStatus)
2936+
? (existing?.task.completedAt ?? now)
2937+
: null,
29352938
updatedAt: now,
29362939
};
29372940
const subagent: ActiveAcpSubagent = existing ?? {
@@ -3058,7 +3061,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
30583061
...subagent.task,
30593062
status: taskStatus,
30603063
result,
3061-
completedAt: acpSubagentStatusIsTerminal(taskStatus) ? now : null,
3064+
completedAt: acpSubagentStatusIsTerminal(taskStatus)
3065+
? (subagent.task.completedAt ?? now)
3066+
: null,
30623067
updatedAt: now,
30633068
};
30643069
const providerThreadId = subagent.task.providerThreadId;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ type SessionUpdateHandler = Parameters<
417417

418418
/**
419419
* Routes fx's hook events through the adapter's session update handlers. A
420-
* session fx does not confirm hooks for (fx 0.0.13) keeps the ACP-only view.
420+
* session fx does not confirm hooks for keeps the ACP-only view.
421421
*/
422422
export function withFxSubagentHooks(
423423
runtime: AcpSessionRuntime.AcpSessionRuntime["Service"],

0 commit comments

Comments
 (0)