Skip to content

fix(codex): record a 402 account move as a quota recovery - #7231

Closed
vadymhimself wants to merge 2 commits into
lidge-jun:devfrom
vadymhimself:fix/followup-codex-402
Closed

vadymhimself wants to merge 2 commits into
lidge-jun:devfrom
vadymhimself:fix/followup-codex-402

Conversation

@vadymhimself

@vadymhimself vadymhimself commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • CodeRabbit on fix: carry OAuth combo cooldown, account rotation and health evidence fixes #7224 (core-codex-account.ts): a Codex pool 402 account move was recorded as oauth-account-429. causeForRecoveryKind maps that to rate-limit, so metrics counted a quota recovery as rate_limit, and the Logs page labelled it an OAuth 429.
  • Adds oauth-account-402, mapped to quota-exhausted and wired into the recovery roster, the cooldown set, the Logs.tsx label map and all locale catalogs. In failure-stage-model.test.ts, the invariant 'no recovery kind maps to a cause resending cannot fix' now exempts only this kind, with a comment saying why.

Follow-up to the batch-2 bundle (#7224/#7225), which landed at a head from before this review finding was fixed on the source PR. The same commit was offered on the bundle.

Verification

  • Red on dev 7a42860 with only the new tests: bun test tests/responses/responses-account-label.test.ts tests/lib/failure-stage-model.test.ts gives 24 pass, 2 fail (oauth-account-429 recorded).
  • Green: 37 pass, 0 fail. GUI tsc -b: clean.
  • Screenshot (synthetic log row, isolated test home): Logs page showing the Codex 402 recovery label
  • bun x tsc --noEmit: clean.
  • tests/test-layout.test.ts and tests/ci-workflows/file-size-ratchet.test.ts: pass.
  • GUI build (cd gui && bun run build, i.e. tsc -b && vite build) on 9ea4be7: exit 0, built clean; only the existing >500 kB chunk-size warning.
  • bun run structure:check: passed (structure/transports/responses.md now distinguishes oauth-account-402 quota recovery from oauth-account-429 rate-limit recovery).
  • Full suite not run locally; the change is confined to the files above and their focused tests.

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.

🤖 Generated with Claude Code

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Account quota exhaustion (HTTP 402) is now distinguished from rate limits when requests retry using another account, improving recovery reporting and cooldown tracking.
  • New Features
    • Request logs show a dedicated account-quota-exhausted recovery reason, translated into English, German, French, Japanese, Korean, Brazilian Portuguese, Russian, Turkish, Vietnamese, Simplified Chinese, and Traditional Chinese.

A Codex 402 move was recorded as oauth-account-429, so request metrics
counted it as rate_limit and the dashboard labelled it an OAuth 429.
Add oauth-account-402 mapped to quota-exhausted and wire it into the
cooldown set, the dashboard label map and all locale catalogs.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@vadymhimself

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 177170e8-0e86-444e-90e0-f1a0f8397bd8
📥 Commits

Reviewing files that changed from the base of the PR and between 455c30a and 9ea4be7.

📒 Files selected for processing: 1
  • structure/transports/responses.md

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

📝 Walkthrough

The recovery flow now identifies OAuth account quota exhaustion (402) separately from rate limits (429). The new recovery kind is included in failure and cooldown mappings, checked in request metrics, and displayed with localized log labels.

Changes: OAuth account recovery

Layer / File(s) Summary
Classify account quota exhaustion
src/usage/telemetry-contract.ts, src/server/responses/core-codex-account.ts, src/lib/request-failure-model.ts, tests/lib/failure-stage-model.test.ts, structure/transports/responses.md
The recovery-kind roster includes oauth-account-402. The response logic selects it for status 402, and the failure model maps it to quota-exhausted. The test now expects this recovery kind to map to a futile cause. The transport documentation describes the distinction between 402 and 429.
Track quota recovery
src/routing/analytics.ts, tests/responses/responses-account-label.test.ts
Cooldown analytics recognizes oauth-account-402. A response test checks attempt records and verifies that final metrics count one quota recovery and no rate-limit recoveries.
Display the recovery reason
gui/src/pages/Logs.tsx, gui/src/i18n/*.ts
The log recovery catalog maps oauth-account-402 to a localized key. Translation catalogs add labels for the account quota exhaustion reason.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 9ea4b

The change adds a separate recovery kind for 402 account moves and updates its documentation. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 18 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: recording HTTP 402 Codex account moves as quota recoveries.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 18 files. (1 skipped: 1 unsupported.)

Resolution

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • 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.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@lidge-jun

Copy link
Copy Markdown
Owner

Being carried into #7236 with your authorship preserved; this PR will be closed when the bundle lands.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions
github-actions Bot marked this pull request as draft October 16, 2026 09:02
lidge-jun added a commit that referenced this pull request Oct 16, 2026
#7230, #7231, #7232, #7233) (#7236)

Carries four vadymhimself follow-ups onto dev:

- #7230: the combo sibling check peeks the round-robin ring without advancing it, while the failed account's cooldown is still recorded.
- #7231: a Codex account move after a 402 is recorded as quota recovery, separate from 429 rate recovery, through persistence, metrics, analytics and Logs labels.
- #7232: the Anthropic server-tool input buffer is capped on the incoming fragment (4,096 code units), so one oversized fragment cannot exceed the bound.
- #7233: refused-then-served usage rows are priced from the served attempt, and client cancels keep an unknown cost. A usage-less refusal never changes a row's pricing classification. A row with a leading refusal summarizes exactly like the same row without it, under dev's existing partial-cost contract.

Co-authored-by: Vadym O <bolein95@gmail.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Landed on dev via #7236 in a02cecd, carried with Co-authored-by: Vadym O bolein95@gmail.com. That bundle is reviewed and validated (lidge full suite with 0 new failures, mini Windows focused 48/48, hosted CI green). #7233's pricing kept dev's existing partial-cost contract and pins refusal invariance. Details are on #7236. Thank you, @vadymhimself. Closing this one as superseded by that landing.

@lidge-jun lidge-jun closed this Oct 16, 2026
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