openai/codex · error · anyhow::Error

codex turn end for {codex_turn_id} used thread {event_thread

Error message

codex turn end for {codex_turn_id} used thread {event_thread_id}, but the turn belongs to {}

What it means

Error "codex turn end for {codex_turn_id} used thread {event_thread_id}, but the turn belongs to {}" thrown in openai/codex.

Source

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

            },
        );
        Ok(())
    }

    /// Marks a Codex turn terminal and validates any thread id carried by the raw event.
    pub(super) fn end_codex_turn(
        &mut self,
        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,
        )?;

View on GitHub (pinned to 339751715c)

When it happens

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