Skip to content

feat(cli): per-user-turn token stats derived from the usage ledger (#379) - #389

Merged
ajianaz merged 2 commits into
developfrom
feat/turn-response-stats
Oct 16, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/turn-response-stats

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

What

Per-user-turn token stats in tole status and the status JSON (usage_report.turns).

Why

#379. Stats were only available as session totals; a per-turn view needs unknown to stay unknown and must survive restarts.

Changes

  • usage_report.rs: turn_stats folds the durable usage ledger by user turn (a usage row belongs to the turn open at the entry it is attached to; the stop-gate feedback message does not open a turn). Fields: input / output / cache-read / cache-write / reasoning tokens, steps, cost_usd.
  • Unknown-nonzero rule: each field is the sum over the steps that reported it and None / null / n/a when none did; never coerced to 0. No elapsed time is carried (it is not measured).
  • Derived at read time instead of a second persisted record: the raw rows are already durable, so there is no new schema, nothing to drift, and old sessions fold the same way (no compat risk).
  • Wired into tole status (per turn: lines), GET /sessions/{id}/status and tole_session_status (additive turns array); README, docs/mobile-control.md, CHANGELOG.
  • Cost: cost_usd is summed from ledger rows that carry one; it is not populated by any provider path today, so it reads null.
  • Not changed: the pre-existing usage: line of tole status and the session-level totals still render unknown as 0; changing them would alter existing output and JSON shapes.

Testing

  • 7 new unit tests: grouping incl. stop-gate feedback, unknown stays unknown, partial reporting, cache-write spellings and cost, old/odd sessions, and a JSONL round-trip (commit, reopen, stats equal and match the provider usage block exactly, nothing invented).
  • fmt, clippy -D warnings, cargo test --workspace pass; cora review --staged clean.
  • Not done: a live run against a real provider (none configured here); the round-trip test covers the restart path.

Refs #379

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 63d3a02 into develop Oct 16, 2026
17 checks passed
@ajianaz
ajianaz deleted the feat/turn-response-stats branch October 16, 2026 04:19
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