Surface the credit budget wham/usage already reports - #160
Conversation
wham/usage carries a third exhaustion axis on its own clock: a credit budget with its own limit, usage and reset, independent of the two rate limit windows. normalizeWham read only rate_limit_reset_credits, so an account could sit healthy on both windows and still be refused with nothing on any surface to explain it. The numeric fields arrive as strings and both spend_control and its individual_limit are nullable, so every field is parsed defensively and the whole reading stays optional — an account without spend controls produces exactly the snapshot it did before.
|
Merged as The framing that sold it is the risk running opposite to the feature: most accounts have no spend control, so this shows for a few while a rendering regression would hit everyone. Pinning that with exact-match assertions on the projected rows, rather than checking a value is undefined, is the form that actually catches it — and I confirmed by mutation rather than taking it on trust. Making the bar unconditional reddens four, including three window-projection tests with nothing to do with this feature, which is exactly the blast radius the assertion shape is there to expose. The three parsing traps are worth keeping in the record, because each is silently wrong rather than loudly wrong: numbers arriving as strings, On what you left out: agreed on both, and the routing one is the interesting half. Sticky placement weighs window pressure only, so it will currently favour an account with 1% of its credit budget left over one at 60% of its 5-hour window — and
Gate on the merge: core 147, opencode 1372, pi 14, typecheck and biome clean. |
Closes #158.
wham/usagereturns a credit budget with its own limit, usage and reset clock.normalizeWhamread onlyrate_limit_reset_credits.available_countand dropped the rest, so nothing — sidebar,/openai-quota, quota manager — could see it.Why it is a third axis, not a missing field
Live probe against a
team-plan account:That account was at 0% on its 5-hour window and 51% on its 7-day window while 20% through a credit budget resetting a month out — a clock unrelated to either rate-limit window. An account can therefore be healthy on both bars we render and still be refused, which today surfaces as an unexplained failure on an account showing headroom.
What this adds
normalizeWhamparsesspend_control.individual_limitand thecreditsbooleans into an optional reading onOAuthQuotaSnapshot, reusing the existingtoResetIsocoercionQuotaManagerand sidebar state on the same plumbing asprimary/secondary/openai-quotashows a credit-budget line when present, omits it entirely when absentParsing
Three things from the probe that a reasonable implementation would get wrong:
"2500","501.7787666320801"), not numbersspend_controlandindividual_limitare independently nullablecredits.balanceisnullwhilehas_creditsistrue— no balance does not mean no creditsEvery field is parsed defensively and the whole reading stays optional.
The regression that mattered
Most accounts have no spend control, so the feature shows for a few while a rendering regression would hit everyone. That case is pinned by an exact-match assertion on the projected rows — primary and secondary only, plus an explicit assertion that no spend-control row exists — rather than by checking the value is undefined.
I verified it by mutation rather than taking it on trust: making the bar unconditional reddens three tests, including two pre-existing window-projection tests that have nothing to do with this feature.
Deliberately not in this PR
Routing. Sticky-balanced placement weighs window pressure only, so it will currently send cold sessions to an account with 1% of its credit budget left, and
spend_control.reachedis the boolean that flips when the budget is gone. Wiring that in changes placement behaviour rather than display and wants its own review — happy to follow up.model_usage.credits_would_enable(per-model availability gated behind buying credits) is also left alone, though it is directly relevant togpt-6-astrabeing in the allow-list.Gates from the repo root:
build,format:check(157 files),lint(157 files),types(3 projects),test— 147 core + 1367 OpenCode + 14 Pi.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Surfaces the credit budget
wham/usagealready reports, so accounts no longer look healthy on both rate-limit windows while spend controls are close to refusing traffic. PreviouslynormalizeWhamkept only reset-credit counts and dropped the budget; now it reaches the sidebar as a third bar and/openai-quotaas a credit line. Closes #158.New Features
spend_control,individual_limit, andcredits.balancecan benull.model_usage.credits_would_enableis left untouched.Written for commit 87cdca9. Summary will update on new commits.