-
-
Notifications
You must be signed in to change notification settings - Fork 69.4k
[Bug]: openclaw status --json intermittently reports negative inputTokens #25242
Description
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
- Initiate a long-running OpenClaw session with continuous interaction.
- Periodically run
openclaw status --jsonfrom a separate process (e.g., via a Python script callingsubprocess.run(["openclaw", "status", "--json"], ...)or directly viaexectool).- Note: The
stdoutofopenclaw status --jsonoften 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.
- Note: The
- Observe the
inputTokensvalue in thesessions.recent[0].inputTokensfield 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.