Skip to content

build(rust): migrate crates to edition 2024 - #1308

Merged
ryoppippi merged 2 commits into
mainfrom
codex/update-rust-edition-2024
Jun 13, 2026
Merged

build(rust): migrate crates to edition 2024#1308
ryoppippi merged 2 commits into
mainfrom
codex/update-rust-edition-2024

Conversation

@ryoppippi

@ryoppippi ryoppippi commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

  • migrate all Rust crates from edition 2021 to edition 2024
  • align treefmt rustfmt configuration with edition 2024
  • apply cargo fix, clippy --fix, and rustfmt output for edition-compatible code

Notes

  • This is intentionally separate from the Rust 1.96 toolchain bump in build(rust): update toolchain to 1.96.0 #1307.
  • Most source churn is mechanical rustfmt import ordering and Clippy let-chain simplification after switching the edition.
  • Rust 2024 makes std::env::set_var/remove_var unsafe, so test-only environment guards now wrap those calls in unsafe blocks.

Validation

  • cargo fix --manifest-path rust/Cargo.toml --workspace --edition
  • cargo test --manifest-path rust/Cargo.toml --workspace
  • just fmt
  • cargo clippy --fix --allow-dirty --manifest-path rust/Cargo.toml --release --workspace --all-targets -- -D warnings
  • nix flake check --print-build-logs

View with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is enabled.


Summary by cubic

Migrate all Rust crates to edition 2024 and align formatting. No functional changes; adopts 2024 syntax/safety rules and centralizes test env-var handling.

  • Refactors
    • Set edition = "2024" in all crates and updated treefmt rustfmt edition to 2024.
    • Applied cargo fix, clippy --fix, and rustfmt for 2024 patterns (let-chains, import ordering).
    • Centralized unsafe env-var access in tests with a shared EnvVarGuard (process-wide mutex + RAII), replacing ad-hoc locks and direct mutations.

Written for commit 00f4790. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Chores
    • Updated Rust edition to 2024 across the project.
    • Internal refactors for consistency: simplified conditionals, reordered imports, and cleaned up assertion formatting.
  • Tests
    • Test helpers and environment guards standardized; tests reformatted without changing behavior.

Update all Rust crate manifests from edition 2021 to 2024 now that the workspace toolchain is on Rust 1.96. Align treefmt rustfmt configuration with the crate edition so local formatting and flake checks use the same parser mode. Apply cargo fix, clippy --fix, and rustfmt output for edition-compatibility changes such as env var unsafe calls, expr_2021 macro fragments, let-chain collapses, and import ordering.
@pullfrog

pullfrog Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

no API key found — this repo is configured to use deepseek/deepseek-v4-pro, which needs DEEPSEEK_API_KEY, but the runner has no key for it.

To fix: add the key as a GitHub Actions secret (referenced from your workflow's env: block) or as a Pullfrog secret in the console — or switch this repo to a different model (free models need no key).

Open repo secrets → · Configure model → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@ryoppippi

Copy link
Copy Markdown
Member Author

@coderabbitai review
@cubic-dev-ai review

@coderabbitai

coderabbitai Bot commented Jun 12, 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: ac1df5c6-758b-4e31-bc5b-5605c91d193d

📥 Commits

Reviewing files that changed from the base of the PR and between 315250c and 00f4790.

📒 Files selected for processing (13)
  • rust/crates/ccusage-test-support/src/lib.rs
  • rust/crates/ccusage/src/adapter/codebuff/loader.rs
  • rust/crates/ccusage/src/adapter/droid/loader.rs
  • rust/crates/ccusage/src/adapter/gemini/loader.rs
  • rust/crates/ccusage/src/adapter/gemini/mod.rs
  • rust/crates/ccusage/src/adapter/gemini/paths.rs
  • rust/crates/ccusage/src/adapter/goose/paths.rs
  • rust/crates/ccusage/src/adapter/kilo/loader.rs
  • rust/crates/ccusage/src/adapter/kimi/loader.rs
  • rust/crates/ccusage/src/adapter/kimi/mod.rs
  • rust/crates/ccusage/src/adapter/kimi/paths.rs
  • rust/crates/ccusage/src/adapter/qwen/mod.rs
  • rust/crates/ccusage/src/main.rs
💤 Files with no reviewable changes (3)
  • rust/crates/ccusage/src/adapter/gemini/paths.rs
  • rust/crates/ccusage/src/adapter/gemini/loader.rs
  • rust/crates/ccusage/src/adapter/kimi/mod.rs

📝 Walkthrough

Walkthrough

Updates workspace to Rust edition 2024, consolidates nested conditionals into let-chain guards, introduces a shared EnvVarGuard for tests, and normalizes imports, formatting, and test assertions across many crates.

Changes

Rust Edition 2024 + Workspace normalization

Layer / File(s) Summary
Edition and formatter updates
nix/treefmt.nix, rust/crates/*/Cargo.toml
Changed rustfmt/Cargo edition settings from 2021 to 2024 across the repository.
Let-chain conditional refactors
rust/crates/ccusage/src/* and selected cli crates
Refactored nested if let/if patterns into single if let ... && ... style guard expressions; behavior preserved.
Test support & EnvVarGuard
rust/crates/ccusage-test-support/src/lib.rs, many #[cfg(test)] modules under adapter/* and tests in main.rs
Introduced/exported EnvVarGuard and replaced ad-hoc test env handling with scoped EnvVarGuard::set(...) usage; test assertions reformatted.
Import reordering and formatting-only edits
rust/crates/ccusage-cli/*, rust/crates/ccusage-terminal/*, rust/crates/ccusage/src/*, adapter modules
Reflowed and reordered use statements, adjusted pub re-exports, and reformatted tests/assertions without functional changes.
Minor algorithmic reflows
selected functions in blocks.rs, cost.rs, output.rs, pricing.rs, opencode
Small rewrites (e.g., dedupe checks, compact parsing) converted to chained guards preserving original outputs and flows.

Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • pullfrog

Poem

🐰 I hopped through crates and tidy trees,

Edition bumped with gentle ease,
Let-chains stitched where nests were deep,
Env guards hold the tests' safe sleep,
Imports sorted, all in rows—hooray, we leap!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.62% which is insufficient. The required threshold is 80.00%. 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 PR title 'build(rust): migrate crates to edition 2024' clearly and concisely summarizes the main change—migrating Rust crates from edition 2021 to edition 2024, which is the primary objective across all modified files.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/update-rust-edition-2024

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

@cubic-dev-ai

cubic-dev-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review
@cubic-dev-ai review

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 12, 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 00f4790 Commit Preview URL

Branch Preview URL
Jun 12 2026, 08:40 PM

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch PR details
gh pr view 1308 --repo ccusage/ccusage

echo "=== PR Files Changed ==="
gh pr diff 1308 --repo ccusage/ccusage

Length of output: 117545



@ryoppippi: This is a clean, well-scoped edition migration. All changes are mechanical and fall into the expected categories. Here's the summary:

Review

Edition & tooling

  • All four Cargo.toml files and nix/treefmt.nix correctly updated.

Import reordering

  • Purely mechanical rustfmt output — types/re-exports sorted before free functions, alphabetical within groups. No semantic impact.

Let-chain flattening

  • All nested if let { if cond { … } }if let … && cond { … } conversions look semantically correct. The most complex case in codex/parser.rs (the replay deduplication logic) was carefully inspected and is equivalent to the original.

unsafe env var calls

  • Correctly applied in test-only code as required by Rust 2024. Most guards are paired with a mutex (ENV_LOCK in codebuff/droid, QWEN_DATA_DIR_LOCK, KILO_DATA_DIR_LOCK) or RAII cleanup structs. A few tests in main.rs and kimi/paths.rs mutate env vars with save/restore but no explicit lock — this is a pre-existing concern, not introduced here, and is common in Rust test suites.

expr_2021 macro fragment

  • Correct choice. In Rust 2024, expr accepts additional forms (e.g. const { }) that expr_2021 does not, preserving the original macro contract for fs_fixture!.

Minor formatting

  • thread::spawn(move || loop { … })thread::spawn(move || { loop { … } }) is identical at the MIR level.
  • Inline if/else collapsing in hour_12/am_pm, multi-line vec![], assert!() reformatting — all cosmetic.

No functional changes detected. The PR is ready to merge.

@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

ccusage

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

@ccusage/ccusage-darwin-arm64

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

@ccusage/ccusage-darwin-x64

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

@ccusage/ccusage-linux-arm64

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

@ccusage/ccusage-linux-x64

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

@ccusage/ccusage-win32-x64

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

commit: 00f4790

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: 315250cf0656
Base SHA: 7a550caae5cc

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

Package runner startup

Execution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one bunx -p <url> ccusage --version run with an empty Bun install cache. Warm reuses that cache and reports the median of repeated runs.

Package SHA Execution setup Bunx temp cache Bunx warm median Warm samples
Base pkg.pr.new 7a550caae5cc 766.5ms 662.9ms 26.9ms 3
PR pkg.pr.new 315250c 1.027s 788.1ms 28.1ms 3

Cached bunx execution performance

Runs the same large fixture through bunx -p <pkg.pr.new URL> ccusage after the Bun install cache has already been populated by the startup measurement. This separates cached package-runner execution from first-fetch package materialization.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base package: 7a550caae5cc; PR package: 315250c. Both run through bunx -p <pkg.pr.new URL> ccusage using the warmed Bun install cache from package runner startup, 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
bunx -p <pkg> ccusage claude --offline --json 1.01 GiB 280.2ms 239.0ms 1.17x 704.75 MiB 720.50 MiB 1.02x 3.59 GiB/s 4.21 GiB/s
bunx -p <pkg> ccusage codex --offline --json 1.01 GiB 101.9ms 107.5ms 0.95x 92.00 MiB 92.25 MiB 1.00x 9.88 GiB/s 9.37 GiB/s

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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 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 239.0ms 4.21 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 212.4ms 4.74 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 94.3ms 10.67 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 72.4ms 13.91 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 rust/target/release/ccusage directly. 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 19.9ms 2.4ms 8.35x 43.00 MiB 2.75 MiB 0.06x 0.08 MiB/s 0.65 MiB/s
claude session --offline --json 0.00 MiB 19.2ms 2.6ms 7.33x 43.25 MiB 2.75 MiB 0.06x 0.08 MiB/s 0.59 MiB/s
codex daily --offline --json 0.00 MiB 16.6ms 2.5ms 6.64x 43.00 MiB 3.00 MiB 0.07x 0.05 MiB/s 0.34 MiB/s
codex session --offline --json 0.00 MiB 17.4ms 2.1ms 8.10x 43.00 MiB 3.00 MiB 0.07x 0.05 MiB/s 0.40 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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs rust/target/release/ccusage directly. 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 245.7ms 227.4ms 1.08x 754.25 MiB 728.25 MiB 0.97x 4.10 GiB/s 4.43 GiB/s
codex --offline --json 1.01 GiB 93.9ms 75.9ms 1.24x 91.25 MiB 93.50 MiB 1.02x 10.72 GiB/s 13.26 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 17.33 KiB 17.33 KiB -0.00 KiB 1.00x
installed native package binary 3837.94 KiB 3837.88 KiB -0.06 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: 315250cf0656
Base SHA: 7a550caae5cc

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

Package runner startup

Execution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one bunx -p <url> ccusage --version run with an empty Bun install cache. Warm reuses that cache and reports the median of repeated runs.

Package SHA Execution setup Bunx temp cache Bunx warm median Warm samples
Base pkg.pr.new 7a550caae5cc 572.2ms 715.2ms 23.9ms 3
PR pkg.pr.new 315250c 758.8ms 828.1ms 23.9ms 3

Cached bunx execution performance

Runs the same large fixture through bunx -p <pkg.pr.new URL> ccusage after the Bun install cache has already been populated by the startup measurement. This separates cached package-runner execution from first-fetch package materialization.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base package: 7a550caae5cc; PR package: 315250c. Both run through bunx -p <pkg.pr.new URL> ccusage using the warmed Bun install cache from package runner startup, 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
bunx -p <pkg> ccusage claude --offline --json 1.01 GiB 268.3ms 250.2ms 1.07x 712.00 MiB 747.25 MiB 1.05x 3.75 GiB/s 4.02 GiB/s
bunx -p <pkg> ccusage codex --offline --json 1.01 GiB 114.3ms 101.5ms 1.13x 92.75 MiB 92.75 MiB 1.00x 8.81 GiB/s 9.92 GiB/s

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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 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 233.4ms 4.31 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 214.5ms 4.69 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 89.3ms 11.27 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 77.4ms 13.01 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 16.6ms 17.7ms 0.94x 43.00 MiB 42.75 MiB 0.99x 0.09 MiB/s 0.09 MiB/s
claude session --offline --json 0.00 MiB 18.8ms 19.6ms 0.96x 43.00 MiB 43.00 MiB 1.00x 0.08 MiB/s 0.08 MiB/s
codex daily --offline --json 0.00 MiB 17.1ms 16.3ms 1.05x 43.25 MiB 43.25 MiB 1.00x 0.05 MiB/s 0.05 MiB/s
codex session --offline --json 0.00 MiB 16.3ms 19.5ms 0.84x 42.75 MiB 43.00 MiB 1.01x 0.05 MiB/s 0.04 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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 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 252.9ms 241.7ms 1.05x 730.75 MiB 712.50 MiB 0.98x 3.98 GiB/s 4.17 GiB/s
codex --offline --json 1.01 GiB 89.0ms 92.3ms 0.97x 90.25 MiB - - 11.31 GiB/s 10.91 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 17.33 KiB 17.33 KiB -0.00 KiB 1.00x
installed native package binary 3837.94 KiB 3837.88 KiB -0.06 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.

@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.

3 issues found across 100 files

Partial review: This PR has more than 50 files, so cubic reviewed the highest-priority files first. During the trial, paid plans get a higher file limit.
You can try an ultrareview to bypass the file limit, comment @cubic-dev-ai ultrareview. Learn more.

Fix all with cubic | Re-trigger cubic

Comment thread rust/crates/ccusage/src/adapter/gemini/mod.rs Outdated
Comment thread rust/crates/ccusage/src/adapter/codebuff/loader.rs Outdated
Comment thread rust/crates/ccusage/src/adapter/droid/loader.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rust/crates/ccusage/src/adapter/goose/paths.rs`:
- Around line 62-69: The per-adapter static ENV_LOCK in goose::paths (used
around unsafe env::set_var and env::remove_var in EnvDirGuard and its Drop impl)
must be replaced with a single, repo-wide process lock and all places that
mutate process env (Goose paths, CLAUDE_CONFIG_DIR_LOCK in main.rs,
QWEN_DATA_DIR_LOCK, GEMINI_DATA_DIR_LOCK, KIMI_DATA_DIR_LOCK, etc.) must use
that same lock; update the goose::paths code to acquire the global lock before
calling unsafe { env::set_var(GOOSE_PATH_ROOT_ENV, dir) } in EnvDirGuard::new
and hold the lock (or release only after) so Drop::drop also acquires the same
global lock before calling unsafe { env::remove_var(GOOSE_PATH_ROOT_ENV) }, and
change other modules/tests to reference this single global symbol (e.g.,
PROCESS_ENV_LOCK) instead of their local locks so all process-wide env mutations
are serialized.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d9f1ed7-30c7-4000-ad3e-1ffaadcf7060

📥 Commits

Reviewing files that changed from the base of the PR and between 7a550ca and 315250c.

📒 Files selected for processing (100)
  • nix/treefmt.nix
  • rust/crates/ccusage-cli/Cargo.toml
  • rust/crates/ccusage-cli/src/help_codegen.rs
  • rust/crates/ccusage-cli/src/lib.rs
  • rust/crates/ccusage-cli/src/parser.rs
  • rust/crates/ccusage-cli/src/tests.rs
  • rust/crates/ccusage-terminal/Cargo.toml
  • rust/crates/ccusage-terminal/src/lib.rs
  • rust/crates/ccusage-terminal/src/table.rs
  • rust/crates/ccusage-terminal/src/title.rs
  • rust/crates/ccusage-test-support/Cargo.toml
  • rust/crates/ccusage-test-support/src/lib.rs
  • rust/crates/ccusage/Cargo.toml
  • rust/crates/ccusage/src/adapter/all/loader.rs
  • rust/crates/ccusage/src/adapter/all/mod.rs
  • rust/crates/ccusage/src/adapter/all/report.rs
  • rust/crates/ccusage/src/adapter/all/tests.rs
  • rust/crates/ccusage/src/adapter/all/types.rs
  • rust/crates/ccusage/src/adapter/amp/loader.rs
  • rust/crates/ccusage/src/adapter/amp/mod.rs
  • rust/crates/ccusage/src/adapter/amp/parser.rs
  • rust/crates/ccusage/src/adapter/amp/report.rs
  • rust/crates/ccusage/src/adapter/claude/daily.rs
  • rust/crates/ccusage/src/adapter/claude/mod.rs
  • rust/crates/ccusage/src/adapter/claude/paths.rs
  • rust/crates/ccusage/src/adapter/codebuff/loader.rs
  • rust/crates/ccusage/src/adapter/codebuff/mod.rs
  • rust/crates/ccusage/src/adapter/codebuff/parser.rs
  • rust/crates/ccusage/src/adapter/codebuff/paths.rs
  • rust/crates/ccusage/src/adapter/codebuff/report.rs
  • rust/crates/ccusage/src/adapter/codex/aggregate.rs
  • rust/crates/ccusage/src/adapter/codex/loader.rs
  • rust/crates/ccusage/src/adapter/codex/mod.rs
  • rust/crates/ccusage/src/adapter/codex/parser.rs
  • rust/crates/ccusage/src/adapter/codex/paths.rs
  • rust/crates/ccusage/src/adapter/codex/report.rs
  • rust/crates/ccusage/src/adapter/copilot/loader.rs
  • rust/crates/ccusage/src/adapter/copilot/mod.rs
  • rust/crates/ccusage/src/adapter/copilot/parser.rs
  • rust/crates/ccusage/src/adapter/copilot/paths.rs
  • rust/crates/ccusage/src/adapter/copilot/report.rs
  • rust/crates/ccusage/src/adapter/droid/loader.rs
  • rust/crates/ccusage/src/adapter/droid/mod.rs
  • rust/crates/ccusage/src/adapter/droid/parser.rs
  • rust/crates/ccusage/src/adapter/droid/paths.rs
  • rust/crates/ccusage/src/adapter/droid/report.rs
  • rust/crates/ccusage/src/adapter/gemini/loader.rs
  • rust/crates/ccusage/src/adapter/gemini/mod.rs
  • rust/crates/ccusage/src/adapter/gemini/parser.rs
  • rust/crates/ccusage/src/adapter/gemini/paths.rs
  • rust/crates/ccusage/src/adapter/gemini/report.rs
  • rust/crates/ccusage/src/adapter/goose/loader.rs
  • rust/crates/ccusage/src/adapter/goose/mod.rs
  • rust/crates/ccusage/src/adapter/goose/parser.rs
  • rust/crates/ccusage/src/adapter/goose/paths.rs
  • rust/crates/ccusage/src/adapter/goose/report.rs
  • rust/crates/ccusage/src/adapter/hermes/loader.rs
  • rust/crates/ccusage/src/adapter/hermes/mod.rs
  • rust/crates/ccusage/src/adapter/hermes/parser.rs
  • rust/crates/ccusage/src/adapter/hermes/report.rs
  • rust/crates/ccusage/src/adapter/kilo/loader.rs
  • rust/crates/ccusage/src/adapter/kilo/mod.rs
  • rust/crates/ccusage/src/adapter/kilo/parser.rs
  • rust/crates/ccusage/src/adapter/kilo/report.rs
  • rust/crates/ccusage/src/adapter/kimi/loader.rs
  • rust/crates/ccusage/src/adapter/kimi/mod.rs
  • rust/crates/ccusage/src/adapter/kimi/parser.rs
  • rust/crates/ccusage/src/adapter/kimi/paths.rs
  • rust/crates/ccusage/src/adapter/kimi/report.rs
  • rust/crates/ccusage/src/adapter/openclaw/loader.rs
  • rust/crates/ccusage/src/adapter/openclaw/mod.rs
  • rust/crates/ccusage/src/adapter/openclaw/parser.rs
  • rust/crates/ccusage/src/adapter/openclaw/paths.rs
  • rust/crates/ccusage/src/adapter/openclaw/report.rs
  • rust/crates/ccusage/src/adapter/opencode/loader.rs
  • rust/crates/ccusage/src/adapter/opencode/mod.rs
  • rust/crates/ccusage/src/adapter/opencode/parser.rs
  • rust/crates/ccusage/src/adapter/opencode/report.rs
  • rust/crates/ccusage/src/adapter/pi/loader.rs
  • rust/crates/ccusage/src/adapter/pi/mod.rs
  • rust/crates/ccusage/src/adapter/pi/parser.rs
  • rust/crates/ccusage/src/adapter/pi/paths.rs
  • rust/crates/ccusage/src/adapter/pi/report.rs
  • rust/crates/ccusage/src/adapter/qwen/loader.rs
  • rust/crates/ccusage/src/adapter/qwen/mod.rs
  • rust/crates/ccusage/src/adapter/qwen/parser.rs
  • rust/crates/ccusage/src/adapter/qwen/paths.rs
  • rust/crates/ccusage/src/adapter/qwen/report.rs
  • rust/crates/ccusage/src/blocks.rs
  • rust/crates/ccusage/src/cli.rs
  • rust/crates/ccusage/src/commands/mod.rs
  • rust/crates/ccusage/src/config.rs
  • rust/crates/ccusage/src/config_schema.rs
  • rust/crates/ccusage/src/cost.rs
  • rust/crates/ccusage/src/date_utils.rs
  • rust/crates/ccusage/src/main.rs
  • rust/crates/ccusage/src/output.rs
  • rust/crates/ccusage/src/pricing.rs
  • rust/crates/ccusage/src/progress.rs
  • rust/crates/ccusage/src/summary.rs

Comment thread rust/crates/ccusage/src/adapter/goose/paths.rs Outdated
Add a shared test-support environment variable guard that holds a single process-wide mutex while temporarily setting environment variables. Replace module-local locks and direct unsafe env mutations in tests with the shared RAII guard so Rust 2024 unsafe environment access is isolated in one audited helper and restored consistently.
@ryoppippi

Copy link
Copy Markdown
Member Author

@coderabbitai review
@cubic-dev-ai review

Addressed the environment mutation review feedback in 00f4790 by centralizing temporary env var mutation behind a shared test-support RAII guard with one process-wide mutex. Local validation: cargo test --manifest-path rust/Cargo.toml --workspace; nix flake check --print-build-logs.

@cubic-dev-ai

cubic-dev-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review
@cubic-dev-ai review

Addressed the environment mutation review feedback in 00f4790 by centralizing temporary env var mutation behind a shared test-support RAII guard with one process-wide mutex. Local validation: cargo test --manifest-path rust/Cargo.toml --workspace; nix flake check --print-build-logs.

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

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: 00f4790e24a0
Base SHA: 7a550caae5cc

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

Package runner startup

Execution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one bunx -p <url> ccusage --version run with an empty Bun install cache. Warm reuses that cache and reports the median of repeated runs.

Package SHA Execution setup Bunx temp cache Bunx warm median Warm samples
Base pkg.pr.new 7a550caae5cc 1.031s 1.608s 21.5ms 3
PR pkg.pr.new 00f4790 902.8ms 1.547s 21.5ms 3

Cached bunx execution performance

Runs the same large fixture through bunx -p <pkg.pr.new URL> ccusage after the Bun install cache has already been populated by the startup measurement. This separates cached package-runner execution from first-fetch package materialization.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base package: 7a550caae5cc; PR package: 00f4790. Both run through bunx -p <pkg.pr.new URL> ccusage using the warmed Bun install cache from package runner startup, 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
bunx -p <pkg> ccusage claude --offline --json 1.01 GiB 252.8ms 240.2ms 1.05x 739.75 MiB 727.50 MiB 0.98x 3.98 GiB/s 4.19 GiB/s
bunx -p <pkg> ccusage codex --offline --json 1.01 GiB 83.9ms 82.6ms 1.02x 91.00 MiB 94.25 MiB 1.04x 11.99 GiB/s 12.18 GiB/s

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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 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 246.7ms 4.08 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 219.2ms 4.59 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 75.8ms 13.28 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 61.0ms 16.50 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 14.7ms 14.5ms 1.01x 42.75 MiB 43.00 MiB 1.01x 0.11 MiB/s 0.11 MiB/s
claude session --offline --json 0.00 MiB 14.4ms 14.7ms 0.98x 43.00 MiB 43.00 MiB 1.00x 0.11 MiB/s 0.11 MiB/s
codex daily --offline --json 0.00 MiB 14.6ms 14.3ms 1.02x 43.00 MiB 43.00 MiB 1.00x 0.06 MiB/s 0.06 MiB/s
codex session --offline --json 0.00 MiB 14.4ms 14.3ms 1.01x 42.75 MiB 43.00 MiB 1.01x 0.06 MiB/s 0.06 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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 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 245.3ms 246.1ms 1.00x 739.75 MiB 720.00 MiB 0.97x 4.11 GiB/s 4.09 GiB/s
codex --offline --json 1.01 GiB 76.7ms 76.2ms 1.01x 92.25 MiB 90.25 MiB 0.98x 13.13 GiB/s 13.21 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 17.33 KiB 17.33 KiB -0.00 KiB 1.00x
installed native package binary 3837.94 KiB 3837.88 KiB -0.06 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.

@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 100 files

Partial review: This PR has more than 50 files, so cubic reviewed the highest-priority files first. During the trial, paid plans get a higher file limit.
You can try an ultrareview to bypass the file limit, comment @cubic-dev-ai ultrareview. Learn more.

Re-trigger cubic

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: 00f4790e24a0
Base SHA: 7a550caae5cc

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

Package runner startup

Execution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one bunx -p <url> ccusage --version run with an empty Bun install cache. Warm reuses that cache and reports the median of repeated runs.

Package SHA Execution setup Bunx temp cache Bunx warm median Warm samples
Base pkg.pr.new 7a550caae5cc 2.284s 2.772s 22.8ms 3
PR pkg.pr.new 00f4790 937.2ms 822.9ms 23.3ms 3

Cached bunx execution performance

Runs the same large fixture through bunx -p <pkg.pr.new URL> ccusage after the Bun install cache has already been populated by the startup measurement. This separates cached package-runner execution from first-fetch package materialization.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base package: 7a550caae5cc; PR package: 00f4790. Both run through bunx -p <pkg.pr.new URL> ccusage using the warmed Bun install cache from package runner startup, 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
bunx -p <pkg> ccusage claude --offline --json 1.01 GiB 268.4ms 247.5ms 1.08x 726.25 MiB 741.00 MiB 1.02x 3.75 GiB/s 4.07 GiB/s
bunx -p <pkg> ccusage codex --offline --json 1.01 GiB 89.2ms 86.5ms 1.03x 92.25 MiB 89.75 MiB 0.97x 11.28 GiB/s 11.65 GiB/s

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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 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 240.8ms 4.18 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 230.9ms 4.36 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 78.5ms 12.83 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 62.9ms 16.02 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 rust/target/release/ccusage directly. 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 15.6ms 2.1ms 7.59x 43.00 MiB 2.75 MiB 0.06x 0.10 MiB/s 0.75 MiB/s
claude session --offline --json 0.00 MiB 14.9ms 2.0ms 7.59x 42.75 MiB 2.75 MiB 0.06x 0.10 MiB/s 0.79 MiB/s
codex daily --offline --json 0.00 MiB 13.9ms 1.8ms 7.72x 43.00 MiB 3.00 MiB 0.07x 0.06 MiB/s 0.48 MiB/s
codex session --offline --json 0.00 MiB 14.3ms 1.7ms 8.18x 42.75 MiB 3.00 MiB 0.07x 0.06 MiB/s 0.49 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, 2,597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs rust/target/release/ccusage directly. 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 251.5ms 240.6ms 1.05x 740.50 MiB 722.50 MiB 0.98x 4.00 GiB/s 4.18 GiB/s
codex --offline --json 1.01 GiB 76.6ms 61.1ms 1.25x 91.75 MiB 91.50 MiB 1.00x 13.15 GiB/s 16.47 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 17.33 KiB 17.33 KiB -0.00 KiB 1.00x
installed native package binary 3837.94 KiB 3837.88 KiB -0.06 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 5816e64 into main Jun 13, 2026
38 checks passed
@ryoppippi
ryoppippi deleted the codex/update-rust-edition-2024 branch June 13, 2026 13:52
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.

1 participant