Repository navigation
feat(core,cli): per-step wire-size breakdown and usage report (#211 part 1) - #356
Merged
Merged
Conversation
…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]>
🔍 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]>
This was referenced Oct 9, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/ACPtole_session_statustool.fact/missiongainscached_tokens.Why
#211 decided to measure before optimizing. The ledger already holds
cached_tokensbut 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+ purewire_stats(&Value)(characters viachars().count():system_chars= leading system message content text,tools_chars= serializedtoolsarray (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 fromrequest_bodyBEFORE the streaming envelope.turn.rs: the per-stepUsageRecordmerges the stats undertole_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: newusage_reportmodule (usage_report(&[UsageRecord]) -> UsageReport, tolerant,n/a/nullfor unknown).tole statusprints it AFTER the existing lines (unchanged); serve status gets an additiveusage_reportobject;tole_session_statusreturns the same object;fact/missiongetscached_tokens(same function;tokens_in_out/tokens_used()/steps_used()untouched).Notes: consumer-tolerance assumption for the status JSON: clients must ignore unknown fields (only
usage_reportis added;id/entries/busyunchanged) -- documented in mobile-control.md. Budget invariant preserved: a provider that reports request sizes but nousagestill leaves atole_wire-only ledger row (kept for the PR 2 metric), but one shared helper (usage_report::reports_provider_usage) excludes such rows, sosteps_used(step budget,fact/mission.steps) andUsageReport.stepscount only rows with provider usage, exactly as before; tokens contribute 0. Tests: wire-only ledger givessteps_used == 0andtokens_used == 0; a mixed ledger counts only provider-usage rows.Testing
tier1_wire_shape_stabilityandrequest_body_keeps_durable_log_text_untouchedpass unmodified; newcomplete_sends_request_body_unchanged_and_reports_its_statscaptures the real request over a mock HTTP server and asserts it equalsrequest_bodybyte for byte (minusstream/stream_options).wire_statsof the body),usage_reportmatrix (no usages, no wire, wire, each cached key name, missing prompt, first/last growth),tole statuse2e (legacy lines unchanged +n/ablock), serve status JSON, session-status tool, mission registercached_tokenswithtokens_in_out/stepsunchanged.tole_wiremerge, breaking thecached_read_tokenskey, and removing the per-call refresh each make a test fail.cargo test --workspace, bare and shell-tools profiles (check/clippy/test) andtole-core --no-default-features --testsall pass;cora review --staged: no issues.Part of #211
🤖 Generated with Claude Code