{"record":{"id":"b06220246e3aaa88","repo":"openai/codex","slug":"turn-failed-with-status-turn-status-value","errorCode":null,"errorMessage":"turn failed with status {turn.status.value}","messagePattern":"turn failed with status (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdk/python/src/openai_codex/_run.py","lineNumber":65,"sourceCode":"\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\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/sdk/python/src/openai_codex/_run.py#L47-L83","documentation":"Error \"turn failed with status {turn.status.value}\" thrown in openai/codex.","triggerScenarios":"Thrown at sdk/python/src/openai_codex/_run.py:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the turn status and its error details, then retry the turn after addressing the reported failure."],"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"}