mirror of
https://github.com/openai/codex.git
synced 2026-11-28 23:34:06 +00:00
Add memory dual writing and v2 readiness reporting (#43827)
## Why Allow v2 memories to build in the background while the selected memory version continues supplying context, and let clients check whether v2 has enough consolidated data and a valid summary to use. ## What changed - Add `memories.dual_write`, disabled by default, to run v1 and v2 extraction and consolidation concurrently with separate stores and directories. - Add the experimental `memory/status` endpoint, returning `v2ConsolidatedThreads` and `v2Ready`. Readiness requires a valid v2 summary and a consolidation thread count meeting `minConsolidatedThreads` (default 20, supported range 1–4096). - Persist the largest thread count from a successful consolidation across pruning and clear it on memory reset. - Share v2 summary validation between consolidation and status reporting, and tag memory metrics with `memory_version`. ## Testing Add tests for independent dual-write outputs, preserving existing notes without importing them into v2, and readiness behavior across consolidation ownership checks, missing summaries, configurable thresholds, thread deletion, and memory reset. GitOrigin-RevId: 54417cc60bf419062401355c0da8c79119995f61
This commit is contained in:
1 parent
553df1c691
commit
2cbbf0c9b5
19 files changed
+475
-59
No files matched your search
@@ -0,0 +1,50 @@
|
||||
//! Reports v2 readiness without exposing memory contents or persistence details to clients.
|
||||
|
||||
use super::*;
|
||||
use codex_app_server_protocol::MemoryStatusParams;
|
||||
use codex_app_server_protocol::MemoryStatusResponse;
|
||||
use codex_protocol::MemoryVersion;
|
||||
|
||||
impl ThreadRequestProcessor {
|
||||
pub(crate) async fn memory_status(
|
||||
&self,
|
||||
params: MemoryStatusParams,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
let minimum = params.min_consolidated_threads.unwrap_or(20);
|
||||
if !(1..=4096).contains(&minimum) {
|
||||
return Err(invalid_params(
|
||||
"minConsolidatedThreads must be between 1 and 4096",
|
||||
));
|
||||
}
|
||||
let db = self
|
||||
.state_db
|
||||
.as_ref()
|
||||
.ok_or_else(|| internal_error("sqlite state db unavailable for memory status"))?;
|
||||
let store = db
|
||||
.memories_for_version(MemoryVersion::V2)
|
||||
.await
|
||||
.map_err(|error| internal_error(format!("failed to open v2 memory state: {error}")))?;
|
||||
let count = store
|
||||
.max_consolidated_thread_count()
|
||||
.await
|
||||
.map_err(|error| internal_error(format!("failed to read memory progress: {error}")))?;
|
||||
let root = self
|
||||
.config
|
||||
.codex_home
|
||||
.join(MemoryVersion::V2.directory_name());
|
||||
let summary = tokio::fs::read_to_string(root.join("memory_summary.md"))
|
||||
.await
|
||||
.ok();
|
||||
let ready = count >= minimum
|
||||
&& summary
|
||||
.as_deref()
|
||||
.is_some_and(codex_memories_write::workspace::is_valid_v2_summary);
|
||||
Ok(Some(
|
||||
MemoryStatusResponse {
|
||||
v2_consolidated_threads: count,
|
||||
v2_ready: ready,
|
||||
}
|
||||
.into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user