fix: parse OpenRouter/Nous "in the output" error format in parse_available_output_tokens_from_error() - #38659
Closed
Xeron2000 wants to merge 1 commit into
Closed
Conversation
…lable_output_tokens_from_error() OpenRouter-compatible providers (Nous Research, OpenRouter) return output-cap-too-large errors in a format that was not recognized: "... requested about N tokens (A of text input, B of tool input, K in the output)" Previously, the is_output_cap_error guard required the literal string "max_tokens" to appear in the error, which the OpenRouter format does not contain. This caused the function to return None, falling through to the input-too-large compression path instead of the max_tokens auto-reduction path. On fresh sessions with nothing to compress, this led to an infinite Session auto-reset loop. Changes: - Guard now also recognizes '(\d+) in the output' as an output-cap error - New extraction path computes available = context_length - text_input - tool_input - Added 7 tests for Anthropic format, OpenRouter/Nous format, and negative cases
This was referenced Jun 4, 2026
Contributor
|
This appears to be implemented on current main by a later merged fix. Automated hermes-sweeper review evidence:
Closing as implemented on main. Thanks for the clear report and PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parse_available_output_tokens_from_error()inagent/model_metadata.pyonly recognized Anthropic's output-cap error format ("available_tokens: N"). OpenRouter-compatible providers (Nous Research, OpenRouter) use a different format:The function returned
Nonefor these errors because:is_output_cap_errorguard required literal"max_tokens"— OpenRouter format doesn't contain itavailable = context - text_input - tool_inputBug impact
On fresh sessions:
max_tokenslarger thancontext_length - input_tokenscontext_overflow✅parse_available_output_tokens_from_error()returnsNone→ falls through to input-too-large compression path ❌Session auto-resetUser sees repeated "Session auto-reset" and
/newhas no effect because the actual fix is reducingmax_tokens, not clearing history.Changes
is_output_cap_errornow also matches'(\d+) in the output'as an output-cap error indicatoravailable_output = context_length - text_input - tool_inputfrom the OpenRouter/Nous error formatFixes #38652