openai/codex · error · anyhow::Error

thread cannot be moved before itself

Error message

thread {thread_id} cannot be moved before itself

What it means

Bailed by move_thread_to_section when the destination ('before' thread) is the thread being moved. Moving a thread before itself is a no-op-with-cycle; rejected as invalid input. Nearby guard rejects nonexistent section ids separately.

Solutions

  1. Choose a different before_thread_id that refers to another thread in the destination section
  2. Omit before_thread_id to append the thread to the end of the section
Defensive patterns

Strategy: validation

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.

Appendix: 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)