Skip to content

fix(billing): add parentheses around breakdown in billing formula display - #4415

Open
octo-patch wants to merge 1 commit into
QuantumNous:mainfrom
octo-patch:fix/issue-4406-billing-formula-parentheses
Open

fix(billing): add parentheses around breakdown in billing formula display#4415
octo-patch wants to merge 1 commit into
QuantumNous:mainfrom
octo-patch:fix/issue-4406-billing-formula-parentheses

Conversation

@octo-patch

@octo-patch octo-patch commented Apr 24, 2026

Copy link
Copy Markdown

Fixes #4406

Problem

The billing formula shown in the log's "计费过程" (billing process) section was missing parentheses around the breakdown expression, creating a visual ambiguity about operator precedence.

Current display:

提示 24143 tokens / 1M tokens * $5.000000 + 补全 702 tokens / 1M tokens * $25.000000 * 分组倍率 0.1 = $0.013827

A user reading this literally (following standard math precedence where * binds tighter than +) would compute:

  • prompt × $5 + completion × $25 × groupRatio ≈ $0.122 — ~10× larger than the actual deduction

Root Cause

In web/src/helpers/render.jsx, the template string used for the final billing formula was:

'{{breakdown}} * {{ratioType}} {{ratio}} = {{symbol}}{{total}}'

The breakdown part is a +-separated sum of prompt and completion costs, but it was not wrapped in parentheses, so when rendered, the group ratio visually appears to apply only to the last term.

Solution

Wrap {{breakdown}} in parentheses in the template:

'({{breakdown}}) * {{ratioType}} {{ratio}} = {{symbol}}{{total}}'

After fix:

(提示 24143 tokens / 1M tokens * $5.000000 + 补全 702 tokens / 1M tokens * $25.000000) * 分组倍率 0.1 = $0.013827

This correctly conveys that the group ratio applies to the whole sum. The backend billing logic is unchanged and was already correct — this is a display-only fix.

Files Changed

  • web/src/helpers/render.jsx — updated template string
  • web/src/i18n/locales/{en,zh-CN,zh-TW,fr,ja,ru,vi}.json — updated i18n key to match new template

Testing

The formula renders with parentheses, and the computed total matches the actual deduction. No backend changes required.

Summary by CodeRabbit

  • Style
    • Updated billing formula display formatting across all supported languages including English, French, Japanese, Russian, Vietnamese, Simplified Chinese, and Traditional Chinese for improved visual clarity and consistency in pricing calculations.

…play (fixes QuantumNous#4406)

The billing formula template was missing parentheses around the breakdown
expression, causing visual ambiguity about operator precedence. Users reading
the formula literally would compute a value ~10x off from the actual charge,
since the group ratio should apply to the entire (prompt + completion) sum,
not just the completion portion.

Before: prompt_tokens * $5 + completion_tokens * $25 * groupRatio 0.1 = total
After:  (prompt_tokens * $5 + completion_tokens * $25) * groupRatio 0.1 = total

Updated the i18n key in all locale files (en, zh-CN, zh-TW, fr, ja, ru, vi)
to match the corrected template. The backend billing logic is unchanged and
was already correct.
@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: de014e3b-4cdd-4a39-8b54-cf118b772c6e

📥 Commits

Reviewing files that changed from the base of the PR and between 65b1654 and 87dcb3f.

📒 Files selected for processing (8)
  • web/src/helpers/render.jsx
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/fr.json
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/ru.json
  • web/src/i18n/locales/vi.json
  • web/src/i18n/locales/zh-CN.json
  • web/src/i18n/locales/zh-TW.json

Walkthrough

Updates Claude model billing text rendering by wrapping the breakdown portion in parentheses to clarify that the group ratio applies to the entire sum of components. Synchronizes all i18n locale files with the new parenthesized template key.

Changes

Cohort / File(s) Summary
Billing Display Template
web/src/helpers/render.jsx
Wrapped {{breakdown}} in parentheses within the template string to produce ({{breakdown}}) * {{ratioType}} {{ratio}} = {{symbol}}{{total}}, clarifying that the ratio multiplier applies to the entire breakdown sum.
i18n Locale Files
web/src/i18n/locales/en.json, web/src/i18n/locales/fr.json, web/src/i18n/locales/ja.json, web/src/i18n/locales/ru.json, web/src/i18n/locales/vi.json, web/src/i18n/locales/zh-CN.json, web/src/i18n/locales/zh-TW.json
Updated translation keys to match the parenthesized breakdown form ({{breakdown}}) * {{ratioType}} {{ratio}} = {{symbol}}{{total}} instead of the unparenthesized variant, ensuring locale lookups resolve correctly with the updated template.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

  • fix(i18n): fill missing translations in i18n. #2314: Added the original unparenthesized billing template translation entries ({{breakdown}} * {{ratioType}} {{ratio}} = {{symbol}}{{total}}); this PR fixes the mathematical operator precedence ambiguity by adding parentheses to those same template keys.

Poem

🐰 A rabbit hops through templates bright,
Adding parentheses left and right!
(breakdown) now groups with care,
Ratios multiply fair and square,
Billing clarity floats through the air! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 title clearly and accurately summarizes the main change: adding parentheses around the breakdown variable in the billing formula display template.
Linked Issues check ✅ Passed All code changes directly address issue #4406: wrapping breakdown in parentheses in the render template and synchronizing i18n keys across all locale files to match the updated template format.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the billing formula display issue—updating render.jsx and i18n locale files. No unrelated modifications or scope creep detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
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.

日志「计费过程」展示文案缺少括号,字面优先级与实际扣费相差 ~10 倍

1 participant