Skip to content

[Bug]: openclaw status --json intermittently reports negative inputTokens #25242

@c990china

Description

@c990china

Summary

I've observed an intermittent issue where the openclaw status --json command (and consequently the session_status tool) reports a negative value for inputTokens for the main agent's current session.

Steps to reproduce

  1. Initiate a long-running OpenClaw session with continuous interaction.
  2. Periodically run openclaw status --json from a separate process (e.g., via a Python script calling subprocess.run(["openclaw", "status", "--json"], ...) or directly via exec tool).
    • Note: The stdout of openclaw status --json often includes non-JSON lines (e.g., [plugins] ... registration messages, gateway connect failed) before the actual JSON object. This non-JSON prefix needs to be handled if parsing the output programmatically.
  3. Observe the inputTokens value in the sessions.recent[0].inputTokens field within the parsed JSON output.

Expected behavior

inputTokens should always be a non-negative (zero or positive) integer, representing the cumulative tokens consumed by the session.

Actual behavior

When running openclaw status --json (or session_status within an agent's context), the inputTokens field in the JSON output occasionally shows a negative number (e.g., -284957, -296318). outputTokens appears to remain positive.

This occurs seemingly randomly and affects the accuracy of token usage tracking.

OpenClaw version

2026.2.19-2 (45d9b20) (as per openclaw status output)

Operating system

Linux 6.17.0-1008-gcp (x64)

Install method

package (pnpm)

Logs, screenshots, and evidence

Please attach the complete log output from running `openclaw status --json` when a negative `inputTokens` value is observed. (e.g., copy-paste terminal output or take a screenshot).

Impact and severity

Impact:

  • Leads to inaccurate reporting of token usage.
  • Breaks downstream scripts designed to track and summarize token consumption, as negative values are unexpected and logically incorrect for cumulative usage.

Severity: High (as it affects the accuracy of a core metric)

Additional information

Temporary Mitigation (Agent-side):
As a workaround, my agent-side script (record_tokens.py) that logs token usage now clamps any negative inputTokens values to 0 before recording, but this does not fix the root cause in the OpenClaw core.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions