Hmbown/CodeWhale · error

state db connection mutex poisoned

Error message

state db connection mutex poisoned

What it means

StateStore::conn guards its SQLite connection mutex; poisoning means a previous operation panicked mid-transaction (transactions roll back on drop, but the connection's state is no longer vouchable), so all subsequent DB access fails closed until the store is reopened.

Solutions

  1. Restart the process owning the state db; the connection mutex was poisoned by a panic mid-operation and the guard refuses to continue on unverifiable connection state.
  2. Find and fix the panic that poisoned the mutex; the open transaction was already rolled back.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/state/src/lib.rs:365 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/a7d7314e9109f125. Report an issue: GitHub.

Appendix: source

Thrown at crates/state/src/lib.rs:365

                    db_path.display()
                );
            }
        }
        Ok(())
    }

    /// Returns the filesystem path of the underlying SQLite database.
    pub fn db_path(&self) -> &Path {
        &self.db_path
    }

    fn conn(&self) -> Result<MutexGuard<'_, Connection>> {
        // Poisoning means a panic mid-operation; any open transaction was
        // rolled back when it dropped, but surface the condition rather than
        // silently continuing on a connection whose state we can't vouch for.
        self.conn
            .lock()
            .map_err(|_| anyhow::anyhow!("state db connection mutex poisoned"))
    }

    fn init_schema(conn: &Connection) -> Result<()> {
        let mut user_version: u32 = conn.query_row("PRAGMA user_version;", [], |row| row.get(0))?;
        if user_version == 0 {
            // Guard each ALTER: a database restored with a v0 header (or
            // stamped by a racing process that crashed before setting
            // user_version) can already carry these columns, and an
            // unguarded ADD COLUMN aborts the whole open with
            // "duplicate column name".
            let add_parent_entry_id = if column_exists(conn, "messages", "parent_entry_id")? {
                ""
            } else {
                "ALTER TABLE messages ADD COLUMN parent_entry_id INTEGER NULL;"
            };
            let add_current_leaf_id = if column_exists(conn, "threads", "current_leaf_id")? {
                ""
            } else {

View on GitHub (pinned to 73e0f67d83)