Codex intermittently segfaults when starting pytest in Conda env, while same repo/tests work in user terminal and Cursor

Resolved 💬 3 comments Opened Mar 14, 2026 by guido-h Closed Jul 2, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

Title: Codex intermittently segfaults when starting pytest in Conda env, while same repo/tests work in user terminal and Cursor

Product: Codex desktop app / Codex coding agent runner
Date/time: March 14, 2026, America/Los_Angeles
OS: macOS
Repo: /Users/guido/dev/cerbex/CBE_P

Issue:
Codex intermittently fails to validate unit tests in a Conda environment. In this repo, pytest startup sometimes exits with Segmentation fault: 11 under Codex, even when following the repo’s required Conda workflow exactly. The same commands work for the user in their own terminal and have also worked in some other Codex/Cursor sessions, so this appears intermittent and runner-specific.

Expected behavior:
Codex should be able to activate the existing Conda env and run pytest reliably, or at minimum fail with a normal Python/test error rather than a segfault.

Actual behavior:
Inside Codex, after:

  1. cd /Users/guido/dev/cerbex/CBE_P
  2. source /Users/guido/anaconda3/etc/profile.d/conda.sh
  3. conda activate CBE_P
  4. pytest tests/unit/api/test_hotel_websocket.py -q

pytest sometimes crashes immediately with:
Segmentation fault: 11

Additional observations:

  • python -c "import pytest; print(pytest.__version__)" succeeds in the same activated env.
  • python -m pytest --version can segfault under Codex.
  • The same repo and env work from the user’s terminal outside Codex.
  • Some Codex sessions succeed; others fail, so the issue appears intermittent.
  • We explicitly ruled out command drift:
  • no .venv
  • no poetry run pytest
  • no conda run
  • persistent PTY shell used
  • Repo docs were updated to standardize this flow, but the segfault still occurs in some Codex sessions.

Why this matters:
The agent can write tests but cannot always validate them, which makes unit-test tasks unreliable in Conda-based repos.

Artifacts available:

  • conversation transcript showing repeated segfaults in Codex
  • repo-local instructions used by the agent
  • exact commands above

View original on GitHub ↗

3 Comments

etraut-openai contributor · 5 months ago

Thanks for the bug report. I want to make sure I understand. The title seems to imply that codex is segfaulting, but when I read the description, it sounds like pytest is segfaulting. Can you clarify which it is and fix the title if it's pytest that's crashing?

jiamo · 5 months ago

In my env:
LC_ALL=C.UTF-8 python -m pytest will break
while codex has such ENV, claude doesn't has it.

jiamo · 5 months ago

I dug this down to a concrete root cause on macOS.

What I can reproduce reliably:

  • In Codex unified exec, child processes get LC_ALL=C.UTF-8
  • On my macOS Python env, LC_ALL=C.UTF-8 python -c "import readline" segfaults
  • env -u LC_ALL python -c "import readline" succeeds
  • pytest imports readline during startup, so python -m pytest --version and normal pytest runs can crash before collection

So the failure is not just “pytest is flaky in Codex”. The stronger root cause is that unified exec forces LC_ALL=C.UTF-8, and that locale value is not safe on macOS.

Suggested direction:

  • do not force LC_ALL in unified exec
  • inherit the user’s locale by default
  • if a UTF-8 fallback is still needed, only apply it when no locale vars are set, and avoid hardcoding C.UTF-8 on macOS

Workarounds I verified:

  • env -u LC_ALL python -m pytest ...
  • disabling unified exec / running locally outside unified exec

codex itself https://github.com/openai/codex/compare/main...jiamo:codex:fix/unified-exec-macos-locale?expand=1