Context window utilization is monitored or bounded
Why it matters
Multi-turn chat applications that accumulate conversation history without any token management will eventually exceed the model's context window — at which point the API returns a 400 error and the conversation becomes unusable. Beyond hard failure, unbounded context accumulation drives token costs up linearly with conversation length. Users in long sessions pay a disproportionately high cost per message as the prompt grows. ISO 25010:2011 performance-efficiency requires that software resource consumption is proportional to task requirements. A sliding window or summarization strategy prevents both the failure mode and the cost spiral.
Severity rationale
Low because the failure is deterministic but deferred — applications only break when a conversation reaches the context limit, which may take dozens of turns, but the architectural defect is present from the first message.
Remediation
Add conversation history trimming before each API call in src/app/api/chat/route.ts:
const MAX_CHARS = 400_000 // ~100k tokens at ~4 chars/token; adjust per model
function trimHistory(messages: Message[]): Message[] {
const system = messages.filter(m => m.role === 'system')
let history = messages.filter(m => m.role !== 'system')
while (history.join('').length > MAX_CHARS && history.length > 2) {
history = history.slice(2) // Drop oldest user+assistant turn pair
}
return [...system, ...history]
}
Also catch the API's token-limit error explicitly and return a recoverable error state rather than a 500.
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 Response Quality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · performance-efficiency — Resource utilisation
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-response-quality·automated