Skip to content

codex exec --json hangs indefinitely when --image flag is used #5773

@jet-ds

Description

@jet-ds

Bug Description

codex exec --json hangs indefinitely when the --image flag is used. The CLI successfully initializes (thread.started event is emitted) but then never processes the request or emits any further events.

Environment

  • Codex CLI Version: 0.50.0
  • Platform: macOS (Darwin 25.0.0)
  • Installation: npm global install (npm i -g @openai/codex)

Minimal Reproduction

# Create or use any test image
echo "Describe what you see in this image" | codex exec --json --image /path/to/any/image.png

Expected behavior:

  • Codex should process the image and prompt
  • Stream events like item.*, agent_message_delta, agent_message, etc.
  • Eventually emit turn.completed or task_complete

Actual behavior:

  1. Emits {"type":"thread.started","thread_id":"..."}
  2. Hangs indefinitely - no further output
  3. Never completes, must be killed manually

Without Images: Works Fine

echo "Write a hello world script" | codex exec --json --cd /tmp

This works perfectly and streams all expected events (item.completed, agent_message, etc.).

Additional Context

  • The bug exists in both 0.49.0 and 0.50.0
  • The hang occurs after initialization, suggesting a state machine bug in the event loop
  • The TypeScript SDK (@openai/codex-sdk) is also affected since it uses --image flags internally
  • No errors are emitted to stderr
  • The process doesn't crash; it just stops producing output

Workaround

Currently using a timeout mechanism to detect the hang:

try:
    line = await asyncio.wait_for(
        process.stdout.readline(), timeout=90
    )
except asyncio.TimeoutError:
    # Kill and report error
    process.kill()

Impact

This makes image-based workflows completely unusable in non-interactive mode, which is critical for CI/CD pipelines and programmatic integrations.

Related Issues

This may be related to:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions