Repository navigation
feat(runtime): charge context deltas at the ratio the provider measurement established (RR7) - #127
Merged
lg2m merged 1 commit intoSep 22, 2026
Conversation
…ement established (RR7) The measured-occupancy chain seeds from the provider's reported input tokens but charged every byte delta at the fixed four bytes per token. On a code-heavy transcript (~3.1 B/t) each appended turn was under-charged by about 22 %, so the estimate drifted low across a long run until the provider rejected the request. adjust_measured_tokens now charges and credits at the ratio the measurement itself implies (measured bytes over measured tokens, rounded to nearest, clamped to 2-6, defaulting to 4 below 2 000 measured tokens). The run loop calibrates once against the whole measured request and applies each component's delta at that ratio. The raw byte estimate for an unmeasured first request is unchanged; RR6 covers a provider rejection of it. Tests: deltas_are_charged_at_the_ratio_the_measurement_established; calibration_holds_the_estimate_within_ten_percent_on_a_code_heavy_transcript (eight turns at 3.1 B/t, worst error under 10 % where the default is 22 % under per delta); existing chain and checkpoint tests unchanged. Closes ENG-869.
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.
Stacked on #126 (RR6). RR7 of
docs/plans/run-reliability.md; audit finding R02 (d), deferred from F04. Closes ENG-869.Behaviour
The measured-occupancy chain (C6) already seeds each request from the provider's reported
input_tokens, but it charged every byte delta at the fixed 4 bytes/token. On a code-heavy transcript (~3.1 B/t) each appended turn was under-charged by ~22 %, so the estimate drifted low across a long run until the provider rejected the request — the case RR6 now recovers, but better not to get there.adjust_measured_tokensnow charges and credits at the ratio the measurement itself implies —calibrated_bytes_per_token(measured_tokens, measured_bytes): rounded to nearest, clamped to 2–6 B/t, defaulting to 4 below 2 000 measured tokens (noise floor where the system prompt dominates). The run loop calibrates once against the whole measured request and applies each component's delta at that ratio (adjust_measured_tokens_at).Unchanged: the raw 4 B/t estimate for an unmeasured first request (nothing to calibrate against), the compatibility rules for reuse, and the storage backstop. No schema or protocol change.
Verification
deltas_are_charged_at_the_ratio_the_measurement_established: 3 B/t code, 5 B/t prose, both directions, clamp bounds, noise floor.calibration_holds_the_estimate_within_ten_percent_on_a_code_heavy_transcript— the plan's acceptance criterion: eight turns at 3.1 B/t, worst error < 10 %; the default would be 22 % under on every delta.cargo test -p qq-core --liball green; workspace clippy-D warningsand fmt clean.Docs
architecture.md§ resolved model (occupancy reuse paragraph); ledger entry.