fix: #38652 - detect OpenRouter/Nous "in the output" format in parse_available_output_tokens_from_error() - #38726
Closed
lfgogogo wants to merge 1 commit into
Closed
Conversation
…_output_tokens_from_error() When using OpenRouter-compatible providers, max_tokens-too-large errors use "X in the output" phrasing instead of Anthropic's "available_tokens" keyword. This caused parse_available_output_tokens_from_error() to return None, falling through to input-compression recovery (which fails on fresh sessions) and triggering an infinite auto-reset loop. Add regex-based detection for the OpenRouter/Nous error format to extract context_length, text_input, and tool_input, then calculate available output tokens as context_length - text_input - tool_input. Closes NousResearch#38652 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
|
Duplicate of #38659 (first competing open fix for #38652, same file/function |
Contributor
|
Closing as already implemented on Automated hermes-sweeper review found the same OpenRouter/Nous output-cap parsing is already shipped:
Thanks for the fix; the prior duplicate discussion was right that this needed consolidation, and the current main branch now covers the requested behavior. |
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
When using OpenRouter-compatible providers (Nous Research inference, OpenRouter), the
parse_available_output_tokens_from_error()function fails to detect "output cap too large" errors, causing an infinite auto-reset loop.This fix adds regex-based detection for the OpenRouter/Nous error format:
It calculates
available_output = context_length - text_input - tool_input, allowing Hermes to auto-reducemax_tokensand retry instead of falling into the input-compression recovery path (which fails on fresh sessions).Before: "Session auto-reset" loops forever because
/newdoesn't fix the root cause (themax_tokensconfig value).After: Hermes detects the output-cap error, reduces
max_tokens, retries successfully, and warns the user.Changes
agent/model_metadata.py—parse_available_output_tokens_from_error():is_output_cap_errorguard to also match\d+\s+in\s+the\s+outputavailable = context_length - text_input - tool_inputCloses #38652
🤖 Generated with Claude Code