Skip to content

fix(classifier): retry provider-injected parameter 400s instead of aborting the turn - #91643

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/90261-injected-param-retry
Aug 21, 2026
Merged

fix(classifier): retry provider-injected parameter 400s instead of aborting the turn#91643
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/90261-injected-param-retry

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

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 main with authorship preserved. Closes #90257.

Root cause

The Codex OAuth backend (chatgpt.com/backend-api/codex) intermittently injects prompt_cache_retention into its own upstream call and then rejects it with HTTP 400 invalid_parameter. Hermes never sends that field on this route (_default_prompt_cache_retention_for_request() returns None for that host). The error was classified as a non-retryable format_error, which tripped the is_client_error abort 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 strips prompt_cache_retention from 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_SENDERS dict + _is_server_injected_param_rejection() helper; new branch in _classify_400 (before request-validation) returning retryable server_error; guard in _classify_by_status (500/502 branch) so proxy-surfaced rejections stay retryable
  • tests/agent/test_error_classifier.py: TestServerInjectedParameterRejection (10 tests, incl. 4 boundary/regression guards)

Validation

Before After
Codex 400 prompt_cache_retention format_error, non-retryable, turn dies server_error, retryable, retry loop recovers
Same error from meta-ai (legitimate sender) format_error, non-retryable format_error, non-retryable (unchanged)
Genuine max_tokens 400 format_error, non-retryable format_error, non-retryable (unchanged)
Same 400 via 500/502 proxy format_error, non-retryable server_error, retryable
codex.nekos.me 502 unknown param format_error, non-retryable format_error, non-retryable (unchanged)
  • 107 tests passed in tests/agent/test_error_classifier.py
  • E2E verified with real imports: all 5 test cases pass
  • Ruff: clean

…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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API codex P2 Medium — degraded but workaround exists labels Aug 21, 2026
@kshitijk4poor
kshitijk4poor merged commit 6e53628 into NousResearch:main Aug 21, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex OAuth: provider-injected prompt_cache_retention 400 aborts the turn instead of retrying

3 participants