Files
docker-agent/pkg/modelerrors
Trung Nguyen a6c7044988 feat(modelerrors): classify overflow errors by kind
Split the single ContextOverflowError bucket into three OverflowKinds so
the runtime and clients can react differently to each:

  * tokens — conversation exceeds the model's context window.
            Compaction can usually help.
  * wire   — request body exceeds the provider's wire-level limit
            (e.g. HTTP 413). The latest turn alone is over the cap;
            compaction-as-retry cannot help.
  * media  — image, PDF, or similar attachment too large.

Classification runs two tiers, in order:

  1. Structured signals (high confidence): HTTP 413, body.error.type =
     "request_too_large", body.error.code = "context_length_exceeded".
  2. Provider-prose substring patterns as fallback, covering the
     observed wording across Anthropic, OpenAI, Bedrock, Gemini,
     Mistral, Groq, Vertex, OpenRouter, Ollama, Kimi, MiniMax, z.ai,
     and others. Best-effort; provider wording is not contractual.

FormatError now returns three distinct, actionable, provider-agnostic
messages instead of one. The runtime emits new ErrorCodes
"request_too_large" and "media_too_large" alongside the existing
"context_exceeded" so external consumers can render the right hint.

Behaviour is preserved: IsContextOverflowError matches the same set of
errors as before, retry classification is unchanged, and auto-compaction
still fires on overflow. NewContextOverflowError now auto-fills Kind
from the underlying error so existing wrap sites get the correct shape
for free.
2026-05-19 11:04:22 +02:00
..