fix(classifier): retry provider-injected parameter 400s instead of aborting the turn - #91643
Merged
kshitijk4poor merged 1 commit intoAug 21, 2026
Conversation
…orting The Codex OAuth backend (chatgpt.com/backend-api/codex) intermittently injects prompt_cache_retention into its own upstream call and then rejects it, returning HTTP 400 invalid_parameter. Hermes never sends that field on this route (see agent/transports/codex.py::_default_prompt_cache_retention_ for_request, which only sets it for api.meta.ai and bedrock-mantle hosts). Reproduced live: a minimal 1-message request carrying no cache parameters at all failed 4/20 (20%) with this error, so the rejection is not deterministic and retrying the identical request is the correct recovery. Previously the catch-all in _classify_400 returned format_error/ retryable=False, which tripped the is_client_error abort gate in conversation_loop and killed the turn on the first attempt - burning an entire large-context request (~550k tokens) per failure. Classify these as retryable server_error (should_compress=False - the request shape was never the problem). The same guard is applied to the sibling 5xx request-validation branch, where a fronting proxy can surface the identical rejection. Deliberately narrow: keyed on parameters we only send on specific routes, and skipped when the current provider is one that legitimately sends them, so a genuine client-side bad parameter (max_tokens on GPT-5) still fails fast as a format_error.
This was referenced Aug 21, 2026
Codex OAuth: provider-injected prompt_cache_retention 400 aborts the turn instead of retrying
#90257
Closed
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
A 400 blaming a parameter the client never sent is retried instead of aborting the turn, when the parameter is one Hermes only sends on specific routes and the current provider is not one of those routes.
Salvages #90261 by @troyrowe-resource, cherry-picked onto current
mainwith authorship preserved. Closes #90257.Root cause
The Codex OAuth backend (
chatgpt.com/backend-api/codex) intermittently injectsprompt_cache_retentioninto its own upstream call and then rejects it with HTTP 400invalid_parameter. Hermes never sends that field on this route (_default_prompt_cache_retention_for_request()returnsNonefor that host). The error was classified as a non-retryableformat_error, which tripped theis_client_errorabort gate and killed the turn on the first attempt — discarding a large-context request (~410-550k tokens) over a transient provider fault that clears ~80% of the time on retry.This is complementary to the merged wire guard (#90243,
_sanitize_consumer_codex_request()), which stripsprompt_cache_retentionfrom Hermes's outgoing request. The wire guard can't prevent the provider's own backend from injecting the field server-side.Changes
agent/error_classifier.py:_SERVER_INJECTED_PARAM_SENDERSdict +_is_server_injected_param_rejection()helper; new branch in_classify_400(before request-validation) returning retryableserver_error; guard in_classify_by_status(500/502 branch) so proxy-surfaced rejections stay retryabletests/agent/test_error_classifier.py:TestServerInjectedParameterRejection(10 tests, incl. 4 boundary/regression guards)Validation
prompt_cache_retentionformat_error, non-retryable, turn diesserver_error, retryable, retry loop recoversmeta-ai(legitimate sender)format_error, non-retryableformat_error, non-retryable (unchanged)max_tokens400format_error, non-retryableformat_error, non-retryable (unchanged)format_error, non-retryableserver_error, retryablecodex.nekos.me502 unknown paramformat_error, non-retryableformat_error, non-retryable (unchanged)tests/agent/test_error_classifier.py