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

Abierto Apto para principiantes
#63,732 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
devtools

Línea de trabajo

El error está en resolve_codex_bin en sdk/python/src/openai_codex/client.py, que devuelve un codex_bin relativo sin convertirlo en absoluto, por lo que el posterior lanzamiento del subproceso con un cwd distinto lo resuelve mal. Empieza leyendo esa función y la llamada al subproceso que usa args = [str(codex_bin)]. Está terminado cuando una prueba de regresión en sdk/python/tests/test_artifact_workflow_and_binaries.py, junto a la prueba existente de override explícito del ejecutable, confirma que rutas relativas como ./custom-codex y build/custom-codex se resuelven a rutas absolutas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Rust
Estrellas
136k
Forks
21.6k
Merge medio
1 min
PR fusionados (30 d)
998

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de openai/codex

Todos los issues de openai/codex

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.