Repository navigation
fix(llm): TTL split only counts as evidence when consistent with its own aggregate - #5
Merged
danielzarioiu merged 1 commit intoOct 10, 2026
Conversation
…own aggregate
Anthropic documents cache_creation_input_tokens == ephemeral_5m +
ephemeral_1h for a final usage snapshot. Captured production snapshots
violate that invariant (stream_basic: aggregate 13 with {5m:0,1h:0};
thinking: aggregate 1 with {5m:0,1h:0} — sub-minimum cache markers), and
reading those zeros as authoritative would silently unprice the residual
aggregate downstream (the accounting settlement now rejects the same
contradiction, so the producer must not certify it as evidence either).
- CacheCreationSplit::evidence_against: per-TTL buckets become evidence
only when they sum to the SAME usage object's aggregate; contradictory
splits degrade to unknown — settlement keeps failing closed on the
collapsed meter instead.
- Streaming converters (passthrough + translation): message_start and
message_delta both route through the guard; a consistent delta
(including an explicit consistent zero) still wins over message_start,
and a contradictory delta leaves earlier evidence untouched.
- Buffered Usage::cache_ttl_split: same invariant on the pass-through
parse. Client-facing wire untouched (parse-only; json_passthrough).
- Goldens: the four anthropic snapshots drop exactly the two forwarded
0/0 evidence fields (per-diff verified) — contradictory splits are no
longer certified.
agent-llm 429/429 (427 + 2), agentgateway 2229/2229, fmt + clippy clean.
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.
P0-C of the cache-write double-metering correction (accounting-side PR is separate and already rejects split-vs-aggregate contradictions at settlement). Anthropic documents cache_creation_input_tokens == 5m + 1h for a final snapshot; captured production snapshots violate it (aggregate 13 / 1 with {5m:0,1h:0} — sub-minimum cache markers). This guard refuses to certify contradictory splits as evidence (degrades to unknown, fail-closed preserved), on the streaming paths (message_start + delta, delta-wins-when-consistent, contradictory-delta-never-clobbers) and the buffered pass-through parse. Client wire untouched. Goldens drop exactly the two forwarded 0/0 fields each. NOT built or released — pending approval. agent-llm 429/429, agentgateway 2229/2229, fmt+clippy clean.