Repository navigation
Description
What version of the IDE extension are you using?
26.616.32156
What subscription do you have?
ChatGPT Pro 5x
Which IDE are you using?
VS ode
What platform is your computer?
Ubuntu 24.04 (Linux 6.8)
What issue are you seeing?
Summary
anyio.to_thread.run_sync(...) never returns when the code is executed by the Codex CLI, but the exact same script on the same machine and same Python returns immediately in a normal terminal. Any library that offloads blocking work to a worker thread via anyio's threadpool (e.g. starlette/FastAPI FileResponse, which calls os.stat in a thread) therefore hangs only under Codex.
Environment
OS: Ubuntu 24.04 (Linux 6.8)
Python: 3.13
anyio: <fill in python3 -c "import anyio,importlib.metadata as m;print(m.version('anyio'))">
Codex CLI: <version, 26.616.32156>
Minimal reproduction
import asyncio, os, tempfile
import anyio
async def main():
fd, path = tempfile.mkstemp(); os.close(fd)
try:
try:
r = await asyncio.wait_for(anyio.to_thread.run_sync(os.stat, path), timeout=5)
except asyncio.TimeoutError:
print("HANG: anyio.to_thread.run_sync did not return within 5s"); return
print(f"OK: returned (st_size={r.st_size})")
finally:
os.unlink(path)
asyncio.run(main())
Steps
In a normal terminal: python3 codex_repro.py → prints OK.
Ask Codex CLI to run the same file (or run it from inside a Codex task) → prints HANG (the threaded call never completes within 5s).
Expected
anyio.to_thread.run_sync should complete and return, identically to a normal shell.
Actual
Inside the Codex CLI execution sandbox the threaded call never returns. It is reproducible with a clean virtualenv (python3 -m venv venv && venv/bin/pip install anyio), so it is not a user package-environment issue and not an anyio bug — the divergence is between the Codex execution environment and a normal shell.
Impact
Any async code that uses a worker threadpool under Codex can deadlock. A common real-world case: FileResponse in Starlette/FastAPI hangs when exercised with httpx.ASGITransport inside Codex, which silently breaks route-level tests run via Codex.
Notes
Likely related to how the Codex sandbox sets up threads / the event loop's default executor. Happy to provide more diagnostics.
What steps can reproduce the bug?
Minimal reproduction
import asyncio, os, tempfile
import anyio
async def main():
fd, path = tempfile.mkstemp(); os.close(fd)
try:
try:
r = await asyncio.wait_for(anyio.to_thread.run_sync(os.stat, path), timeout=5)
except asyncio.TimeoutError:
print("HANG: anyio.to_thread.run_sync did not return within 5s"); return
print(f"OK: returned (st_size={r.st_size})")
finally:
os.unlink(path)
asyncio.run(main())
Steps
In a normal terminal: python3 codex_repro.py → prints OK.
Ask Codex CLI to run the same file (or run it from inside a Codex task) → prints HANG (the threaded call never completes within 5s).
Expected
anyio.to_thread.run_sync should complete and return, identically to a normal shell.
What is the expected behavior?
No response
Additional information
No response
Activity
github-actions commentedon Jun 19, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action