fix(usage): recompute normalized estimated totals - #1831
Conversation
|
✅ Deterministic PR hygiene checks passed. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe request log now recomputes token totals when input estimates are merged with provider usage or capped at the model context window. Tests cover adapter, local request, and Cursor checkpoint estimates. ChangesRequest-log token usage correction
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This narrowly scoped change recomputes estimated usage totals for affected accounting paths, with targeted tests and required checks reported passing; no actionable merge-blocking risk remains beyond normal review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
✅ READY
Review readiness checklist
✅ 4/4 boxes ticked. This pull request is already Ready for Review. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
7f028e3 to
bdb4543
Compare
bdb4543 to
6df4cc6
Compare
|
Rebased onto current Exact-head validation passed: typecheck, 12 focused usage-cap tests (21 assertions), privacy scan, and diff check. Stable patch ID is unchanged. The local-all-CI, findings, and ready boxes remain unchecked until exact-head maintained CI and bot review complete. Maintainer action requested: please approve the fork-gated Cross-platform CI run 32027835255 and React Doctor run 32027835277. |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Thanks @luvs01, merged. This is useful because usage accounting now stays internally consistent when an estimated input count is replaced or capped. Before this, |
Summary
usage.totalTokensconsistent when a request-side estimate replaces the logged input count.Exact base:
b5a6654786a2bafb0759dae92bbcfc47515de1c3Exact head:
6df4cc6f734b87792a98af3bbc21388931c76165Why
This is a narrow follow-up to #1653. The context-window cap corrected
inputTokens, but an existing explicittotalTokenscould retain its pre-cap value. The same inconsistency was possible when a larger local estimate replaced the adapter's input count.That left nested usage and the outer attempt total contradictory, and legacy/display aggregation could continue honoring the stale explicit total.
Behavior
totalTokens = combinedInputTokens + outputTokens.totalTokens = contextWindow + outputTokens.input = checkpoint - output, so output is added exactly once.contextTotalTokens, cache counters, routing, credentials, prompts, and request payloads are unchanged.Verification
tests/request-log-estimate-cap.test.ts— 12 pass, 0 fail, 21 assertions.bun run typecheck,bun run privacy:scan, andgit diff --check— passed.fb434b9d-930e-4000-8220-f3e8a3b59162— CLEAN, 0 findings, complete coverage of the changed production source.9aecddbc80a79cc26bbf8aa3d0c624e92355fe83.Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit
Bug Fixes
Tests