Repository navigation
feat(task): a run's usage summary as JSON, with the bound word its cost line prints - #914
Merged
Merged
Conversation
…st line prints Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
summarizesums a run's usage ledger by role and model, and the CLI prints it as one cost line per run. The word that says what the figure is (at least, at most, estimated, unpriced) came from a private rule incli/usage_output.py, and nothing gave the summary as data. So any other reader that shows a run's cost (a web page, an API field, an export) would have to copy the rule and pick its own field names. This gives the summary one JSON shape, with the CLI's word in it, so every reader shows the same figure and the same word.Change
Bound(task/usage/summary.py), aStrEnum, says what a cost figure is:exact,at_least,at_most,estimatedorunpriced.Share.boundandUsageSummary.boundgive it by the rule that was the CLI's:unpricedwhen nothing was priced;estimatedwhen the figure is both a lower and an upper bound;at_leastwhen some usage was unpriced, partial or still running;at_mostwhen some cost was priced on an assumed rate;exactotherwise.UsageSummary.input_tokensandoutput_tokens: the shares' counts summed, None when no share counted them.Share.to_dict()andUsageSummary.to_dict(attempts=True): plain JSON values. Every key is always there, and a figure nothing gave is null, never 0.unpriced,assumedandpartialflags.attempts=Falsegivesattempts: nullfor a total over several runs, ascost_line(..., attempts=False)leaves the attempts out.bound(the value with a space for the underscore, none forexact)._costkeeps no rule of its own, and every line it prints is unchanged.USEDin.github/scripts/check_plugin_api.pylistssummarize,UsageSummary,ShareandBound, since code outside the repo reads them; a later break needs a!title.AGENTS.md's ledger paragraph names the shape.{"cost_usd": 0.0007, "bound": "estimated", "input_tokens": 1500, "output_tokens": 15, "attempts": 2, "sources": ["harness", "litellm@1.80.0"], "shares": [ {"role": "solver", "model": "gpt-4.1-mini", "cost_usd": 0.0005, "bound": "estimated", "input_tokens": 1200, "output_tokens": 12, "unpriced": false, "assumed": true, "partial": true}, {"role": "judge", "model": "mystery-1", "cost_usd": null, "bound": "unpriced", "input_tokens": 300, "output_tokens": 3, "unpriced": true, "assumed": false, "partial": false}]}Testing
tst/unit/task/usage/summary_test.py:boundon the summary and on each share;to_dict()for a ledger with priced, unpriced, partial, running, assumed and harness-reported entries, checks that it round-trips throughjson.dumps, and thatattempts=Falsegives null.summary_test.py,tst/unit/bundle/run_test.py,tst/unit/cli/submit_runs_test.pyandtst/integration/cli/run_usage_by_model_test.pypass without edits: 74 unit tests and the integration test.summarizeandto_dict:unpricedand nothing else;boundon every summary.Those runs read
at_least,unpricedandexact;at_mostandestimatedare covered by the unit tests.check_plugin_api.py --base origin/main: no break to the plugin surface.Docs
The costs page should give this JSON shape and what each
boundvalue means, as the CLI's words already do.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge.Summary
The PR adds a shared JSON shape for run costs and makes the CLI read its cost label from
Bound.Reviews (2) · Last reviewed commit: "refactor(task): sum a summary's token co..." · Reviewed by Greptile