Skip to content

tj context shows unweighted re-read shares and names ended sessions as action items #593

Description

@anshss

Problem

tj context (cli/cmd_context.py) has two defects that a sibling command already fixed for itself.

1. Raw, unweighted re-read shares. cmd_context.py:137 and :218 render diag.reread_share / c.reread_share directly — a raw ratio of re-read tokens to total tokens. Cache-read tokens are billed (and rate-limited) well below a fresh input token, so a raw token-count ratio overstates how much of a user's actual quota re-reading consumes. ContextDiagnostic already exposes a quota-weighted version of the same figure: quota_weighted_reread_share (core/context_diagnostic.py:389) and quota_weighted_work_share (core/context_diagnostic.py:403), both computed from the per-turn TurnComposition.quota_weighted_reread_share (core/context_diagnostic.py:267). cmd_context.py doesn't read either property. Neither does cmd_tokenmaxx.py, which also renders the raw diag.reread_share (cli/cmd_tokenmaxx.py:111).

2. A reclaim list that names already-ended sessions. cmd_context.py:214-225 lists up to three individual compact_candidates by session id ("session <id> — X% re-read... → /compact mid-session... to reclaim that quota"). compact_candidates is built by _compact_candidates() (core/context_diagnostic.py:825), which groups TurnComposition rows by session_id over the full queried window (turns = load_turn_compositions(conn, since, until, agent_id) at core/context_diagnostic.py:567) — it has no concept of "still active." So the printed advice to run /compact "mid-session" routinely names sessions that have already ended, which is not actionable: a closed session can't be compacted.

Expected

  • tj context and tj tokenmaxx render the quota-weighted shares (quota_weighted_reread_share / quota_weighted_work_share) as their headline percentages, the same way another command in this codebase already does. Raw token-ratio shares may still be shown, but only under an explicit "raw tokens" label if kept for debugging — never presented as the quota share.
  • The reclaim section stops naming individual past sessions. It should report an aggregate instead (how many of the analyzed sessions crossed the compact threshold, and what share of the window's re-read tokens they represent), with a note that only the live session is actually actionable.

Where to look

  • tokenjam/cli/cmd_context.py:137 and :218 — raw reread_share reads
  • tokenjam/cli/cmd_context.py:214-225 — the per-session reclaim list
  • tokenjam/cli/cmd_tokenmaxx.py:111 — raw diag.reread_share read
  • tokenjam/core/context_diagnostic.py:267,389,403 — the existing quota-weighted properties to reuse
  • tokenjam/core/context_diagnostic.py:825_compact_candidates(), which has no "still live" filter

Done when

  • No default tj context or tj tokenmaxx output presents a raw token ratio as a quota share.
  • Neither command's default output names an individual ended session as something to act on; the reclaim message is aggregate-only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedOpen for external contribution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions