hermes - 💡(How to fix) Fix [Bug] Max-iterations summary request leaks schema-foreign keys (tool_name) → strict gateways (OpenCode Go / Fireworks) return 400 [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When the agent hits its max-iteration budget and falls into the summary path (handle_max_iterations in agent/chat_completion_helpers.py), the outgoing request still carries message keys that are not part of the Chat Completions schema — most notably tool_name on tool-result messages. Strict OpenAI-compatible gateways reject the whole request with HTTP 400. The user gets "I reached the maximum iterations (60) but couldn't summarize. Error: …" instead of a summary, after a long tool-using session.

Observed on OpenCode Go (provider: opencode-go, model: opencode-go/kimi-k2.6, base_url https://opencode.ai/zen/go/v1), whose backend is now Fireworks-backed and validates the schema strictly.

Error Message

When the agent hits its max-iteration budget and falls into the summary path (handle_max_iterations in agent/chat_completion_helpers.py), the outgoing request still carries message keys that are not part of the Chat Completions schema — most notably tool_name on tool-result messages. Strict OpenAI-compatible gateways reject the whole request with HTTP 400. The user gets "I reached the maximum iterations (60) but couldn't summarize. Error: …" instead of a summary, after a long tool-using session. Error code: 400 - {'error': {'type': 'invalid_request_error', 'message': "Error from provider: 70 request validation errors: Extra inputs are not

Root Cause

The main request path runs messages through ChatCompletionsTransport.convert_messages(), which strips tool_name (SQLite FTS bookkeeping written by make_tool_result_message()), the codex_* reasoning carriers, and all Hermes-internal _-prefixed scaffolding keys.

But handle_max_iterations hand-builds its message list and calls chat.completions.create() directly, bypassing the transport. Its per-message loop only pops ("reasoning", "finish_reason", "_thinking_prefill"):

https://github.com/NousResearch/hermes-agent/blob/main/agent/chat_completion_helpers.py#L1281-L1288

So tool_name (and codex_*) leak straight to the wire on the summary call.

Fix Action

Fixed

Code Example

Error code: 400 - {'error': {'type': 'invalid_request_error', 'message':
"Error from provider: 70 request validation errors: Extra inputs are not
permitted, field: 'messages[3].tool_name', value: 'browser_navigate';
Extra inputs are not permitted, field: 'messages[5].tool_name', ...
'messages[9].tool_name' ..."}}
RAW_BUFFERClick to expand / collapse

Summary

When the agent hits its max-iteration budget and falls into the summary path (handle_max_iterations in agent/chat_completion_helpers.py), the outgoing request still carries message keys that are not part of the Chat Completions schema — most notably tool_name on tool-result messages. Strict OpenAI-compatible gateways reject the whole request with HTTP 400. The user gets "I reached the maximum iterations (60) but couldn't summarize. Error: …" instead of a summary, after a long tool-using session.

Observed on OpenCode Go (provider: opencode-go, model: opencode-go/kimi-k2.6, base_url https://opencode.ai/zen/go/v1), whose backend is now Fireworks-backed and validates the schema strictly.

Symptom

Error code: 400 - {'error': {'type': 'invalid_request_error', 'message':
"Error from provider: 70 request validation errors: Extra inputs are not
permitted, field: 'messages[3].tool_name', value: 'browser_navigate';
Extra inputs are not permitted, field: 'messages[5].tool_name', ...
'messages[9].tool_name' ..."}}

Normal turns are fine — only the iteration-budget summary call fails — so it only surfaces on long tool-heavy sessions (e.g. a browser task that runs the budget to 60/60).

Root cause

The main request path runs messages through ChatCompletionsTransport.convert_messages(), which strips tool_name (SQLite FTS bookkeeping written by make_tool_result_message()), the codex_* reasoning carriers, and all Hermes-internal _-prefixed scaffolding keys.

But handle_max_iterations hand-builds its message list and calls chat.completions.create() directly, bypassing the transport. Its per-message loop only pops ("reasoning", "finish_reason", "_thinking_prefill"):

https://github.com/NousResearch/hermes-agent/blob/main/agent/chat_completion_helpers.py#L1281-L1288

So tool_name (and codex_*) leak straight to the wire on the summary call.

Reproduction (provider probe)

Minimal Chat Completions payload to the OpenCode Go endpoint with kimi-k2.6:

payloadresult
tool-result message with tool_nameHTTP 400 Extra inputs are not permitted, field: 'messages[1].tool_name'
same message without tool_nameHTTP 200

Confirms the single offending field.

Proposed fix

Mirror convert_messages() in the summary path: also drop tool_name, codex_reasoning_items, codex_message_items, and any _-prefixed key, before the request is sent. (Copy-on-write is already in place, so internal history keeps the fields for FTS / Codex-fallback.)

I have a PR ready with this fix plus a regression test in TestHandleMaxIterations (asserts the summary request carries none of the schema-foreign keys; fails on main, passes with the fix). scripts/run_tests.sh for test_run_agent.py + test_chat_completions.py: 423/423 passing.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [Bug] Max-iterations summary request leaks schema-foreign keys (tool_name) → strict gateways (OpenCode Go / Fireworks) return 400 [1 pull requests]