Python SDK: Relative codex_bin overrides pass validation but fail during subprocess launch

オープン 初心者向け
#63,732 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
devtools

調査の方向性

バグは 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 の本文から書いたものです。

説明

app-server bug
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
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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/codex のほかの issue

openai/codex の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。