Skip to content

Escape turn metadata headers as ASCII JSON#19620

Merged
etraut-openai merged 5 commits intomainfrom
etraut/ascii-turn-metadata-header
Apr 29, 2026
Merged

Escape turn metadata headers as ASCII JSON#19620
etraut-openai merged 5 commits intomainfrom
etraut/ascii-turn-metadata-header

Conversation

@etraut-openai
Copy link
Copy Markdown
Collaborator

Why

x-codex-turn-metadata is sent as an HTTP/WebSocket header, but Codex was serializing the metadata JSON with raw UTF-8 string contents. When a workspace path contains non-ASCII characters, common HTTP stacks can reject or corrupt that header before the request reaches the provider.

Fixes #17468. Also addresses the duplicate WebSocket report in #19581.

What changed

  • Added codex_utils_string::to_ascii_json_string, a shared helper that serializes JSON normally while escaping non-ASCII string content as \uXXXX.
  • Switched turn metadata header serialization, including merged Responses API client metadata, to use the ASCII-safe JSON helper.
  • Added coverage for non-ASCII workspace paths and non-ASCII client metadata while preserving the same parsed JSON values.

Verification

  • cargo test -p codex-utils-string
  • cargo test -p codex-core turn_metadata
  • just bazel-lock-check

@etraut-openai etraut-openai requested a review from a team as a code owner April 26, 2026 01:05
Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request Apr 26, 2026
Comment thread codex-rs/utils/string/src/json.rs
Comment thread codex-rs/utils/string/src/json.rs
Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Percent encoding might be a more HTTP-native solution for this.

@etraut-openai etraut-openai merged commit 4241df4 into main Apr 29, 2026
25 checks passed
@etraut-openai etraut-openai deleted the etraut/ascii-turn-metadata-header branch April 29, 2026 22:35
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Official codex-cli 0.120.0 sends raw multibyte JSON in x-codex-turn-metadata, breaking HTTP interoperability

2 participants