Skip to content

Show budget spend and threshold in ucode usage - #261

Open
andy-xu-db wants to merge 3 commits into
mainfrom
andy/update-ucode-usage
Open

Show budget spend and threshold in ucode usage#261
andy-xu-db wants to merge 3 commits into
mainfrom
andy/update-ucode-usage

Conversation

@andy-xu-db

@andy-xu-db andy-xu-db commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

ucode usage shows tokens only — no dollar spend or budget context.

Change

Add the caller's coding-agent budget spend and alert threshold to the ucode usage summary, read off AI Gateway's coding-agent-configs:recommendModel (posted with an empty available_models, since we want the spend the recommendation was based on, not the recommendation — recommended_models is ignored):

Budget spend: $2.34 of $5,000.00 (0%)
[█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░]

Amounts are parsed as Decimal. The endpoint is off by default per org, so absence returns a reason string rather than raising — the lines are simply omitted and the rest of the report is unchanged.

Testing

29 new unit tests; 1167 passed, ruff clean.

Verified against the live endpoint on a workspace with the flag on: current_spend 2.3441188 / effective_threshold 5000 renders as $2.34 of $5,000.00 (0%). A workspace with the flag off returns FEATURE_DISABLED and correctly renders no lines.

`ucode usage` reported tokens only, with no dollar figure. Surface the caller's
live coding-agent budget spend against its alert threshold, from the AI Gateway
`coding-agent-configs:resolveCurrentBudgetSpend` endpoint.

    Budget spend: $12.34 of $100.00 (12%)
    [███░░░░░░░░░░░░░░░░░░░░░░░░░░░]

- databricks.py: `resolve_current_budget_spend` POSTs an empty body (caller and
  workspace come from the bearer) and parses both amounts as `Decimal`. Absence
  is the common case — the endpoint is behind a per-org SAFE flag (default off),
  needs a coding-agent config, and returns both fields unset when no budget
  matches — so all of it comes back as a reason string, never an exception. A
  spend without a threshold counts as no spend, mirroring the server's
  `BudgetSpend.fromProto`.
- ui.py: `format_usd` (half-up to cents) and `format_meter` (clamped to [0, 1];
  a nonzero fraction fills at least one cell so a small real spend doesn't read
  as an empty bar).
- usage.py: `render_budget_lines` + a `budget_spend` arg on
  `render_usage_summary`. Unavailable spend omits the lines rather than failing
  the report; a zero threshold shows the bare amount, since there is no whole to
  be a fraction of.

Co-authored-by: Isaac
@andy-xu-db
andy-xu-db force-pushed the andy/update-ucode-usage branch from 55973b2 to 68d3b5b Compare August 3, 2026 22:32
@andy-xu-db
andy-xu-db marked this pull request as ready for review August 4, 2026 20:01
@andy-xu-db
andy-xu-db marked this pull request as draft August 4, 2026 21:04
@andy-xu-db
andy-xu-db marked this pull request as ready for review August 4, 2026 21:04
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