codex-rs/core/src/memories/README.md
This module runs a startup memory pipeline for eligible sessions.
Memory prompt templates live under codex-rs/core/templates/memories/.
stage_one_system.mdstage_one_input.mdconsolidation.mdread_path.mdcodex, edit those undated template files in place.openai/project/agent_memory/write harness repo, not here.The pipeline is triggered when a root session starts, and only if:
It runs asynchronously in the background and executes two phases in order: Phase 1, then Phase 2.
Phase 1 finds recent eligible rollouts and extracts a structured memory from each one.
Eligible rollouts are selected from the state DB using startup claim rules. In practice this means the pipeline only considers rollouts that are:
What it does:
raw_memoryrollout_summaryrollout_slugConcurrency / coordination:
Job outcomes:
succeeded (memory produced)succeeded_no_output (valid run but nothing useful generated)failed (with retry backoff/lease handling in DB)Phase 1 is the stage that turns individual rollouts into DB-backed memory records.
Phase 2 consolidates the latest stage-1 outputs into the filesystem memory artifacts and then runs a dedicated consolidation agent.
What it does:
last_usage falls outside the configured
max_unused_days windowlast_usage, falls back to generated_at so fresh
never-used memories can still be selectedusage_count first, then by the most recent
last_usage / generated_atraw_memories.md (merged raw memories, latest first)rollout_summaries/ (one summary file per retained rollout)If there is input, it then:
added,
retained, removed)Selection diff behavior:
selected_for_phase2 = 1 and persist the matching
selected_for_phase2_source_updated_atselected_for_phase2 baseline until
the next successful Phase 2 run rewrites itadded or retained; a
refreshed thread stays added until Phase 2 successfully selects its newer
snapshotremovedrollout_summaries/ and raw_memories.md
keep the union of the current selection and the previous successful
selection, so removed-thread evidence stays available during forgettingWatermark behavior:
new_watermark using the max of:
source_updated_at timestamp in the stage-1 inputs it actually loadedIn practice, this phase is responsible for refreshing the on-disk memory workspace and producing/updating the higher-level consolidated memory outputs.