Skip to content

[codex] fix OpenAI Codex primary 5h quota reset#2980

Draft
anzhiyu-c wants to merge 1 commit into
Wei-Shaw:mainfrom
anzhiyu-c:codex/fix-openai-codex-primary-5h
Draft

[codex] fix OpenAI Codex primary 5h quota reset#2980
anzhiyu-c wants to merge 1 commit into
Wei-Shaw:mainfrom
anzhiyu-c:codex/fix-openai-codex-primary-5h

Conversation

@anzhiyu-c

@anzhiyu-c anzhiyu-c commented Jun 2, 2026

Copy link
Copy Markdown

Summary

  • Treat primary-window Codex 5h quota headers as used percent instead of inverting them as remaining percent.
  • Keep the legacy secondary-window 5h remaining-percent conversion.
  • Add regression cases for both an exhausted primary 5h window and an available primary 5h window (primary_used_percent=0).

Root cause

When OpenAI sends the 5h Codex limit in the primary quota window (x-codex-primary-window-minutes: 300), x-codex-primary-used-percent is already a used percentage. The previous normalization always calculated 100 - raw for the canonical 5h used percent, so a primary 5h value of 0 became 100. That can make an account with available 5h quota display as fully exhausted.

The same inversion also affects reset selection when primary=5h is exhausted, because the canonical 5h used percent may no longer reflect the actual upstream limit state.

Validation

  • go test -tags=unit ./internal/service -run 'TestCalculateOpenAI429ResetTime|TestOpenAIUpdateCodexUsageSnapshotFromHeaders|TestNormalizedCodexLimits'\n- go test -tags=unit ./internal/service

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@anzhiyu-c anzhiyu-c force-pushed the codex/fix-openai-codex-primary-5h branch from 4bc57bc to bfd2e35 Compare June 2, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant