Skip to content

Fix monitoring: count retry attempts correctly and use K/M/B token units#187

Merged
liuw1535 merged 1 commit into
yanshifrom
codex/fix-request-count-in-monitoring-center
Jun 4, 2026
Merged

Fix monitoring: count retry attempts correctly and use K/M/B token units#187
liuw1535 merged 1 commit into
yanshifrom
codex/fix-request-count-in-monitoring-center

Conversation

@liuw1535

@liuw1535 liuw1535 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Monitoring reported each retry as a successful request because retry failures were not tracked separately from the final response, causing totals to be inflated; token unit formatting in the dashboard used Chinese large-number units instead of English compact units.

Description

  • Change src/utils/usageStats.js to accept successCount/failedCount, add toSafeCount(), and update record() to aggregate per-day and per-model requests, success, and failed using those counts.
  • Add recordUsageAttemptFailure(req, ...) helper and wire it into the retry flow so failed retry attempts are accumulated on req.apiUsageMetrics instead of being mis-counted as successes.
  • Call the new onAttemptFailure callback in src/server/handlers/common/retry.js so callers can record failed attempts, and add onAttemptFailure to createRetryOptions in src/server/handlers/openai.js, src/server/handlers/claude.js, src/server/handlers/gemini.js and src/server/handlers/geminicli.js to invoke recordUsageAttemptFailure(req, { model }) on retry failures.
  • Update the request-tracking middleware in src/server/index.js to pass successCount and failedCount into usageStats.record() based on req.apiUsageMetrics.failedAttempts and the final res.statusCode so totals reflect conversation attempts (e.g. 3 failures + 1 success → total 4).
  • Change frontend token formatting in public/js/monitor.js to use formatTokenNumber() with K/M/B abbreviations and apply it to Tokens card, model legend and donut center.

Testing

  • Ran static syntax checks: node --check on src/utils/usageStats.js, src/server/index.js, src/server/handlers/common/retry.js, src/server/handlers/openai.js, src/server/handlers/claude.js, src/server/handlers/gemini.js, src/server/handlers/geminicli.js and public/js/monitor.js, which completed without errors.
  • Attempted npm run build:linux to validate packaging, but pkg failed to fetch Node base binaries/source (remote 403 Forbidden), which is an environment/remote-cache issue unrelated to the code changes.

Codex Task

@liuw1535 liuw1535 merged commit fcf86c1 into yanshi Jun 4, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant