Repository navigation
fix: quota-weight quickstart headline, drop named-session reclaim list - #437
Conversation
… list (#119) The "Where your quota goes" headline reported a RAW token share as "quota" (e.g. "95.0% of your tokens went to re-reading context"), but cache-read tokens are billed at a fraction of a base input token in both API pricing and Anthropic's subscription rate-limit weighting — the same discount every current model row in tokenjam/pricing/models.toml applies (cache reads at 0.1x, output at 5x). A raw share mixes "tokens" and "quota" framings and overstates re-reading's actual cost. Added quota_weighted_reread_share / quota_weighted_work_share (and their underlying quota_weighted_tokens) to TurnComposition and ContextDiagnostic in context_diagnostic.py, using named constants (CACHE_READ_QUOTA_WEIGHT, OUTPUT_QUOTA_WEIGHT) cited to the pricing table. Chose to weight the computation rather than just retitle the box, since the whole point of tokenjam's quota-native framing is that the number should mean what it says — retitling to "raw tokens" would abandon that thesis rather than fix the mismatch. The raw reread_share/total_tokens fields are unchanged for existing consumers (tj context, tj tokenmaxx); only quickstart's headline now reads quota-weighted. Also dropped the per-session "Biggest reclaim opportunities" list: a user has thousands of sessions and never returns to one closed days ago, so naming past sessions as "actionable" is noise regardless of framing. In its place, one aggregate line (no session IDs) reporting how many sessions cleared the existing compact-candidate threshold and what share of the window's re-read tokens they represent — actionability lives in the live statusline, not a retrospective list. Co-Authored-By: Claude <[email protected]>
|
| Filename | Overview |
|---|---|
| tokenjam/core/context_diagnostic.py | Adds CACHE_READ_QUOTA_WEIGHT / OUTPUT_QUOTA_WEIGHT constants, quota_weighted_tokens / quota_weighted_reread_share on TurnComposition (documented as groundwork for #122), and total_quota_weighted_tokens / quota_weighted_reread_share / quota_weighted_work_share on ContextDiagnostic; all existing properties and raw token fields are untouched. |
| tokenjam/cli/cmd_quickstart.py | Switches the two headline lines from raw diag.reread_share / computed work_share to diag.quota_weighted_reread_share / diag.quota_weighted_work_share, and replaces the per-session compact-candidate list with an aggregate count+share line; no other rendering paths are affected. |
| tests/unit/test_context_diagnostic.py | Adds three new tests: quota-weighted share math (pinned formula), JSON round-trip, and a live pricing-table cross-check that fails loudly if models.toml drift away from the assumed ratios. |
| tests/unit/test_quickstart.py | Adds three new quickstart CLI tests: headline wording (quota vs. tokens), aggregate reclaim section (no session IDs), and omission of the reclaim section when no compact candidates exist; uses Rich-safe border-stripping for panel text assertions. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[tj quickstart _render] --> B[ContextDiagnostic]
B --> C[total_quota_weighted_tokens\nR×0.1 + I + O×5.0 + W]
C --> D[quota_weighted_reread_share\nR×0.1 / total_qw]
C --> E[quota_weighted_work_share\n I + O×5.0 / total_qw]
D --> F[Headline: X% of your quota\nwent to re-reading]
E --> G[Headline: Y% went to\nnet-new work]
B --> H{compact_candidates?}
H -- yes --> I[Aggregate line:\nN of your S sessions ran\ncontext-heavy enough…]
H -- no --> J[Reclaim section omitted]
I --> K[Pointer to live statusline]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[tj quickstart _render] --> B[ContextDiagnostic]
B --> C[total_quota_weighted_tokens\nR×0.1 + I + O×5.0 + W]
C --> D[quota_weighted_reread_share\nR×0.1 / total_qw]
C --> E[quota_weighted_work_share\n I + O×5.0 / total_qw]
D --> F[Headline: X% of your quota\nwent to re-reading]
E --> G[Headline: Y% went to\nnet-new work]
B --> H{compact_candidates?}
H -- yes --> I[Aggregate line:\nN of your S sessions ran\ncontext-heavy enough…]
H -- no --> J[Reclaim section omitted]
I --> K[Pointer to live statusline]
Reviews (2): Last reviewed commit: "fix: address PR #437 review — guard drif..." | Re-trigger Greptile
| # content this turn, not a re-read, so they're outside the discount this | ||
| # reflects. Named constants (not inlined) so the ratio's provenance is visible | ||
| # at every call site. | ||
| CACHE_READ_QUOTA_WEIGHT = 0.1 | ||
| OUTPUT_QUOTA_WEIGHT = 5.0 |
There was a problem hiding this comment.
Hardcoded weights could silently drift from
models.toml
CACHE_READ_QUOTA_WEIGHT = 0.1 and OUTPUT_QUOTA_WEIGHT = 5.0 are documented to match the ratios in tokenjam/pricing/models.toml, but nothing enforces that. If a new model row is added with a different ratio, or the cache-read discount changes, these constants stay stale and the headline quietly reports the wrong quota split with no failing test. A small test that reads the pricing table and asserts every Anthropic model row matches the expected ratios (or that the constants are at least internally consistent with the table's current values) would close this gap.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/core/context_diagnostic.py
Line: 138-142
Comment:
**Hardcoded weights could silently drift from `models.toml`**
`CACHE_READ_QUOTA_WEIGHT = 0.1` and `OUTPUT_QUOTA_WEIGHT = 5.0` are documented to match the ratios in `tokenjam/pricing/models.toml`, but nothing enforces that. If a new model row is added with a different ratio, or the cache-read discount changes, these constants stay stale and the headline quietly reports the wrong quota split with no failing test. A small test that reads the pricing table and asserts every Anthropic model row matches the expected ratios (or that the constants are at least internally consistent with the table's current values) would close this gap.
How can I resolve this? If you propose a fix, please make it concise.…indent - Add a doc comment on TurnComposition.quota_weighted_tokens / quota_weighted_reread_share noting they are deliberate groundwork for #122 (tj context / tj tokenmaxx switching to quota-weighted shares) and are not yet consumed by any renderer — so a future cleanup pass doesn't delete them as dead code (Greptile P2). - Add test_quota_weight_constants_match_anthropic_pricing_table: reads tokenjam/pricing/models.toml via load_pricing_table() and asserts every Anthropic row's cache_read/input and output/input ratios match CACHE_READ_QUOTA_WEIGHT / OUTPUT_QUOTA_WEIGHT. A future pricing change that drifts the ratio now fails loudly instead of silently invalidating the quickstart headline's credibility (Greptile P2). - Drop the stray 4-space leading indent on the reclaim aggregate's second line so it renders flush with the sentence above instead of misaligned inside the panel (copy nit from founder review). Co-Authored-By: Claude <[email protected]>
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]>
Summary
Two independent fixes to
tj quickstart's "Where your quota goes" box, kept in one PR because they touch the same_rendersection.(a) Headline was raw tokens mislabeled as quota.
diag.reread_shareistotal_reread_tokens / total_tokens— a raw token share. Cache-read tokens are billed at a fraction of a base input token in both API pricing and Anthropic's subscription rate-limit weighting (every current model row intokenjam/pricing/models.tomlprices cache reads at 0.1x input, output at 5x — consistent across the whole table, not a per-model coincidence). Reporting the raw share as "quota" overstates re-reading's real cost.Added
quota_weighted_reread_share/quota_weighted_work_share(backed byquota_weighted_tokens) toTurnCompositionandContextDiagnosticintokenjam/core/context_diagnostic.py, using two named constants (CACHE_READ_QUOTA_WEIGHT = 0.1,OUTPUT_QUOTA_WEIGHT = 5.0) with a comment citing the pricing table. Chose to weight the computation rather than just retitle the box — the whole point of tokenjam's quota-native framing is that the number should mean what it says; retitling to "raw tokens" abandons that thesis instead of fixing the mismatch. The rawreread_share/total_tokensproperties are untouched, sotj contextandtj tokenmaxx(which still use them) are unaffected — only quickstart's headline now reads quota-weighted. New fields also round-trip into the--jsonpayload.Verified against my own
~/.claude/projectshistory (61 sessions, 8823 turns): rawreread_share= 94.98% (matches the reported "95.0%" figure almost exactly) vs.quota_weighted_reread_share= 57.46% — a much bigger correction than the original back-of-envelope "~92%" estimate, because a full accounting also weights output tokens 5x heavier (comparatively rare but expensive), not just the cache-read discount alone.(b) Per-session "Biggest reclaim opportunities" list was unactionable noise. A user has thousands of ended sessions and never returns to one closed days ago, so naming individual past sessions as "actionable" is noise regardless of copy. Replaced the list with one aggregate line (no session IDs): how many sessions cleared the existing compact-candidate threshold and what share of the window's re-read tokens they represent, pointing at the live statusline as the actionable surface instead.
Before / after (real output against my own logs)
Before:
After:
Scope note
Another PR (branch
statusline-preview) is concurrently adding a new statusline-preview section to the same_renderfunction incmd_quickstart.py. This PR is scoped to the composition-math/labels change and the reclaim-section removal only, to keep the two diffs merging cleanly. This PR should merge first.Test plan
uv run pytest tests/unit/ tests/synthetic/ tests/agents/ tests/integration/— 2169 passed, 1 pre-existing skiptest_quota_weighted_reread_share_discounts_cache_reads,test_quota_weighted_fields_in_json_payload(context_diagnostic),test_quickstart_headline_reads_as_quota_not_raw_tokens,test_quickstart_reclaim_section_is_aggregate_not_named_sessions,test_quickstart_no_compact_candidates_omits_reclaim_section(quickstart)uv run ruff checkclean on both changed source filestj quickstart --since 30dand--jsonagainst real~/.claude/projectshistory to eyeball the new output and confirm the JSON fields🤖 Generated with Claude Code