x-codex-turn-metadata header with non-ASCII git remote URLs causes 400 Bad Request on Azure OpenAI
What version of Codex CLI is running?
0.106.0
What subscription do you have?
Azure openai api
Which model were you using?
gpt-5.3-codex
What platform is your computer?
Windows11, wsl
What terminal emulator and version are you using (if applicable)?
Windows Terminal
What issue are you seeing?
When a git repository has a remote URL containing non-ASCII characters (e.g., Japanese characters in a Windows UNC path), Codex CLI fails with an empty ERROR: message and exits.
What steps can reproduce the bug?
- Set up a git repository with a non-ASCII remote URL:
git remote set-url origin '\\server\日本語パス\repo.git'
- Configure Codex to use an Azure OpenAI provider
- Run codex exec "echo hello"
- Observe ERROR: with no message and exit code 1
What is the expected behavior?
Non-ASCII characters in git remote URLs should be properly encoded or sanitized before being placed in HTTP headers. Alternatively, the remote URL could be omitted from the header if it contains non-ASCII characters.
Additional information
Root cause:
Codex includes git remote URLs in the x-codex-turn-metadata HTTP header. When the remote URL contains non-ASCII characters (e.g., \\172.16.xxx.yy\全国共有ネットワークドライブ\projectx\repo.git), these characters get mojibake-encoded in the HTTP header as \\\\172.16.xxx.yy\\å¨å½å±æï¼å¶éæï¼\\.... Azure API Management rejects the request with 400 Bad Request and an empty response body (content-length: 0).
11 Comments
I can reproduce a closely related variant of this issue on codex-cli 0.110.0 on macOS.
Environment:
In my case, the trigger is not a non-ASCII git remote URL. The trigger is a non-ASCII workspace path. The repository is located under a path containing Chinese directory names, specifically path segments such as
作业and实验室.Masked log excerpt:
startup websocket prewarm setup failed: stream disconnected before completion: UTF-8 encoding error: failed to convert header to a str for header name 'x-codex-turn-metadata' with value: "{\\"turn_id\\":\\"<turn-id>\\",\\"workspaces\\":{\\"/Users/<user>/Library/Mobile Documents/com~apple~CloudDocs/作业/实验室/2024/<repo>\\":{\\"associated_remote_urls\\":{\\"origin\\":\\"git@github.com:<owner>/<repo>.git\\"},\\"latest_git_commit_hash\\":\\"<commit-hash>\\",\\"has_changes\\":true}},\\"sandbox\\":\\"none\\"}"
So this appears to be the same root cause at the
x-codex-turn-metadataheader layer, but with a different non-ASCII source: workspace path entries inworkspaces[...], not only remote URLs.Expected behavior: Codex should sanitize, omit, or otherwise avoid placing non-ASCII workspace metadata into HTTP/WebSocket headers.
If you haven't already done so, please report this to the Azure folks.
Thanks for the quick reply. Just to clarify, this repro is not using Azure OpenAI API. I'm using a Pro subscription with the standard Codex/OpenAI setup on codex-cli 0.110.0 on macOS.
I suspect my comment may have been easy to read as Azure-related because the original issue is about Azure, but in my case the trigger appears to be the non-ASCII workspace path metadata in
x-codex-turn-metadata, not an Azure-specific remote URL or proxy issue.Same mechanism: non-ASCII workspace path (not git remote)
Environment
D:\CloudSync\download\ai-study 통합(Korean characters통합= "unified")Problem
The
x-codex-turn-metadataHTTP header includes the CWD workspace path. When the workspace folder name contains non-ASCII characters (Korean UTF-8:\xed\x86\xb5\xed\x95\xa9), the header value violates RFC 7230 (ISO-8859-1 only), causing an encoding error.This is the same root cause as the git remote URL issue reported here — Codex inserts raw non-ASCII bytes into HTTP headers without percent-encoding.
Trigger
The error surfaces when WebSocket connection fails with 1008 (Policy Violation) and Codex falls back to HTTPS. During HTTPS request header construction, the non-ASCII workspace path in
x-codex-turn-metadatacauses the failure.Workaround
Renaming the workspace folder to ASCII-only characters resolves the issue.
Suggestion
All values injected into
x-codex-turn-metadata(and any other HTTP headers) should be percent-encoded or Base64-encoded to handle non-ASCII paths safely. This affects:Related issues
I can reproduce a closely related variant on the Windows Codex app (
26.306.996.0).In my case the non-ASCII bytes are not coming from a git remote URL. They appear inside the
workspacesobject inx-codex-turn-metadata, where the workspace path itself is included.What I see
stream disconnected before completion: UTF-8 encoding error: failed to convert header to a str for header name 'x-codex-turn-metadata'Error snippet
Minimal repro
This makes it look broader than non-ASCII git remote URLs: any non-ASCII value serialized into
x-codex-turn-metadatamay be able to break request/stream handling depending on the producer/client path.Root Cause
TurnMetadataBag::to_header_value()inturn_metadata.rsserializes workspacepaths and git remote URLs directly into JSON via
serde_json::to_string(). Whenthose strings contain non-ASCII characters (e.g. Japanese directory names such as
/home/ユーザー/プロジェクト, or Windows UNC paths like\\サーバー\共有), theresulting JSON contains raw non-ASCII bytes.
RFC 7230 §3.2.6 restricts HTTP field values to visible US-ASCII characters.
Azure API Management enforces this strictly, returning
400 Bad Requestwith anempty body when the header violates it.
Proposed Fix
Apply JSON Unicode escaping (
\uXXXX) to any non-ASCII characters afterserde_json::to_string(), before the value is placed in the header. This keepsthe header ASCII-only while remaining fully transparent to any standard JSON
parser on the receiving side — no corresponding decoder is required.
The change is limited to two files:
codex-rs/core/src/turn_metadata.rs(+26 / -1)codex-rs/core/src/turn_metadata_tests.rs(+36 / -0) — regression testverifying that a Japanese workspace path produces an ASCII-only header that
round-trips correctly through a standard JSON parser.
No other files need to change. I have a working implementation ready if the team
would like to invite a PR.
same issues, please fix
I can reproduce the same underlying issue in a different path-based case, not just non-ASCII git remote URLs.
Environment:
0.116.0tmuxgpt-5.4Observed behavior:
On every Codex interaction, the client first fails on the WebSocket transport and falls back to HTTPS with:
I previously suggested escaping non‑ASCII as
\uXXXXinx-codex-turn-metadataas a short‑term mitigation. That is not an RFC violation, but it has readability and surrogate/double‑escape edge cases.A safer short‑term fix is to Base64‑encode the header value (encode on send, decode on receive). Base64 yields an ASCII‑only header, avoids those edge cases, and only requires localized changes at the send/receive boundary.
\uXXXXis an acceptable stopgap, but I strongly recommend following up with Base64. I can open a small PR to implement this and update tests.@etraut-openai
I've successfully reproduced a very similar 400 Bad Request issue on Azure OpenAI as described in this thread, caused by non-ASCII characters in the workspace/project path (in my case, Japanese characters).
This seems closely related to Issue #15463 as well, where Cyrillic characters in the workspace path cause UTF-8 decode failures in the
x-codex-turn-metadataheader during reconnect/streaming.Reproduction details:
/feedbackcommand)C:\git\日本語プロジェクト,C:\日本語フォルダ名\日本語プロジェクト.git)Both issues appear to share the same root cause: the
x-codex-turn-metadataheader includes unsanitized or improperly encoded non-ASCII (multi-byte) characters from the workspace path/git remote/etc., which Azure rejects as invalid headers (while the original OpenAI endpoint might tolerate it or decode differently).Would it be possible to triage this together with #15463? Proper percent-encoding, base64 encoding, or sanitization of the path/metadata before placing it in the header should resolve both cases.
Happy to provide sanitized path examples, version details, or any additional logs if helpful. Thank you for looking into this!
fix it please