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; 9 remain after this review. 📝 WalkthroughWalkthroughThe request log now recomputes nested and outer 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: 🟡 Moderate · up to The PR updates normalized usage totals, with focused tests and validation passing, but it remains draft and required exact-head CI has not yet been confirmed; it is not merge-ready until those checks pass. Possibly related PRs
Suggested labels: 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 |
⏳ DRAFT
What to do
Review readiness checklist
2/4 boxes ticked. This PR stays in draft until every box above is ticked. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
usage.totalTokensconsistent when a request-side estimate replaces the logged input count.Exact base:
b81314cd29b78fecb447df882dc4fc1a987434b9Exact head:
7f028e369c8d09146615fca632c9725c37da6202Why
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
bun run typecheck— pass on both runtimes.bun run privacy:scan— pass on both runtimes.git diff --check— pass.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