Codex intermittently segfaults when starting pytest in Conda env, while same repo/tests work in user terminal and Cursor
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:
cd /Users/guido/dev/cerbex/CBE_Psource /Users/guido/anaconda3/etc/profile.d/conda.shconda activate CBE_Ppytest 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 --versioncan 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
3 Comments
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?
In my env:
LC_ALL=C.UTF-8 python -m pytestwill breakwhile codex has such ENV, claude doesn't has it.
I dug this down to a concrete root cause on macOS.
What I can reproduce reliably:
LC_ALL=C.UTF-8LC_ALL=C.UTF-8 python -c "import readline"segfaultsenv -u LC_ALL python -c "import readline"succeedspytestimportsreadlineduring startup, sopython -m pytest --versionand normal pytest runs can crash before collectionSo 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:
LC_ALLin unified execC.UTF-8on macOSWorkarounds I verified:
env -u LC_ALL python -m pytest ...codex itself https://github.com/openai/codex/compare/main...jiamo:codex:fix/unified-exec-macos-locale?expand=1