You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have you searched for related issues? Yes. fix: handle non-UTF8 Codex stderr #4480 proposed the fix below and was closed for lack of a real Codex CLI reproduction; this issue is that reproduction.
Describe the bug
CodexExec.run decodes the Codex CLI's stderr as strict UTF-8 (src/agents/extensions/experimental/codex/exec.py:207). On Windows with a non-UTF-8 code page, when the npm-installed codex.CMD shim fails, cmd.exe writes its error in that code page, so the SDK raises UnicodeDecodeError instead of RuntimeError: Codex exec exited with code 1: ..., and both the exit code and the message are lost.
When #4480 was closed, the request was: "please provide the OS, Codex CLI version, invocation or configuration, and a reproduction or captured stderr byte sequence with secrets removed."
OS: Windows 10 (10.0.19045), Traditional Chinese, ANSI and OEM code page 950
Codex CLI: 0.157.1 from npm install @openai/codex, resolved by find_codex_path() to node_modules\.bin\codex.CMD
Invocation:Codex(env={"CODEX_API_KEY": ...}). env replaces the CLI process environment (codex_options.py: "do not inherit os.environ"), so Node.js is not on its PATH and the shim fails before Codex starts. A PATH of only C:\Windows\System32, as a service account might have, gives the same result.
That is cp950 for '"node"' 不是內部或外部命令、可執行的程式或批次檔。, the localized form of "'node' is not recognized as an internal or external command, operable program or batch file." On an English system the same message is ASCII, so it decodes.
With the one-line change from #4480, .decode("utf-8", errors="replace"), the same run raises RuntimeError: Codex exec exited with code 1: '"node"' ... with the exit code and "node" intact. That is also how the rest of the SDK decodes subprocess output: src/ has 57 .decode("utf-8", errors="replace") calls, including the Docker sandbox's stdout and stderr (src/agents/sandbox/sandboxes/docker.py:560-561). If you want the text itself as well, .decode("oem") recovers it in full on this machine, as a Windows-only fallback.
Debug information
Agents SDK version: 0.22.3 from PyPI, and main at 588826c
Python version: 3.11.6
Operating system: Windows 10 (10.0.19045), code page 950
Model and model provider: not reached; the CLI fails before any request
Does the issue reproduce with the latest Agents SDK release? Yes, 0.22.3
Does the issue occur consistently or intermittently? Consistently
File "...\agents\extensions\experimental\codex\exec.py", line 207, in run
stderr_text = b"".join(stderr_chunks).decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa4 in position 9: invalid start byte
Repro steps
With codex from npm install @openai/codex on PATH, on Windows with a non-UTF-8 code page:
importasynciofromagents.extensions.experimental.codeximportCodexasyncdefmain():
# `env` replaces os.environ for the Codex CLI process, so Node.js is not on its PATH# and the npm shim fails; cmd.exe reports that in the console code page.codex=Codex(env={"CODEX_API_KEY": "sk-test-not-a-real-key"})
thread=codex.start_thread({"skip_git_repo_check": True})
awaitthread.run("say hi")
asyncio.run(main())
Expected behavior
RuntimeError: Codex exec exited with code 1: ... with the CLI's message, as on an English system.
Investigated and written by Claude Code, which also ran the reproduction on my machine.
Please read this first
Describe the bug
CodexExec.rundecodes the Codex CLI's stderr as strict UTF-8 (src/agents/extensions/experimental/codex/exec.py:207). On Windows with a non-UTF-8 code page, when the npm-installedcodex.CMDshim fails,cmd.exewrites its error in that code page, so the SDK raisesUnicodeDecodeErrorinstead ofRuntimeError: Codex exec exited with code 1: ..., and both the exit code and the message are lost.When #4480 was closed, the request was: "please provide the OS, Codex CLI version, invocation or configuration, and a reproduction or captured stderr byte sequence with secrets removed."
npm install @openai/codex, resolved byfind_codex_path()tonode_modules\.bin\codex.CMDCodex(env={"CODEX_API_KEY": ...}).envreplaces the CLI process environment (codex_options.py: "do not inherit os.environ"), so Node.js is not on itsPATHand the shim fails before Codex starts. APATHof onlyC:\Windows\System32, as a service account might have, gives the same result.That is cp950 for
'"node"' 不是內部或外部命令、可執行的程式或批次檔。, the localized form of "'node' is not recognized as an internal or external command, operable program or batch file." On an English system the same message is ASCII, so it decodes.With the one-line change from #4480,
.decode("utf-8", errors="replace"), the same run raisesRuntimeError: Codex exec exited with code 1: '"node"' ...with the exit code and"node"intact. That is also how the rest of the SDK decodes subprocess output:src/has 57.decode("utf-8", errors="replace")calls, including the Docker sandbox's stdout and stderr (src/agents/sandbox/sandboxes/docker.py:560-561). If you want the text itself as well,.decode("oem")recovers it in full on this machine, as a Windows-only fallback.Debug information
mainat 588826cRepro steps
With
codexfromnpm install @openai/codexonPATH, on Windows with a non-UTF-8 code page:Expected behavior
RuntimeError: Codex exec exited with code 1: ...with the CLI's message, as on an English system.Investigated and written by Claude Code, which also ran the reproduction on my machine.