fix: learn "duplicate field" rejections (alias collision) and retry without the alias #136487
<!-- hermes-autotriage -->
<!-- action=reviewed-pr pr=136487 head=ef66bdd at=2026-10-11T08:10Z -->
Reviewed for #136486. Adding "duplicate field" to _UNKNOWN_FIELD_PHRASES does make the learner fire, and the new test passes. But it only gives the right answer on must-echo routes. That's why the test model (mimo-v2.6-pro on custom) behaves.
Gap on non-must-echo routes. rejected_reasoning_fields() (agent/message_sanitization.py ~L939-942) widens to all carriers whenever the body names reasoning_content. That rule fits an unknown-field error, where the schema lacks the field. A duplicate-field error means the opposite: reasoning_content is the field the schema reads, and the alias is the extra one. On a route where needs_reasoning_echo() is False, nothing subtracts RC afterwards, so both carriers are learned as rejected and reasoning replay switches off completely for that route. I checked this with the patched phrase list on a plain vLLM-style custom route:
a = SimpleNamespace(provider="custom", model="qwen3-32b", base_url="http://vllm.local/v1",
api_mode="chat_completions", _reasoning_rejecting_routes={}, session_id=None)
sent = [{"role": "assistant", "content": "", "reasoning": "t", "reasoning_content": "t"}]
record_reasoning_field_rejection(a, "messages[0]: duplicate field `reasoning_content`", sent)
# -> frozenset({'reasoning', 'reasoning_content'})
reasoning_replay_route("chat_completions", a.provider, a.model, a.base_url,
rejected=rejected_reasoning_carriers(a)).carriers
# -> frozenset() (the issue's table shows reasoning_content alone returns 200)
Suggested change: handle the alias collision as its own case in rejected_reasoning_fields(). When the matched phrase is duplicate field, return sent & {R, RD}, keeping reasoning_content no matter which key the body names, and keep the existing all-carriers widening for real unknown-field errors. A second parametrized row in the new test, using a non-must-echo custom model and asserting route.carriers == {"reasoning_content"}, would cover this. That row fails on the current head.
Everything else looks right: the one-retry/no-loop guard holds, and the rejection is still stored per (provider, host, model) in model_config.
Thanks for the careful review — you're right: the must-echo subtraction was load-bearing, and the widening turned an alias collision into a full reasoning-replay shutdown on non-must-echo routes.
Pushed 527acd57 implementing your suggestion. rejected_reasoning_fields() now handles the alias collision as its own case: when the body says duplicate field, it returns sent & {R, RD} — dropping only the alias carriers and keeping reasoning_content no matter which key the body names — while real unknown-field errors keep the existing all-carriers widening. The must-echo subtraction in record_reasoning_field_rejection() becomes a no-op for this case, so one rule now serves both tiers.
The regression test is parametrized with the second row you asked for: a non-must-echo custom model (qwen3-32b on http://vllm.local/v1) asserting route.carriers == {"reasoning_content"}. That row fails on the previous head exactly with your repro (both carriers learned -> empty carriers) and passes with the fix; tests/agent/test_reasoning_replay_routes.py is 17/17.
Full tests/agent on Python 3.14.7 with the CI extras: 11002 passed, 41 skipped. Under parallel (xdist) execution 15 tests failed; a serial re-run of that exact set showed 13 pass (parallel flakiness) and 2 — test_runtime_self_protection.py::test_find_delete_over_own_venv_is_detected and test_nt_namespace_guard.py::test_file_tools_reject_raw_string_without_resolving — fail identically on the pre-change head, so they are unrelated to this diff.
Approval conclusion
GitHub requires explicit repository access for a formal approval, so I am recording the approval conclusion as a commented review.
Reviewed at 527acd575a978032427aa4b2bcd92efd2f5dfaa4.
The follow-up commit fixes the non-must-echo gap from the earlier review. rejected_reasoning_fields() now treats duplicate field as an alias collision, so it learns only the extra alias carriers and keeps reasoning_content. The existing per-route state and one-retry guard still own the recovery.
I checked both paths. A custom MiMo route keeps the required pad. A plain custom qwen3 route keeps reasoning_content without the pad. Repeating the same error does not retry again. Errors that do not name a sent reasoning carrier still fall through.
The scope is small and in the right layer: 8 production lines and one parametrized regression test. Current main has not changed either touched file since this PR's base. GitHub reports no hosted checks for this head.
Validation:
scripts/run_tests.sh tests/agent/test_error_classifier.py tests/agent/test_auxiliary_parameter_rung_chaining.py tests/agent/test_reasoning_replay_routes.py tests/hermes_cli/test_reasoning_command.py -q passed all 233 tests.reasoning and reasoning_content.The current head resolves the previous finding and preserves the existing route-local recovery behavior.
Reviewed at 527acd575a. I loaded the head version of agent/message_sanitization.py
as a module and ran a matrix of (error body, sent message) cases throughrejected_reasoning_fields → record_reasoning_field_rejection → reasoning_replay_route,
so the statements below are measured rather than read off the diff.
Verified — no action needed
The fix does what the second commit claims. Full chain on the issue's exact body,sent = {reasoning_content, reasoning}:
| route | recorded | carriers after re-shape | pad |
|---|---|---|---|
| custom / mimo-v2.6-pro (must-echo) | {reasoning} | {reasoning_content} | True |
| custom / qwen3-32b (non-must-echo) | {reasoning} | {reasoning_content} | False |
| custom / deepseek-flash | {reasoning} | {reasoning_content} | True |
| deepseek / deepseek-v4-flash | {reasoning} | {reasoning_content} | True |
The non-must-echo row is the one the first revision got wrong, and it is now correct.
The "no sibling call sites" claim holds. _UNKNOWN_FIELD_PHRASES has exactly one
consumer (the gate at :936) and rejected_reasoning_fields exactly one caller
(:995); a repo-wide search for both names returns 4 hits, all in this file. Extending
the phrase tuple cannot reach anything else.
Behavioural change is confined to bodies containing duplicate field. Before this
PR no such body passed the gate at all, so nothing else can shift.
#16135 / #17400 cannot regress. reasoning_content is never in {reasoning,, so no must-echo route can lose it — confirmed by construction and by
reasoning_details}
the table above.
Unrelated duplicate keys stay inert. duplicate field \messages\` with afrozenset()
reasoning-carrying request → .
Findings
1. The alias branch differs from the widening rule in exactly one case — worth saying so
Enumerating every named subset for sent = {reasoning_content, reasoning}:
named widening rule (old) alias branch (new)
['reasoning'] ['reasoning'] ['reasoning']
['reasoning_details'] ['reasoning'] ['reasoning']
['reasoning_content'] ['reasoning', 'reasoning_content'] ['reasoning'] <-- only diff
The branch changes the outcome only when the body names reasoning_content, and only
by keeping reasoning_content the widening rule would have dropped. So it is exactly
equivalent to:
if "duplicate field" in body and RC in named:
return frozenset(sent & {R, RD})
Not asking you to change it — but the narrower condition states the intent ("the duplicate
is the carrier riding along with the field the schema reads, so the schema clearly reads
that field") and confines the new path to the case it exists for. The current form is
correct either way.
2. A body that only mentions reasoning near messages now strips it
_NAMED_FIELD_RES[R] is a proximity heuristic — messages[^\n]{0,80}?(?<![\w])reasoning(?![\w]) —duplicate field
not a key-name match. That was harmless while the gate only admitted unknown-field
complaints. Now that is gated, a body like:
messages[2]: duplicate field `x`, reasoning ok
with sent = {reasoning_content, reasoning} returns {reasoning} — reasoning is droppedx
even though the duplicate the schema named was . Reachability is limited (the standardreasoning
serde message names one key and does not otherwise mention ), and the blast
radius is one carrier for one session on one route, with a single retry and no loop. Just
flagging it, since this class of body was previously inert.
3. The reasoning_details term is untested
sent & {R, RD} vs sent & {R} is indistinguishable in the suite — the test's assistantreasoning_details
message never carries . That term is not dead code: _ALL_CARRIERS isopenrouter
the carrier set for / kilocode / ai-gateway / nous, so RD does go onreasoning_details
the wire for those routes. Adding to the test's sent would exercise it{reasoning, reasoning_details}
(measured: a message carrying all three drops and keepsreasoning_content).
4. Two small doc touch-ups
's docstring still documents only the widening policy ("arejected reasoning_content
… takes all three"). The new branch implements the opposite
policy and is undocumented there.
The comment above fields -= {RC} in record_reasoning_field_rejection reads as if that
subtraction is load-bearing. On the alias path it is a no-op (the branch already excludes
reasoning_content), so a reader could mistake where the protection actually comes from.5. Stating a non-goal so it isn't assumed covered
A route that sends only
reasoning_content and still receives
duplicate field \reasoning_content\ learns nothing: sent & {R, RD}` is empty, so noretry is recorded and the turn still falls back. That is arguably the right call — there is
nothing left to drop — but it is the same "no way to disable replay for a route" gap raised
in the linked issue, so it is worth naming as out of scope rather than leaving it implicit.
Verdict
The fix is correct and the second commit addresses the real hole. None of the above blocks
merge; 2 and 3 are the two I would act on if you touch the PR again.
Acted on findings 2 and 3 from this review (and 4). Pushed 26c36a67.
Finding 2 — a body that only mentions a carrier near messages no longer strips it. The branch
now reads the key the rejection names (duplicate field X`) and takes the alias path only when Xduplicate field and RC in named
is a carrier this request actually sent; anything else learns nothing, as it did before this PR. One
correction to the review's suggestion 1: narrowing to is exactlymessages[2]: duplicate field
equivalent to the previous form — your own enumeration shows it — so it does not close finding 2 on
its own. x, reasoning ok with sent = {reasoning_content, reasoning}x
names , and _NAMED_FIELD_RES[R]'s proximity match puts reasoning in named; the narrowingRC not in named
still falls through to the widening rule ( -> sent & {R, RD}) and dropsreasoning. The key has to come from the message body, not from named.
Finding 3 — reasoning_details is covered. New test drives a nous route (all three carriers on
the wire) with a message carrying all three: the strip is {reasoning, reasoning_details} andreasoning_content survives. With only two carriers sent the two forms are indistinguishable, as you
said.
Finding 4 — both comments fixed. rejected_reasoning_fields's docstring now documents thefields -= {RC}
alias-collision policy next to the widening policy; the comment above says outright
that the subtraction is a no-op on the duplicate-field path, so the protection there is not read as
coming from it.
Finding 5 — stated as a non-goal in the PR description (section below), with a test pinning the
behaviour: a route sending only reasoning_content that is told it is a duplicate learns nothing and
still falls back.
Validation on 26c36a67:assert frozenset({'reasoning'}) == frozenset()
for bothmessages[1]: duplicate field
content, reasoning is fine and messages[2]: duplicate field x,
reasoning ok — and pass on this head.tests/agent/test_reasoning_replay_routes.py 21 passed (17 before).test_error_classifier.py test_auxiliary_parameter_rung_chaining.py
test_reasoning_replay_routes.py tests/hermes_cli/test_reasoning_command.py 237 passed.agent.message_sanitization (21 files): 419 passed, 1 xfailed.
Diff is now 8 production lines + 3 tests; no rebase needed (neither touched file moved on main`).
Independent reproduction and end-to-end verification on two more stacks — the alias collision is not litellm/vLLM-specific:
z-ai GLM (glm-5.3) and Moonshot (kimi-k3), both reached through an OpenAI-compat gateway (9router, LAN). Same wording from both:
HTTP 400: {"message":"Failed to deserialize the JSON body into the target type: duplicate field `reasoning_content` ...","type":"Bad Request","code":400}
Minimal repro against glm-5.3, identical payloads except the assistant turn's reasoning keys:
reasoning + reasoning_content (same text) → 400 duplicate field \reasoning_content\` only → 200, model answers normallyTwo details that pin the mechanism:
1. Each key appears exactly once in the wire JSON (the request body parses clean with a duplicate-key check), yet the error names reasoning_content twice-seen — only alias-folding produces that.
2. The reported serde column equals the exact byte length of the compact request body (95725 in the failing production request) — the buffered-map end-of-object position, matching alias-aware deserialization rather than a literal duplicate.
End-to-end on the branch: replayed the exact failing production payload (assistant replay with both keys via the custom/LAN route, so _LOCAL_CARRIERS = {RC, R}) — 400 unpatched; with the learned reasoning strip applied, reasoning_content survives and the same payload returns 200. Rejection persisted in session model_config, resumed session completes on the configured model instead of falling back. The branch's dedicated duplicate-field branch (not the phrase-only widening) is what keeps reasoning_content on this non-must-echo route — under the phrase-only approach described in the PR summary, a custom route would have stripped both carriers and silently dropped reasoning replay entirely. The summary's "The fix is the one phrase" paragraph describes an earlier iteration; the current diff is the one that is correct for all routes, so it may be worth updating the description for reviewers.
Applied this branch to a pinned install and ran the local suite: 42 passed (test_reasoning_replay_routes + test_deepseek_reasoning_content_echo), including the OpenRouter-format three-carrier case where {R, RD} drop while reasoning_content` stays.
Independently confirmed the duplicate field wording on a different stack — Hermes v0.22.2+1128.g868b9f2 → New API v1.0.0-rc.40 → NVIDIA NIM z-ai/glm-5.3.
Replaying an assistant turn with both reasoning and reasoning_content returns:
HTTP 400: Failed to deserialize the JSON body into the target type: duplicate field `reasoning_content`
Oracle check: either key alone returns 200; both together return 400 (reproduces on a 212-byte body). Today that 400 is classified not-retryable, so the configured model never answers and the fallback takes over.
Adding this wording to _UNKNOWN_FIELD_PHRASES would let the rejection be learned and the turn recover on retry. Complementary to #139186, which removes the alias for remote custom providers before the wire copy is built.
Cross-referencing the corroborating report just added to #136486 — it includes a datapoint the reviews here haven't covered: NVIDIA NIM rejects the pair directly, with no alias-introducing relay in the path. z-ai/glm-5.3 + both spellings → 400 ` duplicate field reasoning_content in 2.1s (259-byte body, rejected pre-inference); reasoning_content only → 200; openai/gpt-oss-20b accepts the pair (200) — the strictness is per-model-family on NIM's side.
We've been running the same pair-aware semantics as 26c36a67 in production since 2026-10-19 across a gateway fronting ~30 NIM routes: first contact learns, one clean retry, zero duplicate field 400s since.
Also worth noting for triage: on custom routes at RFC-1918 base URLs (the self-hosted-proxy-in-front-of-NIM topology), #139186's row removal doesn't change behavior — is_local_endpoint()` keeps the pair there — so this PR is the only recovery for that shape. Full probe matrix + details: https://github.com/NousResearch/hermes-agent/issues/136486#issuecomment-6274081145
Adding an independent production data point for the NIM case, from a Hermes git install (v0.22.5, bf0203a) pointed directly at NVIDIA NIM with no relay, proxy or litellm in the path.
Setup: model.provider: custom, model.base_url: https://integrate.api.nvidia.com/v1, model.default: deepseek-ai/deepseek-v4.1-flash.
Oracle check (direct to the endpoint):
| replay body | result |
|---|---|
| assistant turn with reasoning and reasoning_content | HTTP 400 Failed to deserialize the JSON body into the target type: duplicate field \reasoning_content\` (212-byte body, rejected pre-inference) |reasoning_content
| same turn with only | HTTP 200 |
So deepseek-ai/deepseek-v4.1-flash is in the strict group too (smoke007's comment covers z-ai/glm-5.3 and openai/gpt-oss-20b).
Why Hermes emits the pair on a bare NIM endpoint. _REASONING_CARRIER_ROUTES has no NIM row — git grep 'integrate.api.nvidia.com' origin/main → 0 hits — so provider: custom falls through to the _LOCAL_CARRIERS row and ships {reasoning_content, reasoning} on every replayed assistant turn. Nothing in the path introduces the alias; the duplicate is ours to avoid. That is what #139186 targets, and it is why the phrase here is necessary but not sufficient on its own for NIM users.
Blast radius is worse than "the fallback answers". The permanent 400 also ends non-interactive runs. A 0 9 * cron job (daily briefing, telegram delivery) here failed on six consecutive days with exactly this error — 2026-10-16 09:51, 10-17 09:09, 10-19 09:01, 10-21 09:41, 10-22 09:16, 10-24 11:18 — nine consecutive executions recorded as failures, with no output delivered and no visible error to the user. In interactive CLI sessions the same 400 shows up as a canned error line instead of the answer.
Payload-size dependency. Every recorded occurrence is at a large body — column 72149 / 72520 / 72755 / 77092 / 78571 / 83139 / 101501. Short conversations and toy repros pass, which is probably why this reads as intermittent rather than deterministic.
Corroborating the review finding. Our local build still carries the pre-review widening (sent & _ALL_CARRIERS when the body names reasoning_content). Because the model id here contains deepseek, needs_reasoning_echo() matches on the model substring and the must-echo subtraction keeps reasoning_content, so it heals anyway — but on this same endpoint a non-DeepSeek-named model takes the other branch and drops both carriers. The narrowing to sent & {R, RD} that the review asked for is doing real work; that failure mode is reproducible, not theoretical, from the custom` + NIM host combination.
What fixed it here: this PR's phrase plus the NIM carrier row from #139186 (applied locally, uncommitted). Zero recurrences since — where before it failed every day — including a long interactive session that previously reproduced within minutes.
Happy to run the PR branch against this endpoint and report back (2 probes + the cron path) if that is useful.
We are using the Rust frontend for vLLM serving local models in our organization. Until this is fixed, I'm unable to use Hermes as the Rust frontend chokes on redundant reasoning flags. Is this targeted for inclusion in a release soon? I added my feedback and confirmation of the bug 136486.
@teknium1 — friendly ping for review. #136486 now has seven independent reproductions across different stacks (litellm→vLLM, 9router→GLM serde, 9router→z-ai GLM + Moonshot Kimi, NVIDIA NIM direct on glm-5.3, flint, vLLM Rust frontend), including two confirmed error wordings — `duplicate field reasoning_content and duplicate field 'reasoning' — both covered by this PR's phrase-based matcher.
Several reproducers validated this exact patch end-to-end: 400 → rejection learned → one clean retry → 200, and a cron job that had failed 19 consecutive runs completed its next run after applying it.
The issue also documents a second failure mode this matcher can't catch (pair-tolerant routes silently burn ~27k duplicated tokens/turn until context_length_exceeded`), which is why #139186 is the primary fix and this PR is the heal-after-rejection net. Both have been open for 2+ weeks since the regression landed in 336b1158 — on affected routes every real multi-turn conversation 400s and falls back while single-turn health checks stay green.
Happy to test or help revise. Thanks!
Independent production confirmation of this fix — and a backend class the thread doesn't have yet: DeepSeek's own API, not vLLM.
Stack: Hermes (this tree) → self-hosted new-api gateway → cli-proxy-api (CPA, Go) → tokenrhythm.studio (LiteLLM) → DeepSeek official API (serde/Rust deserializer). base_url is a Tailscale-private address, so the route resolves to custom → _LOCAL_CARRIERS = {reasoning_content, reasoning} and every replayed assistant turn carries both keys.
Evidence (2026-11-02, one host): 6 rejected POST /v1/chat/completions in CPA's error logs (13:39, 13:50, 13:53, 13:54, 13:56, 14:05 CST), all UPSTREAM_ERROR with
Failed to deserialize the JSON body into the target type:
duplicate field `reasoning_content` at line 1 column 94569 (also 313670 / 786996 / 787036)
Two details that may help triage:
1. The request body has no literal duplicate JSON keys. Parsing each logged body with an object_pairs_hook duplicate detector returns zero collisions — the "duplicate" is the serde alias (reasoning aliasing reasoning_content), exactly as described in #136486. CPA's log shows it forwards the body verbatim, so the double-write is Hermes-side, on the carriers route_reasoning_carriers() picks for custom/private-IP routes.
2. Both keys in one message is the trigger, and it is not size- or tool-related. Minimal payload with {"reasoning_content": "r", "reasoning": "r"} → HTTP 400 at column 265; the same message with reasoning_content only → 200. Every one of the 6 failing bodies contained at least one assistant message with both keys.
Real-world impact shape: the same gateway has a second upstream lane that tolerates both keys, so failures look intermittent — the request sometimes 200s on the tolerant lane and 400s on the strict one. That matches @youruch's "two upstream lanes differ in strictness" datapoint on #136486 and explains why a same-gateway model switch appears to "fix" it.
Fix validated: I run an equivalent patch (keep the named/canonical key, drop the alias carriers, retry once) in this stack — retry after dropping reasoning returns 200, and tests/agent/test_reasoning_replay_routes.py passes (16/16) with a minimal-repro test added. Semantics match this PR, so +1 on merging it; happy to test a rebased branch against this DeepSeek/LiteLLM lane if useful.
Rebased onto main@c5f347ebe9 (2026-11-02) and re-verified. Everything below is measured on that tree, not read off the diff. The autotriage gap from the first review (non-must-echo route losing reasoning_content too) is fixed in the third commit.
Tests, three runs on the same tree:
| tree | result |
| --- | --- |
| main@c5f347ebe9 + this PR's test file, unpatched message_sanitization.py | 2 failed — test_duplicate_field_rejection_strips_the_alias_and_keeps_reasoning_content, both the must-echo and the non-must-echo row |
| this PR rebased on main@c5f347ebe9, tests/agent/test_reasoning_replay_routes.py | 21 passed |
| + test_message_sanitization_policy.py + test_image_rejection_fallback.py | 96 passed |
Lint lane: python scripts/check --base upstream/main → 14 checks, ok; code health 2 files vs c5f347ebe9b8: 0 blocking, 0 advisory.
Merge state: mergeable: true, rebaseable: true, and the three commits apply onto current main with no conflicts (git merge-tree --write-tree → clean). The one thing keeping the PR blocked is that no check-run has ever been reported on the head SHA — fork PRs need a maintainer to approve workflow runs before CI exists, so there is nothing green (or red) to look at.
Not in main, not in the latest release: agent/message_sanitization.py at main@c5f347ebe9 and at tag v0.22.7 still carries the old _UNKNOWN_FIELD_PHRASES tuple, and _LOCAL_CARRIERS = {reasoning_content, reasoning} is still the row the generic custom provider resolves to. So the reported failure mode is unchanged on the shipping tree: the first reply works, every turn after it 400s and falls back.
Scope: _UNKNOWN_FIELD_PHRASES has exactly one consumer (the gate in rejected_reasoning_fields) and that function exactly one caller, both in this file. Before this PR no body containing duplicate field passed the gate, so nothing outside that path can shift.
@teknium1 — you touched agent/message_sanitization.py yesterday (a7732d031e, 0d76f7ee60); the patch sits on top of those with no conflicts. The two sibling PRs are the same issue from the other end: #139186 stops giving remote custom providers the local-engine carrier pair at all (no failed turn, but it changes what unknown local-ish endpoints receive), #144585 is the same phrase-list approach as this one. They're complementary rather than duplicates — either shape alone clears the reported bug, and I'm happy to fold this into whichever one you'd rather take.
Branch force-pushed on top of the current main tip e26e0e4b67 (3 commits, 2 files, +113/-2 — nothing else dragged in by the rebase). Re-ran tests/agent/test_reasoning_replay_routes.py on that base: 21 passed. Head is now 5a84aab559; test/check numbers in the comment above were measured on c5f347ebe9, this run on e26e0e4b67.
Seriously, how long will this take to get the fix into main? I've not been able to use Hermes for over a month now. @teknium1 Can we get this branch deployed?
Thanks @Paxy. This landed through #154604 (merge ac248c819a). Your three commits went in as they were, with your authorship kept.
What was added on top, and why:
custom gateways get reasoning_content only and never send the pair. Your learner covers loopback and LAN endpoints, which still get both keys.messages[N] ... reasoning proximity regex, a path-less ` duplicate field reasoning (NIM-style wording) learned nothing and kept failing on every turn. A live run showed that on your head plus kvnloo's commit; it recovers after one retry on the merged head. "duplicate field" also came out of _UNKNOWN_FIELD_PHRASES., and only when it sat in the same assistant message as reasoning_content. sent & {R, RD} also dropped reasoning_details, which on OpenRouter-format routes would strip signed details for the rest of the session.Closing as merged via #154604. Thanks for the careful review rounds.
PRATHAMESH75
Paxy
What does this PR do?
Adds
"duplicate field"to_UNKNOWN_FIELD_PHRASESsorecord_reasoning_field_rejection()learnsalias-collision rejections and retries once without the offending carrier.
A relay whose ChatMessage schema treats
reasoningas an alias ofreasoning_content(a serdedeserializer in front of vLLM, behind litellm) rejects a replayed assistant message that carries
both keys:
Today that wording matches none of the phrases in
_UNKNOWN_FIELD_PHRASES, so nothing is recorded,the same 400 recurs on every turn (the replayed message stays in history), the error is classified
not-retryable, and the fallback chain answers instead of the configured model. Full reproduction
(3 payload probes + agent.log signature) in the linked issue.
The fix is the one phrase; the existing logic already does the right thing afterwards:
rejected_reasoning_fields()widens to all sent carriers when the body namesreasoning_content,and
record_reasoning_field_rejection()subtracts the must-echo field — soreasoningis recordedas rejected for
(provider, host, model),reasoning_content(the field the relay requires andreads) stays, the request is retried once, and the rejection persists in the session's
model_config(survives--resume/ gateway restart).Related Issue
Fixes #136486
Type of Change
Changes Made
agent/message_sanitization.py: add"duplicate field"(with a comment naming the alias-collisioncase) to
_UNKNOWN_FIELD_PHRASES.tests/agent/test_reasoning_replay_routes.py: addtest_duplicate_field_rejection_strips_the_alias_and_keeps_the_must_echo— asserts the alias islearned and dropped,
reasoning_contentsurvives with the must-echo pad intact, and an identicalrepeat is not retried (no loop).
Testing
assert frozenset() == frozenset({'reasoning'})), passes after.pytest tests/agent/test_error_classifier.py tests/agent/test_auxiliary_parameter_rung_chaining.pytests/agent/test_reasoning_replay_routes.py tests/hermes_cli/test_reasoning_command.py →
232 passed.
(history carrying a reasoning message) 400s and falls back on the unpatched build, and completes
on the model after the change.
Risk / exclusions
the key the body names is a carrier this request sent: a
duplicate fieldx`complaint about somefrozenset()other key still yields
— no behavioural change for other error classes, and no carrierreasoningis stripped for a body that only mentions
nearmessages.
Must-echo routes keep reasoning_content(subtraction inrecord_reasoning_field_rejection),
No sibling call sites: rejected_reasoning_fields()so this cannot regress #16135 / #17400.
is the single gate for this class
Non-goal (named, not fixed): a route that sends only reasoning_content(image-content rejection has its own, separate matcher).
and is told
duplicate fieldreasoning_contentlearns nothing —sent & {R, RD}` is empty, there is no carrierleft to drop, so no retry is recorded and the turn still falls back. This is the same "no way to
switch reasoning replay off for a route" gap the linked issue raises at the end; it is out of scope
here and pinned by a test so the behaviour stays intentional.