Skip to content

fix(claude): count requestless resp_ content blocks once - #1935

Merged
ryoppippi merged 2 commits into
mainfrom
pullfrog/issue-1934-run-39301753264-attempt-1
Oct 19, 2026
Merged

ryoppippi merged 2 commits into
mainfrom
pullfrog/issue-1934-run-39301753264-attempt-1

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Requestless Claude Code lines whose message.id is an OpenAI Responses API resp_ ID were counted once per content block, doubling usage. is_anthropic_message_id now accepts resp_ as well as msg_, so those lines collapse by session across content-block timestamps, the same as msg_ IDs.

  • rust/adapters/claude/src/lib.rs: accept the resp_ prefix.
  • rust/adapters/claude/src/README.md: mention resp_ in the requestless dedupe note.
  • Tests: resp_ cases for the entries loader (lib.rs), the daily loader (daily.rs), and a CLI test covering daily/weekly/monthly/session totals.

Closes #1934

Co-authored-by: StartupBros [email protected]


Summary by cubic

Fixes requestless Claude Code lines with an OpenAI resp_ message ID being counted once per content block. The deduplication logic now treats resp_ IDs the same as Anthropic msg_ IDs, collapsing content-block lines for one response across timestamps.

  • Updates is_anthropic_message_id so resp_ prefix matches alongside msg_, affecting usage_dedupe_hash and the entry/daily loaders.
  • Adds unit tests for both loaders and a CLI integration test covering daily, weekly, monthly, and session reports.
  • Documents the msg_/resp_ collapse behavior in the adapter README.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c6b80cff-7e05-442b-97c2-5836656edcb1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide ca27db7 Commit Preview URL

Branch Preview URL
Oct 19 2026, 06:45 PM

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

ccusage

npx https://pkg.pr.new/ccusage@1935

@ccusage/ccusage-darwin-arm64

npx https://pkg.pr.new/@ccusage/ccusage-darwin-arm64@1935

@ccusage/ccusage-darwin-x64

npx https://pkg.pr.new/@ccusage/ccusage-darwin-x64@1935

@ccusage/ccusage-linux-arm64

npx https://pkg.pr.new/@ccusage/ccusage-linux-arm64@1935

@ccusage/ccusage-linux-x64

npx https://pkg.pr.new/@ccusage/ccusage-linux-x64@1935

@ccusage/ccusage-win32-x64

npx https://pkg.pr.new/@ccusage/ccusage-win32-x64@1935

commit: ca27db7

@github-actions

Copy link
Copy Markdown
Contributor Author

ccusage performance comparison

PR SHA: ca27db7e7a48
Base SHA: 3d3ca0b02b72

Performance comparison skipped.

Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided.

Base package: 3d3ca0b02b72

@github-actions

Copy link
Copy Markdown
Contributor Author

ccusage performance comparison

PR SHA: ca27db7e7a48
Base SHA: 3d3ca0b02b72

Performance comparison skipped.

Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided.

Base package: 3d3ca0b02b72

@ryoppippi
ryoppippi merged commit 0861e7f into main Oct 19, 2026
48 checks passed
@ryoppippi
ryoppippi deleted the pullfrog/issue-1934-run-39301753264-attempt-1 branch October 19, 2026 19:06
Buster210 added a commit to Buster210/ccusage that referenced this pull request Oct 20, 2026
Borrow upstream's claude resp_ dedupe fix (ccusage#1935) and the zstd 0.14.3 bump
(ccusage#1936), plus the models.dev and LiteLLM snapshot refreshes that move the
litellm pin to 497f31d4. Keep 20.0.34 numbering; DO NOT push a v20.0.37 tag
from this fork.

Hand-resolved conflicts:

- rust/adapters/claude/src/lib.rs: upstream's is_anthropic_message_id now also
  accepts OpenAI Responses API `resp_` ids, so requestless lines that Claude
  Code writes one per content block collapse instead of doubling usage. The
  fork's private visibility and its collapse_replays dedupe stay. Upstream's
  two tests are ported to the fork's push_deduped_entry signature and to
  read_usage_file's Result.
- rust/adapters/claude/src/README.md: take upstream's wording, which documents
  the msg_/resp_ exception to the timestamp-scoped requestless rule.
- rust/Cargo.toml: take zstd 0.14.3, keep the fork's exact `=` pin style.
- .github/workflows/release.yaml: keep the fork's tag-only release. Upstream's
  tagpr job and the songmu/tagpr action bump do not apply here.
- apps/ccusage/package.json, docs/package.json, package.json: keep 20.0.34.
  Upstream's 20.0.37 bump is dropped.
- packages/ccusage-*/package.json (6 files): stay deleted. The fork ships no
  npm wrapper packages and the release workflow does not read them.
- rust/adapters/claude/src/daily.rs: stays deleted. The fork's daily path
  lives in lib.rs and shares the dedupe helper the fix changes.
Buster210 added a commit to Buster210/ccusage that referenced this pull request Oct 20, 2026
Upstream tip: c76874e (2026-10-20, chore(pricing): update models.dev snapshot)
Previous fork base: 0c58b88 (the upstream commit this fork was synced to)

Synced 83 upstream commits on top of 0c58b88: 56 automated pricing
snapshot refreshes and the following meaningful ones:

  1cd29f5 chore(deps): update pnpm to v12.13.0 (ccusage#1907)
  e4f63ba chore(deps): update node.js to >=24.22.0 (ccusage#1908)
  130e502 ci: regenerate bun.nix automatically (ccusage#1909)
  259ec33 feat(adapter): report stored cost in JSON model breakdowns (ccusage#1903)
  c1eb448 chore: release v20.0.35 (ccusage#1901)
  2a0875f ci(pricing): update snapshots on push to main and daily instead of hourly (ccusage#1914)
  b090428 chore(deps): update github/codeql-action action to v4.39.0 (ccusage#1912)
  4dcf7f5 fix(nix): pin models-dev-gen remeda to models.dev's version and stop Renovate drift (ccusage#1915)
  46edb28 fix(nix): stop the dev shell from copying the whole repository (ccusage#1917)
  58ec8f1 fix(nix): let commits succeed in worktrees without a loaded dev shell (ccusage#1920)
  a570a6f fix(nix): vendor Cargo deps without import-from-derivation (ccusage#1918)
  f6d28c5 fix(antigravity): map model IDs 1418/1419 to gemini-4-argon (ccusage#1905)
  ce439e5 fix(antigravity): map model ID 1050 to gemini-3.1-flash-lite (ccusage#1902)
  e62a66f chore(deps): update pnpm to v12.14.0 (ccusage#1923)
  117ae68 ci(nix): make the macOS Nix cache save a trimmed store with the Crane layers (ccusage#1921)
  7a063a0 ci: shorten the Windows native build critical path (ccusage#1924)
  85ebca3 perf(rust): move pricing snapshots into a leaf crate (ccusage#1922)
  8fe3f47 perf(nix): build Crane layers with the binary's feature resolution (ccusage#1925)
  ac289aa perf(pricing): give the pricing refresh a verify-only TLS 1.3 rustls provider (ccusage#1927)
  d097f74 chore(deps): update rust crate rustls to 0.23.46 (ccusage#1928)
  f8aaf89 docs: use the compact pkg.pr.new URL for bunx previews [ci skip] (ccusage#1929)
  f56bb3d chore: release v20.0.36 (ccusage#1916)
  aaafb41 chore(deps): update dependency vitepress-plugin-group-icons to ^1.8.1 (ccusage#1931)
  0861e7f fix(claude): count requestless resp_ content blocks once (ccusage#1935)
  867c9f3 chore: release v20.0.37 (ccusage#1933)
  fa40bfd chore(deps): update songmu/tagpr action to v1.21.3 (ccusage#1937)
  de99d15 chore(deps): update rust crate zstd to 0.14.3 (ccusage#1936)

Fork wins kept: the SQLite on-disk cache with --live-only and the per-namespace
ledger, the pi adapter and its per-path namespaces, the OpenCode V2 loader, the
FxHash/Cow hot paths, the table renderer, clear-cache, and the tag-only release
workflow. Upstream's own release and tagpr machinery stays out.

Hand-resolved conflicts:

  rust/adapters/claude/src/lib.rs: upstream's resp_ message-id dedupe (ccusage#1935) lands
    beside the fork's requestless replay and collapse_replays rules.
  rust/adapters/claude/src/README.md: upstream's wording for the msg_/resp_ exception.
  rust/Cargo.toml: zstd 0.14.3, keeping the fork's exact `=` pin style.
  .github/workflows/release.yaml: the fork's tag-only release, without upstream's
    tagpr job or the songmu/tagpr action bump.
  apps/ccusage/package.json, docs/package.json, package.json: keep 20.0.34;
    upstream's 20.0.37 bump is dropped.
  packages/ccusage-*/package.json (6 files): stay deleted; the fork ships no npm
    wrapper packages and the release workflow does not read them.
  rust/adapters/claude/src/daily.rs: stays deleted; the fork's daily path lives in
    lib.rs and shares the dedupe helper the fix changes.

Fixes made while landing this sync, folded in so the merge stands green on its own:

  fix(ci): save the Nix store from the native build composites. The nested
    cache-nix-action read an empty primary-key at post-job and every native
    build failed; upstream's defer-save pattern is the fix.
  fix(rust): keep the agent-recorded cost for deleted sources. The recorded_cost
    ledger column carries it, so storedCost survives a deleted file. The ledger
    schema version stays at 2: the column is not a LedgerEntry field, so the blob
    layout is unchanged and the previously released binary keeps working.
  fix(rust): make the file fingerprint helper private, the one hawk finding. It is
    inherited from the pre-sync master, not introduced here.

Keep 20.0.34 numbering; DO NOT push a v20.0.34 tag from this fork (release.yaml
would publish fork bytes under upstream identity).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Requestless Claude Code lines with an OpenAI resp_ message id are counted once per content block

2 participants