Skip to content

feat(admin): show turn spend beside cache health in the metrics viewer - #647

Closed
yzxcj797 wants to merge 2 commits into
yc-software:mainfrom
yzxcj797:feat/spend-viewer-586f
Closed

feat(admin): show turn spend beside cache health in the metrics viewer#647
yzxcj797 wants to merge 2 commits into
yc-software:mainfrom
yzxcj797:feat/spend-viewer-586f

Conversation

@yzxcj797

@yzxcj797 yzxcj797 commented Aug 21, 2026

Copy link
Copy Markdown

Summary

Completes #645's surface: the metrics endpoint grew a spend block, but the admin viewer still showed only the cache line — an operator opening the page could not see what the scope spends.

Implementation

renderSpend adds one statline directly under cache health on the metrics page: model spend as currency (fmtUsd), turns with known cost, and summed output tokens — same statline/fmtTokens vocabulary as its neighbour, same empty-scope vanishing behaviour.

Stacked on #645 (the spend data lands there) — merge order: #645 first.

Testing

  • New viewer contract test asserts the renderer exists, renders beside cache health, and formats both totals; CRLF-normalized so the check is line-ending agnostic. Differential: fails with the viewer change stashed.
  • tsc --noEmit clean against the stacked base.

Follow-up to #586


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…/metrics

The budget now debits the LlmCallUsage the harnesses meter, but an
operator planning which models to run qm on still had to join spend out
of session_llm_requests by hand: turn_metrics carried the cache columns
and no cost, no output tokens.

Harness turn results gain costUsage {outputTokens, costUsd} alongside
cacheUsage -- pi sums its per-call stats, claude reports the SDK's
running cost total with the fallback branch flagging unknown cost, and
the mock harness reports its deterministic usage. The orchestrator
lands both on TurnMetricSample, turn_metrics grows output_tokens and
cost_usd (ALTER TABLE ADD COLUMN IF NOT EXISTS, so existing deployments
migrate in place), and /v1/admin/metrics returns a spend block:
samples, turnsWithKnownCost, costUsdTotal, outputTokensTotal.

Follow-up to yc-software#586
The metrics endpoint grew a spend block, but the viewer still showed
only the cache line -- an operator opening the page still could not see
what the scope spends. renderSpend adds one statline under cache health:
model spend as currency, turns with known cost, and summed output
tokens, using the same fmtTokens/fmtPct vocabulary as its neighbour.
@time-attack

Copy link
Copy Markdown
Collaborator

Thanks for this, @yzxcj797 — and sorry for the slow response.

We're closing this PR. Per CONTRIBUTING.md, since coding agents write most of the underlying code now, we'd rather receive feature ideas as a short human-written note in adrs/ — informal is great, just the idea in your own words — and bugs as a plain issue. If we're aligned we're happy to burn our own tokens on the implementation, and we'll credit you as co-author.

We don't want your idea to get lost, so we've captured it in #755 to triage on our side. Please feel free to open an adrs/ note if you feel strongly about the approach. Appreciate you engaging with the repo!

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