openai/codex · error · RuntimeError

turn completed event not received

Error message

turn completed event not received

What it means

_collect_turn_result consumed the entire notification stream for the turn_id without ever receiving a TurnCompletedNotification. The stream ended (closed, failed, or misrouted) before the terminal event, so no final result can be assembled.

Solutions

  1. Check the connection to the Codex runtime and retry the turn; the completed event was never delivered.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at sdk/python/src/openai_codex/_run.py:85 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/0c273ed857802ade. Report an issue: GitHub.

Appendix: source

Thrown at sdk/python/src/openai_codex/_run.py:85

def _collect_turn_result(stream: Iterator[Notification], *, turn_id: str) -> TurnResult:
    completed: TurnCompletedNotification | None = None
    items: list[ThreadItem] = []
    usage: ThreadTokenUsage | None = None

    for event in stream:
        payload = event.payload
        if isinstance(payload, ItemCompletedNotification) and payload.turn_id == turn_id:
            items.append(payload.item)
            continue
        if isinstance(payload, ThreadTokenUsageUpdatedNotification) and payload.turn_id == turn_id:
            usage = payload.token_usage
            continue
        if isinstance(payload, TurnCompletedNotification) and payload.turn.id == turn_id:
            completed = payload

    if completed is None:
        raise RuntimeError("turn completed event not received")

    _raise_for_failed_turn(completed.turn)
    turn = completed.turn
    return TurnResult(
        id=turn.id,
        status=turn.status,
        error=turn.error,
        started_at=turn.started_at,
        completed_at=turn.completed_at,
        duration_ms=turn.duration_ms,
        final_response=_final_assistant_response_from_items(items),
        items=items,
        usage=usage,
    )


async def _collect_async_turn_result(
    stream: AsyncIterator[Notification], *, turn_id: str

View on GitHub (pinned to 339751715c)