BigPizzaV3/CodexPlusPlus · error · anyhow::Error

Codex 会话数据库缺少必要字段

Error message

Codex 会话数据库缺少必要字段

What it means

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.

Solutions

  1. Ensure the Codex CLI version that owns the home directory is current so its sessions db has the expected schema
  2. Delete/regenerate the sessions database with the official codex client (back it up first)
  3. Verify you passed the correct CODEX_HOME — a stale/foreign home may hold an outdated schema

Example fix

// before (schema drift)
let db = home.join("sessions/state.db"); // old schema, no rollout_path
// after
// upgrade codex client so the sessions table contains id + rollout_path,
// then rerun import_rollout
Defensive patterns

Strategy: validation

Validate before calling

let conn = rusqlite::Connection::open(&db_path)?;
let mut stmt = conn.prepare("PRAGMA table_info(sessions)")?;
let cols: Vec<String> = stmt.query_map([], |r| r.get::<_, String>(1))?.flatten().collect();
if !(cols.contains(&"id".into()) && cols.contains(&"rollout_path".into())) {
    anyhow::bail!("sessions 表缺少 id/rollout_path 列,请升级 codex");
}

Try / catch

match import_rollout(&home, &payload) {
    Err(e) if e.to_string().contains("缺少必要字段") => eprintln!("sessions 数据库 schema 不兼容,请升级 codex 客户端"),
    other => other?,
}

Prevention

When it happens

Trigger: import_rollout -> register_imported_thread against a sessions db whose schema is missing id or rollout_path columns.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/abde4da6e6941457. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/session_share.rs:349

    add!("source", source.to_string());
    add!("model_provider", model_provider.to_string());
    add!("cwd", cwd);
    add!("title", title.to_string());
    add!("sandbox_policy", r#"{"type":"disabled"}"#.to_string());
    add!("approval_mode", "never".to_string());
    add!("tokens_used", 0_i64);
    add!("has_user_event", 1_i64);
    add!("archived", 0_i64);
    add!("cli_version", cli_version.to_string());
    add!("first_user_message", first_message.clone());
    add!("thread_source", thread_source.to_string());
    add!("preview", first_message);
    add!("history_mode", history_mode.to_string());
    add!("recency_at", timestamp);
    add!("recency_at_ms", timestamp.saturating_mul(1000));

    if !columns.contains("id") || !columns.contains("rollout_path") {
        bail!("Codex 会话数据库缺少必要字段");
    }
    let names = values.iter().map(|(name, _)| *name).collect::<Vec<_>>();
    let placeholders = (1..=names.len())
        .map(|index| format!("?{index}"))
        .collect::<Vec<_>>();
    let sql = format!(
        "INSERT OR REPLACE INTO threads ({}) VALUES ({})",
        names.join(", "),
        placeholders.join(", ")
    );
    let params = values
        .iter()
        .map(|(_, value)| value.as_ref())
        .collect::<Vec<_>>();
    db.execute(&sql, rusqlite::params_from_iter(params))?;
    Ok(())
}

View on GitHub (pinned to b1ed92e5e4)