Repository navigation
#111: Add estimated_recoverable_usd to every savings analyzer - #119
Merged
Merged
Conversation
Give every analyzer that produces a usable recommendation a consistent, heuristic estimated-recoverable figure so it can be summarized in one place. New fields on the result dataclasses (downsize/cache/script/trim): estimated_recoverable_usd, estimated_recoverable_tokens, estimate_basis, estimate_confidence (always "heuristic" in v1; named distinctly from the pre-existing structural `confidence` on wave-2 findings to avoid a clash). Per-analyzer heuristics: - downsize: aliases the existing monthly_savings_usd; tokens from candidate_tokens. - cache: gap to an 80% efficacy ceiling × input tokens × (input − cache-read rate delta), summed across rows; None for models with no cache-read rate. - script: full cost (and tokens) of sessions in each deterministic cluster. - trim: low-significance tokens × window-average input rate; None when capture is off or llmlingua is missing. cache-recommend and budget-projection intentionally do not emit a figure. Estimates serialize through report_to_dict (so /api/v1/optimize carries them) and round-trip through report_from_dict. CLI rendering is unchanged — the new fields are read by the API/UI, not the existing render paths. Every analyzer's caveat language is preserved. Tests: per-analyzer USD within a hand-calculated bound, None in not-ready states, non-empty estimate_basis, and a report_to_dict/from_dict round trip. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
anilmurty
commented
Jun 17, 2026
anilmurty
left a comment
Contributor
Author
There was a problem hiding this comment.
Review: ✅ Approve with nits
Acceptance criteria — all met:
- ✓
confidence→estimate_confidencerename is justified. Wave-2 findings (cache_efficacy.py:71,prompt_bloat.py:102,workflow_restructure.py:102,cache_recommend.py:53) already useconfidence: "structural"for a different axis (structural vs replay_validated). The newestimate_confidence: "heuristic"describes a different axis. Collapsing would have been semantic overloading. - ✓
model_downgrade.py:206is a literal alias —estimated_recoverable_usdandmonthly_savings_usdshare the same computed value. - ✓
cache_efficacy.py:80-115formula matches spec:gap = max(0, 0.80 − efficacy) × cacheable input tokens × (input rate − cache-read rate).EFFICACY_CEILING = 0.80is a module constant (line 63). Skips rows whencache_read_per_mtok <= 0(line 98) and whenrate_delta <= 0(line 101). - ✓
prompt_bloat.pyreturnsNonein both not-ready states (capture off at:287-294, llmlingua missing at:301-306)._window_avg_input_rateis token-weighted across the actual model mix — better than spec. - ✓
cache-recommendandbudget-projectionuntouched (correct — not savings analyzers). - ✓ CLI render paths don't read the new fields. Round-trip works via
runner.py:250-380asdict/constructor paths. - ✓ Tests cover USD bounds,
Nonein not-ready states, non-empty basis, round-trip.
Nits / follow-ups (non-blocking):
runner.py:42—_utcnow()usesdatetime.now(tz=timezone.utc)rather thantokenjam.utils.time_parse.utcnow()(CLAUDE.md rule #9). Pre-existing, not introduced by this PR, but the file is touched here — easy to clean up while we're at it.tests/unit/test_optimize_recoverable.py:195—assert finding.estimate_basis == "" or finding.estimate_basis is not Noneis a tautology (""is notNone, so the right operand is always true). Likely meant== ""for the not-ready case.prompt_bloat.py:396—low_sig_tokens = total_bloat / CHARS_PER_TOKENwhereCHARS_PER_TOKEN = 4. Reasonable approximation for English prose, but theestimate_basisstring doesn't disclose the conversion. Worth surfacing in the UI hover text once Lens lands.workflow_restructure.py:194—cluster_costis the full historical cost of clustered sessions, not window-normalized. Basis text is honest, but the figure isn't directly comparable to monthly-projected numbers on other tiles. Follow-up to either window-normalize or annotate the time basis explicitly.
CI green on 3.10 / 3.11 / 3.12 + TS. No blockers. Good to merge.
- runner.py: _utcnow() and report_from_dict fallbacks now use tokenjam.utils.time_parse.utcnow() instead of datetime.now(tz=timezone.utc) (CLAUDE.md Rule 9). - test_optimize_recoverable.py: the not-ready trim assertion was a tautology; assert estimate_basis == "" for that path. Addresses PR #119 review nits. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
Author
|
Thanks for the thorough review! Addressed in 04f3330:
For the two follow-ups (script estimate is full-historical vs monthly-projected on other tiles + |
This was referenced Jun 17, 2026
anilmurty
marked this pull request as ready for review
June 18, 2026 05:07
1 of 3 tasks
4 tasks done
anshss
added a commit
that referenced
this pull request
Jul 9, 2026
fix: quota-weight quickstart headline, drop named-session reclaim list (#119)
6 tasks done
anshss
added a commit
that referenced
this pull request
Jul 9, 2026
Combining #437 (ticket-119: aggregate reclaim line, never names a past session) with #438 (statusline live preview: shows the exact statusline line one concrete named session would have triggered, by design) broke CI: test_quickstart_reclaim_section_is_aggregate_not_named_sessions asserted "sess-heavy" absent from the ENTIRE quickstart output, which was true when #437 was authored (quickstart never named a session anywhere) but stopped being true once #438 added a later section that intentionally names its preview session as a concrete "what you'd have seen live" example — itself covered by dedicated #438 tests (`test_quickstart.py` asserts "session sess-recent would have shown this at turn 3" / "session sess-old ... turn 5"). Both invariants are correct and neither feature should be reverted: the quota-composition PANEL must never name a session (#119's actual intent — see the "(#119)" comment at cmd_quickstart.py's aggregate line), while the separate, later statusline-preview section legitimately does. Scoped the assertion to the panel's own text (everything before the preview section's fixed intro, "With the statusline installed") instead of the whole rendered output. Co-Authored-By: Claude <[email protected]>
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.
Closes #111.
Every analyzer that produces a usable recommendation now also produces a
consistent, heuristic estimated-recoverable figure, so the Lens Overview can
summarize "recoverable waste" in one band. The honesty discipline carries
forward — every number is "estimated recoverable", never "saves you", and each
analyzer keeps its existing caveat language.
Contract (added to each savings analyzer's result dataclass)
estimated_recoverable_usd: float | None— api-billed framingestimated_recoverable_tokens: int | None— subscription / local framingestimate_basis: str— one-line heuristic explanation (the "estimated" tag's hover text)estimate_confidence: str = "heuristic"— named distinctly from thepre-existing structural
confidencefield on the wave-2 findings to avoid asemantic clash.
Nonemeans "no estimate for this finding state" (e.g. trim with capture off).Per-analyzer heuristic
monthly_savings_usd; tokens fromcandidate_tokens.Nonefor models with no cache-read rate.Nonewhen capture is off orllmlinguais missing.Plumbing
report_to_dict(so/api/v1/optimizecarries them) and round-trip throughreport_from_dict.Tests
tests/unit/test_optimize_recoverable.py: per-analyzer USD within ahand-calculated bound,
Nonein not-ready states, non-emptyestimate_basis,and a
report_to_dict/report_from_dictround-trip. Full suite green;mypyand
ruffclean.Scope guardrails honoured
No new analyzer; no change to which analyzers run by default; registry pattern
unchanged; CLI output format unchanged.