{"record":{"id":"c2a144a4dab8ace7","repo":"openai/codex","slug":"memory-import-requires-the-codex-state-database","errorCode":null,"errorMessage":"memory import requires the Codex state database","messagePattern":"memory import requires the Codex state database","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"codex-rs/external-agent-migration/src/memory_import.rs","lineNumber":70,"sourceCode":"\npub(super) async fn import(\n    codex_home: &Path,\n    external_agent_home: &Path,\n    state_db: Option<&StateDbHandle>,\n    selected_memory: &[String],\n) -> io::Result<MemoryImportOutcome> {\n    let selected_memory = selected_memory\n        .iter()\n        .map(String::as_str)\n        .collect::<BTreeSet<_>>();\n    if selected_memory.is_empty() {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidInput,\n            \"memory import requires at least one selected memory\",\n        ));\n    }\n    let state_db = state_db.ok_or_else(|| {\n        io::Error::new(\n            io::ErrorKind::NotConnected,\n            \"memory import requires the Codex state database\",\n        )\n    })?;\n    let memory_root = codex_home.join(\"memories\");\n    codex_memories_write::workspace::prepare_memory_workspace(&memory_root)\n        .await\n        .map_err(io::Error::other)?;\n    let memory_files = discover_external_memory_files(external_agent_home)?;\n    let copy_outcome = copy_resources(codex_home, &memory_files, &selected_memory)?;\n    if copy_outcome.workspace_changed\n        && let Err(err) = state_db\n            .memories()\n            .enqueue_global_consolidation(chrono::Utc::now().timestamp())\n            .await\n    {\n        tracing::warn!(error = %err, \"failed to enqueue imported memory consolidation\");\n    }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/external-agent-migration/src/memory_import.rs#L52-L88","documentation":"import() requires a live Codex state database handle and returns io::Error(NotConnected, 'memory import requires the Codex state database') when state_db is None (codex-rs/external-agent-migration/src/memory_import.rs:69-74). After copying memory files into codex_home/memories, the import enqueues a global memory consolidation through the state DB; without the handle there is no way to schedule it, so the call refuses rather than importing untracked files.","triggerScenarios":"Calling import(..., None /* state_db */, ...) - the handle was never opened, an earlier open failure was swallowed, or a test/CLI path forgot to construct the StateDbHandle.","commonSituations":"Refactors that changed import's signature leaving some caller passing None; migration run in a context where the state DB failed to open (locked, missing permissions, wrong codex_home); unit tests with a temp codex_home but no state DB.","solutions":["Open the Codex state database for the target codex_home and pass Some(&handle) before importing","If the DB open failed earlier in the flow, propagate that error instead of continuing with None","In tests, create a StateDbHandle against a temp directory so import runs against real (temporary) state"],"exampleFix":"// before\nlet outcome = import(&codex_home, &external_home, None, &selected).await?; // NotConnected\n\n// after\nlet state_db = StateDbHandle::open(&codex_home).await?; // or reuse the app's existing handle\nlet outcome = import(&codex_home, &external_home, Some(&state_db), &selected).await?;","handlingStrategy":"validation","validationCode":"let Some(state_db) = state_db.as_ref() else {\n    // open it or fail loudly - import cannot run without it\n    anyhow::bail!(\"state database unavailable; cannot import memory\");\n};","typeGuard":null,"tryCatchPattern":"match err.kind() {\n    io::ErrorKind::NotConnected => { /* open/repair the state DB, then retry import */ }\n    _ => return Err(err),\n}","preventionTips":["Open the state DB once at startup and thread &StateDbHandle through migration calls","Never map a failed DB open to None - propagate the error","ErrorKind::NotConnected here means 'handle not supplied', not a network problem"],"tags":["migration","memory-import","state-db","rust"],"backgroundTag":"missing-database-connection","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}