Skip to content

fix: show Extra Usage Utilization before the month's first charge - #668

Open
eric-engberg wants to merge 2 commits into
sirmalloc:mainfrom
eric-engberg:fix/extra-usage-utilization-zero
Open

eric-engberg wants to merge 2 commits into
sirmalloc:mainfrom
eric-engberg:fix/extra-usage-utilization-zero

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

Extra Usage Utilization now shows 0.0% (and an empty bar) when extra usage is enabled but nothing has been charged yet this month. Before, it rendered nothing at all.

Why

Until the first extra-usage charge of the month, the usage API reports utilization: null while still reporting the monthly limit and the amount spent ($0):

"extra_usage": { "is_enabled": true, "monthly_limit": 5000, "used_credits": 0.0, "utilization": null, "currency": "USD" }

The widget treated the missing utilization as no data and rendered nothing. Extra Usage Used and Extra Usage Remaining showed $0.00 and the full limit next to it, so the empty slot looked broken on every account with extra usage turned on. This shows up on a Max account right after turning extra usage on, and the Enterprise response in usage-fetch.test.ts, which mirrors a real account, has the same shape.

How

When the API reports no utilization, the widget works it out from the amount spent and the monthly limit (spent 梅 limit 脳 100), the same ratio the API reports once there's a charge. The API's own value still wins whenever it's present. Without a monthly limit (or with a limit of 0) the widget renders nothing, as before (#413). No extra fetches: the spent and limit fields come in the same response and are already cached, and the existing rule that treats missing extra-usage detail fields as conclusive is unchanged.

Demo

The same line rendered from a fake usage cache (no login, no API call): first at $0 spent with no utilization from the API, then at $12.50 of a $50 limit, which is unchanged.

Powerline: before

Extra Usage widgets at $0 before the fix, Powerline mode

Powerline: after

Extra Usage widgets at $0 after the fix, Powerline mode

Plain: before

Extra Usage widgets at $0 before the fix, plain mode

Plain: after

Extra Usage widgets at $0 after the fix, plain mode

Testing

  • New tests: the utilization is derived at $0 and at $12.50 of $50; the API value wins over the derived one; no limit or a 0 limit still renders nothing.
  • On today's main (with docs: explain an empty status line in one folder (workspace trust)聽#606 and feat(git-is-fork): render forks as an editable glyph聽#617 merged in locally): bun test gives 2785 pass, 0 fail (Bun 1.4.2), and bun run lint passes.
  • The changed test file under Node (Vitest): 12 pass (9 existing and 3 new).
  • Built CLI under Bun 1.4.2 and Node 26.10.0 with a usage cache at $0 spent: all runtimes give identical output in plain and Powerline modes, and it differs from main only by the added Utilization output. The TUI opens and exits cleanly under both.
  • Piped render from a usage cache at $0 spent: main renders no Utilization widgets, this branch renders Overage: 0.0%. With an API-reported utilization the output is unchanged.

Until the first extra-usage charge of the month, the usage API reports
`utilization: null` alongside the monthly limit and the amount spent
($0). The widget treated the missing utilization as no data and
rendered nothing, so it looked broken on every account with extra
usage enabled until the first charge.

When the API reports no utilization, work it out from the amount spent
and the monthly limit. An API-reported value still wins, and accounts
without a monthly limit render nothing, as before.
# Conflicts:
#	src/widgets/ExtraUsageUtilization.ts
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