fix(pi): reject invalid source costs in auto mode - #1666
Conversation
Keep raw Pi costs for display output while treating negative and non-finite source values as unavailable in Auto mode. Reuse token pricing for default and named stores and preserve missing-pricing diagnostics when fallback pricing is unavailable. Co-authored-by: robert7k <robert7k@users.noreply.github.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
ccusage-guide | 0d73faf | Commit Preview URL Branch Preview URL |
Aug 30 2026, 02:59 AM |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughPI parsing now normalizes invalid source costs in ChangesPI cost handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change makes Auto mode ignore negative or non-finite Pi source costs and recalculate from tokens while preserving Display and Calculate behavior; it is localized and merge-ready after normal checks, with no actionable merge-blocking risk remaining. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes address issue
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 Clippy (1.97.1)Clippy execution failed 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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes This review covers the Pi adapter's handling of invalid source costs and its associated regression tests.
- Auto-mode fallback. Negative and non-finite source costs are excluded only in
Auto, allowing token pricing to be used while preserving raw values forDisplayand token-based behavior forCalculate. - Store and diagnostic consistency. The filtered source cost is used for both default and named-store calculation and missing-pricing detection, and effective costs remain part of replay matching.
- Regression coverage. Tests cover default and named stores, known and missing pricing, negative and zero values, and non-finite source costs. Focused Pi tests and unified adapter tests pass.
@v0 or keep the SHA fresh with Dependabot | View workflow run | Using GPT Luna (free via Pullfrog for OSS) | 𝕏
ccusage
@ccusage/ccusage-darwin-arm64
@ccusage/ccusage-darwin-x64
@ccusage/ccusage-linux-arm64
@ccusage/ccusage-linux-x64
@ccusage/ccusage-win32-x64
commit: |
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |

Fixes #1514\n\nPi source costs can be negative or non-finite for some OpenRouter models.\n\nThis keeps the raw source value for Display mode, recalculates from tokens in Auto mode when the source value is negative or non-finite, and keeps Calculate mode token-based. The behavior is covered for the default Pi store, named stores, known pricing, and missing pricing.\n\nValidation:\n- Pi adapter tests: 28 passed\n- rustfmt --check\n- clippy with warnings denied\n\nThe issue reporter is included as a commit co-author.
Summary by cubic
Fixes #1514 by rejecting negative and non-finite Pi source costs in Auto mode, so Auto mode recalculates from tokens instead of using an invalid value. Display mode still shows the raw source cost, and Calculate mode remains token-based. Added tests for default and named stores, with known and missing pricing.
Written for commit 0d73faf. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests