Description
Epic: graph-2026-10-review-surface Tier: mechanical Execution: sequant_run Blocked by: #1523, #1504, #1507
- Blocked by: tracker: graph-2026-10-review-surface — the acceptance criterion as the unit every surface shows: producer, renderers, cost, verdict attribution, Read-first comment, issue form #1523
- Blocked by: feat(run): a dropped error leaves a trace — noteSuppressed() counts into the run log, batch-executor's 25 silent catches converted #1504
- Blocked by: refactor(workflow): split runIssueWithLogging (1,620 lines) into stage functions of ≤ 200 counted lines, behaviour-preserving #1507
Problem
"Cost per run: whose API key, rough tokens or dollars, and whether the separate review session doubles the bill" was the cold reader's blocking question. The product already knows: .sequant/metrics.json carries metrics.costUSD and tokensUsed per run (154 of 420 runs on this checkout, $935.69 in total; the last run $6.45 and 69,641 tokens for three issues), and sequant stats prints a phase × model table under "SDK estimate, not a billing statement". It is shown nowhere a user looks after a run. This node surfaces the same record in the run summary, the run log (optional cost) and sequant logs, with the same wording (I-7). A run with no metrics record says cost unrecorded, never $0.00.
Acceptance Criteria
- AC-1: The summary prints the cost line from the metrics record. Evidence:
npx vitest run src/lib/cli-ui/run-renderer.cost.test.ts→≥ 3 passed, 0 failed(a run withcostUSD: 6.45, tokensUsed: 69641printscost $6.45 (SDK estimate) · 69,641 tokens; a run with no record printscost unrecorded; a run with tokens but no cost prints tokens andcost unrecorded) - AC-2: The run log carries
costas an optional run-level field (metrics are per run, not per issue) and the version is unchanged. Evidence:grep -cE 'cost: ' src/lib/workflow/run-log-schema.ts→≥ 1andgrep -c 'version: z.literal(1)' src/lib/workflow/run-log-schema.ts→1 - AC-3:
sequant logs <run>prints it. Evidence:npx vitest run src/commands/logs.cost.test.ts→≥ 2 passed, 0 failed - AC-4: One source (I-2, RD-C). Evidence:
grep -rlE 'total_cost_usd|costUSD' src/lib/cli-ui src/commands/logs.ts | wc -l | tr -d ' '→0andgrep -c 'cost' src/lib/cli-ui/run-renderer-types.ts→≥ 1(renderers take the number from the run-log or summary input; only the orchestrator's usage helper andmetrics-writer.tsread the SDK's figure) - AC-5: The wording is the stats wording. Evidence:
grep -c 'SDK estimate' src/lib/cli-ui/format.ts→≥ 1(a non-test file; the earlier glob counted test files) - AC-6: The docs say where the number comes from. Evidence:
grep -c 'SDK estimate' docs/reference/run-command.md→≥ 1
Prior fixes / producers
- Producers of cost:
metrics-writer.ts(fix(metrics): tokensUsed is 0 on every recorded run — capture-tokens.sh reads .usage (transcripts carry .message.usage) and run reads the wrong dir; wire SDK modelUsage tokens+costUSD per phase × model into metrics and stats #986 revived the dead token metrics via fix(#986): source token and cost metrics from the SDK modelUsage map #1010; feat(config): model roles — semantic indirection between phase policy/ladders and concrete model strings #975 added per-model usage). Two prior fixes on this record; the AC states the outcome (every surface shows the writer's number) rather than a site. src/commands/logs.tsis refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471's and chore(lib): convert the remaining ~94 empty catches to noteSuppressed, forbid empty catch bodies by lint, show the count in sequant logs #1505's file;log-writer.tsandrun-log-schema.tsare feat(run): a dropped error leaves a trace — noteSuppressed() counts into the run log, batch-executor's 25 silent catches converted #1504's. This node lands after feat(run): a dropped error leaves a trace — noteSuppressed() counts into the run log, batch-executor's 25 silent catches converted #1504; itslogs.tsblock waits for chore(lib): convert the remaining ~94 empty catches to noteSuppressed, forbid empty catch bodies by lint, show the count in sequant logs #1505 if that has not merged (cluster rule in §8).
May touch
src/lib/workflow/log-writer.ts, run-log-schema.ts (optional cost, after #1504's block), src/lib/cli-ui/run-renderer-types.ts (optional cost on the summary input), the renderer implementations, src/commands/run-display.ts (where the summary input is assembled), the summary assembly in batch-executor.ts (toIssueSummary, after #1507, or the module #1507 extracts), src/commands/logs.ts, tests, docs/reference/run-command.md, CHANGELOG.
Non-Goals
- Billing accuracy or a price table of our own (the SDK's estimate is the number).
- Changing
sequant stats. - Any new flag (I-4).
- Any edit under
plugin/,.claude/skills/,templates/skills/(I-1).
Done when
A run ends with its cost on the terminal, and the same number is in its log and in sequant logs.
Activity
docs(#1523): HANDOFF.md for graph-2026-10-review-surface — W0 and #1520…
admarble commentedon Oct 26, 2026
Complexity: Standard (6 ACs, 6 directories)
AC Quality Check
Run against the base branch (
main@ 00bb5ac):grep … | wc -lalready prints0today. It gates nothing. Tighten to a pair: the same grep→ 0ANDgrep -c 'cost' src/lib/cli-ui/run-renderer-types.ts → ≥ 1(the renderer takes a number it did not read from the SDK).src/lib/cli-ui/*.tsincludes*.test.ts. Exclude tests:grep -c 'SDK estimate' src/lib/cli-ui/run-renderer.ts→ ≥ 1. Today it is 0, so it fails until the work is done.cost:→ 0 today) and AC-1/AC-3 (new test files) fail today, so they gate real work.Scope Assessment
Non-Goals: present (no billing accuracy, no
statschange, no new flag, nothing underplugin/,.claude/skills/,templates/skills/).Verdict: ✅ SCOPE_OK
Blockers: #1504 and #1507 are CLOSED; #1505 is CLOSED (so the
logs.tsblock no longer waits). #1523 is the tracker (kept open by design).Acceptance Criteria
AC-1: Summary prints the cost line
Verification: Unit Test (
run-renderer.cost.test.ts, new)Scenario: Given
costUSD 6.45, tokensUsed 69641→ WhenrenderSummaryruns → Thencost $6.45 (SDK estimate) · 69,641 tokens; no record →cost unrecorded; tokens only → tokens pluscost unrecorded.Assumptions:
cost: 0is not printed as$0.00; the writer already storesundefinedfor 0 (run-orchestrator.ts:2472).AC-2: Run log carries optional run-level
cost, version unchangedVerification: Unit Test (schema parse of an old log without
costand a new one with it) + the two greps.Scenario: Given a v1 log with no
cost→ When parsed → Then valid; withcost: {...}→ valid.AC-3:
sequant logs <run>prints itVerification: Integration Test (
logs.cost.test.ts, new, ≥ 2: with cost, without →cost unrecorded)AC-4: One source
Verification: grep pair (tightened above)
AC-5: Stats wording
Verification: tightened grep above
AC-6: Docs
Verification:
grep -c 'SDK estimate' docs/reference/run-command.md → ≥ 1. Today 0.Implementation Plan
Key finding — ordering. In
run-orchestrator.tsthe run log is finalized (logWriter.finalize, ~L1796) BEFORErecordMetrics(~L1810) computesdriverTotals(L2337). The cost does not exist yet when the log is written. The summary also has no access to it (RunResultcarries no cost).Phase 1: Compute once, hand to all three surfaces
recordMetrics(L2300–2360:phaseUsage,driverTotals, fallback) into a helper that returns{ costUSD?, tokensUsed }. Call it once beforelogWriter.finalize;recordMetricsconsumes the same value (one source, no second sum).LogWriter.finalize({ cost })setsfinalLog.cost(likesuppressed, L387). Schema: optionalcost: z.object({ usd: z.number().nonnegative().optional(), tokens: z.number().int().nonnegative().optional() }).optional()after thesuppressedblock;version: z.literal(1)untouched.costtoRunResultso the summary input can carry it.Phase 2: Render
run-renderer-types.ts: optionalcostonSummaryRenderInput.run-display.tsdisplaySummarypassesresult.costto both the renderer and therenderRunSummaryfallback. Implement the line inrun-renderer.ts(all modes) via a shared formatter informat.ts, which holds the only "SDK estimate" string for the CLI-UI.logs.tsdisplayLogSummary(~L71–96): print the same formatter's output fromlog.cost; absent →cost unrecorded.Phase 3: Tests and docs
run-renderer.cost.test.ts(3 cases),logs.cost.test.ts(2 cases), schema back-compat test. Update snapshots incli-ui/__snapshots__if a summary fixture gains the line.docs/reference/run-command.md: a "Cost" subsection naming.sequant/metrics.json/ the SDK estimate. CHANGELOG entry.Mutation records (CLAUDE.md "Testing"): the gate tests for AC-1, AC-3 and AC-4/5 need
Mutation-verified: AC-N — <mutation>; <test file path> failed; restored.lines in the PR body, e.g. delete thecost unrecordedbranch and confirm the AC-1 test fails.Design Review
cli-ui/format.ts; numbers computed once in the orchestrator and passed down. Renderers andlogs.tsnever readcostUSD..sequant/metrics.jsonfromlogs/renderers (a second reader, and the latest record may not be this run's); rejected: adding a field per issue (cost is not attributable per issue).suppressed(feat(run): a dropped error leaves a trace — noteSuppressed() counts into the run log, batch-executor's 25 silent catches converted #1504), a run-level optional field written infinalize. Prior fixes on the cost record: fix(metrics): tokensUsed is 0 on every recorded run — capture-tokens.sh reads .usage (transcripts carry .message.usage) and run reads the wrong dir; wire SDK modelUsage tokens+costUSD per phase × model into metrics and stats #986/fix(#986): source token and cost metrics from the SDK modelUsage map #1010, feat(config): model roles — semantic indirection between phase policy/ladders and concrete model strings #975 (2 issues). The AC states the outcome (every surface shows the writer's number), and Phase 1 collapses the producers into one computation, so this is fixing the class, not another site.recordMetrics, notlog-writer.ts; see Open Questions.agent-driver.ts(costUSD),run-orchestrator.tsrecordMetrics→metrics-writer.ts. Consumers today:stats.ts. New consumers:log-writer.ts(via finalize),run-display.ts/renderer,logs.ts. One computation, three consumers; a parity test asserts the log'scost.usdequals the metrics record'scostUSDfor the same fixture run.Feature Quality Planning
All standard checks pass. Notable items:
--quiet/non-TTY renderer and the dry-run path must not print a cost line (dry run has no cost).finalizeearly):costmay be partial; label stays the same, absent if unknown.Open Questions
(SDK estimate); I-7 wants "not a billing statement" on every cost display. Recommendation: print the AC-1 line exactly and add a mutedSDK estimate, not a billing statementfootnote once under the summary and inlogs. Impact: without it, I-7 is unmet; with it, AC-1 still passes.log-writer.tsreads the SDK figure; in the plan it receives the number from the orchestrator. Recommendation: edit the AC text to "only the orchestrator's usage helper andmetrics-writer.tsread the SDK's figure". Impact: if left,/qamay read it literally and flag AC_NOT_MET.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Mechanical, well-bounded; ACs declare unit/integration evidence, but the tests are the deliverable and written in exec, so testgen adds little. No UI/browser, no security surface. Tiering note: the tracker says
sequant_run; do not backgroundsequant run(bg-pty kill).Label Review
Current: graph-2026-10-review-surface
Recommended: + planned
Quality Loop: Won't auto-enable (SCOPE_OK).
admarble commentedon Oct 26, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
Gaps:
fix(#1527): MCP sequant_logs carries cost; cost on the abort path; pa…
fix(#1527): the caveat line follows a recorded cost only, in the summ…
admarble commentedon Oct 27, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 6/6 met
Gaps:
sequant_logsover MCP now carriescost, and its tool description names the estimate.RunResultJSDoc is back aboveRunResult.sequant logs.costequals the metrics record'scostUSDandtokensUsed(run-orchestrator.phase-policy.test.ts:552).fix(#1527): the parallel path records finished issues for costSoFar t…
admarble commentedon Oct 27, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 6/6 met
Gaps:
test(#1527): costSoFar through the real execute() on both paths; the …
admarble commentedon Oct 27, 2026
QA Verdict: NEEDS_VERIFICATION
AC coverage: 6/6 met
Gaps:
Needs human review:
admarble commentedon Oct 27, 2026
QA Verdict: READY_FOR_MERGE
AC coverage: 6/6 met
feat(#1527): cost per run where a user looks — one line in the run su…