Compaction/Safeguard: skip faux non-text markers

This commit is contained in:
Rodrigo Uroz 2026-02-27 19:25:47 +00:00 committed by Josh Lehman
parent b656de6de7
commit 3a8cf6a863
No known key found for this signature in database
GPG Key ID: D141B425AC7F876B
2 changed files with 14 additions and 1 deletions

View File

@ -546,6 +546,19 @@ describe("compaction-safeguard recent-turn preservation", () => {
expect(section).toContain("[non-text content: image]");
});
it("does not add non-text placeholders for text-only content blocks", () => {
const section = formatPreservedTurnsSection([
{
role: "assistant",
content: [{ type: "text", text: "plain text reply" }],
timestamp: 1,
} as unknown as AgentMessage,
]);
expect(section).toContain("- Assistant: plain text reply");
expect(section).not.toContain("[non-text content]");
});
it("clamps preserve count into a safe range", () => {
expect(resolveRecentTurnsPreserve(undefined)).toBe(3);
expect(resolveRecentTurnsPreserve(-1)).toBe(0);

View File

@ -220,7 +220,7 @@ function formatNonTextPlaceholder(content: unknown): string | null {
typeCounts.set(type, (typeCounts.get(type) ?? 0) + 1);
}
if (typeCounts.size === 0) {
return "[non-text content]";
return null;
}
const parts = [...typeCounts.entries()].map(([type, count]) =>
count > 1 ? `${type} x${count}` : type,