openai/codex · error · anyhow::Error

codex turn end referenced unknown turn

Error message

codex turn end referenced unknown turn {codex_turn_id}

What it means

A turn-end event referenced a codex_turn_id that was never started, so there is no turn object to mark terminal.

Solutions

  1. Ensure turn start events precede turn ends
  2. Drop end events for unknown turns
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/rollout-trace/src/reducer/thread.rs:179 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/9b1e2af37db35097. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/rollout-trace/src/reducer/thread.rs:179

        seq: RawEventSeq,
        wall_time_unix_ms: i64,
        thread_id: Option<String>,
        codex_turn_id: CodexTurnId,
        status: ExecutionStatus,
    ) -> Result<()> {
        if let Some(event_thread_id) = thread_id.as_deref()
            && let Some(turn) = self.rollout.codex_turns.get(&codex_turn_id)
            && turn.thread_id != event_thread_id
        {
            bail!(
                "codex turn end for {codex_turn_id} used thread {event_thread_id}, \
                 but the turn belongs to {}",
                turn.thread_id
            );
        }

        let Some(turn) = self.rollout.codex_turns.get_mut(&codex_turn_id) else {
            bail!("codex turn end referenced unknown turn {codex_turn_id}");
        };
        turn.execution.ended_at_unix_ms = Some(wall_time_unix_ms);
        turn.execution.ended_seq = Some(seq);
        turn.execution.status = status.clone();
        self.terminate_running_code_cells_for_turn_end(
            seq,
            wall_time_unix_ms,
            &codex_turn_id,
            &status,
        )?;
        self.close_running_inference_calls_for_turn_end(
            seq,
            wall_time_unix_ms,
            &codex_turn_id,
            &status,
        );
        Ok(())
    }

View on GitHub (pinned to 339751715c)