mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(agent-core): avoid a crash when empty output has a negative line limit (#103425)
* fix(agent-core): avoid empty truncation crash * refactor(agent-core): simplify empty truncation handling --------- Co-authored-by: Peter Steinberger <steipete@gmail.com> Co-authored-by: Peter Steinberger <peter@steipete.me>
This commit is contained in:
@@ -201,8 +201,8 @@ export function truncateHead(content: string, options: TruncationOptions = {}):
|
||||
});
|
||||
}
|
||||
|
||||
const firstLineBytes = utf8ByteLength(input.lines[0]);
|
||||
if (firstLineBytes > input.maxBytes) {
|
||||
const firstLine = input.lines[0];
|
||||
if (firstLine !== undefined && utf8ByteLength(firstLine) > input.maxBytes) {
|
||||
return buildTruncationResult(input, {
|
||||
content: "",
|
||||
truncated: true,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { truncateHead } from "./truncate.js";
|
||||
|
||||
describe("session tool truncation facade", () => {
|
||||
it.each([
|
||||
{ limit: "maxLines", options: { maxLines: -1 }, truncatedBy: "lines" as const },
|
||||
{ limit: "maxBytes", options: { maxBytes: -1 }, truncatedBy: "bytes" as const },
|
||||
])("handles empty content with a negative $limit", ({ options, truncatedBy }) => {
|
||||
expect(truncateHead("", options)).toMatchObject({
|
||||
content: "",
|
||||
truncated: true,
|
||||
truncatedBy,
|
||||
totalLines: 0,
|
||||
totalBytes: 0,
|
||||
outputLines: 0,
|
||||
outputBytes: 0,
|
||||
firstLineExceedsLimit: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user