Count cache tokens in telemetry, budget and report #16

Merged
hermes merged 1 commits from cache-tokens into main 2026-11-13 18:30:07 +00:00
Collaborator

orch counted only fresh input + output. hx reports input_tokens as the uncached part; cached input is in cache_read_tokens / cache_write_tokens. Johannes' hx stats on a bench session: input 39519 (fresh 2, cache read 39375, cache write 142), output 161, while orch report showed 134 tok/run.

  • Run state and telemetry now carry cache_read_tokens / cache_write_tokens; tokens() = fresh + cache read + cache write + output. Old telemetry lines load with cache = 0.
  • max_tokens budget now counts the full usage per request (it would have fired far too late).
  • orch status shows the total; orch report has a cache column (share of input served from the cache). cmd adapters get the two new fields in run.
  • orch eval token deltas use the full count too.

Note: numbers in telemetry written before this change stay low (cache is not recoverable from old lines; hx stats SESSION has the truth).

Verification: sh tests/all.sh exit 0, 20 unit tests (incl. the real numbers above: 39680 total, 100 % cache), e2e: budget test with 1160 tokens/turn per fake turn stops at turn 2 with spent 2320 (fresh-only counting would never reach the 2000 limit in 5 turns). Flake loop 5/5 under load.

orch counted only fresh input + output. hx reports `input_tokens` as the uncached part; cached input is in `cache_read_tokens` / `cache_write_tokens`. Johannes' `hx stats` on a bench session: input 39519 (fresh 2, cache read 39375, cache write 142), output 161, while `orch report` showed 134 tok/run. - Run state and telemetry now carry `cache_read_tokens` / `cache_write_tokens`; `tokens()` = fresh + cache read + cache write + output. Old telemetry lines load with cache = 0. - `max_tokens` budget now counts the full usage per request (it would have fired far too late). - `orch status` shows the total; `orch report` has a `cache` column (share of input served from the cache). cmd adapters get the two new fields in `run`. - `orch eval` token deltas use the full count too. Note: numbers in telemetry written before this change stay low (cache is not recoverable from old lines; `hx stats SESSION` has the truth). Verification: `sh tests/all.sh` exit 0, 20 unit tests (incl. the real numbers above: 39680 total, 100 % cache), e2e: budget test with 1160 tokens/turn per fake turn stops at turn 2 with spent 2320 (fresh-only counting would never reach the 2000 limit in 5 turns). Flake loop 5/5 under load.
hermes added 1 commit 2026-11-13 18:29:39 +00:00
hermes merged commit 374cf28aed into main 2026-11-13 18:30:07 +00:00
hermes deleted branch cache-tokens 2026-11-13 18:30:07 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: johannes/orch#16