Skip to content

fix(codex): probe quota from backend-api /wham/usage - #466

Merged
caigee-cmd merged 1 commit into
caigee-cmd:mainfrom
yoruuuchan:fix/codex-quota-usage-endpoint
Nov 4, 2026
Merged

caigee-cmd merged 1 commit into
caigee-cmd:mainfrom
yoruuuchan:fix/codex-quota-usage-endpoint

Conversation

@yoruuuchan

Copy link
Copy Markdown
Contributor

Problem

Client.Quota builds the usage probe on ChatBase (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. Quota then swallowed the failure and returned the in-memory cache, which is only filled from chat response headers.

An account already marked quota_exhausted never gets routed a chat, so its headers are never observed again: the stale snapshot stays forever and SaveQuota keeps re-writing quota_exhausted. Observed locally: a six-day-old snapshot (primary window 100%) while the real usage was 0% / 54%.

Fix

  • Probe https://chatgpt.com/backend-api/wham/usage (new UsageBase constant) instead of the chat-prefixed path. It returns rate_limit.primary_window / secondary_window, which quotaFromUsage already parses.
  • Return the probe error when no windows are cached, so a failing probe is visible in the maintenance sweep instead of looking like "no data".

Verification

  • go build ./..., go vet ./internal/providers/codex/..., gofmt clean.
  • New tests: probe hits the backend-api root and not the /codex/ prefix; a probe failure with no cache returns an error; cached windows observed from chat survive a probe failure.
  • Live: the stuck account flipped quota_exhausted -> ready, windows refreshed to 0% (5h) / 54% (7d) with a current fetched_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。

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.
@caigee-cmd
caigee-cmd merged commit 391c889 into caigee-cmd:main Nov 4, 2026
6 checks passed
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.

2 participants