{"record":{"id":"abde4da6e6941457","repo":"BigPizzaV3/CodexPlusPlus","slug":"codex-abde4d","errorCode":null,"errorMessage":"Codex 会话数据库缺少必要字段","messagePattern":"Codex 会话数据库缺少必要字段","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/session_share.rs","lineNumber":349,"sourceCode":"    add!(\"source\", source.to_string());\n    add!(\"model_provider\", model_provider.to_string());\n    add!(\"cwd\", cwd);\n    add!(\"title\", title.to_string());\n    add!(\"sandbox_policy\", r#\"{\"type\":\"disabled\"}\"#.to_string());\n    add!(\"approval_mode\", \"never\".to_string());\n    add!(\"tokens_used\", 0_i64);\n    add!(\"has_user_event\", 1_i64);\n    add!(\"archived\", 0_i64);\n    add!(\"cli_version\", cli_version.to_string());\n    add!(\"first_user_message\", first_message.clone());\n    add!(\"thread_source\", thread_source.to_string());\n    add!(\"preview\", first_message);\n    add!(\"history_mode\", history_mode.to_string());\n    add!(\"recency_at\", timestamp);\n    add!(\"recency_at_ms\", timestamp.saturating_mul(1000));\n\n    if !columns.contains(\"id\") || !columns.contains(\"rollout_path\") {\n        bail!(\"Codex 会话数据库缺少必要字段\");\n    }\n    let names = values.iter().map(|(name, _)| *name).collect::<Vec<_>>();\n    let placeholders = (1..=names.len())\n        .map(|index| format!(\"?{index}\"))\n        .collect::<Vec<_>>();\n    let sql = format!(\n        \"INSERT OR REPLACE INTO threads ({}) VALUES ({})\",\n        names.join(\", \"),\n        placeholders.join(\", \")\n    );\n    let params = values\n        .iter()\n        .map(|(_, value)| value.as_ref())\n        .collect::<Vec<_>>();\n    db.execute(&sql, rusqlite::params_from_iter(params))?;\n    Ok(())\n}\n","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/session_share.rs#L331-L367","documentation":"register_imported_thread writes a row into the Codex sessions SQLite database by dynamically detecting existing columns. If the target table lacks the mandatory \"id\" or \"rollout_path\" columns, the library cannot build a valid INSERT and aborts with this message.","triggerScenarios":"import_rollout -> register_imported_thread against a sessions db whose schema is missing id or rollout_path columns.","commonSituations":"Pointing the tool at an old/incompatible codex home whose database schema predates current versions; a corrupted or hand-created sessions database; a codex upgrade that renamed columns.","solutions":["Ensure the Codex CLI version that owns the home directory is current so its sessions db has the expected schema","Delete/regenerate the sessions database with the official codex client (back it up first)","Verify you passed the correct CODEX_HOME — a stale/foreign home may hold an outdated schema"],"exampleFix":"// before (schema drift)\nlet db = home.join(\"sessions/state.db\"); // old schema, no rollout_path\n// after\n// upgrade codex client so the sessions table contains id + rollout_path,\n// then rerun import_rollout\n","handlingStrategy":"validation","validationCode":"let conn = rusqlite::Connection::open(&db_path)?;\nlet mut stmt = conn.prepare(\"PRAGMA table_info(sessions)\")?;\nlet cols: Vec<String> = stmt.query_map([], |r| r.get::<_, String>(1))?.flatten().collect();\nif !(cols.contains(&\"id\".into()) && cols.contains(&\"rollout_path\".into())) {\n    anyhow::bail!(\"sessions 表缺少 id/rollout_path 列，请升级 codex\");\n}","typeGuard":null,"tryCatchPattern":"match import_rollout(&home, &payload) {\n    Err(e) if e.to_string().contains(\"缺少必要字段\") => eprintln!(\"sessions 数据库 schema 不兼容，请升级 codex 客户端\"),\n    other => other?,\n}","preventionTips":["保持 codex CLI 与 CodexPlusPlus 版本同步","升级前备份 sessions 数据库","不要手工改动 sessions 表结构"],"tags":["database","schema","session"],"backgroundTag":"schema-validation-failed","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"}