Skip to content

Commit 3c7be77

Browse files
committed
fix(agents): apply truncation cap to structured tool-result fallback (#97267)
Preserve the existing TOOL_RESULT_MAX_CHARS truncation invariant in the new structured-block JSON serialization fallback path. ClawSweeper review noted the path was added without cap coverage.
1 parent 073990e commit 3c7be77

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/agents/embedded-agent-subscribe.tools.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,14 @@ describe("extractToolResultText", () => {
441441
expect(withoutText).toBeDefined();
442442
expect(withoutText).toContain("resource");
443443
});
444+
445+
it("truncates large structured fallback output to TOOL_RESULT_MAX_CHARS (#97267)", () => {
446+
const bigData = "x".repeat(10_000);
447+
const text = extractToolResultText({
448+
content: [{ type: "resource", resource: { data: bigData } }],
449+
});
450+
expect(text).toBeDefined();
451+
expect(text!.length).toBeLessThanOrEqual(8100);
452+
expect(text).toContain("(truncated)");
453+
});
444454
});

src/agents/embedded-agent-subscribe.tools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ export function extractToolResultText(result: unknown): string | undefined {
303303
}
304304
}
305305
if (fallbackParts.length > 0) {
306-
return fallbackParts.join("\n");
306+
const joined = fallbackParts.join("\n");
307+
return truncateToolText(joined);
307308
}
308309
}
309310

0 commit comments

Comments
 (0)