Lightweight coding agent that runs in your terminal
Rust
feat: house-keeping memories 2 (#20000)
jif-oai21e19912e0cd
diff --git a/codex-rs/memories/write/src/lib.rs b/codex-rs/memories/write/src/lib.rsindex c92d5b6524..63f1565710 100644--- a/codex-rs/memories/write/src/lib.rs+++ b/codex-rs/memories/write/src/lib.rs@@ -7,6 +7,7 @@mod control;mod extensions;mod guard;+mod metrics;mod phase1;mod phase2;mod prompts;diff --git a/codex-rs/memories/write/src/metrics.rs b/codex-rs/memories/write/src/metrics.rsnew file mode 100644index 0000000000..caa77565db--- /dev/null+++ b/codex-rs/memories/write/src/metrics.rs@@ -0,0 +1,11 @@+pub(crate) const MEMORY_STARTUP: &str = "codex.memory.startup";++pub(crate) const MEMORY_PHASE_ONE_JOBS: &str = "codex.memory.phase1";+pub(crate) const MEMORY_PHASE_ONE_E2E_MS: &str = "codex.memory.phase1.e2e_ms";+pub(crate) const MEMORY_PHASE_ONE_OUTPUT: &str = "codex.memory.phase1.output";+pub(crate) const MEMORY_PHASE_ONE_TOKEN_USAGE: &str = "codex.memory.phase1.token_usage";++pub(crate) const MEMORY_PHASE_TWO_JOBS: &str = "codex.memory.phase2";+pub(crate) const MEMORY_PHASE_TWO_E2E_MS: &str = "codex.memory.phase2.e2e_ms";+pub(crate) const MEMORY_PHASE_TWO_INPUT: &str = "codex.memory.phase2.input";+pub(crate) const MEMORY_PHASE_TWO_TOKEN_USAGE: &str = "codex.memory.phase2.token_usage";diff --git a/codex-rs/memories/write/src/phase1.rs b/codex-rs/memories/write/src/phase1.rsindex 120ff870b1..a3a85b8e8b 100644--- a/codex-rs/memories/write/src/phase1.rs+++ b/codex-rs/memories/write/src/phase1.rs@@ -1,5 +1,9 @@use crate::STAGE_ONE_PROMPT;use crate::build_stage_one_input_message;+use crate::metrics::MEMORY_PHASE_ONE_E2E_MS;+use crate::metrics::MEMORY_PHASE_ONE_JOBS;+use crate::metrics::MEMORY_PHASE_ONE_OUTPUT;+use crate::metrics::MEMORY_PHASE_ONE_TOKEN_USAGE;use crate::runtime::MemoryStartupContext;use crate::runtime::StageOneRequestContext;use codex_config::types::MemoriesConfig;@@ -32,10 +36,6 @@ const JOB_LEASE_SECONDS: i64 = 3_600;const JOB_RETRY_DELAY_SECONDS: i64 = 3_600;const THREAD_SCAN_LIMIT: usize = 5_000;const PRUNE_BATCH_SIZE: usize = 200;-const MEMORY_PHASE_ONE_JOBS: &str = "codex.memory.phase1";-const MEMORY_PHASE_ONE_E2E_MS: &str = "codex.memory.phase1.e2e_ms";-const MEMORY_PHASE_ONE_OUTPUT: &str = "codex.memory.phase1.output";-const MEMORY_PHASE_ONE_TOKEN_USAGE: &str = "codex.memory.phase1.token_usage";struct JobResult {outcome: JobOutcome,diff --git a/codex-rs/memories/write/src/phase2.rs b/codex-rs/memories/write/src/phase2.rsindex 2d092abfb2..14954c49e4 100644--- a/codex-rs/memories/write/src/phase2.rs+++ b/codex-rs/memories/write/src/phase2.rs@@ -1,5 +1,9 @@use crate::build_consolidation_prompt;use crate::memory_root;+use crate::metrics::MEMORY_PHASE_TWO_E2E_MS;+use crate::metrics::MEMORY_PHASE_TWO_INPUT;+use crate::metrics::MEMORY_PHASE_TWO_JOBS;+use crate::metrics::MEMORY_PHASE_TWO_TOKEN_USAGE;use crate::prune_old_extension_resources;use crate::rebuild_raw_memories_file_from_memories;use crate::runtime::MemoryStartupContext;@@ -30,10 +34,6 @@ const REASONING_EFFORT: codex_protocol::openai_models::ReasoningEffort =const JOB_LEASE_SECONDS: i64 = 3_600;const JOB_RETRY_DELAY_SECONDS: i64 = 3_600;const JOB_HEARTBEAT_SECONDS: u64 = 90;-const MEMORY_PHASE_TWO_JOBS: &str = "codex.memory.phase2";-const MEMORY_PHASE_TWO_E2E_MS: &str = "codex.memory.phase2.e2e_ms";-const MEMORY_PHASE_TWO_INPUT: &str = "codex.memory.phase2.input";-const MEMORY_PHASE_TWO_TOKEN_USAGE: &str = "codex.memory.phase2.token_usage";#[derive(Debug, Clone, Default)]struct Claim {diff --git a/codex-rs/memories/write/src/start.rs b/codex-rs/memories/write/src/start.rsindex 0ad8b27301..f7bf11e6f6 100644--- a/codex-rs/memories/write/src/start.rs+++ b/codex-rs/memories/write/src/start.rs@@ -1,4 +1,5 @@use crate::guard;+use crate::metrics::MEMORY_STARTUP;use crate::phase1;use crate::phase2;use crate::runtime::MemoryStartupContext;@@ -12,8 +13,6 @@ use codex_protocol::protocol::SessionSource;use std::sync::Arc;use tracing::warn;-const MEMORY_STARTUP: &str = "codex.memory.startup";-/// Starts the asynchronous startup memory pipeline for an eligible root session.////// The pipeline is skipped for ephemeral sessions, disabled feature flags, and