Skip to content

feat: trigger memories from user turns with cooldown#19970

Merged
jif-oai merged 6 commits intomainfrom
jif/memories-turn-start
Apr 28, 2026
Merged

feat: trigger memories from user turns with cooldown#19970
jif-oai merged 6 commits intomainfrom
jif/memories-turn-start

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented Apr 28, 2026

Why

Memory startup was tied to thread lifecycle events such as create, load, and fork. That can run memory work before a thread receives real user input, and it makes startup cost scale with thread management instead of actual turns. Moving the trigger to thread/sendInput keeps memory startup aligned with the first real user turn and lets it use the current thread config at turn time.

The idea is to prevent ghost cost due to pre-warm triggered by the app

Turn-based startup can also make global phase-2 consolidation easier to request repeatedly, so this adds a success cooldown and tightens the default startup scan window.

What Changed

  • Start codex_memories_write::start_memories_startup_task after a non-empty thread/sendInput turn is submitted, instead of from thread create/load/fork paths:
    if turn_has_input {
    let config_snapshot = thread.config_snapshot().await;
    codex_memories_write::start_memories_startup_task(
    Arc::clone(&self.thread_manager),
    Arc::clone(&self.auth_manager),
    thread_id,
    Arc::clone(&thread),
    thread.config().await,
    &config_snapshot.session_source,
    );
    }
  • Expose CodexThread::config() so app-server can pass the live config into memory startup at turn time.
  • Add a six-hour successful-run cooldown for global phase-2 consolidation via SkippedCooldown:
    if status == "done" && finished_at.is_some_and(|finished_at| finished_at > cooldown_cutoff)
    {
    tx.commit().await?;
    return Ok(Phase2JobClaimOutcome::SkippedCooldown);
  • Reduce memory startup defaults to at most 2 rollouts over 10 days:
    pub const DEFAULT_OTEL_ENVIRONMENT: &str = "dev";
    pub const DEFAULT_MEMORIES_MAX_ROLLOUTS_PER_STARTUP: usize = 2;
    pub const DEFAULT_MEMORIES_MAX_ROLLOUT_AGE_DAYS: i64 = 10;
    pub const DEFAULT_MEMORIES_MIN_ROLLOUT_IDLE_HOURS: i64 = 6;

Verification

Updated the memory runtime coverage around phase-2 reclaim behavior, including phase2_global_lock_respects_success_cooldown.

@jif-oai jif-oai requested a review from a team as a code owner April 28, 2026 11:47
@jif-oai jif-oai changed the title feat: trigger memories at first turn Start memories only on first root turn Apr 28, 2026
@jif-oai jif-oai changed the title Start memories only on first root turn feat: trigger memories at first turn Apr 28, 2026
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Apr 28, 2026

@codex review

Co-authored-by: Codex <noreply@openai.com>
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6a051a98b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/app-server/src/codex_message_processor.rs Outdated
Comment thread codex-rs/app-server/src/codex_message_processor.rs Outdated
@jif-oai jif-oai changed the title feat: trigger memories at first turn [do not merge]feat: trigger memories at first turn Apr 28, 2026
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Apr 28, 2026

@codex review

@jif-oai jif-oai changed the title [do not merge]feat: trigger memories at first turn feat: trigger memories based on turns instead of threads Apr 28, 2026
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c75cb9386f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/app-server/src/codex_message_processor.rs
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Apr 28, 2026

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1592afbb03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/app-server/src/codex_message_processor.rs
Comment thread codex-rs/app-server/src/codex_message_processor.rs
@jif-oai jif-oai changed the title feat: trigger memories based on turns instead of threads feat: trigger memories from user turns with cooldown Apr 28, 2026
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Apr 28, 2026

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4a6885b78

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/app-server/src/codex_message_processor.rs
Comment thread codex-rs/app-server/src/codex_message_processor.rs
Comment thread codex-rs/state/src/runtime/memories.rs Outdated
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Apr 28, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jif-oai jif-oai merged commit a9e5c34 into main Apr 28, 2026
24 of 25 checks passed
@jif-oai jif-oai deleted the jif/memories-turn-start branch April 28, 2026 14:23
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant