Skip to content

feat(task): a run's usage summary as JSON, with the bound word its cost line prints - #914

Merged
earakely-scale merged 2 commits into
mainfrom
edgararakelyan/usage-summary-json
Nov 24, 2026
Merged

earakely-scale merged 2 commits into
mainfrom
edgararakelyan/usage-summary-json

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

summarize sums 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 in cli/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), a StrEnum, says what a cost figure is: exact, at_least, at_most, estimated or unpriced. Share.bound and UsageSummary.bound give it by the rule that was the CLI's:
    • unpriced when nothing was priced;
    • estimated when the figure is both a lower and an upper bound;
    • at_least when some usage was unpriced, partial or still running;
    • at_most when some cost was priced on an assumed rate;
    • exact otherwise.
  • UsageSummary.input_tokens and output_tokens: the shares' counts summed, None when no share counted them.
  • Share.to_dict() and UsageSummary.to_dict(attempts=True): plain JSON values. Every key is always there, and a figure nothing gave is null, never 0.
    • A share gives its role, model, cost, bound, token counts and its unpriced, assumed and partial flags.
    • The summary gives its cost, bound, token counts, attempts, sources and its shares in role order.
    • attempts=False gives attempts: null for a total over several runs, as cost_line(..., attempts=False) leaves the attempts out.
  • The CLI takes each word from bound (the value with a space for the underscore, none for exact). _cost keeps no rule of its own, and every line it prints is unchanged.
  • USED in .github/scripts/check_plugin_api.py lists summarize, UsageSummary, Share and Bound, 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:
    • every case also checks bound on the summary and on each share;
    • a new case pins to_dict() for a ledger with priced, unpriced, partial, running, assumed and harness-reported entries, checks that it round-trips through json.dumps, and that attempts=False gives null.
  • The cost-line checks in summary_test.py, tst/unit/bundle/run_test.py, tst/unit/cli/submit_runs_test.py and tst/integration/cli/run_usage_by_model_test.py pass without edits: 74 unit tests and the integration test.
  • Real ledgers: 300 recent runs' stored ledgers (1,140 entries) through summarize and to_dict:
    • every shape round-trips through JSON with all its keys;
    • a null cost goes with unpriced and nothing else;
    • the word the CLI prints matches bound on every summary.
      Those runs read at_least, unpriced and exact; at_most and estimated are 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 bound value means, as the CLI's words already do.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence 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.

  • Run usage summaries now share one JSON shape and cost label.

Reviews (2) · Last reviewed commit: "refactor(task): sum a summary's token co..." · Reviewed by Greptile

…st line prints

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 24, 2026 17:21
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit e387339 into main Nov 24, 2026
61 of 63 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/usage-summary-json branch November 24, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant