{"record":{"id":"a7d7314e9109f125","repo":"Hmbown/CodeWhale","slug":"state-db-connection-mutex-poisoned","errorCode":null,"errorMessage":"state db connection mutex poisoned","messagePattern":"state db connection mutex poisoned","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/state/src/lib.rs","lineNumber":365,"sourceCode":"                    db_path.display()\n                );\n            }\n        }\n        Ok(())\n    }\n\n    /// Returns the filesystem path of the underlying SQLite database.\n    pub fn db_path(&self) -> &Path {\n        &self.db_path\n    }\n\n    fn conn(&self) -> Result<MutexGuard<'_, Connection>> {\n        // Poisoning means a panic mid-operation; any open transaction was\n        // rolled back when it dropped, but surface the condition rather than\n        // silently continuing on a connection whose state we can't vouch for.\n        self.conn\n            .lock()\n            .map_err(|_| anyhow::anyhow!(\"state db connection mutex poisoned\"))\n    }\n\n    fn init_schema(conn: &Connection) -> Result<()> {\n        let mut user_version: u32 = conn.query_row(\"PRAGMA user_version;\", [], |row| row.get(0))?;\n        if user_version == 0 {\n            // Guard each ALTER: a database restored with a v0 header (or\n            // stamped by a racing process that crashed before setting\n            // user_version) can already carry these columns, and an\n            // unguarded ADD COLUMN aborts the whole open with\n            // \"duplicate column name\".\n            let add_parent_entry_id = if column_exists(conn, \"messages\", \"parent_entry_id\")? {\n                \"\"\n            } else {\n                \"ALTER TABLE messages ADD COLUMN parent_entry_id INTEGER NULL;\"\n            };\n            let add_current_leaf_id = if column_exists(conn, \"threads\", \"current_leaf_id\")? {\n                \"\"\n            } else {","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/state/src/lib.rs#L347-L383","documentation":"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.","triggerScenarios":"Thrown at crates/state/src/lib.rs:365 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["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.","Find and fix the panic that poisoned the mutex; the open transaction was already rolled back."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}