Repository navigation
feat(diagnostics-otel): export cache-write TTL buckets on generic usage keys - #184661
ryan-dyer-sp wants to merge 6 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR adds provider-reported five-minute and one-hour cache-write counts to generic GenAI span attributes. Example: A model call reports 600,000 five-minute and 400,000 one-hour cache-write tokens.
Review scores
ProductKind: Feature · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR provides useful TTL-aware telemetry with no verified code defect, but changing the deliberately chosen export vocabulary still needs owner direction. Priority: P2 Decision needed
Before merge
FindingsNone. Agent review detailsHow this fits togetherThe diagnostics-otel plugin maps normalized model usage into span attributes, which OTLP exporters deliver to telemetry backends for analysis and pricing. flowchart LR
A[Provider usage] --> B[Diagnostic event]
B --> C[Model recorder]
C --> D[Usage attribute mapper]
D --> E[OTLP exporter]
E --> F[Backend usage mapping]
F --> G[TTL pricing]
Technical reviewBest possible solution: With owner approval, retain the two additions in the existing mapper while preserving the combined totals and OpenClaw attributes. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the combined generic cache-write count and OpenClaw TTL counts, but omits the dotted TTL attributes recognized by updated Langfuse; no target code was executed during this read-only review. Is this the best way to solve the issue? The proposed implementation is the smallest complete export extension: two mappings in the existing owner, matching documentation, and one extended boundary regression. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2a16e47f90a4. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +7, Tests +29, Docs +1. Total +37 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed November 4, 2026, 8:34 AM ET / 13:34 UTC (Revision 6). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review . You seem hung up on double pricing for downstream consumers, but are ignoring that they are already broken for any 1h caches currently. |
|
🦞👀 Re-review progress:
|
4830b5d to
61f09a2
Compare
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…dition Drop the stale OpenClaw-scoping statements superseded by the generic keys (code comment, docs sentence, test title/absence assertion) and cite the OTel GenAI conventions on the generic rows instead: the standard defines no TTL attributes and keeps cache counters as subsets of the authoritative gen_ai.usage.input_tokens blend.
Merge the split OpenClaw/generic cache-write TTL tests back into one boundary test: one service setup, one event set, one pass, asserting both usage vocabularies' values and key sets. Reviewer note: the split duplicated the setup for no extra coverage.
…ted sub-namespace Switch the generic TTL keys from the flat input_cache_creation_1h/_5m spelling to gen_ai.usage.cache_creation.5m/1h_input_tokens, the dotted breakdown shape Langfuse openclaw#19420 normalizes to priced input_cache_creation_5m/_1h usage types while rebalancing the total to its unattributed remainder. Each write prices exactly once on current Langfuse; on earlier deployments the keys stay unpriced pass-through buckets and the combined total prices once, unchanged.
7dad6f5 to
b6d72e1
Compare
…dget The cache-write TTL boundary test grows net +29 test lines over the base ceiling (exact git numstat delta of the export suite changes). Allocate that growth for PR openclaw#184661 per the test-line cost budget.
…-specific references Rewrap the emitter and test comments to the repo's wider comment width and describe the decomposition contract in consumer-neutral terms. Resize the test-line allocation record to the resulting exact net delta (25).
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
What Problem This Solves
Backends that price
gen_ai.usage.*usage types cannot price Anthropic's separately-reported cache-write TTL buckets: #171663 exportedcache_creation.ephemeral_5m_input_tokens/ephemeral_1h_input_tokensonly on the OpenClaw-specific vocabulary (openclaw.model_call.usage.*), where generic usage-type consumers never see them. That is already breaking live pricing, not just a missing feature: Langfuse's own default Claude pricing ships a distinctinput_cache_creation_1hrate ($4.00per MTok vs$2.50for 5m/combined onclaude-sonnet-5), and any deployment using 1-hour prompt caching today has those writes priced at the combined rate — a 37.5% undercount on the 1h tokens — because the reported bucket never reaches the pricing rows.User Impact
model.callspans now also carrygen_ai.usage.cache_creation.5m_input_tokens/gen_ai.usage.cache_creation.1h_input_tokens, exported verbatim when the provider reports them (explicit zero included) and absent otherwise. The keys sit in the standard's own cache-write sub-namespace (gen_ai.usage.cache_creation.*), in the same dotted breakdown shape Langfuse natively maps (#19420, merged 2026-10-28, first release after v4.71.0): current Langfuse normalizes them to itsinput_cache_creation_5m/_1husage types — the exact rows its Claude default prices define — prices each bucket at its own rate, and rebalances the combined key to its unattributed remainder, so each write prices exactly once regardless of the backend price table. On earlier deployments the breakdown keys land as unpriced pass-through buckets (the split is visible in dashboards) and the combined total prices exactly once, unchanged from today. No producer-side configuration is needed either way.Why This Change Was Made
gen_ai.*is the OpenTelemetry GenAI semantic-conventions namespace (open-telemetry/semantic-conventions-genai; registry: docs/registry/attributes/gen-ai.md, all attributes Development status). The standard defines cache counters as subsets of one authoritative prompt total —gen_ai.usage.input_tokens"SHOULD include all types of input tokens, including cached tokens",gen_ai.usage.cache_creation.input_tokens"SHOULD be included in" it — but no TTL attributes (the 5m/1h split is Anthropic-specific). These two keys extend the standard's cache-write sub-namespace with the provider-reported breakdown, in the same nested shape the standard already uses.#171663's review kept the TTL split OpenClaw-specific so generic consumers could not price a total and its breakdown together. Since then the major generic consumer fixed that exact concern natively: Langfuse #19420 rebalances dotted
gen_ai.usage.cache_creation.*_input_tokensbreakdown keys, normalizing them to the priced usage types its Claude default prices define. Emitting the breakdown in that shape means the decomposition is enforced by the consumer's own mapping (older consumers see unpriced extra buckets, never additive prices) rather than depending on producers to omit provider-reported facts. Draft status is intentional pending maintainer direction on that reversal.Evidence
Real behavior proof, current head
61f09a29e64(rebased onto upstream/main4fc73d6995b; built CLI) against a self-hosted Langfuse v4 deployment running past #19420 (worker bundle verified to contain the rebalance code; containers recreated 2026-10-29). One real non-streaming Anthropic Messages call, provider-reported counts verbatim, secrets/hosts redacted. The span:openclaw.model.callGENERATION, modelclaude-sonnet-5-5, 2026-10-29 14:04:00 UTC, trace1d75af08dc8b5968b8b35002a2119d6b, spanca9195870b43044b.Dotted breakdown on a both-conventions price table: combined auto-zeroed, write priced exactly once
Provider reported a 9,170-token cache write (all 5m,
ephemeral_1h = 0explicitly) plus a 36,162-token cache read. The deployment's price table for the model carries both conventions (combinedinput_cache_creation$2.50 +input_cache_creation_5m$2.50 +input_cache_creation_1h$4.00 per MTok) — the configuration that double-prices a total-plus-breakdown emission.As ingested (
usage_details→cost_details):The breakdown was normalized to
input_cache_creation_5m: 9170/_1h: 0(priced against the TTL rows), and the combined key was rebalanced to its unattributed remainder: 0 — so the combined row contributed nothing despite existing. One 9,170-token write → $0.022925, exactly once, with no backend row hygiene.Contrast: the flat spelling on the same upgraded deployment does not rebalance
A control call emitted the earlier flat spelling (
gen_ai.usage.input_cache_creation_5m) through a pre-switch build: same deployment, same price table. Its span (2026-10-29 13:59:21 UTC, trace0da97d95e3b2ea22d56a16119d39ff77, spane35db4463bc30e8c) showsinput_cache_creation: 36,162— the full total, not a remainder — priced $0.090405 by the combined row alongside_5m$0.090405: the same write priced twice. #19420's rebalance triggers on the dotted breakdown keys only; the flat spelling leaves the combined total intact. The dotted emission shape is what makes the consumer-side decomposition apply.Tests and checks:
extensions/diagnostics-otel/src/service.otlp-export.test.ts— one boundary test,exports cache-write TTL facts on generic and OpenClaw usage keys(single setup/event set), asserting both vocabularies verbatim: generic dotted TTL keys and OpenClaw TTL keys export mixed 1h/5m buckets, explicit zeros, and stay absent when unreported, with per-family key-set expectations. Base-red verified: with onlyservice-genai-attributes.tsreverted to upstream/main, that test fails on the generic TTL assertions (keys absent on base) while the remaining 20 tests pass; restored, the suite passes.tsgo:extensions, formatting, scoped oxlint on the changed files, andgit diff --checkall pass on the rebased head. No attribute row other than the two new keys changes.