Python SDK: Relative codex_bin overrides pass validation but fail during subprocess launch
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
バグは sdk/python/src/openai_codex/client.py の resolve_codex_bin にあり、相対パスの codex_bin を絶対パスにせず返すため、後で別の cwd でサブプロセスを起動すると誤って解決されます。まず、その関数と、args = [str(codex_bin)] を使うサブプロセス呼び出しを読んでください。完了条件は、sdk/python/tests/test_artifact_workflow_and_binaries.py の既存の明示的な実行ファイル上書きテストの隣に回帰テストを追加し、./custom-codex や build/custom-codex のような相対パスが絶対パスに解決されることを確認することです。
索引モデルが issue の本文から書いたものです。
説明
What issue are you seeing?
The Python SDK accepts a relative path to an explicitly configured Codex executable and verifies that the file exists, but can subsequently fail to launch it with FileNotFoundError.
This affects developers using a local Codex build with a separate workspace configured via CodexConfig.cwd. A second case occurs when a local executable is specified as ./codex: conversion through pathlib.Path removes the leading ./, so the executable is no longer looked up using the explicit relative pathname.
Version and environment
- Source: main at ae21235afbd5ba6556c2ab4b64f6afc96a139ef8. The affected code was rechecked on main before submission.
- Reproduction environment: Linux, CPython 3.13.5.
- No model or API request is needed to reproduce the launch failure.
Steps to reproduce
From a directory containing a locally compiled executable at target/debug/codex (adjust the build path as necessary), run:
from pathlib import Path
from openai_codex import CodexConfig
from openai_codex.client import CodexClient
binary = Path("target/debug/codex")
assert binary.is_file()
workspace = Path("test-workspace").absolute()
workspace.mkdir(exist_ok=True)
client = CodexClient(CodexConfig(
codex_bin="./target/debug/codex",
cwd=str(workspace),
))
try:
client.start()
finally:
client.close()
The binary must be executable, and the workspace should not contain a matching relative build path.
This example illustrates the SDK call path. The actual executed validation used the repository's resolver implementation and a local executable stub, rather than a full Codex build.
Actual behavior
The existence check succeeds, but the subsequent process creation raises:
FileNotFoundError: [Errno 2] No such file or directory: 'target/debug/codex'
An explicitly configured executable such as ./codex-local-repro also fails on POSIX when that executable is not in PATH, even if the parent and child working directories are identical.
Expected behavior
An executable path that passes the SDK's validation should continue to refer to the same file when the SDK launches the subprocess, regardless of the subprocess's configured working directory.
Root cause
In client.py:178–188, resolve_codex_bin checks the path and returns it without making it absolute:
codex_bin = Path(config.codex_bin)
if not ops.path_exists(codex_bin):
raise FileNotFoundError(...)
return codex_bin
In client.py:242–278, the SDK constructs the executable argument using args = [str(codex_bin)] and subsequently launches it with cwd=self.config.cwd.
On POSIX, a relative executable path containing a directory component is interpreted relative to the child working directory. In the single-component case, str(Path("./codex")) produces "codex", losing the explicit relative path notation.
Validation
I ran an isolated reproduction using the exact resolver function body from the repository, temporary executable shell stubs, and Python's actual subprocess API. I then repeated the same cases with the proposed one-line correction.
| Executable configuration | Current resolver | Patched resolver |
|---|---|---|
./codex-local-repro, same cwd, executable absent from PATH |
FileNotFoundError | Launched |
build/codex-local-repro, separate workspace cwd |
FileNotFoundError | Launched |
build/codex-local-repro, unchanged cwd |
Launched | Launched |
| Absolute executable path, separate workspace cwd | Launched | Launched |
All eight behavioral assertions passed. This verifies the resolver-to-subprocess behavior; the full installed SDK, actual Codex CLI and repository integration suite were not run.
Related issues
Searches of existing issues and pull requests for codex_bin, resolve_codex_bin, relative executable paths, and Python SDK startup behavior did not identify a direct duplicate.
Proposed resolution
Make an explicitly configured executable path absolute relative to the calling process before checking its existence and passing it to subprocess creation.
- codex_bin = Path(config.codex_bin)
+ codex_bin = Path(config.codex_bin).absolute()
This preserves the existing parent-directory interpretation used by validation, avoids unnecessarily resolving symbolic links, and leaves bundled executable resolution unchanged. As a workaround, callers can currently pass an absolute codex_bin path.
Add the following regression test alongside the existing explicit executable override test:
@pytest.mark.parametrize(
"relative_path",
["./custom-codex", "build/custom-codex"],
)
def test_relative_codex_bin_returns_absolute_path(
tmp_path, monkeypatch, relative_path
):
from openai_codex import client as client_module
monkeypatch.chdir(tmp_path)
binary = tmp_path / relative_path
binary.parent.mkdir(parents=True, exist_ok=True)
binary.touch()
config = client_module.CodexConfig(codex_bin=relative_path)
assert client_module._resolve_codex_bin(config) == binary
An additional subprocess integration test using an executable stub and a different workspace cwd would cover the actual launch failure. The proposed fix requires no new dependencies.
- 主要言語
- Rust
- スター
- 136k
- フォーク
- 21.6k
- 平均マージ
- 1分
- マージ済み PR(30日)
- 998
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/codex のほかの issue
-
bug CLI performance
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
app bug
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
app bug skills windows-os
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
bug CLI TUI
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
openai/codex#63725 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
app bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
area: cli good first issue type: feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
[Bug] Windows Ghidra provider rejects a PATH-only JDK: bare `java.exe` probe fails with Win32 87オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
renaming a provider to a taken name fails with a raw sql error対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンarea:storage kind:bug priority:p3 ready
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
bug bugfix
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
storytold/photocraft#16975 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信