Repository navigation
fix(codex): probe quota from backend-api /wham/usage - #466
Merged
caigee-cmd merged 1 commit intoNov 4, 2026
Merged
Conversation
The usage probe was built on ChatBase, which carries the /codex chat prefix: /backend-api/codex/wham/usage answers with the Cloudflare 403 interstitial, so every probe failed. Quota() swallowed that failure and returned the in-memory cache, which is only filled from chat response headers. An account already marked exhausted never runs a chat, so the stale snapshot stayed in place forever and SaveQuota kept the account at quota_exhausted. Probe /backend-api/wham/usage instead, and report a probe failure when no windows are cached so the sweep surfaces the real error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Client.Quotabuilds the usage probe onChatBase(https://chatgpt.com/backend-api/codex), so it requests/backend-api/codex/wham/usage. That path answers with the Cloudflare 403 interstitial, so every probe fails.Quotathen swallowed the failure and returned the in-memory cache, which is only filled from chat response headers.An account already marked
quota_exhaustednever gets routed a chat, so its headers are never observed again: the stale snapshot stays forever andSaveQuotakeeps re-writingquota_exhausted. Observed locally: a six-day-old snapshot (primary window 100%) while the real usage was 0% / 54%.Fix
https://chatgpt.com/backend-api/wham/usage(newUsageBaseconstant) instead of the chat-prefixed path. It returnsrate_limit.primary_window/secondary_window, whichquotaFromUsagealready parses.Verification
go build ./...,go vet ./internal/providers/codex/...,gofmtclean./codex/prefix; a probe failure with no cache returns an error; cached windows observed from chat survive a probe failure.quota_exhausted->ready, windows refreshed to 0% (5h) / 54% (7d) with a currentfetched_at, and a chat through it answered 200.中文
Quota把用量探测拼在了聊天前缀ChatBase上,请求/backend-api/codex/wham/usage,该路径返回 Cloudflare 403 拦截页;失败又被静默吞掉并退回只在聊天响应里填过的内存缓存。已被标成quota_exhausted的账号不会再有聊天流量,于是永远拿不到新数据,快照和状态一起卡死(本地实测卡了六天、真实用量 0%/54%)。改为探测
https://chatgpt.com/backend-api/wham/usage,并在没有缓存窗口时如实返回探测错误。已用真实账号验证:状态恢复 ready、窗口刷新为 0%/54%、对话 200。