{"record":{"id":"10af9678ba2c3f6e","repo":"openai/codex","slug":"turn-error-message","errorCode":null,"errorMessage":"turn.error.message","messagePattern":"turn\\.error\\.message","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdk/python/src/openai_codex/_run.py","lineNumber":64,"sourceCode":"    last_unknown_phase_response: str | None = None\n\n    for item in reversed(items):\n        agent_message = _agent_message_item_from_thread_item(item)\n        if agent_message is None:\n            continue\n        if agent_message.phase == MessagePhase.final_answer:\n            return agent_message.text\n        if agent_message.phase is None and last_unknown_phase_response is None:\n            last_unknown_phase_response = agent_message.text\n\n    return last_unknown_phase_response\n\n\ndef _raise_for_failed_turn(turn: Turn) -> None:\n    if turn.status != TurnStatus.failed:\n        return\n    if turn.error is not None and turn.error.message:\n        raise RuntimeError(turn.error.message)\n    raise RuntimeError(f\"turn failed with status {turn.status.value}\")\n\n\ndef _collect_turn_result(stream: Iterator[Notification], *, turn_id: str) -> TurnResult:\n    completed: TurnCompletedNotification | None = None\n    items: list[ThreadItem] = []\n    usage: ThreadTokenUsage | None = None\n\n    for event in stream:\n        payload = event.payload\n        if isinstance(payload, ItemCompletedNotification) and payload.turn_id == turn_id:\n            items.append(payload.item)\n            continue\n        if isinstance(payload, ThreadTokenUsageUpdatedNotification) and payload.turn_id == turn_id:\n            usage = payload.token_usage\n            continue\n        if isinstance(payload, TurnCompletedNotification) and payload.turn.id == turn_id:\n            completed = payload","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/sdk/python/src/openai_codex/_run.py#L46-L82","documentation":"Error \"turn.error.message\" thrown in openai/codex.","triggerScenarios":"Thrown at sdk/python/src/openai_codex/_run.py:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the turn error message carried by the event and fix the underlying cause reported by the runtime."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}