Repository navigation
feat(cli): baseline comparison — waste rules vs naive baselines (#85) - #137
Merged
Merged
Conversation
Answers the #85 question with data: do the 12 finding types explain more spend than the trivial "flag whatever is expensive" baselines — the top 10% rounds by input-side tokens, and the largest tool results filling the same volume as the rules' waste. - Claim.billedOn + Finding.sources (#85): the round that first billed each claimed token, gated behind computeFindings(..., withSources) so snapshots stay byte-identical; thinking_heavy spreads over its turn ∝ thinkingTokens - new corpus:baseline CLI: per-session rules$/cost vs baseline$/cost, rules $ outside the top rounds, top money the rules do not explain, top rounds without findings; corpus aggregation with medians/quartiles, per-type $, paired win/tie/loss and a Wilson 95% CI — CANNOT ANSWER under 10 fully priced sessions or a majority excluded, INCONCLUSIVE on a straddling CI - image tool results (screenshots) bill as vision tokens (~1.6k), not chars/4 of the base64 payload — the old estimate put one Read at 155k "tokens" and tripped wasted-usd-le-cost on a real session (30-session corpus: 0 invariant violations after the fix, 1 before) Corpus (30 largest local sessions, aggregates only): rules median 14.7% of session cost vs 14.7% for the top-10% baseline; paired 16/30 wins, Wilson CI 36.1–69.8% → INCONCLUSIVE. The report says so instead of forcing a verdict. Closes #85 Co-Authored-By: Claude Code <noreply@anthropic.com>
axisrow
commented
Oct 13, 2026
axisrow
left a comment
Owner
Author
There was a problem hiding this comment.
Verdict: Approved
Reviewed origin/main...192da61 — #85 baseline comparison (new src/cli/baseline.ts), per-round sources plumbing in computeFindings/allocateWaste, resultBillingRound, image-result token sizing, listToolResults inventory, tests, and the dist-cli rebuild.
Checked and clean
- Sources invariants: Σ
sources[].tokens==tokensWastedand Σsources[].usd==wastedUsdhold after allocation (verified in tests and by tracingallocateWaste). On headline ("ok") sessions all rounds are priced, so every claim is priced — mixed priced/unpriced sources are unreachable there, which keepsrulesUsdInTop <= rulesUsdandlossOutsideTopSharein [0,1]. - Default path unchanged:
withSources=falsekeeps findings byte-identical (guarded by an explicit test), so committed corpus snapshots,--jsonoutput and the hook consumer see the #84 shape exactly as before. estimateResultTokensmatches the oldestimateTokens(resultText(...))for text-only results and only swaps image payloads for the 1600-token vision budget; every sizing call site (ledger gap accounting, findings walk, cycle motifs, result inventory) was switched together, so no consumer is left on the base64 sizing.- dist-cli bundle faithfully mirrors the src changes; the baseline CLI runs from src via tsx like the other corpus scripts.
Math.ceil(n * 0.1)top-count rounding checked for realistic round counts (10–300) — no float-epsilon surprises.
Minor, non-blocking (no change requested)
failed_callfree part (call args) is attributed in sources to the next round (claims[0].billedOn), while those input tokens were actually billed on the call's own round — documented approximation, negligible effect onrulesUsdInTop.- baseline2 takes each candidate result whole, so its volume can overshoot
wt.tokensWasted— acceptable for a naive baseline, just worth knowing when reading the report. baselineSessionre-builds the rounds-by-turn map locally; exportingroundsByTurnfrom analyzeSession would drop the 5-line duplication.
No inline findings — nothing requires a change.
4 tasks done
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.
Baseline comparison: do the 12 waste rules earn their complexity? (#85)
Answers the #85 question with data: do the finding types explain more spend than the naive "flag whatever is expensive" baselines?
Acceptance criteria (defined before implementation)
The question is answered by six numbers per session, plus a corpus-level verdict:
rules$/costwaste), cache-residency pricing (#82)baseline$/costcontextSize), tie → lower round index; ghost (contextSize 0) and retry-copy rounds never rankbaseline2$/costrules$InTopbilledOn);thinking_heavyspreads over its turn ∝ thinking tokensCANNOT ANSWERunder 10 fully priced sessions or a majority excluded,INCONCLUSIVEon a straddling CIKnown-answer test on a synthetic session: rules $0.06 (38.5% of cost) vs baseline $0.02 (12.8%), wait_loop sources land on rounds 2–6, baseline2 volume/USD to 15 decimal places.
Implementation
Claim.billedOn+Finding.sourcesbehindcomputeFindings(..., withSources)— default off, snapshots/JSON stay byte-identical (guarded by a byte-equality test)thinking_heavy(free, claim-less) is distributed over its turn in the CLI, ∝ thinking tokenspnpm corpus:baselineCLI (src/cli/baseline.ts): per-session rows + corpus aggregation, reuseslistSessionFiles/resolveCorpusDir(Regression corpus of real sessions (local, via .env) with numeric snapshots #79),wilsonInterval(Precision via manual labeling: sample findings, label, report Wilson CI #81), pricing (feat(cli): waste in dollars with cache residency (#82); billed-thinking estimate (#83) #135)wasted-usd-le-costinvariant on 1/30 real sessions (0/30 after the fix); text-only results keep the byte-identical old estimateCorpus result (30 largest local sessions, sonnet-5 + GLM pricing, aggregates only)
The corpus does not decide the question: the Wilson CI straddles 50% for both baselines, and the report says so instead of forcing a verdict. The descriptive numbers are still useful — the rules and the top-10% baseline explain different money: 92% of rules $ lies outside the top rounds, 91% of top money is not explained by the rules, and 64% of top rounds carry no finding at all (candidates for new rules).
thinking_heavyalone is 54% of rules $ — and it is an estimate (billed thinking), which alone keeps the comparison soft.Tests run
pnpm test— 1163/1163 across 87 files (incl. 17 baseline tests + 2 new image-pricing tests)pnpm typecheck,pnpm lint(0 errors), prettier check on all touched filescorpus:snapshoton the 30-session corpus — 0 invariant violations after the image fix (1 before)Known risks / follow-ups
thinking_heavydominates rules $ and is itself an estimate — a sharper answer likely needs measured billed-thinkingCloses #85
🤖 Generated with Claude Code