Skip to content

fix(diagnostics-otel): model call spans drop Anthropic cache-write TTL split - #171663

Merged
steipete merged 7 commits into
openclaw:mainfrom
ryan-dyer-sp:port/anthropic-cache-51h-split
Oct 25, 2026
Merged

steipete merged 7 commits into
openclaw:mainfrom
ryan-dyer-sp:port/anthropic-cache-51h-split

Conversation

@ryan-dyer-sp

@ryan-dyer-sp ryan-dyer-sp commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Anthropic's five-minute and one-hour cache-write counts are lost before model-call traces reach OpenTelemetry collectors, so operators cannot inspect the reported TTL breakdown.

User Impact

Model-call spans preserve both reported TTL buckets under openclaw.model_call.usage.cache_creation_input_tokens_1h and _5m, including explicit zero. Unreported buckets remain absent. Existing generic cache totals and pricing behavior stay intact; consumers can use the OpenClaw attributes for TTL-aware analysis.

Why This Change Was Made

Carry the provider's facts through the existing usage, recovery, and accumulation owners. Keep TTL subsets outside the additive gen_ai.usage.* namespace: emitting both a blended total and its decomposition there causes generic consumers such as Langfuse to charge for the same writes twice.

The accumulator uses optional totals instead of separate reporting flags, and Bedrock sums both TTLs in one snapshot-local loop. Preserve main's consolidation of normalization tests and removal of duplicate transport coverage.

Thanks @ryan-dyer-sp for the original fix and provider/accounting coverage.

Evidence

  • Base regression: five provider-accounting failures expose lost five-minute counts and overwritten one-hour counts during compaction. The real OTLP receiver regression also fails on base because both TTL attributes are absent.
  • Regression tests: all 160 tests across seven affected files pass before and after integrating main. The integrated run took 655.33 seconds wall time (605.12 seconds across five Vitest shards), mostly compiler/worker setup; the assertions themselves are short. Independent Codex review is clean through P2 with no actionable findings.
  • Real local diagnostics service → HTTP/protobuf OTLP receiver: reported 400000 one-hour and 600000 five-minute counts arrive intact; zero and absent controls pass. The generic namespace carries only the blended 1000000 count.
  • Ran Langfuse's extraction and pricing methods from pinned source 6af0b026aa63910cfda67a31834138f6d0ae1d3a against the captured spans. The mixed-TTL example has one existing blended charge of $3.75. A control using the original PR's overlapping generic attributes produces $8.40. This preserves generic pricing rather than adding a new TTL-pricing policy.
  • No current-head authenticated Anthropic/Gateway turn was run; the local exporter/receiver exercised the changed export boundary without provider credentials. Earlier contributor evidence at 0e6ab27f8873a65d8d89cb1634098bdf2716c5d9 exercised a spawned Gateway through Anthropic HTTP into OTLP and observed the same 400000/600000 OpenClaw attributes; that remains prior-revision evidence, not a current-head live run.
  • Matching core and extension type-aware oxlint passed before integration; oxfmt and whitespace checks pass. The final receiver-fixture regression also passed (1 test; 340.20 seconds, mostly worker preparation). Local type/lint reruns hit the nested checkout/shared installation boundary; exact-head CI supplies those checks.
  • Whole change: production +71/-23 (net +48), tests +277/-37 (net +240), docs +1. The added production lines carry typed optional facts through existing owners. Compared with the original revision, the diff shrinks from 17 files / 471 changed lines to 16 files / 409 changed lines.

Exact-head CI, including the CI/security gate, passes for 8771c0302a948716bf23fb8cd978b90646a75ae5. The native watcher reports GREEN with zero pending checks. ClawSweeper found no code issues on this head; its remaining advisory request is a fresh full Gateway/provider trace, whose absence is disclosed above.

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: diagnostics-otel Extension: diagnostics-otel size: S labels Oct 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 14, 2026
@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Preserves reported Anthropic and Bedrock cache-write TTL counts through usage accounting into OpenTelemetry spans.

Example: A response reports 1000000 cache-write tokens: 400000 with one-hour retention and 600000 with five-minute retention.

  • Before: The exported model-call span lacks the TTL breakdown.
  • After: OpenClaw-specific attributes contain 400000 and 600000, while generic usage retains only the 1000000 total.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused patch resolves prior pricing findings and has meaningful boundary regressions, but supplied runtime evidence does not cover the revised production flow.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot inspect provider-reported five-minute and one-hour cache-write counts in model-call traces.
Reason: Restoring reported numeric facts has clear diagnostic value and uses existing provider, accounting, and exporter responsibilities without new configuration.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR fixes a current telemetry defect using existing accounting owners; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: 8771c0302a948716bf23fb8cd978b90646a75ae5

Before merge

  • Add real behavior proof - The reported local diagnostics service and real HTTP/protobuf receiver exercise exporter output for mixed, zero, and absent buckets, but start after the changed provider and agent owners. The reported Gateway exercise at 0e6ab27 predates the substantive accounting revision. Supply redacted terminal output or a trace from a shipped CLI or Gateway Anthropic turn showing provider-reported TTL counts reaching OTLP through the revised owners; remove API keys, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Missing supplied runtime evidence of a shipped CLI or Gateway Anthropic turn traversing the revised provider and agent accounting into OTLP.
Agent review details

How this fits together

Provider adapters normalize response usage, agent accounting preserves and accumulates it, and diagnostics-otel exports numeric model-call attributes to OTLP collectors.

flowchart LR
  A[Provider usage] --> B[Provider accounting]
  B --> C[Agent usage normalization]
  C --> D[Recovery and accumulation]
  C --> E[Model call diagnostics]
  D --> E
  E --> F[OpenTelemetry exporter]
  F --> G[OTLP collector]
Loading

Technical review

Best possible solution:

Retain the focused optional-field propagation and OpenClaw-specific TTL attributes while preserving existing generic totals and pricing.

Do we have a high-confidence way to reproduce the issue?

Current-main source demonstrably drops five-minute provider counts and exports neither TTL bucket; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

The patch is the smallest coherent repair across existing owners: preserve independently reported buckets, retain zero versus absent semantics, and export subsets outside the additive generic namespace.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 745d2e768dff.

Provenance checked

  • Anthropic billing and compaction accounting keeps the original intent (e4d6e56: Shared direct and managed Anthropic accounting preserves provider usage and higher one-hour cache pricing; later compaction accounting distinguishes billing totals from context snapshots.)
  • Bedrock TTL accounting keeps the original intent (be7db27: Use the provider's authoritative TTL breakdown to price one-hour cache writes correctly.)
  • Agent usage accumulation keeps the original intent (97998cb: Preserve complete per-call costs and cached-token accounting across tool loops and attempts.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 351c069 adds extensions/diagnostics-otel/src/service-genai-attributes.ts:134 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 351c069ed235; files: extensions/diagnostics-otel/src/service-genai-attributes.ts)
  • Vincent Koc: Raw commit 5f05410 adds extensions/diagnostics-otel/src/service-genai-attributes.ts:158 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5f054100487f; files: extensions/diagnostics-otel/src/service-genai-attributes.ts)

PR surface

Source +48, Tests +240, Docs +1. Total +289 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 71 23 +48
Tests 7 277 37 +240
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 349 60 +289

Review metrics

Metric Value Why it matters
Production versus test changes Production +71/-23; tests +277/-37 Production growth carries optional facts through existing owners; tests cover provider parsing, compaction, accumulation, recovery, and OTLP export.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Missing TTL detail affects operator observability without blocking model calls or message delivery.
  • merge-risk: 🚨 compatibility: The shared usage and SDK-exposed diagnostic contracts gain optional numeric fields; existing fields and generic pricing remain intact.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-14T03:50:26.515Z sha 3fdfb3b :: needs real behavior proof before merge. :: [P2] Avoid pricing TTL buckets alongside the blended cache-write total
  • reviewed 2026-10-19T12:25:52.716Z sha 0e6ab27 :: blocked before merge. :: [P2] Prevent duplicate pricing of blended and TTL cache-write buckets
  • reviewed 2026-10-19T13:56:12.981Z sha 343b864 :: needs changes before merge. :: [P2] Prevent duplicate pricing of blended and TTL cache-write buckets
  • reviewed 2026-10-21T13:50:51.532Z sha cd82f24 :: needs changes before merge. :: [P2] Prevent duplicate pricing of blended and TTL cache-write buckets
  • reviewed 2026-10-25T03:30:08.633Z sha efee8a4 :: needs real behavior proof before merge. :: none

Reviewed October 24, 2026, 11:59 PM ET / October 25, 2026, 03:59 UTC (Revision 6).

@ryan-dyer-sp
ryan-dyer-sp marked this pull request as draft October 16, 2026 12:53
@ryan-dyer-sp

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 19, 2026
@ryan-dyer-sp

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Oct 22, 2026
…te pricing

Keep the blended generic usage count and export TTL subsets only as OpenClaw attributes. Preserve reported zero and absent buckets across provider usage, recovery, and accumulation. Integrate current main without restoring retired test paths.
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete
steipete merged commit 9999f71 into openclaw:main Oct 25, 2026
164 of 167 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…L split (openclaw#171663)

Preserve reported Anthropic cache-write TTL buckets through provider accounting and model-call diagnostics. Export the breakdown only under OpenClaw attributes so generic pricing does not count the same writes twice.

Preserve explicit zero and absence through normalization, recovery, and accumulation. Regression coverage includes provider compaction and delivery through a real HTTP/protobuf OTLP receiver.

Co-authored-by: ryan-dyer-sp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawtributors PR from a clawtributor docs Improvements or additions to documentation extensions: amazon-bedrock extensions: diagnostics-otel Extension: diagnostics-otel gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants