Skip to content

Commit 79c2d77

Browse files
authored
fix(agents): preserve findings and causes from failed child tasks (#129074)
1 parent 8a1ff39 commit 79c2d77

4 files changed

Lines changed: 65 additions & 9 deletions

File tree

‎src/agents/subagents/announce/subagent-announce-output.test.ts‎

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,36 @@ describe("readSubagentOutput", () => {
517517
});
518518

519519
describe("buildChildCompletionFindings", () => {
520+
it.each([
521+
{
522+
name: "timeout with its preserved failure cause",
523+
outcome: { status: "timeout", error: " provider rejected the request " },
524+
expected: "timeout: provider rejected the request",
525+
},
526+
{
527+
name: "timeout without a failure cause",
528+
outcome: { status: "timeout" },
529+
expected: "timeout",
530+
},
531+
{
532+
name: "ordinary failure with its cause",
533+
outcome: { status: "error", error: " provider rejected the request " },
534+
expected: "error: provider rejected the request",
535+
},
536+
] as const)("describes a $name in parent-visible findings", ({ outcome, expected }) => {
537+
const findings = buildChildCompletionFindings([
538+
{
539+
childSessionKey: "agent:main:subagent:child",
540+
task: "child task",
541+
createdAt: 1,
542+
completion: { resultText: "captured findings" },
543+
execution: { outcome },
544+
},
545+
]);
546+
547+
expect(findings).toContain(`status: ${expected}`);
548+
});
549+
520550
it("hard-bounds each child result and the aggregate parent prompt", () => {
521551
const findings = buildChildCompletionFindings(
522552
Array.from({ length: 8 }, (_, index) => ({
@@ -711,21 +741,27 @@ describe("buildChildCompletionFindings", () => {
711741
expect(findings).toContain("(no output)");
712742
});
713743

714-
it("uses captured fallback output when a resumed completion returns NO_REPLY", () => {
744+
it.each([
745+
{ name: "successful NO_REPLY", status: "ok", resultText: "NO_REPLY" },
746+
{ name: "blank failed", status: "error", resultText: "" },
747+
{ name: "whitespace timed-out", status: "timeout", resultText: " \n\t " },
748+
{ name: "blank unknown", status: "unknown", resultText: "" },
749+
] as const)("uses captured fallback output for a $name completion", ({ status, resultText }) => {
715750
const findings = buildChildCompletionFindings([
716751
{
717752
childSessionKey: "agent:main:subagent:child",
718753
task: "child task",
719754
createdAt: 1,
720755
completion: {
721-
resultText: "NO_REPLY",
756+
resultText,
722757
fallbackResultText: "findings captured before the wake",
723758
},
724-
execution: { outcome: { status: "ok" } },
759+
execution: { outcome: { status } },
725760
},
726761
]);
727762

728763
expect(findings).toContain("findings captured before the wake");
764+
expect(findings).not.toContain("(no output)");
729765
expect(findings).not.toContain("NO_REPLY");
730766
});
731767

‎src/agents/subagents/announce/subagent-announce-output.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,9 @@ function describeSubagentOutcome(outcome?: SubagentRunOutcome): string {
397397
if (outcome.status === "ok") {
398398
return "ok";
399399
}
400-
if (outcome.status === "timeout") {
401-
return "timeout";
402-
}
403-
if (outcome.status === "error") {
404-
return outcome.error?.trim() ? `error: ${outcome.error.trim()}` : "error";
400+
if (outcome.status === "timeout" || outcome.status === "error") {
401+
const error = outcome.error?.trim();
402+
return error ? `${outcome.status}: ${error}` : outcome.status;
405403
}
406404
return "unknown";
407405
}

‎src/agents/subagents/completion/subagent-completion-result.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,26 @@ describe("resolveSubagentCompletionResultText", () => {
4747
}),
4848
).toBe("legacy fallback");
4949
});
50+
51+
it.each([
52+
{ status: "error", resultText: "" },
53+
{ status: "error", resultText: " \n\t " },
54+
{ status: "timeout", resultText: "" },
55+
{ status: "timeout", resultText: " \n\t " },
56+
{ status: "unknown", resultText: "" },
57+
{ status: "unknown", resultText: " \n\t " },
58+
] as const)(
59+
"preserves captured findings when a $status completion has blank primary text ($#)",
60+
({ status, resultText }) => {
61+
expect(
62+
resolveSubagentCompletionResultText({
63+
completion: {
64+
resultText,
65+
fallbackResultText: " actionable captured findings ",
66+
},
67+
execution: { status: "terminal", outcome: { status } },
68+
}),
69+
).toBe("actionable captured findings");
70+
},
71+
);
5072
});

‎src/agents/subagents/completion/subagent-completion-result.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export function resolveSubagentCompletionResultText(entry: {
2525
if (entry.execution.outcome?.status === "ok") {
2626
return selectDeliverableSessionsReply(primary, fallback);
2727
}
28-
return (primary ?? fallback)?.trim() || undefined;
28+
return primary?.trim() || fallback?.trim() || undefined;
2929
}

0 commit comments

Comments
 (0)