openai/codex · error · anyhow::Error

built-in pinned thread section cannot be deleted

Error message

built-in pinned thread section cannot be deleted

What it means

delete_thread_section refuses to remove the built-in pinned section (id == PINNED_THREAD_SECTION_ID). Deleting the system pinned bucket would orphan pinned threads, so only custom sections are deletable.

Solutions

  1. Unpin or move the threads out of the pinned section instead of deleting it
  2. Delete a user-created custom section if that was the intended target
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/state/src/runtime/thread_sections.rs:68 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/6def0ec2230ef4d1. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/state/src/runtime/thread_sections.rs:68

            .map(|appearance| serde_json::to_string(&appearance))
            .transpose()?;
        let section = sqlx::query_as::<_, (String, String, Option<String>)>(
            "UPDATE thread_sections SET name = ?, appearance = CASE WHEN ? THEN ? ELSE appearance END WHERE id = ? RETURNING id, name, appearance",
        )
        .bind(name)
        .bind(replace_appearance)
        .bind(appearance)
        .bind(id)
        .fetch_optional(self.pool.as_ref())
        .await?;

        section.map(ThreadSection::from_row).transpose()
    }

    /// Delete a custom section and return its threads to the unsectioned list.
    pub async fn delete_thread_section(&self, id: &str) -> anyhow::Result<bool> {
        if id == PINNED_THREAD_SECTION_ID {
            anyhow::bail!("built-in pinned thread section cannot be deleted");
        }

        let mut tx = self.pool.begin_with("BEGIN IMMEDIATE").await?;
        sqlx::query(
            "UPDATE threads SET section_position = NULL, section_entered_at_ms = NULL WHERE thread_section_id = ?",
        )
        .bind(id)
        .execute(&mut *tx)
        .await?;

        let deleted = sqlx::query("DELETE FROM thread_sections WHERE id = ?")
            .bind(id)
            .execute(&mut *tx)
            .await?
            .rows_affected()
            > 0;
        tx.commit().await?;

View on GitHub (pinned to 339751715c)