feat(codex): surface turn-level cache and spend telemetry - #646
Open
yzxcj797 wants to merge 3 commits into
Open
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
codex accumulated full per-thread usage live but its turn result carried none of it, so codex turns landed in turn_metrics without the cache or spend telemetry pi and claude already report. The turn result now maps the same thread totals the recordLlmRequest flush uses, through one pure usageToTurnTelemetry helper: cacheUsage (cacheRead/cacheWrite/uncachedInput) and costUsage (outputTokens, costUsd). The codex SDK reports no cost, so costUsd stays 0 -- the same value already persisted to session_llm_requests for these calls. opencode still reports no turn telemetry: its usage is only fetched in the post-return flush, so wiring it needs a restructure noted for follow-up. Follow-up to yc-software#586
The mapping is harness-agnostic; the next harness to report turn telemetry imports it from the module that owns the result shape.
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 #645: codex accumulated full per-thread usage live (
usageByThread, the same totals itsrecordLlmRequestflush reports) but its turn result carried none of it, so codex turns landed inturn_metricswithout the cache or spend telemetry pi and claude already report.Implementation
The turn result maps the summed thread totals through one pure
usageToTurnTelemetryhelper:cacheUsage(cacheRead/cacheWrite/uncachedInput) andcostUsage(outputTokens, costUsd). The codex SDK reports no cost, socostUsdstays0— the same value already persisted tosession_llm_requestsfor these calls, and consistent with #645's claude fallback convention.Stacked on #645 (the
costUsageturn-result field andturn_metricscolumns land there) — rebase or merge order: #645 first.opencode still reports no turn telemetry: its usage is only fetched in the post-return flush, so wiring it needs a small restructure — noted for follow-up rather than smuggled into this change.
Testing
usageToTurnTelemetry): totals → cache + spend shape,nullfor a no-usage turn. Green.outputTokens/cachedInputTokensin its final token-usage notification and asserts both telemetry fields on the turn result (passes where the fake-binary harness tests run; the 9 fake-binary tests fail identically with and without this change on this Windows host —spawnof a shebang script — so the stash differential for them is inconclusive locally).tsc --noEmitclean against the stacked base.Follow-up to #586
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.