Skip to content

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

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

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.
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