Skip to content

feat(cli): baseline comparison — waste rules vs naive baselines (#85) - #137

Merged
axisrow merged 2 commits into
mainfrom
ao/claude-devtools-58/baseline-85
Oct 13, 2026
Merged

axisrow merged 2 commits into
mainfrom
ao/claude-devtools-58/baseline-85

Conversation

@axisrow

@axisrow axisrow commented Oct 13, 2026

Copy link
Copy Markdown
Owner

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:

# Number Method
1 rules$/cost #84 non-overlapping waste $ (kind waste), cache-residency pricing (#82)
2 baseline$/cost whole cost of the top ceil(10%) billed rounds ranked by input-side tokens (in+cr+cw = contextSize), tie → lower round index; ghost (contextSize 0) and retry-copy rounds never rank
3 baseline2$/cost largest tool results filling the same token volume as the rules' waste, priced with the same residency rates
4 rules$InTop #85 sources: each claimed token records the round that first billed it (billedOn); thinking_heavy spreads over its turn ∝ thinking tokens
5 overlap rules $ outside the top rounds; top $ the rules do not explain; share of top rounds without any finding
6 corpus verdict medians/quartiles + per-type $; paired win/tie/loss with a Wilson 95% CI on P(rules > baseline) — CANNOT ANSWER under 10 fully priced sessions or a majority excluded, INCONCLUSIVE on a straddling CI

Known-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

Corpus result (30 largest local sessions, sonnet-5 + GLM pricing, aggregates only)

baseline report (#85) — the 12 finding types' waste $ vs naive baselines, top = 10% of rounds by input-side tokens
corpus: 30 session(s), headline = 30 fully priced; excluded: 0 no-cost, 0 partial-cost, 0 unpriced-waste
per-session share of session cost $:
  rules (waste $)        median   14.7%  p25    8.7%  p75   21.1%  min    4.2%  max   68.8%
  baseline (top 10%)     median   14.7%  p25   13.9%  p75   15.5%  min   10.4%  max   20.3%
paired rules vs top-10%: 16 rules-win / 0 tie / 14 baseline-win — P(rules > baseline) = 53.3% (95% Wilson CI 36.1%–69.8%) over 30 non-tie
  VERDICT: INCONCLUSIVE
paired rules vs largest-results: 11 rules-win / 0 tie / 19 baseline-win — P(rules > baseline) = 36.7% (95% Wilson CI 21.9%–54.5%) over 30 non-tie
  VERDICT: INCONCLUSIVE
overlap with the top rounds:
  rules $ outside top    median   92.1%  p25   80.2%  p75   99.5%  min   60.3%  max   99.9%
  top $ not explained    median   90.9%  p25   74.8%  p75   99.5%  min   55.8%  max   99.9%
  top rounds w/o finding median   63.6%  p25   52.9%  p75   76.6%  min    0.0%  max   91.7%
waste $ by type (30 headline sessions, total $17.46):
  thinking_heavy        102 findings  $    9.4980   54.4% of rules $
  oversized_output       10 findings  $    3.0354   17.4% of rules $
  stall_streak          139 findings  $    2.5186   14.4% of rules $
  cache_dead            103 findings  $    0.7181    4.1% of rules $
  duplicate_call        519 findings  $    0.6757    3.9% of rules $
  wait_loop              14 findings  $    0.5651    3.2% of rules $
  failed_call           572 findings  $    0.4373    2.5% of rules $
  loop_streak            12 findings  $    0.0047    0.0% of rules $
  cycle_motif             1 findings  $    0.0024    0.0% of rules $

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_heavy alone 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 files
  • corpus:snapshot on the 30-session corpus — 0 invariant violations after the image fix (1 before)

Known risks / follow-ups

  • the image vision budget is a fixed ~1600 tok constant (worst case ≤2x off vs the 100x chars/4 error); decoding w/h from payload headers would tighten it
  • thinking_heavy dominates rules $ and is itself an estimate — a sharper answer likely needs measured billed-thinking
  • the corpus is 30 of the largest local sessions of one machine, not a representative sample

Closes #85

🤖 Generated with Claude Code

axisrow and others added 2 commits October 13, 2026 17:58
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 axisrow left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 == tokensWasted and Σ sources[].usd == wastedUsd hold after allocation (verified in tests and by tracing allocateWaste). On headline ("ok") sessions all rounds are priced, so every claim is priced — mixed priced/unpriced sources are unreachable there, which keeps rulesUsdInTop <= rulesUsd and lossOutsideTopShare in [0,1].
  • Default path unchanged: withSources=false keeps findings byte-identical (guarded by an explicit test), so committed corpus snapshots, --json output and the hook consumer see the #84 shape exactly as before.
  • estimateResultTokens matches the old estimateTokens(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_call free 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 on rulesUsdInTop.
  • 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.
  • baselineSession re-builds the rounds-by-turn map locally; exporting roundsByTurn from analyzeSession would drop the 5-line duplication.

No inline findings — nothing requires a change.

@axisrow
axisrow merged commit dab8ca2 into main Oct 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Baseline comparison: do 12 rules explain more spend than "top 10% rounds"?

1 participant