Skip to content

feat: skip memory startup when Codex rate limits are low#19990

Merged
jif-oai merged 4 commits intomainfrom
jif/rate-limits-memories
Apr 28, 2026
Merged

feat: skip memory startup when Codex rate limits are low#19990
jif-oai merged 4 commits intomainfrom
jif/rate-limits-memories

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

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

Why

Memory startup runs in the background after an eligible turn, but it can consume Codex backend quota at exactly the wrong time: when the user is already near a rate-limit boundary. This PR adds a guard so the memory pipeline backs off when the Codex rate-limit snapshot says the remaining budget is too low.

What Changed

  • Added memories.min_rate_limit_remaining_percent with a default of 25, clamped to 0..=100, and regenerated core/config.schema.json.
  • Added codex-rs/memories/write/src/guard.rs, which fetches Codex backend rate limits before memory startup and skips phase 1 / phase 2 when the Codex limit is reached or either tracked window is above the configured usage ceiling.
  • Keeps startup best-effort: non-Codex auth or rate-limit fetch/client failures preserve the existing memory startup behavior.
  • Records a codex.memory.startup counter with status=skipped_rate_limit when startup is skipped.
  • Added config parsing/clamping coverage and guard unit tests.

Verification

  • Added codex-rs/memories/write/src/guard_tests.rs for threshold, primary/secondary window, and reached-limit behavior.
  • Added config tests for TOML parsing and clamping.

@jif-oai jif-oai requested a review from a team as a code owner April 28, 2026 14:36
@jif-oai
Copy link
Copy Markdown
Collaborator Author

jif-oai commented Apr 28, 2026

@codex review

@jif-oai jif-oai changed the title feat: stop memories when rate limits become too low Skip memory startup when Codex rate limits are low Apr 28, 2026
@jif-oai jif-oai changed the title Skip memory startup when Codex rate limits are low feat: skip memory startup when Codex rate limits are low 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: 2edff1624b

ℹ️ 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/memories/write/src/start.rs
Comment thread codex-rs/memories/write/src/start.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

The pipeline is triggered when a root session starts, and only if:
- the session is not ephemeral
- the memory feature is enabled
- the session is not a sub-agent session
- the state DB is available
It runs asynchronously in the background and executes two phases in order: Phase 1, then Phase 2.

P2 Badge Update memories README startup conditions

Documented startup behavior is now stale: start.rs adds a rate-limit guard that can skip phase 1/2, but the README still states startup depends only on ephemeral/feature/sub-agent/state-DB checks and then runs both phases. This mismatch can mislead operators when memories.min_rate_limit_remaining_percent causes unexpected skips.

ℹ️ 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 1b74360 into main Apr 28, 2026
25 checks passed
@jif-oai jif-oai deleted the jif/rate-limits-memories branch April 28, 2026 15:07
@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