mirror of
https://github.com/openai/codex.git
synced 2026-10-30 19:18:49 +00:00
## Summary Generated memory rows and their stage-one/stage-two job state currently live in `state_5.sqlite` alongside thread metadata. That makes memory cleanup and regeneration share the main state schema even though those rows are memory-pipeline data and can be rebuilt independently from the durable thread records. This PR moves the memory-owned tables into a dedicated `memories_1.sqlite` runtime database while keeping thread metadata in `state_5.sqlite`. ## Changes - Adds a separate memories DB runtime, migrator, path helpers, telemetry kind, and Bazel compile data for `state/memory_migrations`. - Introduces `MemoryStore` behind `StateRuntime::memories()` and moves memory table/job operations onto that store. - Drops the old memory tables from the state DB and recreates their schema in `state/memory_migrations/0001_memories.sql`. - Updates memory startup, citation usage tracking, rollout pollution handling, `debug clear-memories`, and app-server `memory/reset` to operate through the memories DB. - Preserves cross-DB behavior by hydrating thread metadata from the state DB when selecting visible memory outputs and checking stage-one staleness. ## Verification - Added/updated `codex-state` tests for deleted-thread memory visibility and already-polluted phase-two enqueue behavior. - Updated `debug clear-memories`, app-server `memory/reset`, and memories startup tests to seed and assert memory rows through `memories_1.sqlite`.
40 lines
1.3 KiB
Rust
40 lines
1.3 KiB
Rust
use std::borrow::Cow;
|
|
|
|
use sqlx::migrate::Migrator;
|
|
|
|
pub(crate) static STATE_MIGRATOR: Migrator = sqlx::migrate!("./migrations");
|
|
pub(crate) static LOGS_MIGRATOR: Migrator = sqlx::migrate!("./logs_migrations");
|
|
pub(crate) static GOALS_MIGRATOR: Migrator = sqlx::migrate!("./goals_migrations");
|
|
pub(crate) static MEMORIES_MIGRATOR: Migrator = sqlx::migrate!("./memory_migrations");
|
|
|
|
/// Allow an older Codex binary to open a database that has already been
|
|
/// migrated by a newer binary running in parallel.
|
|
///
|
|
/// We intentionally ignore applied migration versions that are newer than the
|
|
/// embedded migration set. Known migration versions are still validated by
|
|
/// checksum, so this only relaxes the "database is ahead of me" case.
|
|
fn runtime_migrator(base: &'static Migrator) -> Migrator {
|
|
Migrator {
|
|
migrations: Cow::Borrowed(base.migrations.as_ref()),
|
|
ignore_missing: true,
|
|
locking: base.locking,
|
|
no_tx: base.no_tx,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn runtime_state_migrator() -> Migrator {
|
|
runtime_migrator(&STATE_MIGRATOR)
|
|
}
|
|
|
|
pub(crate) fn runtime_logs_migrator() -> Migrator {
|
|
runtime_migrator(&LOGS_MIGRATOR)
|
|
}
|
|
|
|
pub(crate) fn runtime_goals_migrator() -> Migrator {
|
|
runtime_migrator(&GOALS_MIGRATOR)
|
|
}
|
|
|
|
pub(crate) fn runtime_memories_migrator() -> Migrator {
|
|
runtime_migrator(&MEMORIES_MIGRATOR)
|
|
}
|