Skip to content

Preserve known Claude usage when cache fields are null - #16646

Open
sernote wants to merge 1 commit into
warpdotdev:masterfrom
sernote:codex/preserve-nullable-claude-usage
Open

sernote wants to merge 1 commit into
warpdotdev:masterfrom
sernote:codex/preserve-nullable-claude-usage

Conversation

@sernote

@sernote sernote commented Oct 25, 2026

Copy link
Copy Markdown

Description

A native Claude Code response containing a documented nullable cache field currently loses its entire token-usage observation, including known sibling counters and attribution. Preserve those measured values while leaving null cache values unmeasured and omitted.

The change accepts null only for cache_creation, cache_read_input_tokens, and cache_creation_input_tokens. The shared counter parser takes an explicit nullable-path allowlist; Codex supplies an empty list. Invalid non-null values, negative counts, unsupported nulls, partition-sum validation, and response reconciliation retain their existing behavior.

Found during a cache-telemetry audit using audit-prompt-caching. Independent validation then reproduced the input with unmodified Claude Code 2.1.17 and the failure with Warp's real extractor. Investigation and implementation were AI-assisted with Codex.

Related: #16240 restructures the same crate and preserves independent reporting after invalid data, but its current head still classifies these nullable fields as invalid. This focused fix targets current master and may need to be carried into that change.

Linked Issue

Fixes #16645

  • The linked issue is labeled ready-to-spec or ready-to-implement. — Newly reported reproducible bug; awaiting maintainer triage.
  • Relevant before/after evidence is included below. This changes a pure extraction library and has no rendered UI.

Testing

  • Added five public-extractor regression/guardrail tests: nullable values and attribution/tools, partial totals across mixed responses, retention of a prior complete observation, invalid Claude inputs, and unchanged strict Codex behavior.
  • TDD: the tests failed in three expected ways before the fix; all 36 crate tests passed after it using the real workspace, upstream lockfile and Rust 1.92.0.
  • cargo +1.92.0 test -p warp_harness_usage --locked — passed.
  • cargo +1.92.0 clippy -p warp_harness_usage --locked --all-targets --tests -- -D warnings — passed.
  • Targeted Rust formatting with the repository's import settings ran last and made no additional changes; git diff --check passed.
  • cargo-nextest was unavailable, so Cargo's native runner was used. No substitute crate or alternate dependency versions were used.

Manual producer-to-extractor check: an unmodified pinned @anthropic-ai/claude-code@2.1.17 generated four native JSONL captures against a local fake SSE endpoint. The real Warp extract_claude API was then executed on their assistant records before and after the patch. External networking and access to real user credentials/history were denied during the producer run. Package hashes and the minimal native input are in the linked issue.

Native input Before After
Numeric control Numeric usage and attribution preserved Identical
cache_creation: null No usage/attribution; token coverage unavailable Input 100, output 0, cache read 4096, cache-write aggregate 0 retained; unknown partition object omitted
cache_read_input_tokens: null Same loss Known siblings and attribution retained; cache-read count omitted
cache_creation_input_tokens: null Same loss Known siblings and attribution retained; cache-write aggregate omitted

All three fixed cases retain independent tool coverage and emit no extraction diagnostics. Null is never converted to a measured zero. Production prevalence, provider cache-hit rate, billing impact, and behavior of every Claude Code version were not measured.

  • I have manually tested my changes locally with ./script/run. — Not performed; manual verification exercised the real producer and pure extraction API. No full application build, GUI run, cross-platform checks or full presubmit are claimed.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-BUG-FIX: Preserve known Claude Code usage counters when optional cache fields are null.

Accept only the documented nullable Claude cache fields as unknown so native transcripts retain measured sibling counters and attribution. Keep other Claude and Codex counter validation strict, with regression coverage for partial totals and repeated responses.
@cla-bot

cla-bot Bot commented Oct 25, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @sernote on file. In order for us to review and merge your code, each contributor must visit https://cla.warp.dev to read and agree to our CLA. Once you have done so, please comment @cla-bot check to trigger another check.

@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Oct 25, 2026
@sernote

sernote commented Oct 26, 2026

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Oct 26, 2026
@cla-bot

cla-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude Code usage extraction discards known counters when optional cache fields are null

1 participant