Repository navigation
#17: surface cache_write_tokens so cost reconciles from shown tokens - #149
Merged
Merged
Conversation
On cache-heavy Opus traffic, cache-write is ~91% of cost but was invisible
above the DB — the traces API omitted the field and the UI/tj cost never showed
cache tokens, so a displayed cost couldn't be derived from its own columns
(a trust problem for a cost tool).
- traces API (_span_to_dict) now returns cache_write_tokens alongside
cache_tokens (read).
- UI trace-detail panel + waterfall tooltip render Cache read + Cache write.
- CostRow + get_cost_summary sum cache-read and cache-write; /api/v1/cost rows
carry both + window totals; the UI Cost table and
TOKENS TOKENS
DATE AGENT MODEL IN OUT CACHE R CACHE W COST
──────────────────────────────────────────────────────────────────────────────
2026-06… - - 128.3k 1.1M 494.6M 0 $358.26…
2026-06… - - 172.4k 1.6M 483.9M 2.8M $361.65…
2026-06… - - 5.5k 682.1k 395.7M 36.9k $274.00…
2026-06… - - 125 66.9k 38.5M 0 $47.9370
2026-06… - - 635 180.7k 99.6M 0 $85.3886
2026-06… - - 366 164.5k 65.7M 0 $66.3781
2026-06… - - 45 30.8k 27.3M 0 $21.3287
307.4k 3.8M 1605.2M 2.9M $1214.9…
table gain
CACHE R / CACHE W columns (tool grouping stays cost-only — no token dimension).
Tests: trace detail + /cost expose cache-write (the reporter's exact span
reconciles); UI guard for the rendered fields. Suite green; ruff/mypy clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This was referenced Jun 19, 2026
Merged
HoomanDgtl
pushed a commit
to HoomanDigital/tokenjam
that referenced
this pull request
Jun 20, 2026
Two bugs surfaced by the v0.4.0 pre-release test pass against an install with the daemon running, plus the testing-infra MD files that caught them. ## Bugs fixed **`tj cost` cache columns silently 0 with daemon up.** PR Metabuilder-Labs#149 added `cache_tokens` + `cache_write_tokens` to the DB row, API response, and CLI rendering — but missed the `ApiBackend` shim that the CLI uses when `tj serve` is running. The shim dropped the cache fields on the floor, so they defaulted to 0 even though the JSON response carried the real values. Two-line addition to mirror the wider contract. **`tj optimize` silently skips the Downsize section when no candidates exist.** The Optimize web tab fixed this in PR Metabuilder-Labs#130 (issue Metabuilder-Labs#126) by rendering an explicit "no candidates" state. The CLI render path was overlooked. When other analyzers find content (cache, script, trim, …), the catch-all "No candidates flagged" message doesn't fire either, so Downsize disappears without explanation — reviewers think the analyzer didn't run. Now mirrors the UI: explicit "Downsize: no candidates in this window — sessions don't match the smaller-model shape" empty state. Guarded by the positional `findings` filter so `tj optimize cache` (asking for just cache) doesn't add Downsize noise. ## Testing infrastructure (new) - `tests/manual-pre-release-runner.md` — generic instructions for a sub-agent: find the release-specific checklist, walk each step, capture output, write a structured log to `tests/results/`. - `tests/manual-pre-release-v0.4.0.md` — focused 12-step checklist for the v0.4.0 release. Each step has the structured shape the runner expects (Setup / Test / Expected / Assertions). - `.gitignore`: `tests/results/` — per-run logs are local artifacts, not committed. ## Verification - `pytest tests/unit/ tests/integration/`: 659 passed. - Live with daemon: `tj cost --since 30d --group-by model` now shows `CACHE R 698.8M`, `1530.9M`, etc. instead of `0`. - Live with daemon: `tj optimize --since 30d` prints "① Downsize: no candidates in this window …" when downsize finds nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
HoomanDgtl
pushed a commit
to HoomanDigital/tokenjam
that referenced
this pull request
Jun 20, 2026
TokenJam v0.4.0 — major release. Significant new product surface beyond the 0.3.x patch cadence: - TokenJam Lens UI rebrand: Overview triage front door, Optimize detail tab, real charts (uPlot, vendored offline), URL-state filters, plan-tier-aware framing on all dollar-bearing surfaces. - Reuse — the 5th analyzer + `tj report --reuse` artifact export (HTML + Markdown skeleton sidecars). - New `core/framing.py` — single source of truth for plan-tier rendering, consumed by both CLI and REST API. - `estimated_recoverable_usd` contract on every savings analyzer (Metabuilder-Labs#111), normalized to a single time basis (Metabuilder-Labs#122) so Overview tiles are directly comparable. - `cache_write_tokens` surfaced through DB → API → CLI → UI (Metabuilder-Labs#149) — fixed the ~91% hidden cost driver on cache-heavy workloads. - Security: `.tj/config.toml` untracked (Metabuilder-Labs#145) + CI guard (`tests/unit/test_no_tracked_dev_secrets.py`). - 17 v0.3.5 post-release findings closed (Metabuilder-Labs#141) + 5 Lens UI bug rounds (Metabuilder-Labs#126-Metabuilder-Labs#136) + onboard `--plan` honored on plain path (Metabuilder-Labs#148). ## Also in this commit **Step 6 in the pre-release checklist** is corrected to match real behavior: `tj report --reuse` with the daemon running exits with the "needs direct database access" hint (workaround: `tj stop`). Long-term fix tracked as Metabuilder-Labs#154 for v0.4.1. **Test outputs committed.** `tests/results/` was gitignored; flipping it so per-release pre-release test logs ship as part of the repo for historical reference. Two v0.4.0 result logs included: the first pass (which surfaced two bugs fixed in PR Metabuilder-Labs#153) and the clean re-run after those fixes landed. Co-Authored-By: Claude Opus 4.7 (1M context) <[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 #17 (from the v0.3.5 smoke test #141 — MEDIUM; highest end-user value).
On cache-heavy Opus traffic, cache-write is ~91% of cost but was invisible
above the DB: the traces API omitted the field and the UI /
tj costnevershowed cache tokens, so a displayed cost couldn't be derived from its own
columns. The reporter's span:
Fix
_span_to_dict) returnscache_write_tokensalongsidecache_tokens(read).CostRow+get_cost_summarysum cache-read/write;/api/v1/costrows carry both + window totals; the UI Cost table andtj costgainCACHE R/CACHE Wcolumns (tool grouping stays cost-only).Tests
Trace detail +
/api/v1/costexpose cache-write (the reporter's exact span reconciles); UI guard for the rendered fields. Full suite green (651); ruff/mypy clean.