Skip to content

fix(codex): throttle repeated failed pool quota primes (rebase of #3003) - #3185

Merged
lidge-jun merged 4 commits into
devfrom
codex/3003-quota-prime-throttle
Sep 1, 2026
Merged

fix(codex): throttle repeated failed pool quota primes (rebase of #3003)#3185
lidge-jun merged 4 commits into
devfrom
codex/3003-quota-prime-throttle

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

Maintainer rebase of #3003 by @luvs01 onto current dev — all three commits cherry-picked with author credit preserved, no conflicts — plus the outstanding review fix applied.

Throttles repeated failed pool quota primes so an unreachable or rejecting account cannot turn every prime trigger into another upstream request. A failed attempt is retried once per POOL_CACHE_TTL window, and a newer credential invalidates the previous failure so a re-authenticated account retries immediately.

The review finding, fixed rather than deferred

CodeRabbit left one unresolved thread on src/codex/auth-api.ts, and it was correct:

Prune removed-account attempts before the provider eligibility return. "If an account is removed while the provider is disabled or its mode is not pool, its failed-attempt marker remains. If the same account and credential are restored before POOL_CACHE_TTL expires, the next enabled prime treats the old failure as current and skips the required retry."

The branch already pruned stale markers, but the prune sat after the provider-eligibility early return, so a removal during a disabled window never reached it. Moved ahead of the return.

The existing test covered removal with the provider enabled, which is why this survived review. Added the case the reviewer actually described:

removal purges the backoff even while the provider is disabled — fail a prime to record the marker, remove the account while the provider is disabled, then restore both inside the TTL window and assert the prime dispatches instead of reading the stale failure as current.

Verification

Exact head:

  • bun test ./tests/codex-quota-prime.test.ts22 pass, 0 fail, 81 expect() calls.
  • Red-green verified. Moving the prune back after the early return turns the new case red (21 pass / 1 fail); restoring it returns green. The regression genuinely covers the defect rather than passing vacuously.

Full-suite and typecheck coverage is left to CI on this exact head.

Checklist

  • Targets dev
  • Author credit preserved across all three carried commits
  • The outstanding review finding is fixed on this head, not deferred, with the requested regression
  • Red-green proof recorded
  • No credential storage, OAuth flow, workflow, or release-automation change — this is quota-probe scheduling

luvs01 and others added 4 commits September 2, 2026 02:24
A pool account whose WHAM lookup fails stores no quota, so it stays "unknown"
and every later prime trigger re-selects it as stale and repeats the same
failing request. Successful lookups are already bounded by POOL_CACHE_TTL;
failures had no backoff at all.

Record the last prime attempt per account and give a failed lookup the same
TTL window. The record is keyed by credential generation, so a
re-authentication, refresh, or account removal retries immediately instead of
waiting out a backoff earned by the previous credential.
…y return

The prune sat after the provider-eligibility early return, so an account removed
while the provider was disabled kept its failed-attempt marker. Restoring the
same id inside POOL_CACHE_TTL then read that stale failure as current and
skipped the retry the restored credential was entitled to.

The existing coverage removed an account with the provider enabled, which is why
this survived review. Add the disabled-window case.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 1, 2026 17:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

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 Completed 2026-09-01T17:29:16.876394Z 8010119 PR opened
ℹ️ 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.

@lidge-jun
lidge-jun merged commit fe766e1 into dev Sep 1, 2026
6 checks passed
@github-actions github-actions Bot added the bug Something isn't working label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@lidge-jun
lidge-jun deleted the codex/3003-quota-prime-throttle branch September 1, 2026 17:25

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

Copy link
Copy Markdown

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: 80101192ba

ℹ️ 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 src/codex/auth-api.ts
Comment on lines 1403 to +1404
const q = getAccountQuota(a.id);
return !q || Date.now() - q.updatedAt >= POOL_CACHE_TTL;
if (q) return Date.now() - q.updatedAt >= POOL_CACHE_TTL;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply failure backoff to stale cached quotas

In src/codex/auth-api.ts, when an account already has a quota older than POOL_CACHE_TTL, this branch selects it solely from q.updatedAt and never checks poolQuotaPrimeAttemptedAt. If its refresh then receives a 503, transport error, or unusable response, the old quota remains stale, so every subsequent prime trigger dispatches another WHAM request despite the newly recorded attempt. Apply the matching-generation attempt timestamp to stale cached accounts as well, rather than consulting it only when q is null.

Useful? React with 👍 / 👎.

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.

2 participants