Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/src/components/table/usage-logs/UsageLogsColumnDefs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ function getUsageLogDetailSummary(record, text, billingDisplayMode, t) {
segments: other?.claude
? renderModelPriceSimple(
other.model_ratio,
other?.completion_ratio,
other.model_price,
other.group_ratio,
other?.user_group_ratio,
Expand All @@ -438,6 +439,7 @@ function getUsageLogDetailSummary(record, text, billingDisplayMode, t) {
)
: renderModelPriceSimple(
other.model_ratio,
other?.completion_ratio,
other.model_price,
other.group_ratio,
other?.user_group_ratio,
Expand Down
14 changes: 14 additions & 0 deletions web/src/helpers/render.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ function renderBillingArticle(lines, { showReferenceNote = true } = {}) {
// Shared core for simple price rendering (used by OpenAI-like and Claude-like variants)
function renderPriceSimpleCore({
modelRatio,
completionRatio,
modelPrice = -1,
groupRatio,
user_group_ratio,
Expand Down Expand Up @@ -1359,6 +1360,17 @@ function renderPriceSimpleCore({
}),
});

if (completionRatio) {
segments.push({
tone: 'secondary',
text: i18next.t('补全 {{price}} / 1M tokens', {
price: formatCompactDisplayPrice(
modelRatio * 2.0 * Number(completionRatio),
),
}),
});
}
Comment on lines +1363 to +1372
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify completion_ratio production/consumption and finite-value guards.

echo "== completion_ratio producers/consumers =="
rg -n -C3 '\bcompletion_ratio\b|\bcompletionRatio\b'

echo
echo "== inspect ratio sync guard implementation (if present) =="
fd ratio_sync.go --exec sed -n '560,700p' {}

Repository: QuantumNous/new-api

Length of output: 50376


🏁 Script executed:

sed -n '1298,1380p' web/src/helpers/render.jsx | cat -n

Repository: QuantumNous/new-api

Length of output: 3073


🏁 Script executed:

rg -n 'renderPriceSimpleCore\(' web/src/ -A2 | head -50

Repository: QuantumNous/new-api

Length of output: 393


🏁 Script executed:

rg -n 'formatCompactDisplayPrice' web/src/helpers/render.jsx -A5 | head -40

Repository: QuantumNous/new-api

Length of output: 1262


Guard completionRatio before rendering completion price.

Line 1363 uses truthiness and line 1368 coerces with Number(...), which can render invalid prices when completionRatio is undefined, null, zero, or malformed (¥NaN, ¥Infinity, or inconsistent hiding of numeric zero).

💡 Suggested fix
-      if (completionRatio) {
+      const completionRatioValue = Number(completionRatio);
+      const hasCompletionRatio =
+        completionRatio !== undefined &&
+        completionRatio !== null &&
+        Number.isFinite(completionRatioValue) &&
+        completionRatioValue >= 0;
+      if (hasCompletionRatio) {
         segments.push({
           tone: 'secondary',
           text: i18next.t('补全 {{price}} / 1M tokens', {
             price: formatCompactDisplayPrice(
-              modelRatio * 2.0 * Number(completionRatio),
+              modelRatio * 2.0 * completionRatioValue,
             ),
           }),
         });
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (completionRatio) {
segments.push({
tone: 'secondary',
text: i18next.t('补全 {{price}} / 1M tokens', {
price: formatCompactDisplayPrice(
modelRatio * 2.0 * Number(completionRatio),
),
}),
});
}
const completionRatioValue = Number(completionRatio);
const hasCompletionRatio =
completionRatio !== undefined &&
completionRatio !== null &&
Number.isFinite(completionRatioValue) &&
completionRatioValue >= 0;
if (hasCompletionRatio) {
segments.push({
tone: 'secondary',
text: i18next.t('补全 {{price}} / 1M tokens', {
price: formatCompactDisplayPrice(
modelRatio * 2.0 * completionRatioValue,
),
}),
});
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/src/helpers/render.jsx` around lines 1363 - 1372, Guard the completion
price by converting completionRatio to a numeric value and only render when it's
a finite number (so numeric zero is allowed); specifically, in render.jsx
compute a numeric ratio from completionRatio (e.g., via Number(...) or
Number.isFinite check) and replace the current truthiness check with a check
like Number.isFinite(ratio) before pushing the segment that calls
formatCompactDisplayPrice with modelRatio * 2.0 * ratio, ensuring you use the
validated numeric variable rather than coercing inside the formatting call.


if (shouldShowCache) {
segments.push({
tone: 'secondary',
Expand Down Expand Up @@ -2210,6 +2222,7 @@ export function renderLogContent(

export function renderModelPriceSimple(
modelRatio,
completionRatio,
modelPrice = -1,
groupRatio,
user_group_ratio,
Expand All @@ -2230,6 +2243,7 @@ export function renderModelPriceSimple(
) {
return renderPriceSimpleCore({
modelRatio,
completionRatio,
modelPrice,
groupRatio,
user_group_ratio,
Expand Down