Skip to content

fix(routing): price refused-then-served rows in routing analytics - #7253

Open
vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
vadymhimself:fix/followup-analytics-refused-cost
Open

vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
vadymhimself:fix/followup-analytics-refused-cost

Conversation

@vadymhimself

@vadymhimself vadymhimself commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Verification

  • Red on dev a02cecd with only the new test: bun test tests/routing/routing-analytics.test.ts gives 11 pass, 1 fail (a refused retry before a measured send is priced, matching /api/usage: price coverage 0, expected 1).
  • Green: 12 pass, 0 fail.
  • bun x tsc --noEmit: clean. bun run structure:check: passed.
  • tests/lab/core-lab-boundary.test.ts, the file-size ratchet and every test file that imports routing/analytics: 46 pass, 0 fail.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

🤖 Generated with Claude Code

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Routing analytics now calculate successful-request costs using the complete recorded usage entry, improving cost totals in both aggregate and breakdown views.
    • Costs remain unavailable when an entry cannot be priced, rather than showing an estimated amount.
    • Added test coverage for successful requests following an unreported 429 retry.

successCostUsd passed the aggregate `unreported` status to
estimateRequestCost, so a usage-less 429 before a measured send stayed
unpriced in /api/routing-analytics while /api/usage priced it. It now
reuses computeEntryCost, the same attempt-aware pricing.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5bca7cbd-d602-48c1-a837-0f6799dc68f3
📥 Commits

Reviewing files that changed from the base of the PR and between a02cecd and a530a3d.

📒 Files selected for processing: 2
  • src/routing/analytics.ts
  • tests/routing/routing-analytics.test.ts

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

📝 Walkthrough

Routing analytics now calculates successful-request costs with computeEntryCost using the persisted usage entry. A test covers an unreported 429 attempt followed by a reported successful attempt.

Changes: Routing analytics pricing

Layer / File(s) Summary
Calculate costs from persisted entries
src/routing/analytics.ts, tests/routing/routing-analytics.test.ts
The successful-request cost calculation uses computeEntryCost with the persisted entry and returns a total only when the entry is priced. The test checks that a reported successful attempt after an unreported 429 attempt has full price coverage and a positive cost matching the entry cost.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to a530a

The routing analytics pricing change has no identified issue blocking merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed 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 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 identifies the routing analytics pricing fix for rows that were refused before being served. It matches the main change in src/routing/analytics.ts and the added regression test.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu

@vadymhimself

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@github-actions
github-actions Bot marked this pull request as ready for review October 16, 2026 15:20
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant