Sanitize Codex Responses message translation#139
Merged
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — sanitize chat completions messages during Responses API translation by constructing a new message object with only explicitly allowed fields (role, content, phase, type), stripping unsupported fields like reasoning_content that Codex rejects.
- Build sanitized message from scratch —
convert_message_to_input_itemsnow constructs a newinput_messagemap instead of cloning and mutating the original message, automatically dropping any fields not in the allowlist. - Preserve
phasefor Codex flows — carries over the Codex-specificphasefield from the source message. - Add test for field stripping — verifies
nameandreasoning_contentare absent whiletype,role,content, andphasesurvive translation.
Big Pickle (free) | 𝕏
Collaborator
|
LGTM, thanks! |
xichen1997
enabled auto-merge
May 22, 2026 18:17
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.

Spotted this error when using Weixin with Codex OAuth and replayed chat history contains extra assistant message
fields such as
reasoning_content, which the Codex Responses endpoint does not accept.2026-05-22T16:23:31.353789809Z 2026-05-22T16:23:31.353591Z INFO clawshell::app: Forwarding request to upstream method=GET path=/models virtual_key=vk-openai-codex 2026-05-22T16:23:31.852544426Z 2026-05-22T16:23:31.852419Z WARN clawshell::app: Upstream returned error oauth_provider=codex effective_path=/models status=400 Bad Request response_body={ 2026-05-22T16:23:31.852576536Z "error": { 2026-05-22T16:23:31.852579459Z "message": "[{'type': 'missing', 'loc': ('query', 'client_version'), 'msg': 'Field required', 'input': None}]", 2026-05-22T16:23:31.852581951Z "type": "invalid_request_error", 2026-05-22T16:23:31.852583963Z "param": null, 2026-05-22T16:23:31.852585910Z "code": null 2026-05-22T16:23:31.852588046Z } 2026-05-22T16:23:31.852589789Z } 2026-05-22T16:23:31.852592074Z 2026-05-22T16:23:31.852457Z INFO clawshell::app: Request completed method=GET path=/models query= status=400 Bad Request latency_ms=498 2026-05-22T16:23:31.900669382Z 2026-05-22T16:23:31.900559Z INFO clawshell::app: Forwarding request to upstream method=POST path=/api/show virtual_key=vk-openai-codex 2026-05-22T16:23:31.915812645Z 2026-05-22T16:23:31.915628Z INFO clawshell::app: Request completed method=POST path=/api/show query= status=403 Forbidden latency_ms=15 2026-05-22T16:23:32.722081729Z 2026-05-22T16:23:32.721815Z INFO clawshell::app: Forwarding request to upstream method=POST path=/api/show virtual_key=vk-openai-codex 2026-05-22T16:23:32.756354940Z 2026-05-22T16:23:32.756166Z INFO clawshell::app: Request completed method=POST path=/api/show query= status=403 Forbidden latency_ms=34 2026-05-22T16:23:32.777907955Z 2026-05-22T16:23:32.777738Z INFO clawshell::app: Forwarding request to upstream method=POST path=/api/show virtual_key=vk-openai-codex 2026-05-22T16:23:32.816114667Z 2026-05-22T16:23:32.815940Z INFO clawshell::app: Request completed method=POST path=/api/show query= status=403 Forbidden latency_ms=38 2026-05-22T16:23:33.026752047Z 2026-05-22T16:23:33.026625Z INFO clawshell::app: Forwarding request to upstream method=POST path=/v1/chat/completions virtual_key=vk-openai-codex 2026-05-22T16:23:33.494637368Z 2026-05-22T16:23:33.494519Z WARN clawshell::app: Upstream returned error oauth_provider=codex effective_path=/responses status=400 Bad Request response_body={ 2026-05-22T16:23:33.494667680Z "error": { 2026-05-22T16:23:33.494671450Z "message": "Unknown parameter: 'input[2].reasoning_content'.", 2026-05-22T16:23:33.494689458Z "type": "invalid_request_error", 2026-05-22T16:23:33.494692117Z "param": "input[2].reasoning_content", 2026-05-22T16:23:33.494694623Z "code": "unknown_parameter" 2026-05-22T16:23:33.494696947Z } 2026-05-22T16:23:33.494699117Z }Need help on this PR? Tag
@codesmithwith what you need. Autofix is disabled.