{"record":{"id":"132efe42ae9f14a2","repo":"BigPizzaV3/CodexPlusPlus","slug":"unsupported-local-storage-schema","errorCode":null,"errorMessage":"Unsupported local storage schema","messagePattern":"Unsupported local storage schema","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-data/src/storage.rs","lineNumber":241,"sourceCode":"                result.message = format!(\"{}；侧边栏索引清理失败：{error}\", result.message);\n            }\n        }\n        result\n    }\n\n    pub fn list_local_sessions(&self) -> anyhow::Result<Vec<LocalSession>> {\n        self.list_local_sessions_limited(usize::MAX)\n    }\n\n    pub fn list_local_sessions_limited(&self, limit: usize) -> anyhow::Result<Vec<LocalSession>> {\n        if !self.db_path.exists() {\n            return Ok(Vec::new());\n        }\n        let db = Connection::open(&self.db_path)?;\n        match schema_kind(&db)? {\n            Some(SchemaKind::CodexThreads) => self.list_codex_threads(&db, limit),\n            Some(SchemaKind::CodexAutomationRuns) => self.list_codex_automation_runs(&db, limit),\n            _ => anyhow::bail!(\"Unsupported local storage schema\"),\n        }\n    }\n\n    pub fn list_local_session_ids(&self) -> anyhow::Result<Vec<String>> {\n        if !self.db_path.exists() {\n            return Ok(Vec::new());\n        }\n        let db = Connection::open(&self.db_path)?;\n        let (table, id_column, filter) = match schema_kind(&db)? {\n            Some(SchemaKind::CodexThreads) => (\"threads\", \"id\", codex_thread_filter(&db)?),\n            Some(SchemaKind::CodexAutomationRuns) => (\n                \"automation_runs\",\n                \"thread_id\",\n                \"WHERE COALESCE(thread_id, '') <> ''\".to_string(),\n            ),\n            _ => anyhow::bail!(\"Unsupported local storage schema\"),\n        };\n        let sql = format!(\"SELECT {id_column} FROM {table} {filter} ORDER BY {id_column}\");","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-data/src/storage.rs#L223-L259","documentation":"list_local_sessions_limited opens the local SQLite database and dispatches on the detected schema (schema_kind). Only two layouts are supported — CodexThreads (sessions table with id/title) and CodexAutomationRuns (automation_runs) — any other or undetectable schema makes the adapter bail. This guards against querying an unrecognized database whose column assumptions would not hold.","triggerScenarios":"Calling list_local_sessions / list_local_sessions_limited when db_path points to a SQLite file whose schema matches neither CodexThreads nor CodexAutomationRuns (e.g. sessions table missing required id/title columns, unrelated SQLite file, empty schema), or when schema_kind errors/returns None.","commonSituations":"Pointing the storage adapter at a non-codex SQLite file via misconfigured allowed_db_paths; codex upgrading/changing its session DB layout so an older adapter no longer recognizes it; an empty or partially initialized database file created by another tool.","solutions":["Verify db_path points to the actual codex threads DB (e.g. ~/.codex/... with a sessions table having id and title columns) via sqlite3: SELECT id, title FROM sessions LIMIT 1.","Update CodexPlusPlus to a version whose schema_kind recognizes the current codex DB layout (codex may have changed its schema).","Fix adapter configuration (allowed_db_paths / db_path) so it doesn't target an unrelated SQLite file.","If the DB is corrupt or foreign, restore or reinitialize it through codex."],"exampleFix":"// before\nlet adapter = SQLiteStorageAdapter::new().with_db_path(\"./notes.db\"); // arbitrary sqlite\n// after\nlet adapter = SQLiteStorageAdapter::new()\n    .with_db_path(codex_home.join(\"state\").join(\"threads.sqlite\")); // real codex threads db","handlingStrategy":"validation","validationCode":"use rusqlite::Connection;\nfn storage_is_supported(db_path: &Path) -> anyhow::Result<bool> {\n    let db = Connection::open(db_path)?;\n    Ok(schema_kind(&db)?.is_some())\n}\n// call before list_local_sessions","typeGuard":"fn has_codex_schema(db_path: &Path) -> bool {\n    Connection::open(db_path).ok()\n        .and_then(|db| schema_kind(&db).ok().flatten())\n        .is_some()\n}","tryCatchPattern":"match storage.list_local_sessions_limited(50) {\n    Ok(sessions) => render(sessions),\n    Err(e) if e.to_string().contains(\"Unsupported local storage schema\") => {\n        eprintln!(\"DB schema not recognized; update the app or fix db_path\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Point the adapter only at genuine codex session/automation databases","Run `sqlite3 <db> .schema sessions` after any codex upgrade to confirm the layout still matches","Keep CodexPlusPlus updated when codex changes its DB schema","Check db_path existence and non-emptiness before opening"],"tags":["sqlite","schema","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}