openclaw - ✅(Solved) Fix [Bug]: Dashboard Token 统计不准 [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#49442Fetched 2026-04-08 00:55:14
View on GitHub
Comments
2
Participants
3
Timeline
7
Reactions
0
Timeline (top)
commented ×2labeled ×2cross-referenced ×1mentioned ×1

标题:Dashboard 的 Daily Token Usage 统计包含所有使用同一 API Key 的调用

正文:

Root Cause

标题:Dashboard 的 Daily Token Usage 统计包含所有使用同一 API Key 的调用

正文:

Fix Action

Fixed

PR fix notes

PR #49707: fix(token): tokens usage statistics show "?" when provider returns zero-valued usage

Description (problem / solution / changelog)

Summary

Describe the problem and fix in 2–5 bullets:

Fixed an issue where tokens usage statistics consistently showed "?" instead of actual values when providers return usage data with all fields set to zero (e.g., Qwen free trial tier).

  • Problem: The /status command displayed tokens ?/128k instead of actual token counts, even when the provider returned valid usage data. This affected Qwen and other providers that may return zero-valued usage for free trial accounts or certain configurations.

  • Why it matters:

  • What changed:

Root cause: In src/agents/pi-embedded-subscribe.ts, the recordAssistantUsage function used hasNonzeroUsage(usage) to check if usage should be recorded. This caused the function to skip recording when all usage fields were zero, resulting in:

  1. usageTotals remaining at initial values
  2. getUsageTotals() returning undefined
  3. persistSessionUsageUpdate receiving no valid usage
  4. totalTokensFresh being set to false
  5. Display layer showing "tokens ?" instead of the actual count
  • What did NOT change (scope boundary):

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #49442

User-visible / Behavior Changes

List user-visible changes (including defaults/config).
If none, write None.

Security Impact (required)

  • New permissions/capabilities? (Yes/No) NO
  • Secrets/tokens handling changed? (Yes/No) NO
  • New/changed network calls? (Yes/No) NO
  • Command/tool execution surface changed? (Yes/No) NO
  • Data access scope changed? (Yes/No) NO
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macos 15.6
  • Runtime/container: docker runtimer
  • Model/provider: Qwen2.5
  • Integration/channel (if any): nil
  • Relevant config (redacted): nil

Steps

Expected

if (!hasNonzeroUsage(usage)) {
  return;
}

Actual


if (!usage) {
  return;
}

Fix Effect

  • When the Provider returns usage with a value of 0, totalTokensFresh is correctly set to true.
  • The display layer will show "tokens 0/128k" instead of "tokens ?/128k".
  • Users can now distinguish between no usage data and usage equal to 0.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
  • Edge cases checked:
  • What you did not verify:

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No)
  • Config/env changes? (Yes/No)
  • Migration needed? (Yes/No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
  • Files/config to restore:
  • Known bad symptoms reviewers should watch for:

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk:
    • Mitigation:

Changed files

  • src/agents/pi-embedded-subscribe.ts (modified, +2/-2)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Summary

标题:Dashboard 的 Daily Token Usage 统计包含所有使用同一 API Key 的调用

正文:

问题描述

Dashboard UI 的 "Daily Token Usage" 显示的消耗量包含了所有使用该 API Key 的调用,不仅是 OpenClaw Gateway 本身的消耗。

重现步骤

  1. 在 OpenClaw 配置了 MiniMax API Key

  2. 同一个 API Key 也被用于 LightClaw(或其他第三方服务)

  3. 查看 Dashboard 的 Daily Token Usage

  4. 发现数值远大于 Gateway 实际产生的消耗

期望行为

Dashboard 应该只统计 OpenClaw Gateway 本身产生的 token 消耗,或者明确标注这是"全 API Key 消耗"

环境

  • OpenClaw 版本:2026.3.8

  • 模型:MiniMax M2.5

Steps to reproduce

Dashboard UI

Expected behavior

Dashboard Token 统计不准

Actual behavior

Token 统计不准

OpenClaw version

2026.3.8

Operating system

OpenCloudOS 9

Install method

No response

Model

MiniMax M2.

Provider / routing chain

openclaw

Config file / key location

No response

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To fix the issue of incorrect token usage statistics in the Dashboard, we need to modify the API key usage tracking logic to only include calls made by the OpenClaw Gateway.

Here are the steps:

  • Update the token_usage.py file to filter out calls not made by the OpenClaw Gateway.
  • Add a new column to the token_usage table to store the caller's ID or name.
  • Modify the record_token_usage function to include the caller's ID or name.

Example code:

# token_usage.py
from models import TokenUsage

def record_token_usage(api_key, caller_id, tokens_used):
    # Filter out calls not made by the OpenClaw Gateway
    if caller_id != 'openclaw_gateway':
        return
    
    # Record token usage
    token_usage = TokenUsage(api_key=api_key, caller_id=caller_id, tokens_used=tokens_used)
    token_usage.save()

def get_token_usage(api_key):
    # Get token usage for the OpenClaw Gateway
    token_usage = TokenUsage.objects.filter(api_key=api_key, caller_id='openclaw_gateway')
    return token_usage

Verification

To verify the fix, follow these steps:

  • Make a call to the API using the OpenClaw Gateway.
  • Check the Dashboard's Daily Token Usage statistics to ensure it only includes the call made by the OpenClaw Gateway.
  • Make a call to the API using a different service with the same API key.
  • Check the Dashboard's Daily Token Usage statistics to ensure it does not include the call made by the other service.

Extra Tips

  • Ensure that the caller_id is properly set in the record_token_usage function.
  • Consider adding additional logging or monitoring to detect any issues with the token usage tracking logic.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Dashboard Token 统计不准

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Dashboard Token 统计不准 [1 pull requests, 2 comments, 3 participants]