Repository navigation
fix(chat-completions): drop unknown message-object keys during coercion - #637
Merged
Merged
Conversation
OpenAI's /v1/chat/completions parses the documented chat-message
fields and silently ignores everything else. codex-lb's
chat-to-Responses coercion was instead copying the inbound message
dict wholesale and only overwriting 'content', so any extra key on
a message object (the standard 'name' field, client-internal
bookkeeping keys, etc.) leaked into the Responses 'input' items and
was forwarded upstream verbatim.
The upstream Responses API only accepts 'role' + 'content' on an
input message item. Any other key trips an 'unknown_parameter' hard
error, which the gateway surfaces as a deterministic 502 and which
poisons every later request that replays the same message buffer.
Concrete reproducer (Hermes Agent, 2026-05-15): the agent's
empty-response recovery appends synthetic messages tagged with an
internal '_empty_recovery_synthetic' bookkeeping flag — a normal
client pattern. codex-lb relayed the flag into 'input[N]', upstream
returned 502 Unknown parameter, and the agent's session buffer
replayed the poisoned input on every subsequent turn, producing a
retry flood.
Rewrite _normalize_message_content to emit {role, content} explicitly
instead of copying the inbound message dict. Refusal still folds into
content as a refusal part; tool_calls still flow through their
existing decomposition path (FunctionCallInputItem / message-half
split); the message-item path now matches OpenAI's lenient-input,
strict-output semantics.
Add three unit tests covering: the general unknown-key case (and the
specific '_empty_recovery_synthetic' reproducer), the standard 'name'
field, and the assistant + tool_calls path.
OpenSpec change: drop-unknown-message-fields
Targeted suites: 187 passed.
Broader sweep (unit + integration + e2e proxy): 633 passed, 0 new failures.
Soju06
force-pushed
the
fix/chat-completions-drop-unknown-message-fields
branch
2 times, most recently
from
May 15, 2026 04:34
aeca588 to
ff9e84c
Compare
Soju06
added a commit
that referenced
this pull request
May 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR. ## Pre-merge verification (release-gate e2e) - ✅ CI 18/18 (mergeStateStatus CLEAN) - ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index) - ✅ per-PR e2e extra: 14/14 (#658 strict tool × chat valid/invalid/type-omitted + responses invalid, #650-652 trim replay markers, #516 prev-resp miss mask, #558 prolite plan, #600 token_expired, #635 device poll, #647 frontend 72B, #594 account selection, #640 alembic head, #653/#654 conv archive, #655/#656 weekly pace) - ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite) - ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`) - ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account - ✅ ruff check + ruff format --check + uv run ty check — All clean - ✅ prod parity probe: #637 (unknown-key drop) + #658 (strict tool 400) both confirmed fixed vs prod 1.17.0 ## Behavior change to note in announcements - **#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding. OpenSpec changes shipped in this release (to be archived after tag publish): - deactivate-on-token-expired (#600) - drop-unknown-message-fields (#637) - mask-single-http-previous-response-miss (#516) - normalize-v1-responses-openai-sdk-stream (#639) - start-device-oauth-polling (#635) - support-prolite-plan-capacity (#558) - treat-upstream-overloaded-as-retryable (#601) - validate-password-length (#598) - validate-strict-function-tool-schema (#658)
Soju06
added a commit
that referenced
this pull request
May 17, 2026
Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md "release 이후 archive" workflow. All 12 changes verified shipped in production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d). 1.18.0 (9 changes): - deactivate-on-token-expired (#600) - drop-unknown-message-fields (#637) - mask-single-http-previous-response-miss (#516) - normalize-v1-responses-openai-sdk-stream (#639) - start-device-oauth-polling (#635) [delta header fixed: MODIFIED -> ADDED] - support-prolite-plan-capacity (#558) [delta header fixed: MODIFIED -> ADDED] - treat-upstream-overloaded-as-retryable (#601) - validate-password-length (#598) - validate-strict-function-tool-schema (#658) 1.18.1 (3 changes): - harden-long-codex-websocket-turns (#586) - suppress-duplicate-side-effect-tool-calls (#586) - hotfix-db-pool-pre-ping-and-firewall-cache-ttl (#679) Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat, chat-completions-extensions, database-backends, frontend-architecture, responses-api-compat, usage-refresh-policy). openspec validate --specs: 19/19 passed. Co-authored-by: Hermes Agent <[email protected]>
6 tasks
vitalNohj
pushed a commit
to vitalNohj/codex-lb
that referenced
this pull request
Jul 17, 2026
…on (Soju06#637) OpenAI's /v1/chat/completions parses the documented chat-message fields and silently ignores everything else. codex-lb's chat-to-Responses coercion was instead copying the inbound message dict wholesale and only overwriting 'content', so any extra key on a message object (the standard 'name' field, client-internal bookkeeping keys, etc.) leaked into the Responses 'input' items and was forwarded upstream verbatim. The upstream Responses API only accepts 'role' + 'content' on an input message item. Any other key trips an 'unknown_parameter' hard error, which the gateway surfaces as a deterministic 502 and which poisons every later request that replays the same message buffer. Concrete reproducer (Hermes Agent, 2026-05-15): the agent's empty-response recovery appends synthetic messages tagged with an internal '_empty_recovery_synthetic' bookkeeping flag — a normal client pattern. codex-lb relayed the flag into 'input[N]', upstream returned 502 Unknown parameter, and the agent's session buffer replayed the poisoned input on every subsequent turn, producing a retry flood. Rewrite _normalize_message_content to emit {role, content} explicitly instead of copying the inbound message dict. Refusal still folds into content as a refusal part; tool_calls still flow through their existing decomposition path (FunctionCallInputItem / message-half split); the message-item path now matches OpenAI's lenient-input, strict-output semantics. Add three unit tests covering: the general unknown-key case (and the specific '_empty_recovery_synthetic' reproducer), the standard 'name' field, and the assistant + tool_calls path. OpenSpec change: drop-unknown-message-fields Targeted suites: 187 passed. Broader sweep (unit + integration + e2e proxy): 633 passed, 0 new failures. Co-authored-by: Soju <[email protected]>
vitalNohj
pushed a commit
to vitalNohj/codex-lb
that referenced
this pull request
Jul 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR. ## Pre-merge verification (release-gate e2e) - ✅ CI 18/18 (mergeStateStatus CLEAN) - ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index) - ✅ per-PR e2e extra: 14/14 (Soju06#658 strict tool × chat valid/invalid/type-omitted + responses invalid, Soju06#650-652 trim replay markers, Soju06#516 prev-resp miss mask, Soju06#558 prolite plan, Soju06#600 token_expired, Soju06#635 device poll, Soju06#647 frontend 72B, Soju06#594 account selection, Soju06#640 alembic head, Soju06#653/Soju06#654 conv archive, Soju06#655/Soju06#656 weekly pace) - ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite) - ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`) - ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account - ✅ ruff check + ruff format --check + uv run ty check — All clean - ✅ prod parity probe: Soju06#637 (unknown-key drop) + Soju06#658 (strict tool 400) both confirmed fixed vs prod 1.17.0 ## Behavior change to note in announcements - **Soju06#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding. OpenSpec changes shipped in this release (to be archived after tag publish): - deactivate-on-token-expired (Soju06#600) - drop-unknown-message-fields (Soju06#637) - mask-single-http-previous-response-miss (Soju06#516) - normalize-v1-responses-openai-sdk-stream (Soju06#639) - start-device-oauth-polling (Soju06#635) - support-prolite-plan-capacity (Soju06#558) - treat-upstream-overloaded-as-retryable (Soju06#601) - validate-password-length (Soju06#598) - validate-strict-function-tool-schema (Soju06#658)
vitalNohj
pushed a commit
to vitalNohj/codex-lb
that referenced
this pull request
Jul 17, 2026
…u06#682) Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md "release 이후 archive" workflow. All 12 changes verified shipped in production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d). 1.18.0 (9 changes): - deactivate-on-token-expired (Soju06#600) - drop-unknown-message-fields (Soju06#637) - mask-single-http-previous-response-miss (Soju06#516) - normalize-v1-responses-openai-sdk-stream (Soju06#639) - start-device-oauth-polling (Soju06#635) [delta header fixed: MODIFIED -> ADDED] - support-prolite-plan-capacity (Soju06#558) [delta header fixed: MODIFIED -> ADDED] - treat-upstream-overloaded-as-retryable (Soju06#601) - validate-password-length (Soju06#598) - validate-strict-function-tool-schema (Soju06#658) 1.18.1 (3 changes): - harden-long-codex-websocket-turns (Soju06#586) - suppress-duplicate-side-effect-tool-calls (Soju06#586) - hotfix-db-pool-pre-ping-and-firewall-cache-ttl (Soju06#679) Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat, chat-completions-extensions, database-backends, frontend-architecture, responses-api-compat, usage-refresh-policy). openspec validate --specs: 19/19 passed. Co-authored-by: Hermes Agent <[email protected]>
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
Match OpenAI's
/v1/chat/completionsbehavior on unknown message-object fields. OpenAI parses the documented chat-message fields and silently ignores everything else on the message object. codex-lb's chat→Responses coercion was instead copying the inbound message dict wholesale, so any extra key (the standardnamefield, client-internal bookkeeping keys, etc.) leaked into the Responsesinputitems and was forwarded upstream verbatim. The upstream Responses API only acceptsrole+contenton an input message item — any other key trips anunknown_parameterhard error, which surfaces as a deterministic 502 and poisons every subsequent request that replays the same message buffer.OpenSpec change:
drop-unknown-message-fields.Reproducer
Verified against
https://codex.nekos.me/v1/chat/completionson 2026-05-15, captured from a real Hermes Agent session:The client's empty-response recovery path had appended synthetic messages tagged with
_empty_recovery_synthetic— a normal client pattern (bookkeeping flags on the local message buffer). codex-lb relayed the flag intoinput[N], upstream returned 502, and the client's session buffer replayed the poisoned input on every subsequent turn. The standard chatnamefield reproduces the same 502 the same way.Direct probe before the fix:
Same with any other extra key on a message object.
Root cause
app/core/openai/message_coercion.py::_normalize_message_contentwas building the output message viaupdated = dict(message); updated["content"] = normalized, which copies every key. Result:Fix
Replace the copy-and-overwrite pattern with explicit field selection — emit
{"role": role, "content": normalized_content}and nothing else. Refusal still folds into content as arefusalpart (unchanged); tool_calls still flow through_decompose_assistant_tool_calls(unchanged); the message-item path now matches OpenAI's lenient-input, strict-output contract.Tests
tests/unit/test_chat_request_mapping.pygains three tests:test_chat_unknown_message_keys_are_dropped— general unknown-key case and the_empty_recovery_syntheticreproducertest_chat_message_name_field_is_dropped— standardnamefieldtest_chat_assistant_tool_call_message_drops_unknown_keys— assistant + tool_calls path (the message half emitted alongside the decomposed tool call must also be clean)Results:
tests/unit/test_chat_request_mapping.py+tests/unit/test_openai_requests.py+tests/integration/test_proxy_chat_completions.py+tests/integration/test_openai_client_compat.py+tests/integration/test_openai_compat_features.py— 187 passed.openspec validate drop-unknown-message-fields→ valid.Out of scope
unknown_parametererrors that escape via other paths. The chat-completions adapter already converts upstreaminvalid_request_errorto 400 for non-streaming responses; this PR keeps that behavior unchanged.