Repository navigation
fix(optimize): downsize claude-code card honesty + subagent evidence fix - #709
Conversation
…nd correct the subagent over-powered evidence sentence downsize emitted a tiny-session model-swap card for the claude-code persona that always blanked its suggestion and fell back to advisory prose pointing at other commands, so the common case ended in a number with no fix. downsize now fires only the driver-role card (a real one-paste CLAUDE.md fix) for that persona; the tiny-session/per-agent cards stay for sdk, where switching models per request is a real lever. The downsize detail page also paired a real dollar figure (both cases summed) with candidate-list stats scoped to the tiny-session case alone, so a driver-role-dominated window rendered "0%, 0 of N" beside a nonzero figure. Both stat tiles and the evidence line now read the combined population (DowngradeFinding.n_sessions / percent_of_all_sessions) instead. Separately, every over_powered subagent card claimed the flagged dispatch "did little work (small output, few tool calls)" — language that belongs to the over_provisioned gate. over_powered is set by is_premium_tier(model) plus the cost floor alone and never reads output size or tool-call count, so a dispatch with hundreds of tool calls and a large result was told it did little work, contradicting the numbers on its own card. The sentence now states what the gate actually tests. Pinned by tests that build proposals through the real construction path rather than scanning catalog constants (the prior regression test's blind spot), plus a placement test proving the driver-role finding's per-project write split survives the persona gate unchanged. Co-Authored-By: Claude <[email protected]>
|
| Filename | Overview |
|---|---|
| tokenjam/core/optimize/cost_proposals.py | Retires non-actionable Claude Code tiny-session cards and makes subagent evidence match the actual premium-tier cost gate. |
| tokenjam/core/optimize/analyzers/model_downgrade.py | Computes the combined percentage over tiny-session and driver-role findings consistently with n_sessions. |
| tokenjam/core/optimize/types.py | Adds the combined-population percentage with generic dataclass serialization and hydration support. |
| tokenjam/ui/index.html | Corrects downsize population labels, but renders undefined% for persisted reports created before the new percentage field existed. |
| tests/unit/test_cost_proposals.py | Pins the revised Claude Code persona gate and preserves SDK and mixed behavior. |
| tests/unit/test_downsize_driver_role.py | Verifies driver-role placement remains split across qualifying project destinations. |
| tests/unit/test_subagent_rubric_contradiction.py | Exercises proposal construction to prevent evidence from claiming shape properties absent from the over-powered gate. |
Prompt To Fix All With AI
### Issue 1
tokenjam/ui/index.html:7646
**Stale reports render undefined percentage**
When the dashboard loads a persisted downgrade report produced before `percent_of_all_sessions` was added, the API serves the report without that field and this expression renders `undefined%` until the next optimize scan replaces it. Use a backward-compatible fallback derived from the existing session counts.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix(optimize): stop the downsize Claude ..." | Re-trigger Greptile
| // beside "0%, 0 of N" — two figures over two different populations shown | ||
| // together. `n_sessions`/`percent_of_all_sessions` cover the SAME | ||
| // population the dollar figure does. | ||
| return [{ v: dg.percent_of_all_sessions + '%', l: 'of sessions flagged' }, { v: dg.n_sessions + ' / ' + dg.total_sessions, l: 'flagged sessions' }]; |
There was a problem hiding this comment.
Stale reports render undefined percentage
When the dashboard loads a persisted downgrade report produced before percent_of_all_sessions was added, the API serves the report without that field and this expression renders undefined% until the next optimize scan replaces it. Use a backward-compatible fallback derived from the existing session counts.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/ui/index.html
Line: 7646
Comment:
**Stale reports render undefined percentage**
When the dashboard loads a persisted downgrade report produced before `percent_of_all_sessions` was added, the API serves the report without that field and this expression renders `undefined%` until the next optimize scan replaces it. Use a backward-compatible fallback derived from the existing session counts.
**Knowledge Base Used:**
- [Session Analysis and Export](https://app.greptile.com/metabldr/-/custom-context/knowledge-base/metabuilder-labs/tokenjam/-/docs/session-analysis-export.md)
- [Demo Mode and the Dashboard UI](https://app.greptile.com/metabldr/-/custom-context/knowledge-base/metabuilder-labs/tokenjam/-/docs/demo-ui.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
What was wrong
1.
downsizehanded a Claude Code user a card that ended in no fix.downsizeemits two differently-gated cards: a tiny-session model-swap cardand a driver-role card (fires when a premium model does undelegated work
inline). The tiny-session card unconditionally blanked its suggestion for the
claude-codepersona and fell back to advisory prose pointing at othercommands — so a Claude Code user's common case was a card that stated a
number with no fix attached. The driver-role card, which ships a real
one-paste CLAUDE.md fix, is persona-agnostic and already worked correctly.
The same finding also produced mismatched figures on the downsize detail
page: the past-overspend stat tile rendered a real dollar figure (both cases
summed), while the candidate-list stats on the same page — scoped to the
tiny-session case alone — read
0%/ "0 of N" whenever the driver-role casecarried the whole number.
2. Every
over_poweredsubagent card asserted a property its own gatenever tests.
The evidence sentence said a flagged dispatch "did little work (small
output, few tool calls)." But
over_poweredis set byis_premium_tier(model)plus a cost floor alone (
subagent_rightsizing._flags_for) — it never readsoutput size or tool-call count. That test belongs to the separate
over_provisionedflag. So a dispatch that ran hundreds of tool calls andreturned a large result was told it did little work, directly contradicted
by the numbers rendered on the same card.
What changed
tokenjam/core/optimize/cost_proposals.py:_downsize_to_proposalnowreturns only the driver-role proposal for the
claude-codepersona,never building the tiny-session/per-agent cards for it. Those cards are
unchanged and still fire for
sdk, where routing a request to a cheapermodel is a real, actionable lever. The
over_poweredevidence sentencenow states what its gate actually tests (a premium-tier model above the
per-dispatch cost floor) instead of borrowing
over_provisioned'slow-output language.
tokenjam/core/optimize/types.py/analyzers/model_downgrade.py: addedDowngradeFinding.percent_of_all_sessions, computed alongside the existingn_sessionsfield, so a surface pairing the dollar tile with a sessioncount can read the SAME population the dollar figure sums (both cases)
instead of the tiny-session-only
candidate_sessions/percent_of_sessionspair.tokenjam/ui/index.html: the downsize detail page's stat tiles now readn_sessions/percent_of_all_sessions. The inline evidence line is splitinto two population-scoped sentences (driver-role, tiny-session), each
gated on its own population being nonzero, rather than one sentence that
could show "0 of N" beside a real dollar figure it does not describe.
How it's pinned
tests/unit/test_cost_proposals.py: the old test asserting the tiny-sessionCC-lever fallback fired is inverted (the fallback card no longer fires at
all for
claude-code); a new test confirms a finding carrying both casesyields exactly the driver-role card for that persona.
tests/unit/test_subagent_rubric_contradiction.py: the existing regressiontest in this file only scanned catalog constants (
SUBAGENT_RUBRIC_INTRO,RIGHTSIZE_FIX_TEMPLATE), so it was structurally blind to theevidence=field built inline at proposal-construction time — exactly where the
contradiction lived. New tests build a real
CostProposalthrough theactual construction path on a fixture that is deliberately the opposite of
"little work" (large output, hundreds of tool calls), assert the evidence
text agrees with what
over_powered's gate tests, and guard that theextractor actually found the expected content so the check can't pass
vacuously. A companion test confirms
over_provisionedkeeps its ownlow-output framing.
tests/unit/test_downsize_driver_role.py: a new test proves the personagate on the CARD layer doesn't touch the placement layer — a driver-role
finding whose sessions are seeded across two project roots still splits
into one destination per project, via the same
driver_session_tokens/_placement_weights/rule_placement.build_placement_planpath thefinding always used.
Ran the touched suites plus the surrounding persona/placement/UI tests
locally (
test_downsize_driver_role.py,test_downsize_agent_pricing.py,test_subagent_rubric_contradiction.py,test_rollup_subagent_downsize_dedup.py,test_cost_proposals.py,test_rule_placement.py,test_persona_analyzer_gate.py,test_lens_module_parses.py,test_ui_offline.py, and the relevantintegration CLI/API tests) — all green.
Doc correction
Also corrected the internal analyzer decision record (not part of this repo)
that previously described
downsizewith a single verdict covering only thetiny-session card, which read as "this analyzer has no fix" for Claude Code
even though the driver-role card already shipped a real one.