A context compaction or summarization strategy is implemented for long sessions
Why it matters
Simple FIFO truncation discards messages with no regard for their semantic value. The user's name stated at message 1, a constraint given at message 5, or a decision made at message 10 vanishes permanently when it slides out of the window. In multi-step workflows — job application assistants, planning tools, tutoring systems — this causes visible regression: the AI contradicts itself or asks questions the user already answered. NIST AI RMF MANAGE 2.2 requires managing model limitations that affect outcomes; history amnesia is a direct consequence of ignoring this.
Severity rationale
Medium because hard truncation degrades conversation quality and user trust in extended sessions, without causing an outright crash.
Remediation
Implement a summarization step that fires when history exceeds a turn threshold. Use a cheap, fast model for the summarization call — not the frontier model you use for the primary task.
// src/lib/ai/compaction.ts
export async function compactHistory(
messages: Array<{ role: string; content: string }>,
threshold: number = 20
): Promise<Array<{ role: string; content: string }>> {
if (messages.length <= threshold) return messages;
const toSummarize = messages.slice(0, messages.length - 10);
const recentMessages = messages.slice(messages.length - 10);
const { text: summary } = await generateText({
model: openai("gpt-4o-mini"),
prompt: `Summarize this conversation, preserving key facts, names, goals, and decisions:\n\n${
toSummarize.map(m => `${m.role}: ${m.content}`).join("\n")
}`,
maxTokens: 300,
});
return [
{ role: "system", content: `[Earlier conversation summary]: ${summary}` },
...recentMessages,
];
}
Verify by stating a specific fact at message 1, continuing for 25+ turns, then asking the AI to recall that fact — it should still know it.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the AI Token Optimization Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- owasp-llm:2025 · LLM10 — Unbounded Consumption
- nist-ai-rmf:1.0 · MANAGE 2.2 — Mechanisms to sustain AI risk management are in place
- iso-25010:2011 · performance-efficiency.capacity — Capacity — summarization preserves context within window limits
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-token-optimization·automated