Skip to content

feat(core,cli): per-step wire-size breakdown and usage report (#211 part 1) - #356

Merged
ajianaz merged 2 commits into
developfrom
feat/usage-wire-report
Oct 9, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/usage-wire-report

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1 of 3 of #211 (token efficiency, instrumentation first): a per-step request-size breakdown stored in the usage ledger, and a usage report surfaced in tole status, the serve status JSON and the MCP/ACP tole_session_status tool. fact/mission gains cached_tokens.

Why

#211 decided to measure before optimizing. The ledger already holds cached_tokens but nothing reports it, and nothing says how big the system+tools prefix vs the history is per step. This PR adds only the measurement; the wire, budgets and durable entry shapes are untouched.

Changes

  • tole-core (additive API only): openai::WireStats + pure wire_stats(&Value) (characters via chars().count(): system_chars = leading system message content text, tools_chars = serialized tools array (0 if none), history_chars = serialized other messages, messages = count); Provider::last_wire_stats() additive default method (None). OpenAiProvider::complete() resets it per call and measures the body from request_body BEFORE the streaming envelope.
  • turn.rs: the per-step UsageRecord merges the stats under tole_wire (provider keys untouched). A provider that reports wire stats but no usage still stores {"tole_wire": ...}; neither reported = no record, as before.
  • tole-cli: new usage_report module (usage_report(&[UsageRecord]) -> UsageReport, tolerant, n/a/null for unknown). tole status prints it AFTER the existing lines (unchanged); serve status gets an additive usage_report object; tole_session_status returns the same object; fact/mission gets cached_tokens (same function; tokens_in_out/tokens_used()/steps_used() untouched).
  • Docs: README, docs/mobile-control.md (status field table), docs/architecture.md (ledger row), CHANGELOG. AGENTS.md section 8: 0.8.0 crates.io date 2026-10-08 -> 2026-10-09.

Notes: consumer-tolerance assumption for the status JSON: clients must ignore unknown fields (only usage_report is added; id/entries/busy unchanged) -- documented in mobile-control.md. Budget invariant preserved: a provider that reports request sizes but no usage still leaves a tole_wire-only ledger row (kept for the PR 2 metric), but one shared helper (usage_report::reports_provider_usage) excludes such rows, so steps_used (step budget, fact/mission.steps) and UsageReport.steps count only rows with provider usage, exactly as before; tokens contribute 0. Tests: wire-only ledger gives steps_used == 0 and tokens_used == 0; a mixed ledger counts only provider-usage rows.

Testing

  • Wire unchanged: tier1_wire_shape_stability and request_body_keeps_durable_log_text_untouched pass unmodified; new complete_sends_request_body_unchanged_and_reports_its_stats captures the real request over a mock HTTP server and asserts it equals request_body byte for byte (minus stream/stream_options).
  • New: wire_stats unit tests (empty tools, unicode chars vs bytes, tool messages, exact numbers), per-call semantics, turn-loop storage (merge, provider keys survive, wire-only record, stored == wire_stats of the body), usage_report matrix (no usages, no wire, wire, each cached key name, missing prompt, first/last growth), tole status e2e (legacy lines unchanged + n/a block), serve status JSON, session-status tool, mission register cached_tokens with tokens_in_out/steps unchanged.
  • Mutation-checked (restored via copy-back): dropping the tole_wire merge, breaking the cached_read_tokens key, and removing the per-call refresh each make a test fail.
  • fmt, clippy -D warnings, cargo test --workspace, bare and shell-tools profiles (check/clippy/test) and tole-core --no-default-features --tests all pass; cora review --staged: no issues.

Part of #211

🤖 Generated with Claude Code

…part 1)

Record the serialized request size per provider step under a namespaced
tole_wire key in the usage record (system / tools / history characters),
and derive a usage report (tokens, cache-hit rate, request-size split) for
tole status, the serve status JSON and the session-status tool. fact/mission
gains cached_tokens. Instrumentation only: wire, budgets and durable entry
shapes are unchanged. Also fixes the v0.8.0 release date in AGENTS.md.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

A provider reporting request sizes but no usage leaves a tole_wire-only
ledger row. steps_used (mission step budget, fact/mission.steps) and the
usage report now count only rows with provider usage via one shared helper,
so budget semantics are exactly as before.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@ajianaz
ajianaz merged commit 1ea9a17 into develop Oct 9, 2026
20 checks passed
@ajianaz
ajianaz deleted the feat/usage-wire-report branch October 9, 2026 07:32
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