Uh oh!
There was an error while loading. Please reload this page.
fix(usage): align cost with usage - #97
Conversation
ymkiux
commented
Apr 18, 2026
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 22 minutes and 4 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdded robust session token aggregation and a new CLI session-usage core: a helper computes total tokens from breakdown fields when explicit totals are missing; CLI now delegates session usage listing to a new core module that normalizes model names (including file scanning) with caching and concurrency limits. Tests updated/added. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as "cli.js (caller)"
participant Core as "listSessionUsageCore"
participant Browse as "listSessionBrowse"
participant FileReader as "createSessionModelsFileReader"
participant Parsers as "parseCodex/parseClaude"
CLI->>Core: listSessionUsageCore(params, deps)
Core->>Browse: request session browse (bounded limit)
Browse-->>Core: session list
Core->>Core: normalize per-session fields (models/modelName)
alt models present in browse
Core-->>CLI: include normalized session
else models missing
Core->>FileReader: read models from session file (concurrency-limited, cached)
FileReader-->>Core: models[] or []
alt models found
Core-->>CLI: include normalized session
else
Core->>Parsers: parse limited-bytes session summary
Parsers-->>Core: summary (models/modelName/provider)
Core-->>CLI: include normalized session (if obtained)
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
658cc42 to
9b5417cComparebdd0cd0 to
34d5dbdCompare34d5dbd to
13c9f95CompareThere was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cli/session-usage.js`:
- Around line 1-21: The limiter can let new tasks skip the queue because
`active` is decremented before a queued waiter actually acquires the slot; fix
`createConcurrencyLimiter` so slot acquisition is atomic by moving the increment
into the wake logic: change `next()` to loop while there are queued waiters and
`active < max`, and for each picked waiter increment `active` before calling its
resolve (so the waiter resumes already owning a slot); keep the `active -= 1` in
the `finally` of the worker, and ensure the immediate-path still increments
`active` before running the task. This guarantees queued waiters increment
`active` inside `next()` and cannot be raced past by concurrently submitted
tasks.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 07a2aa58-16ff-462b-9172-7f8650bc883d
📒 Files selected for processing (5)
cli.jscli/session-usage.jstests/unit/session-usage-backend.test.mjstests/unit/web-ui-logic.test.mjsweb-ui/logic.sessions.mjs
✅ Files skipped from review due to trivial changes (1)
- tests/unit/web-ui-logic.test.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
- web-ui/logic.sessions.mjs
📜 Review details
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: github-actions[bot]
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-04-04T01:36:26.964Z
Learning: In PR `#68` for SakuraByteCore/codexmate, github-actions[bot] again flagged that CodeRabbit was introducing breaking changes. The maintainer's absolute constraint (reinforced across PRs `#55`, `#59`, `#67`, `#68`) is: no breaking changes in any review suggestion; limit all feedback to correctness, safety, and quality only within the existing design, without refactoring or altering APIs, interfaces, or behavior.
🔇 Additional comments (5)
cli.js (2)
141-141: Import wiring looks good.The new core import follows the existing CommonJS style and keeps the session-usage implementation isolated from the CLI entrypoint.
4263-4272: Delegation preserves the existing API.
listSessionUsage(params = {})keeps its public signature while passing the existing dependencies and limits into the core module, which matches the PR’s goal without changing callers.tests/unit/session-usage-backend.test.mjs (3)
56-64: LGTM on the binding injection.Defaulting
listSessionUsageCorefrom the loadedusageCorewhile still letting callers override viabindingskeeps existing tests decoupled from the new core module. Thebindings || {}spread also safely handles nullish arguments despite the= {}default.
353-356: Order-insensitive assertion is appropriate.Switching to sorted-array comparison correctly reflects that
listSessionUsageCorenow fans out summary parsing through a concurrency limiter (Promise.alloverlimitNormalize, 32 concurrent tasks incli/session-usage.js), so call order is no longer deterministic. Good defensive fix to avoid flaky tests.
359-423: Test aligns with new 3-tier fallback.The renamed test correctly exercises the early-return branch in
listSessionUsageCorewherebaseModelsderived from the lightweight entry'smodelfield short-circuits before any file I/O or summary parsing. AssertingcodexParsesis empty andmodels === ['gpt-5.3-codex']properly validates that the full-file scan andparseCodexSessionSummaryare both skipped. The >64KB fixture size check also guards the intent of the test.
Uh oh!
There was an error while loading. Please reload this page.
awsl233777
left a comment
There was a problem hiding this comment.
Required checks are green, and the usage/cost alignment change looks ready to merge.
Uh oh!
There was an error while loading. Please reload this page.
Fix usage token total fallback so estimated cost matches usage.
Summary by CodeRabbit
Bug Fixes
Tests