mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 02:42:54 +00:00
feat(tool-truncation): use head+tail strategy to preserve errors during truncation (#20076)
Merged via squash.
Prepared head SHA: 6edebf22b1
Co-authored-by: jlwestsr <52389+jlwestsr@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
committed by
GitHub
parent
d89e1e40f9
commit
606cd0d591
@@ -289,3 +289,25 @@ describe("sessionLikelyHasOversizedToolResults", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("truncateToolResultText head+tail strategy", () => {
|
||||
it("preserves error content at the tail when present", () => {
|
||||
const head = "Line 1\n".repeat(500);
|
||||
const middle = "data data data\n".repeat(500);
|
||||
const tail = "\nError: something failed\nStack trace: at foo.ts:42\n";
|
||||
const text = head + middle + tail;
|
||||
const result = truncateToolResultText(text, 5000);
|
||||
// Should contain both the beginning and the error at the end
|
||||
expect(result).toContain("Line 1");
|
||||
expect(result).toContain("Error: something failed");
|
||||
expect(result).toContain("middle content omitted");
|
||||
});
|
||||
|
||||
it("uses simple head truncation when tail has no important content", () => {
|
||||
const text = "normal line\n".repeat(1000);
|
||||
const result = truncateToolResultText(text, 5000);
|
||||
expect(result).toContain("normal line");
|
||||
expect(result).not.toContain("middle content omitted");
|
||||
expect(result).toContain("truncated");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user