Skip to main content

codex_state/model/
memories.rs

1use chrono::DateTime;
2use chrono::Utc;
3use codex_protocol::ThreadId;
4use std::path::PathBuf;
5
6use super::ThreadMetadata;
7
8/// Stored stage-1 memory extraction output for a single thread.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct Stage1Output {
11    pub thread_id: ThreadId,
12    pub rollout_path: PathBuf,
13    pub source_updated_at: DateTime<Utc>,
14    pub raw_memory: String,
15    pub rollout_summary: String,
16    pub rollout_slug: Option<String>,
17    pub cwd: PathBuf,
18    pub git_branch: Option<String>,
19    pub generated_at: DateTime<Utc>,
20}
21
22/// Result of trying to claim a stage-1 memory extraction job.
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub enum Stage1JobClaimOutcome {
25    /// The caller owns the job and should continue with extraction.
26    Claimed { ownership_token: String },
27    /// Existing output is already newer than or equal to the source rollout.
28    SkippedUpToDate,
29    /// Another worker currently owns a fresh lease for this job.
30    SkippedRunning,
31    /// The job is in backoff and should not be retried yet.
32    SkippedRetryBackoff,
33    /// The job has exhausted retries and should not be retried automatically.
34    SkippedRetryExhausted,
35}
36
37/// Claimed stage-1 job with thread metadata.
38#[derive(Debug, Clone, PartialEq, Eq)]
39pub struct Stage1JobClaim {
40    pub thread: ThreadMetadata,
41    pub ownership_token: String,
42}
43
44#[derive(Debug, Clone, Copy)]
45pub struct Stage1StartupClaimParams<'a> {
46    pub scan_limit: usize,
47    pub max_claimed: usize,
48    pub max_age_days: i64,
49    pub min_rollout_idle_hours: i64,
50    pub allowed_sources: &'a [String],
51    pub lease_seconds: i64,
52}
53
54/// Result of trying to claim a phase-2 consolidation job.
55#[derive(Debug, Clone, PartialEq, Eq)]
56pub enum Phase2JobClaimOutcome {
57    /// The caller owns the global lock and may inspect the memory workspace.
58    Claimed {
59        ownership_token: String,
60        /// Snapshot of `input_watermark` at claim time.
61        input_watermark: i64,
62    },
63    /// The global job is in retry backoff.
64    SkippedRetryUnavailable,
65    /// The global job completed recently enough that consolidation is cooling down.
66    SkippedCooldown,
67    /// Another worker currently owns a fresh global consolidation lease.
68    SkippedRunning,
69}