Skip to content

fix(optimize): downsize claude-code card honesty + subagent evidence fix - #709

Merged
anshss merged 1 commit into
mainfrom
fix/analyzer-card-honesty
Aug 7, 2026
Merged

anshss merged 1 commit into
mainfrom
fix/analyzer-card-honesty

Conversation

@anshss

@anshss anshss commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What was wrong

1. downsize handed a Claude Code user a card that ended in no fix.

downsize emits two differently-gated cards: a tiny-session model-swap card
and a driver-role card (fires when a premium model does undelegated work
inline). The tiny-session card unconditionally blanked its suggestion for the
claude-code persona and fell back to advisory prose pointing at other
commands — 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 case
carried the whole number.

2. Every over_powered subagent card asserted a property its own gate
never tests.

The evidence sentence said a flagged dispatch "did little work (small
output, few tool calls)." But over_powered is set by is_premium_tier(model)
plus a cost floor alone (subagent_rightsizing._flags_for) — it never reads
output size or tool-call count. That test belongs to the separate
over_provisioned flag. So a dispatch that ran hundreds of tool calls and
returned 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_proposal now
    returns only the driver-role proposal for the claude-code persona,
    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 cheaper
    model is a real, actionable lever. The over_powered evidence sentence
    now states what its gate actually tests (a premium-tier model above the
    per-dispatch cost floor) instead of borrowing over_provisioned's
    low-output language.
  • tokenjam/core/optimize/types.py / analyzers/model_downgrade.py: added
    DowngradeFinding.percent_of_all_sessions, computed alongside the existing
    n_sessions field, so a surface pairing the dollar tile with a session
    count can read the SAME population the dollar figure sums (both cases)
    instead of the tiny-session-only candidate_sessions /
    percent_of_sessions pair.
  • tokenjam/ui/index.html: the downsize detail page's stat tiles now read
    n_sessions / percent_of_all_sessions. The inline evidence line is split
    into 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-session
    CC-lever fallback fired is inverted (the fallback card no longer fires at
    all for claude-code); a new test confirms a finding carrying both cases
    yields exactly the driver-role card for that persona.
  • tests/unit/test_subagent_rubric_contradiction.py: the existing regression
    test in this file only scanned catalog constants (SUBAGENT_RUBRIC_INTRO,
    RIGHTSIZE_FIX_TEMPLATE), so it was structurally blind to the evidence=
    field built inline at proposal-construction time — exactly where the
    contradiction lived. New tests build a real CostProposal through the
    actual 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 the
    extractor actually found the expected content so the check can't pass
    vacuously. A companion test confirms over_provisioned keeps its own
    low-output framing.
  • tests/unit/test_downsize_driver_role.py: a new test proves the persona
    gate 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_plan path the
    finding 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 relevant
integration CLI/API tests) — all green.

Doc correction

Also corrected the internal analyzer decision record (not part of this repo)
that previously described downsize with a single verdict covering only the
tiny-session card, which read as "this analyzer has no fix" for Claude Code
even though the driver-role card already shipped a real one.

…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]>
@anshss
anshss requested a review from anilmurty as a code owner August 7, 2026 18:47
@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR narrows Claude Code downsize cards to the actionable driver-role case and aligns optimization evidence and UI statistics with their actual analyzer populations.

  • Adds a combined-session percentage to downgrade findings and uses it in the detail statistics.
  • Separates driver-role and tiny-session evidence in the dashboard.
  • Corrects over-powered subagent evidence to describe its premium-tier and cost-floor gate.
  • Adds regression coverage for persona gating, project-aware placement, and evidence wording.

Confidence Score: 4/5

The stale-report compatibility issue should be fixed before merging because upgrades can leave the Optimize detail page displaying undefined%.

Freshly computed reports carry the new field correctly, but the API intentionally serves older cached report dictionaries unchanged and the UI does not provide a fallback for the missing property.

Files Needing Attention: tokenjam/ui/index.html

Important Files Changed

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

Comment thread tokenjam/ui/index.html
// 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' }];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

@anshss
anshss merged commit 3300831 into main Aug 7, 2026
7 checks passed
@anilmurty
anilmurty deleted the fix/analyzer-card-honesty branch September 18, 2026 21:03
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.

1 participant