feat(metrics): surface turn-level spend on turn_metrics and /v1/admin/metrics - #645
Open
yzxcj797 wants to merge 1 commit into
Open
feat(metrics): surface turn-level spend on turn_metrics and /v1/admin/metrics#645yzxcj797 wants to merge 1 commit into
yzxcj797 wants to merge 1 commit into
Conversation
…/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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #586's second half: the budget now debits the
LlmCallUsagethe harnesses meter (#592, #638), but an operator planning which models to run qm on still has to join spend out ofsession_llm_requestsby hand —turn_metricscarried the cache columns and no cost, no output tokens. This lands turn-level spend where the rest of the turn telemetry already lives.Implementation
costUsage { outputTokens, costUsd }alongside the existingcacheUsage:sumCostUsagenext tosumCacheUsage, both return sites);total_cost_usddelta withusageTotals.output; thefinalResultfallback branch keeps output tokens but reports cost0— the SDK result carries no cost total, andturnsWithKnownCostdistinguishes that downstream;TurnMetricSample;turn_metricsgrowsoutput_tokens BIGINTandcost_usd DOUBLE PRECISIONvia the sink'sALTER TABLE ADD COLUMN IF NOT EXISTSmigration, so existing deployments migrate in place.GET /v1/admin/metricsreturns aspendblock:samples,turnsWithKnownCost,costUsdTotal,outputTokensTotal— the scope-level number an operator plans against, next to the existingcacheblock.Testing
test/turn-metrics-cost.test.tsdrives a mock-harness turn through the full app and asserts the spend block on the metrics endpoint, plus the empty-scope shape. Differential: both tests fail with the source changes stashed (nospendblock).tsc --noEmitclean.Follow-up to #586
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.