openai/codex · error · anyhow::Error

thread {thread_id} cannot be moved before itself

Error message

thread {thread_id} cannot be moved before itself

What it means

Error "thread {thread_id} cannot be moved before itself" thrown in openai/codex.

Source

Thrown at codex-rs/state/src/runtime/thread_section_order.rs:149

            .bind(&thread_id)
            .execute(&mut *tx)
            .await?;
            tx.commit().await?;
            return Ok(true);
        };

        if sqlx::query_scalar::<_, i64>("SELECT 1 FROM thread_sections WHERE id = ?")
            .bind(section)
            .fetch_optional(&mut *tx)
            .await?
            .is_none()
        {
            return Err(anyhow::anyhow!("section {section} does not exist"));
        }

        let before_thread_id = before_thread_id.map(|id| id.to_string());
        if before_thread_id.as_deref() == Some(thread_id.as_str()) {
            return Err(anyhow::anyhow!(
                "thread {thread_id} cannot be moved before itself"
            ));
        }

        if let Some(before_thread_id) = before_thread_id.as_deref() {
            let before_section = sqlx::query_scalar::<_, Option<String>>(
                "SELECT thread_section_id FROM threads WHERE id = ?",
            )
            .bind(before_thread_id)
            .fetch_optional(&mut *tx)
            .await?;
            if before_section.flatten().as_deref() != Some(section) {
                return Err(anyhow::anyhow!(
                    "before thread {before_thread_id} is not in section {section}"
                ));
            }
        }

View on GitHub (pinned to 339751715c)

When it happens

Trigger: Thrown at codex-rs/state/src/runtime/thread_section_order.rs:149 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/70ebead795b5af9d. Report an issue: GitHub.