You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Auto compaction is not triggered by code: context_length_exceeded in API call errors #17746
When the inference provider responds with something like
{
"error": {
"message": "You passed 99073 input tokens and requested 32000 output tokens. However, the model's context length is only 131072 tokens, resulting in a maximum input length of 99072 tokens. Please reduce the length of the input prompt. (parameter=input_tokens, value=99073)",
"type": "invalid_request_error",
"param": null,
"code": "context_length_exceeded"
}
}
with HTTP status code 400, auto compaction is not triggered.
At the moment, context overflow detection is only based on matching certain message patterns and checking for status code 413.
However, to make it more robust, we should also check against the codecontext_length_exceeded. It's fairly standardized because that's what OpenAi returns in this case (they use HTTP status 400, btw.).
This code is already being checked in stream errors, so it only makes sense to check for it in API call errors, too.
Plugins
No response
OpenCode version
1.2.26
Steps to reproduce
Configure a provider that returns a message like above on context overflow. If you do not have access to such a provider, you can fake it by using a proxy that adapts the response accordingly.
Send a large message that will exceed the context limit to the provider.
Observe that you see an error, but auto compaction is not triggered.
Your issue is more specific with a clear root cause analysis (HTTP 400 + code: context_length_exceeded not being checked in non-stream errors), so it may still warrant its own tracking even if related.
Activity
github-actions commentedon Mar 16, 2026
This issue might be a duplicate of existing issues. Please check:
context_length_exceedederrors still occur in agent workflows — reports the samecontext_length_exceedederror code not triggering compaction (though focused on agent workflows and OpenAI provider)Your issue is more specific with a clear root cause analysis (HTTP 400 +
code: context_length_exceedednot being checked in non-stream errors), so it may still warrant its own tracking even if related.ghost91- commentedon Mar 16, 2026