Skip to content

fix(agent): strip gateway replay metadata from messages before API calls (#48523)#48604

Open
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-48523
Open

fix(agent): strip gateway replay metadata from messages before API calls (#48523)#48604
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-48523

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Fixes #48523. When the gateway reloads a session from SQLite, get_messages_as_conversation() attaches internal metadata fields (timestamp, message_id, observed, finish_reason) to message dicts. These fields are not part of the OpenAI Chat Completions schema. Permissive providers silently ignore them, but strict validators (e.g. GLM-5.2 via opencode-go) reject with HTTP 400: 'Extra inputs are not permitted'. This fix adds these fields to the strip list in convert_messages().

…lls (NousResearch#48523)

When the gateway reloads a session from SQLite, get_messages_as_conversation()
attaches internal metadata fields (timestamp, message_id, observed,
finish_reason) to message dicts. These fields are not part of the OpenAI
Chat Completions schema. Permissive providers (OpenAI, OpenRouter) silently
ignore them, but strict validators (e.g. GLM-5.2 via opencode-go) reject
with HTTP 400: 'Extra inputs are not permitted'.

The existing convert_messages() in ChatCompletionsTransport stripped some
internal fields (codex_reasoning_items, tool_name, _-prefixed keys) but
missed the gateway replay metadata. This fix adds timestamp, message_id,
observed, and finish_reason to the strip list and refactors the detection
and removal logic into a shared _STRIP_KEYS tuple for maintainability.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #47875 — both strip gateway/session replay metadata at the same convert_messages() site in agent/transports/chat_completions.py via the same msg.pop(...) loop. #47875 (the earliest open fix for this strict-provider leak, anchoring #48592/#48358) strips timestamp; this PR strips the superset timestamp/message_id/observed/finish_reason at the identical site. More fields at the same strip site is still the same fix. #48575 is a same-day open twin that also dups #47875. The underlying issue #48523 is itself a duplicate of #47868.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert_messages doesn't strip timestamp/message_id/observed/finish_reason — causes 400 with strict providers in gateway mode

2 participants