LiteLLM context-overflow errors not recognized: session hard-fails at context limit instead of compacting #2088
Closed
giova23
started this conversation in
Bug reports
Replies: 2 comments
|
I’m taking a look at this. |
0 replies
|
Merged in #2129; this fix is not released yet. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
LiteLLM context-overflow errors are not recognized: session hard-fails at the context limit instead of compacting
Setup
prime-agent 0.9.3 (installed via npm), talking to a vLLM server fronted by a LiteLLM proxy (OpenAI-compatible,
openai-completionsAPI), model with a 262144-token context window configured viamodels.json.Symptom
When the context fills, the session dies with the raw error and never recovers:
Root cause
isContextOverflow()inpackages/ai/src/utils/overflow.tsmatchesOVERFLOW_PATTERNSagainst the error message. LiteLLM's wording ("Requested token count exceeds the model's maximum context length of X tokens...") matches none of the patterns, so:_isRetryableError()classifies the 400 as retryable and the same over-limit request is re-sent.AgentSession._checkCompaction(Case 1) never runs, so no auto-compaction + retry happens.This is easy to hit in practice: threshold compaction only runs at turn boundaries, so a single turn whose tool outputs grow the context past the hard limit (context window minus max output tokens) produces exactly this unrecoverable error.
Related earlier report of the same failure class: #1490 (a 400 classified retryable and never repaired).
Proposed fix
Add
/requested token count exceeds/itoOVERFLOW_PATTERNS, plus a regression test inpackages/ai/test/overflow.test.tswith the real error text. The patterns are only evaluated forstopReason: "error"messages, so there is no false-positive risk on success paths.I had opened PR #2086 with exactly this before finding the vouched-contributor policy; it was auto-closed. The branch with the change (3 files: overflow pattern + comment, test, changelog fragment) is here if a maintainer wants to pick it up:
https://github.com/giova23/prime-agent/tree/fix-litellm-overflow-detection
Happy to iterate here first if you'd like a different approach (e.g. a broader pattern, or handling this in the retry classifier instead).
All reactions