Skip to content

fix(pi): return zero totals for empty reports - #1674

Merged
ryoppippi merged 2 commits into
ccusage:mainfrom
Nicolas0315:codex/fix-pi-empty-totals-v2
Sep 15, 2026
Merged

ryoppippi merged 2 commits into
ccusage:mainfrom
Nicolas0315:codex/fix-pi-empty-totals-v2

Conversation

@Nicolas0315

@Nicolas0315 Nicolas0315 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Keeps the Pi JSON report shape stable when a selected period has no rows by returning the shared zero-valued totals object instead of null. This branch is rebuilt from current main, so the PR contains exactly one adapter file.

Testing:

  • cargo fmt --manifest-path rust/Cargo.toml --all -- --check
  • cargo test --manifest-path rust/Cargo.toml -p ccusage-adapter-pi --features ccusage-core/fetch-litellm-pricing empty_report_has_zero_totals_object (1 passed)

Summary by cubic

Fixes the Pi adapter report so a selected period with no usage rows returns a zero-valued totals object instead of null, keeping the JSON response shape consistent for consumers. Adds a regression test covering that empty report shape.

Written for commit 5c57e5d. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Reports now consistently include a totals summary, even when no rows are available.
    • Empty reports display zero token and cost values instead of an empty result.

Keep the JSON totals shape stable when a pi report has no usage rows. Add a regression test covering the shared zero-valued totals object.

Refs ccusage#832 and ccusage#1480.
@Nicolas0315

Copy link
Copy Markdown
Contributor Author

@coderabbitai review
@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review
@cubic-dev-ai review

@Nicolas0315 I have started the AI code review. It will take a few minutes to complete.

@coderabbitai

coderabbitai Bot commented Aug 31, 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: 788aafad-c475-4d51-a16f-23d4d77f98c9

📥 Commits

Reviewing files that changed from the base of the PR and between 34c697b and 118be34.

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

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


📝 Walkthrough

Walkthrough

report_from_rows now emits a zero-valued totals object when no rows exist. A unit test verifies the empty daily array and zero token and cost totals.

Changes

Empty report totals

Layer / File(s) Summary
Totals object and validation
rust/adapters/pi/src/report.rs
report_from_rows always uses totals_json(rows). The test verifies zero token counts, totalCost of 0.0, and an empty daily array for empty input.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 5c57e

The Pi report now returns zero-valued totals for empty periods while preserving the response shape, with no actionable merge-blocking risk remaining after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: returning zero totals for empty Pi reports.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@github-actions

Copy link
Copy Markdown
Contributor

Pullfrog could not complete the automated PR review. The PR was left open for maintainer review.

@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

The review covers the single Pi adapter change and its regression test.

  • Stable empty-report totals — report_from_rows now delegates empty inputs to the shared totals_json implementation, producing a zero-valued totals object for Pi reports, and the test verifies the token and cost fields.

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) | 𝕏

@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

@Nicolas0315 I will review the changes in #1674.

⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

azidancorp added a commit to azidancorp/ccusage that referenced this pull request Sep 7, 2026
Upstream through 8841f92: official Antigravity SQLite adapter (ccusage#1677),
ZCode (ccusage#1675) and Grok Build CLI sources, Copilot session-state usage
(ccusage#1676), Codex originator breakdowns and cache-write token accounting
(ccusage#1663, ccusage#1674), date-window file skipping (ccusage#1665), session totals scoped
to the date window (ccusage#1664), OpenCode v2 session usage (ccusage#1668),
timestamp-aware DeepSeek V4 pricing (ccusage#1679), ETag-validated pricing cache
refreshes (ccusage#1672), and numeric-column preservation in narrow tables
(ccusage#1671).

Conflict resolutions per the personal divergence ledger:

- Antigravity: adopt the upstream native adapter wholesale; remove the
  personal heuristic adapter and the antigravity-analysis/ provenance
  directory.
- Codex: keep counting copied parent history (replay.rs stays deleted),
  keep tier changes applying at the following turn_context, keep the
  pre-v0.144.0 fast windows and the 2x fast-multiplier fallback, and keep
  the append-aware grouped cache with serde'd parser state. Integrate
  upstream cache-write tokens, originator sources, session_meta line
  detection, and filter_codex_usage_files date-window skipping. Bump the
  group, per-file event, and all-agent row cache discriminators.
- Claude: rewire the cached daily/session summary wrappers onto
  upstream's date-scoped loaders (ccusage#1664).
- OpenCode: keep WAL-signature cache signatures, the summary cache
  wrapper, and --no-cost -> Display mapping; take upstream's v2 session
  usage loading and split directory loader.
- Pricing: keep the explicit GLM-5.2 rates and 1,000,000-token context
  limit (now via put_builtin_entry for both GLM-5.1 and GLM-5.2); take
  upstream's DeepSeek V4 scheduled rates and catalog rules.
- Terminal: keep full dates whenever the minimum full-date layout fits
  and attached breakdown rows; take upstream's content-aware fallback
  minimums and numeric-column floors, adapting the 80-column regression
  test to the personal full-date policy.
- Presentation: keep the hidden-by-default Models column and the
  all-agent --with-models opt-in; regenerate zcode/copilot session
  snapshots under the wider first-column floor.
- Ledger: audit baseline updated to 8841f92; heuristic Antigravity and
  replay suppression recorded as retired divergences.
@pkg-pr-new

pkg-pr-new Bot commented Sep 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

ccusage

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

@ccusage/ccusage-darwin-arm64

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

@ccusage/ccusage-darwin-x64

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

@ccusage/ccusage-linux-arm64

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

@ccusage/ccusage-linux-x64

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

@ccusage/ccusage-win32-x64

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

commit: 5c57e5d

@ryoppippi
ryoppippi merged commit a4a31c3 into ccusage:main Sep 15, 2026
36 checks passed
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.

2 participants