Repository navigation
feat(#1527): cost per run where a user looks — one line in the run summary, cost in the run log and sequant logs, from the metrics record, labelled "SDK estimate" - #1597
Merged
admarble merged 7 commits intoOct 27, 2026
Conversation
One total computed before the log is written; summary, log and metrics share it. Labelled SDK estimate; absent reads cost unrecorded. Entire-Checkpoint: 705275ea0e04
…y snapshots and the worktree-anchor gate region Entire-Checkpoint: 9bcde7444a9d
…rity test for log vs metrics; RunResult JSDoc back in place QA follow-ups on PR #1597. The MCP logs tool names log.cost in its field-by-field JSON. toRunCost is the one derivation of the run log's cost block from collectUsage's totals, and the signal-path finalizer takes the cost of the issues that had finished through the lazily read orchestrator ref. The parity test pins that the log's cost equals the metrics record's costUSD and tokensUsed, and that the hook-file fallback is read once for both. Entire-Checkpoint: f21a3dab0b5b
…ary as in sequant logs; abort-path cost test; MCP description names the estimate The summary printed the SDK-estimate caveat under cost unrecorded, where there is no figure to qualify, while sequant logs printed it only under a figure. Both now gate it on a recorded cost; the two NonTTY snapshots lose that line. The shutdown wiring test covers the signal-path cost through the lazily read orchestrator ref, and the sequant_logs tool description says what its cost field is. Entire-Checkpoint: e2b8c7c2a17a
…-cost-per-run-where-a-user-looks-one-line-
…oo; parallel is the default QA 2 on PR #1597: executeSequential pushed into completed and executeParallel did not, so an aborted default run logged no cost for the issues that had finished, against what the schema JSDoc says. Entire-Checkpoint: 0928797f5b3e
…parallel push is mutation-verified QA 3 on PR #1597: the parallel-path recording had no regression test. Drives execute() with runIssueWithLogging mocked, once sequential and once parallel, and asserts costSoFar sums what returned. Deleting the parallel push fails exactly the parallel case. Entire-Checkpoint: d1255812fb7e
admarble
deleted the
feature/1527-feat-cli-cost-per-run-where-a-user-looks-one-line-
branch
October 27, 2026 04:04
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
Issue #1527 is implemented and pushed on branch
feature/1527-feat-cli-cost-per-run-where-a-user-looks-one-line-. The orchestrator opens the PR, so none is open from here.The run summary now prints
cost $6.45 (SDK estimate) · 69,641 tokensunder the tally, followed by a muted line,SDK estimate, not a billing statement.sequant logs <run>prints the same line, and the run log carries an optional run-levelcostof{ usd, tokens }withversionstill 1. A run with no record printscost unrecorded, never$0.00. A dry run prints no cost line.How it's built. The spec found that the run log is written before metrics are recorded, so the cost didn't exist yet when the log was finalized. I moved the totals into a new
RunOrchestrator.collectUsageand call it once before the log is written. The log, the summary andmetrics.jsonall take their number from that one total.recordMetricsstill works with its old six arguments, because existing tests call it that way.AC evidence
run-renderer.cost.test.tshas 4 tests, all passing: cost and tokens, no record, tokens only, and the dry-run case.grep -c 'cost: 'onrun-log-schema.tsgives 1, andgrep -c 'version: z.literal(1)'gives 1.logs.cost.test.tshas 3 tests, all passing: with cost, without cost, and schema back-compat.costUSDgrep oversrc/lib/cli-uiandsrc/commands/logs.tsgives 0, andcostappears inrun-renderer-types.ts.SDK estimateappears insrc/lib/cli-ui/format.ts, not inrun-renderer.ts. The AC glob counts it, but the spec's tightened grep (run-renderer.ts≥ 1) would not. I did not edit the AC text.docs/reference/run-command.mdhas a new Cost section. The CHANGELOG has an entry.Checks:
npm run buildandnpm run lintare clean. The affected set was 132 test files. I ran it in 3 shards, then re-ran the failing directories after fixing them:src/lib/workflow/run-orchestrator*,src/lib/cli-uiand the tautology detector all pass. I did not re-run all three shards in full after the fixes.Two existing tests changed
run-renderer.test.ts.snapgained the two cost lines.run-orchestrator.phase-policy.test.tsread only therecordMetricssource region. The hook-file read now lives incollectUsage, so I widened the region to cover both methods.Not done at exec time, done since (see "Runner verification" below)
run-orchestrator.phase-policy.test.tsasserts the log'scostequals the metrics record'scostUSDandtokensUsed, and that the hook-file fallback is read once for both.run-renderer-types.ts, AC-5 countsformat.tsonly, and AC-4's parenthetical names the orchestrator's usage helper.finalizepath writescostfor the issues that had finished, throughcostSoFaron the lazily read orchestrator; both execution paths record, and the parallel push is mutation-verified.Still true
Mutation records for the PR body
cost unrecordedbranch informatCostLinereturnscost $0.00;src/lib/cli-ui/run-renderer.cost.test.tsfailed; restored.displayLogSummary;src/commands/logs.cost.test.tsfailed; restored.I did not run the
parseMutationMarkerscheck from/qa§6i on these markers.Next:
/qaon #1527.Fixes #1527
Runner verification (2026-10-27, final head 9231b67)
Branch after the
sequant_runpasses: QA 1 on0ddfe2467(AC_MET_BUT_NOT_A_PLUS, four findings), then owner-directed fixes58b245b36(MCPsequant_logscarriescost; cost on the signal path throughcostSoFar;toRunCostas the one derivation; parity test log vs metrics;RunResultJSDoc),835cf11ac(caveat line only under a recorded cost, in the summary as insequant logs; abort-path test; MCP description names the estimate), merge ofmaind6daedff5,c92b9cec0(QA 2: the parallel path records finished issues too),9231b67d3(QA 3:costSoFarthrough the realexecute()on both paths). QA 4 was NEEDS_VERIFICATION only because CI had not reported; QA 5 ran aftertestandcanarypassed (see the verdict comment on the issue). QA 5 on9231b67d3: READY_FOR_MERGE, 6/6 met, no gaps.Issue text tightened with the owner's word (2026-10-26): AC-4 pairs the zero-reader grep with
grep -c 'cost' src/lib/cli-ui/run-renderer-types.ts→≥ 1; AC-5 countssrc/lib/cli-ui/format.tsonly; AC-4's parenthetical names the orchestrator's usage helper.ACs re-run on
9231b67d3:npx vitest run src/lib/cli-ui/run-renderer.cost.test.tsgrep -cE 'cost: ' run-log-schema.ts;grep -c 'version: z.literal(1)'npx vitest run src/commands/logs.cost.test.tsgrep -c 'cost' run-renderer-types.tsgrep -c 'SDK estimate' src/lib/cli-ui/format.tsgrep -c 'SDK estimate' docs/reference/run-command.mdMutations reproduced on
9231b67d3: AC-1 (cost unrecordedbranch returnscost $0.00) fails exactlyprints cost unrecorded when the run has no record, 1 failed of 4; AC-3 (cost line deleted fromdisplayLogSummary) failsprints the run's cost and tokensand its sibling, 2 failed of 4. Both restored. ThecostSoFarexecute-path test was mutation-verified in9231b67d3's commit: deleting the parallel push fails exactly the parallel case.Checks:
tscandeslintclean on the branch; freeze grep (plugin/,.claude/skills/,templates/skills/) 0 files; session-link andCo-Authored-Bygrep 0 in commits and diff; 0 behindmain. CI on9231b67d3:testfailed once onready-gate.test.ts > selects the aider driver(5,441 ms against a 5 s timeout, outside this diff, 3/3 local passes), re-run attempt 2 passed;canarypassed;knip-advisoryis the pre-existing 207-export list with none of this branch's symbols.Not in this PR: the MCP server pin is
[email protected], which predates #1520 and this change, sosequant_runover MCP shows neither the Read-first comment nor the cost until a release; #1529's AC-2 (grep -c 'SDK estimate'→1) should match the cost line itself (proposed:grep -cE 'cost \$[0-9]+\.[0-9]{2} \(SDK estimate\)' "$SUMMARY"→1), owner's call when #1529 launches.🤖 Generated by
sequant run