serve: a CLI-harness run's cost is its booked model requests #2303
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.53) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.53 · 516 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.374
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #2303"
general
weight: 0.35
greptile-apps[bot]
Fixes #2275.
Why
A run on a CLI harness (claude-agent, codex) booked no cost. Its model requests are booked: the model proxy writes
runner.requestandrunner.turnrecords with their dollars into the run's session. But the run's end and its view both ignored those records. The result:/v2/usageread $0 or unknown;/v2/statsleft the spend out, so a spend cap reading stats couldn't see it.The learning bench saw every claude-agent run at $0.
What
runner/metrics.ts:bookedSpend(entries, "model" | "paid")sums the booking records. That's every model session's requests atbookedUsd, elseusd, or the paid-tool session's charges. A request with no known cost makes the sum null and keeps its known part.runner/cli-run-spec.ts: the CLI run's end prices the run at its model bookings plus its paid calls. Before, it usedrunMetricsover the CLI record's entries, which carry no per-request cost and so gave $0.store-reads/journal.ts: a CLI run's timeline gets its usage row in the booking's words ("Cost" or "Cost so far", the requests and paid calls), instead of having that row dropped.Before / After
| A claude-agent or codex run | Before | After |
|---|---|---|
| Run row cost (
/v2/stats, caps) | paid calls only; model spend $0 | model bookings + paid calls || Run view and Timeline usage row | none; cost read unknown | one usage row priced at the bookings |
| A request whose cost is unknown | (n/a) | the sum reads null (unknown), never $0 |
Evidence
runner-cli-web-tools.test.mjs: one new test per CLI wire, through a real runner on the faux harness and faux gateway, "a <claude-agent|codex> run's model requests are its cost: the booking's records, one usage row priced at them, and the run row and its view priced the same". Red on main: no usage row. Green on both wires.store-cli-record: the "a CLI run drops the usage row" assertion now expects the booking's row.runTimeline, the CLI spec,runner/metrics,viewOverStoreorstore-reads/journal: 430 pass, 0 fail, 31 skipped (existing skips).Prior art
LiteLLM's proxy and OpenRouter both price a request from the gateway's own usage record, not from what the client reports. Here, the session proxy's booking is the record of truth for a CLI harness, whose own transcript carries no cost.
Test plan
verify+lean.Upgrading: nothing to do. Runs that ended before the upgrade keep their stored cost; their Timeline and view now show the booking's usage row.
ACCEPT_IDENTITY=13 on push: every hit is the sandbox vendor name "Modal" in other changes' commit messages from main.
🤖 Generated with Claude Code
<!-- codesmith:footer -->
---
<a href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796946848&installation_model_id=431113&pr_number=2303&ref=codesmith_pr_footer&repository=Parcha-ai%2Fagentrun&return_to=https%3A%2F%2Fgithub.com%2FParcha-ai%2Fagentrun%2Fpull%2F2303&signature=16f1a87afcaedaae634aaa028151db26cc28f5506c1f070d98aacc942b32a719"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img alt="Autofix with [code]smith" src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png" width="190" height="28"></picture></a>
<sup><a href="https://app.blacksmith.sh/Parcha-ai/codesmith/agentrun/pr/2303?autoLogin=true&ref=codesmith_pr_footer">Open in [code]smith</a> · Need help on this PR? Tag <code>@codesmith-bot</code> with what you need.</sup>
<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->