Fixes #657 - #647
Conversation
Gemini's actual context-overflow error, 'The input token count (X) exceeds the maximum number of tokens allowed (Y).', matches none of the existing _is_context_overflow markers, so it fell through to BAD_REQUEST instead of CONTEXT_OVERFLOW. This meant the runtime never triggered COMPACT_AND_RETRY for Gemini context-limit errors, and the raw error was surfaced to the user instead.
|
Process note: this PR is not tracked by an open issue. Every PR in this repository must map to one corresponding issue so we can triage, prioritise, and avoid duplicate work across contributors. The workflow is: open an issue first → wait for a maintainer to triage and label it → then open the PR that references it. The description says issue creation is restricted for external contributors — that is not the case. Issues are open to everyone, and you already opened #651 yourself. Please open an issue for this Gemini context-overflow misclassification (with the exact provider error string and how you observed it), let a maintainer label it, and then link this PR with Also note that #613 already covers context-overflow classification in the same |
andreapn
left a comment
There was a problem hiding this comment.
Thanks for the report and fix. #670 targets the same issue (#657) and is the PR being taken forward, because this one has blocking problems:
ruff formatfails — the diff deletes a blank line beforedef _is_policy_refusal, leaving one blank line between top-level functions."input token count"is too broad as a marker. Since_is_context_overflow()is anany()over substrings, that phrase alone will classify any error text containing it asCONTEXT_OVERFLOW— including non-overflow token-accounting errors. The second marker you added,"exceeds the maximum number of tokens allowed", already covers the Gemini case on its own.- PR metadata — the title is literally
Fixes #657(leading whitespace, no conventional-commit prefix), and the body says no issue is linked even though #657 exists.
If you'd like to keep this PR alive, please drop the broad "input token count" marker, restore the blank line, and fix the title. Otherwise #670 will close #657.
|
Closing this one — #670 was selected for issue #657 and has been merged. Both PRs identified the same root cause correctly, and the analysis here is good. #670 was picked because:
Thanks for the clear write-up on the impact to |
Linked issue
Fixes # (none — issue creation is restricted for external contributors on
this repo, so there's no issue number to link. The full bug report,
impact, and fix are documented below.)
says what remains.
Summary
Gemini is a fully-supported provider in AgentOS (
geminiis listed in_OPENAI_COMPAT_PROVIDERS). Its real, canonical context-overflow errormessage is:
None of the markers in
_is_context_overflow()("context length","context window","maximum context","input is too long","input exceeds","too many tokens") match this phrasing — "input" and"exceeds" aren't adjacent in the real message, and it says "maximum number
of tokens" rather than "maximum context" or "too many tokens".
As a result, the error was misclassified as
BAD_REQUESTinstead ofCONTEXT_OVERFLOW. Perdecide_recovery_action(), that meansCOMPACT_AND_RETRYnever fired for Gemini users who hit their contextlimit — they got a raw surfaced error instead of AgentOS automatically
compacting the conversation and retrying, which defeats a documented
recovery path for one of AgentOS's headline-supported providers.
This PR adds two markers to
_is_context_overflow()covering Gemini'sfixed surrounding phrasing (not the variable token-count numbers, which
differ per request).
Tests
Added two regression tests to
tests/test_provider_failures.py:test_gemini_input_token_count_message_is_context_overflow— assertsthe exact real-world Gemini message classifies as
CONTEXT_OVERFLOW.test_gemini_input_token_count_message_is_context_overflow_regardless_of_token_counts— same shape with different digit counts, guarding against a marker
that accidentally depends on a specific number of digits.
Commands run locally: