Skip to content

fix(claude): dedupe requestless Anthropic message IDs across timestamps - #1838

Merged
ryoppippi merged 2 commits into
mainfrom
pullfrog/issue-1837-run-37766001119-attempt-1
Oct 9, 2026
Merged

ryoppippi merged 2 commits into
mainfrom
pullfrog/issue-1837-run-37766001119-attempt-1

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

Requestless Claude entries with real Anthropic message IDs (msg_ prefix) now dedupe by (message.id, session) across timestamps in both the entry loader (rust/adapters/claude/src/lib.rs) and the daily loader (rust/adapters/claude/src/daily.rs), keeping the most complete record via the existing replacement logic. Gateway placeholder IDs keep the timestamp-scoped key, preserving the #1635/#1799 behavior. Docs updated in rust/adapters/claude/src/README.md.

Tests: new unit tests for both loaders covering same-session msg_ collapse across timestamps; split the old same-session requestless test into Anthropic-collapse vs gateway-keep cases; new claude_cli test asserting daily/weekly/monthly/session all count two content-block lines once (102 tokens) while the ocgo gateway fixture still counts 3x (306). Ran cargo test -p ccusage-adapter-claude, cargo test -p ccusage --test claude_cli, and cargo test -p ccusage --bin ccusage (all green), plus cargo fmt --check and clippy on the Claude adapter.

Closes #1837


Summary by cubic

Fixes requestless Claude entries with real Anthropic message IDs (msg_ prefix) being counted multiple times when Claude Code writes one line per content block with distinct timestamps for a single response.

  • Requestless entries now dedupe by (message.id, session) across timestamps in both the entry loader and daily loader; gateway placeholder IDs keep the timestamp-scoped key.
  • msg_ prefix is treated as a heuristic since only a request ID proves two lines belong to one response.
  • Adds unit tests for both loaders and claude_cli tests asserting content-block lines are counted once in daily, weekly, monthly, and session reports, including a case where a streamed response straddles midnight.

Written for commit 166a813. Summary will update on new commits.

View guided diff Turn on auto-fix

@coderabbitai

coderabbitai Bot commented Oct 8, 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: 284021e9-365f-40bd-84ff-71a0f6bc858b

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

cloudflare-workers-and-pages Bot commented Oct 8, 2026 •

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 166a813 Commit Preview URL

Branch Preview URL
Oct 09 2026, 10:28 PM

Document that the msg_ prefix is a heuristic and keep the same-timestamp
test on a gateway ID so it still exercises the timestamp-scoped path.
@pkg-pr-new

pkg-pr-new Bot commented Oct 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

ccusage

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

@ccusage/ccusage-darwin-arm64

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

@ccusage/ccusage-darwin-x64

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

@ccusage/ccusage-linux-arm64

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

@ccusage/ccusage-linux-x64

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

@ccusage/ccusage-win32-x64

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

commit: 166a813

@ryoppippi
ryoppippi merged commit 05311f3 into main Oct 9, 2026
35 checks passed
@ryoppippi
ryoppippi deleted the pullfrog/issue-1837-run-37766001119-attempt-1 branch October 9, 2026 23:09
@github-actions github-actions Bot mentioned this pull request Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

ccusage performance comparison

PR SHA: 166a813cb787
Base SHA: 88ed26d61159

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: 88ed26d61159

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

ccusage performance comparison

PR SHA: 166a813cb787
Base SHA: 88ed26d61159

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: 88ed26d61159

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.

Claude usage counted 2-3x when requestId is absent: content-block lines of one response have distinct timestamps

1 participant