Skip to content

fix(pi): reject invalid source costs in auto mode - #1666

Merged
ryoppippi merged 1 commit into
mainfrom
codex/fix/pi-negative-cost
Aug 30, 2026
Merged

ryoppippi merged 1 commit into
mainfrom
codex/fix/pi-negative-cost

Conversation

@ryoppippi

@ryoppippi ryoppippi commented Aug 30, 2026

Copy link
Copy Markdown
Member

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.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved cost display in automatic mode by retaining valid, non-negative source costs.
    • Automatically recalculates costs from token usage when source pricing is negative, invalid, or unavailable.
    • Pricing warnings now consistently reflect the normalized cost information.
    • Preserved existing cost behavior for display-only and calculation modes.
  • Tests

    • Added coverage for default and named pricing sources, invalid costs, recalculation, and pricing warnings.

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>
@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 0d73faf Commit Preview URL

Branch Preview URL
Aug 30 2026, 02:59 AM

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ec906082-7e88-461a-aa08-4e151b4998d6

📥 Commits

Reviewing files that changed from the base of the PR and between 527ec3a and 0d73faf.

📒 Files selected for processing (1)
  • rust/adapters/pi/src/parser.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

PI parsing now normalizes invalid source costs in Auto mode before cost calculation and missing-pricing detection. Tests cover default and named stores across supported cost modes.

Changes

PI cost handling

Layer / File(s) Summary
Normalize source costs and integrate calculations
rust/adapters/pi/src/parser.rs
Auto mode accepts only finite, non-negative source costs. Invalid values are recalculated from tokens for cost and pricing checks. Other modes retain their existing behavior.
Validate cost modes and store variants
rust/adapters/pi/src/parser.rs
Tests cover default and named stores, negative and non-finite costs, zero costs, token-based recalculation, stored display costs, and missing-pricing indicators.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0d73f

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rejecting invalid source costs in Pi Auto mode.
Linked Issues check ✅ Passed The changes address issue #1514 by rejecting negative or non-finite source costs in Auto mode and recalculating costs from tokens instead of displaying invalid negative values. Display and Calculate m…
Out of Scope Changes check ✅ Passed The changes are limited to Pi parser cost handling and related tests. They support the linked issue objectives and do not introduce unrelated scope.
Full details: Linked Issues check

Explanation

The changes address issue #1514 by rejecting negative or non-finite source costs in Auto mode and recalculating costs from tokens instead of displaying invalid negative values. Display and Calculate modes retain their intended behavior.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix/pi-negative-cost

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.

❤️ Share

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 for Display and token-based behavior for Calculate.
  • 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.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using GPT Luna (free via Pullfrog for OSS) | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Aug 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

ccusage

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

@ccusage/ccusage-darwin-arm64

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

@ccusage/ccusage-darwin-x64

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

@ccusage/ccusage-linux-arm64

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

@ccusage/ccusage-linux-x64

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

@ccusage/ccusage-win32-x64

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

commit: 0d73faf

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: 0d73fafe31ce
Base SHA: 527ec3a9cefa

This compares the Rust PR release binary against the configured base package on the same CI runner.

Package runtime diagnostics

Compares 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 /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
All rows run --offline --json, measured by hyperfine with 0 warmups and 1 runs. This isolates wrapper overhead from the installed native optional dependency and the workspace release binary built on the runner.

Command Runtime Input Median Throughput Samples
claude --offline --json Package wrapper 1.01 GiB 387.6ms 2.60 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 346.3ms 2.91 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 124.5ms 8.09 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 104.6ms 9.62 GiB/s 1

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published native ccusage binary from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 2 warmups and 7 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude daily --offline --json 0.00 MiB 40.4ms 15.6ms 2.58x 55.00 MiB 24.71 MiB 0.45x 0.04 MiB/s 0.10 MiB/s
claude session --offline --json 0.00 MiB 33.7ms 7.9ms 4.24x 55.00 MiB 24.71 MiB 0.45x 0.05 MiB/s 0.19 MiB/s
codex daily --offline --json 0.00 MiB 28.4ms 7.8ms 3.63x 55.00 MiB 24.96 MiB 0.45x 0.03 MiB/s 0.11 MiB/s
codex session --offline --json 0.00 MiB 30.0ms 8.9ms 3.38x 55.00 MiB 24.96 MiB 0.45x 0.03 MiB/s 0.10 MiB/s

Large real-world-shaped fixture performance

Generated 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 /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published native ccusage binary from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 0 warmups and 1 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude --offline --json 1.01 GiB 373.8ms 355.0ms 1.05x 972.85 MiB 956.86 MiB 0.98x 2.69 GiB/s 2.84 GiB/s
codex --offline --json 1.01 GiB 126.9ms 101.6ms 1.25x 445.16 MiB 437.17 MiB 0.98x 7.93 GiB/s 9.91 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 19.20 KiB 19.20 KiB +0.00 KiB 1.00x
installed native package binary 4302.03 KiB 4302.16 KiB +0.13 KiB 1.00x

Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: 0d73fafe31ce
Base SHA: 527ec3a9cefa

This compares the PR package against the configured base package on the same CI runner.

Package runtime diagnostics

Compares 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 /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
All rows run --offline --json, measured by hyperfine with 0 warmups and 1 runs. This isolates wrapper overhead from the installed native optional dependency and the workspace release binary built on the runner.

Command Runtime Input Median Throughput Samples
claude --offline --json Package wrapper 1.01 GiB 358.1ms 2.81 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 300.3ms 3.35 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 138.1ms 7.29 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 108.0ms 9.32 GiB/s 1

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published ccusage package from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 2 warmups and 7 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude daily --offline --json 0.00 MiB 45.2ms 36.1ms 1.25x 55.00 MiB 55.00 MiB 1.00x 0.03 MiB/s 0.04 MiB/s
claude session --offline --json 0.00 MiB 35.7ms 37.9ms 0.94x 55.25 MiB 55.25 MiB 1.00x 0.04 MiB/s 0.04 MiB/s
codex daily --offline --json 0.00 MiB 39.0ms 35.3ms 1.10x 55.00 MiB 55.25 MiB 1.00x 0.02 MiB/s 0.02 MiB/s
codex session --offline --json 0.00 MiB 33.7ms 33.3ms 1.01x 55.25 MiB 55.25 MiB 1.00x 0.03 MiB/s 0.03 MiB/s

Large real-world-shaped fixture performance

Generated 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 /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published ccusage package from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 0 warmups and 1 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude --offline --json 1.01 GiB 350.2ms 333.2ms 1.05x 954.86 MiB 934.85 MiB 0.98x 2.88 GiB/s 3.02 GiB/s
codex --offline --json 1.01 GiB 137.4ms 140.1ms 0.98x 417.16 MiB 429.17 MiB 1.03x 7.33 GiB/s 7.19 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 19.20 KiB 19.20 KiB +0.00 KiB 1.00x
installed native package binary 4302.03 KiB 4302.16 KiB +0.13 KiB 1.00x

Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@ryoppippi
ryoppippi merged commit d56ace8 into main Aug 30, 2026
43 checks passed
@ryoppippi
ryoppippi deleted the codex/fix/pi-negative-cost branch August 30, 2026 03:20
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.

openrouter/auto-beta with pi reports negative cost

1 participant