Skip to content

fix(codex): keep local account cooldowns from quarantining combo targets - #7887

Merged
lidge-jun merged 3 commits into
devfrom
fix/7850-local-codex-cooldown
Oct 29, 2026
Merged

lidge-jun merged 3 commits into
devfrom
fix/7850-local-codex-cooldown

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Refs #7850 (the compaction combo cooldown follow-up in this comment). The broader quota-safe compaction proposal in that issue stays open.

When a Codex pool account is cooling down, OpenCodex refuses the request locally with HTTP 429 and a Retry-After equal to that account's remaining cooldown, often hours. Inside a combo, that refusal happens before any serving account is attributed. The combo therefore recorded it as an explicit upstream delay, up to 24 hours, against the whole target. After the account recovered, direct requests worked, but the combo (for example a compactionRouting combo) kept reporting No available targets with a cooldown like 84692s.

This PR marks the ordinary local account-cooldown response with process-local provenance (a WeakSet<Response>; no header or body copy can mint it). The mark is minted in mapCodexAuthContextErrorToResponse, the mapping every combo child's local auth refusal goes through. The response-lifetime wrappers in core-lifetime.ts (including the account-lease wrapper retained compaction delivers through) and combo failure reconstruction carry it, and combo target-cooldown recording ignores the restated Retry-After and reset for marked responses. Those targets fall back to the existing capped local backoff (60 s default, 10 min ceiling), the same treatment Anthropic pool-local refusals already get.

Unchanged: the response and Retry-After the client receives, account cooldown/quota/probe state, and genuine upstream Retry-After (still honored up to 24 h). Main hard-lock, credit-off, Reserve, recovery-withheld and any future subclasses are excluded by exact-class check and keep their current behavior. When every account is cooling, the next attempt after the local backoff is another local refusal with no upstream send.

Verification

Focused files ran with OCX_TEST_NO_QUEUE=1 because the host's shared test queue was saturated by other lanes.

Check Result
New recovery regression in tests/server/server-combo-cooldown-recording.test.ts without the fix fails: target still cooled at 600,000 ms after account recovery
Provenance and recovery tests without the mapper mint 16 pass, 2 fail
Retained-compaction lease regression without the core-lifetime.ts carry 0 pass, 1 fail
server-combo-cooldown-recording, combo-cooldown-reprobe, reasoning-retention-v2, translator-budget-lifetime, request-log-nonstream, file-size-ratchet 134 pass, 0 fail
Same file with controls (copied-header forgery, upstream 24 h ceiling, hard-lock and policy exclusions) pass
Independent review rerun, eight related files 399 pass, 0 fail
Review probes: compact v1 and automatic v2 compaction both reach the fixed combo path; all-exhausted pool makes zero upstream sends 3 pass, 0 fail
bun run typecheck, bun run structure:check, bun run privacy:scan, git diff --check pass
Independent correctness/security reviews R1 PASS; R2 MUSTFIX 1 (retained compaction lease wrapper dropped the mark), fixed; R3 PASS, 0 blocking, with an inventory of every Response re-wrapper on the combo child path

Structure docs updated: structure/runtime.md, structure/providers/openai-accounts.md, structure/transports/responses-failover.md.

Hosted PR CI on head 49e5822e5 passed (27 checks, including gates and test changed). The first head failed the file-size ratchet because src/codex/auth-context.ts grew past 2,000 lines; moving the mint to the mapper left that file byte-identical to dev. That run also timed out tests/responses/ws-native-steering.test.ts at 5,012 ms; it passed locally in 1.5 s and on both later heads.

Not run locally: full bun run test and bun run test:changed (saturated host), and a live provider, pacing/Reserve or Desktop reproduction of the reporter's incident.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of local account cooldowns during failover: repeated retry and reset timing details are no longer carried to subsequent targets, and local backoff is capped.
    • Preserved cooldown identification across response processing so local cooldowns are distinguished from upstream responses with similar content.
    • Policy-based refusals retain their existing status and response details.
  • Documentation
    • Updated guidance on cooldown behavior, failover, and retry timing.

Carry process-local Response provenance for ordinary account cooldown refusals
through combo failure reconstruction. Use capped local target backoff without
changing client retry advice or account admission and policy state.

Keep upstream retry directives and all policy subclasses unchanged; cover
account recovery, wire-copy forgery, the 24-hour ceiling and hard-lock behavior.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between fdc6dd8 and 49e5822.

Files selected for processing: 9
  • src/codex/account-cooldown-response.ts
  • src/server/responses/codex-auth-error.ts
  • src/server/responses/core-combo-failure.ts
  • src/server/responses/core-combo.ts
  • src/server/responses/core-lifetime.ts
  • structure/providers/openai-accounts.md
  • structure/runtime.md
  • structure/transports/responses-failover.md
  • tests/server/server-combo-cooldown-recording.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Walkthrough

Local Codex account-cooldown responses now carry process-local provenance through response reconstruction and lease wrapping. Combo target cooldown recording uses that provenance to omit repeated retry and reset metadata. Tests cover local and upstream responses, response wrapping, and cooldown-policy subclasses.

Changes: Codex cooldown handling

Layer / File(s) Summary
Mark and preserve local cooldown provenance
src/codex/account-cooldown-response.ts, src/server/responses/codex-auth-error.ts, src/server/responses/core-combo-failure.ts, src/server/responses/core-lifetime.ts, tests/server/server-combo-cooldown-recording.test.ts
Exact CodexAccountCooldownError instances mark their responses. Combo failure reconstruction and lifetime wrappers carry the marker. Tests check that consumption and lease wrapping preserve it, copied response content does not, and cooldown subclasses remain unmarked.
Record combo target cooldowns
src/server/responses/core-combo.ts, tests/server/server-combo-cooldown-recording.test.ts, structure/providers/openai-accounts.md, structure/runtime.md, structure/transports/responses-failover.md
Combo target recording omits retryAfter and resetAt for marked local cooldown responses. Tests verify local cooldown backoff, upstream retry limits, and recovery after account health is cleared. The documentation describes this handling and its exclusions.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • Issue 7587: The change prevents a local Codex cooldown from applying retry and reset values to a combo target. The broader Desktop compatibility and consent design remains outside this change.
  • Issue 7850: The change alters combo cooldown handling for marked local Codex cooldowns, but does not implement the proposed compaction recovery user experience.

Suggested reviewers: luvs01

Merge Risk: Minimal · up to 49e58

Local cooldowns use capped target backoff without changing client retry advice. No merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing local Codex account cooldowns from quarantining combo targets.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 6 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 28, 2026
…r mapper

Move the exact-class provenance mark from cooldownErrorResponse into
mapCodexAuthContextErrorToResponse, the single mapping every combo child's local
auth refusal goes through. This keeps src/codex/auth-context.ts at its 1999-line
size, below the 2000-line file-size ratchet threshold, and the tests now mint the
refusal through that mapper.
…wrappers

Retained compaction v2 delivers each child response through finalizeAccountLease,
which re-creates the Response and dropped the process-local cooldown mark, so a
late local refusal could again record the account's long Retry-After against the
combo target. Carry the mark in both core-lifetime wrappers and cover the lease
boundary with a regression.
@lidge-jun
lidge-jun marked this pull request as ready for review October 28, 2026 08:44
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 28, 2026 08:44
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-28T08:44:47.043774Z 49e5822 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant