Files
magpie/docs
yetone 8bf9cb99d4 codex: an account with bought credits goes on on them, heard as Codex hears them
123xtv03k on X (v0.1.4233): Codex alone goes on on an account's bought
credits once its plan is used up; through magpie the account stopped.

Codex itself sends no opt-in for credits. It reads
x-codex-credits-has-credits, -unlimited and -balance from every reply,
the 429 included, and `credits` on the codex.rate_limits event
(parse_credits_snapshot; both bools required). magpie knew of credits
only from /wham/usage, read about once a minute, so the 429 that used a
window up was taken as out, and the rest lasted till the window renewed.

- heardCodexCredits reads the headers on every Codex reply (routed and
  the relay's 429), codexEventCredits the event; an image limit's are
  left out. provider.NoteCodexCredits marks the account's windows and
  allowance on credits and clears Held, so Usage doesn't call it out.
- A rest taken for a used-up window before the credits were known is
  lifted once they are, heard or read (provider.OnCredits, creditsKnown),
  only when the account's "Use credits" is on.
- The relay's hold for an account on credits refused twice is at most
  fallbackCooldown (1 minute), like the routed path's, not till reset.
- No header or flag is sent that Codex doesn't send.

Run (mote, at this head rebased on b466aa280; 79b10c5a9 since touches only LESSONS.md): go vet for darwin, linux
and windows of internal/provider and internal/gateway; go test -count=1
-timeout 45m ./internal/provider ./internal/gateway: ok (provider 137s, gateway 907s). gofmt -l
clean.
Broken by hand: without the heardCodexCredits calls, the OnCredits
registration and the hold clamp, every new gateway subtest but "says
none" goes red.
Not tried: a real account holding credits (the owner's hold none). The
Usage card's balance text still comes from /wham/usage only.
2026-11-15 13:28:34 +08:00
..