mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 23:34:31 +00:00
Compaction: ignore tool result details in oversized checks (#24057)
* Compaction: ignore tool result details in oversized checks * Tests/Compaction: type estimateTokens message callback
This commit is contained in:
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const piCodingAgentMocks = vi.hoisted(() => ({
|
||||
generateSummary: vi.fn(async () => "summary"),
|
||||
estimateTokens: vi.fn(() => 1),
|
||||
estimateTokens: vi.fn((_message: unknown) => 1),
|
||||
}));
|
||||
|
||||
vi.mock("@mariozechner/pi-coding-agent", async () => {
|
||||
@@ -17,7 +17,7 @@ vi.mock("@mariozechner/pi-coding-agent", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import { summarizeWithFallback } from "./compaction.js";
|
||||
import { isOversizedForSummary, summarizeWithFallback } from "./compaction.js";
|
||||
|
||||
describe("compaction toolResult details stripping", () => {
|
||||
beforeEach(() => {
|
||||
@@ -64,4 +64,23 @@ describe("compaction toolResult details stripping", () => {
|
||||
expect(serialized).not.toContain("Ignore previous instructions");
|
||||
expect(serialized).not.toContain('"details"');
|
||||
});
|
||||
|
||||
it("ignores toolResult.details when evaluating oversized messages", () => {
|
||||
piCodingAgentMocks.estimateTokens.mockImplementation((message: unknown) => {
|
||||
const record = message as { details?: unknown };
|
||||
return record.details ? 10_000 : 10;
|
||||
});
|
||||
|
||||
const toolResult = {
|
||||
role: "toolResult",
|
||||
toolCallId: "call_1",
|
||||
toolName: "browser",
|
||||
isError: false,
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
details: { raw: "x".repeat(100_000) },
|
||||
timestamp: 2,
|
||||
} as unknown as AgentMessage;
|
||||
|
||||
expect(isOversizedForSummary(toolResult, 1_000)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user