You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(observability): read Anthropic cache tokens instead of under-reporting input by orders of magnitude
`input_tokens` on an Anthropic-style usage envelope is the UNCACHED remainder,
not the whole prompt. This engine's prompts cache well -- a stable system prompt
plus repo context -- so on a cache hit the real prompt sits in
cache_read_input_tokens while input_tokens holds a handful of leftovers. Nothing
read those fields, on either the ORB or the miner.
Live evidence minutes after deploying orb-v3.7.0-beta.9, which is the image that
first carried #10212's fix for the scrubber that had been nulling tokens
entirely: a review that produced 787 output tokens and cost $0.21 reported TWO
input tokens, while the local ollama model on the same box reported 2,706. The
gap was invisible until tokens started arriving at all.
Parse cache_read_input_tokens and cache_creation_input_tokens and report them in
their own right, rather than folding them into inputTokens. That is what the
provider means by each field, and cache reads price at a fraction of fresh
input, so summing them in would trade one wrong number for another. PostHog
models the distinction directly and prices the two separately.
Also set $ai_cache_reporting_exclusive when cache fields are present. PostHog
otherwise auto-detects the convention from $ai_provider, and this deployment
reports "claude-code" / "claude-cli" / "agent-sdk" rather than "anthropic",
so the auto-detection would read the envelope as inclusive and price the cached
prompt as fresh input. The key names themselves are the exclusive-counting
convention, so their presence is the signal -- no provider-name sniffing.
Fixed in all four parsers that had the gap: the ORB's extractCliUsage, the
miner's deliberately-duplicated copy in cli-subprocess-driver, the Agent-SDK
driver's result reader, and through it runChatGrounding, which shares it.
Closes#10246
0 commit comments