Skip to content

Commit 9152389

Browse files
committed
fix(web-fetch): report actual spill character count
1 parent 6c8a1ea commit 9152389

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/agents/tools/web-fetch.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ async function spillWebFetchContent(
316316
// maxChars/maxCharsCap bound the model-visible return text. Recoverable spill
317317
// uses this fixed file cap so vanished pages can still be read after truncation.
318318
const content = truncateUtf16Safe(value, WEB_FETCH_SPILL_MAX_CHARS);
319+
const spilledChars = content.length;
319320
const fullOutputPath = await writePrivateTempFile(
320321
"openclaw-web-fetch",
321322
wrapWebContent(content, "web_fetch"),
@@ -325,7 +326,7 @@ async function spillWebFetchContent(
325326
const spillNote = sourceTruncated
326327
? " Spilled available content from truncated response."
327328
: spillCapped
328-
? ` Spilled first ${WEB_FETCH_SPILL_MAX_CHARS} chars.`
329+
? ` Spilled first ${spilledChars} chars.`
329330
: "";
330331
const fullOutputFooter = formatFullOutputFooter(fullOutputPath);
331332
const footer = `\n\n[Showing truncated web_fetch content. ${fullOutputFooter}.${spillNote}]`;
@@ -345,7 +346,7 @@ async function spillWebFetchContent(
345346
text,
346347
wrappedLength: text.length,
347348
fullOutputPath,
348-
spilledChars: content.length,
349+
spilledChars,
349350
spillTruncated,
350351
};
351352
}

src/agents/tools/web-tools.fetch.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ describe("web_fetch extraction fallbacks", () => {
516516

517517
const result = await tool?.execute?.("call", { url: "https://example.com/spill-utf16" });
518518
const details = result?.details as {
519+
text?: string;
519520
fullOutputPath?: string;
520521
spilledChars?: number;
521522
spillTruncated?: boolean;
@@ -525,6 +526,7 @@ describe("web_fetch extraction fallbacks", () => {
525526
}
526527

527528
expect(details.spilledChars).toBe(WEB_FETCH_SPILL_MAX_CHARS - 1);
529+
expect(details.text).toContain(`Spilled first ${WEB_FETCH_SPILL_MAX_CHARS - 1} chars.`);
528530
expect(details.spillTruncated).toBe(true);
529531
const spilledText = await readFile(details.fullOutputPath, "utf8");
530532
expect(spilledText).toContain(prefix);

0 commit comments

Comments
 (0)