openclaw - ✅(Solved) Fix [Bug]: LM Studio token stats not shown in /status (regression from 3.2 to 3.23) [2 pull requests, 1 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#54995Fetched 2026-04-08 01:33:52
View on GitHub
Comments
0
Participants
1
Timeline
12
Reactions
0
Author
Participants
Timeline (top)
referenced ×6cross-referenced ×2labeled ×2closed ×1

After upgrading OpenClaw from 2026.3.2 to 2026.3.23, /status shows Context: 0% and no token/cache info when using LM Studio backend. Works fine with Ollama and online models on the same version. Confirmed LM Studio API returns correct usage field via curl.

Root Cause

After upgrading OpenClaw from 2026.3.2 to 2026.3.23, /status shows Context: 0% and no token/cache info when using LM Studio backend. Works fine with Ollama and online models on the same version. Confirmed LM Studio API returns correct usage field via curl.

Fix Action

Fix / Workaround

Workaround:

  • Use online models if token visibility is needed
  • Downgrade to 2026.3.2
  • Or rely on Compactions count to infer context pressure (functional despite display issue)

PR fix notes

PR #55041: fix: use transcript usage as fallback for /status token display

Description (problem / solution / changelog)

Fixes #54995

Root Cause

Both /status command and session_status tool call buildStatusMessage with includeTranscriptUsage: false. This disables the fallback path that reads token counts from the session transcript JSONL file.

For custom providers like LM Studio, Ollama, or DashScope that use api: openai-completions, the agent meta store may not have usage data populated — so /status shows Context: 0/131k (0%).

Fix

Set includeTranscriptUsage: true in both call sites:

  • src/agents/tools/session-status-tool.ts
  • src/auto-reply/reply/commands-status.ts

This enables the existing fallback logic in buildStatusMessage which already has proper guards — it only uses transcript data when the meta store has zero/missing values, never overwriting valid data.

Safety

  • readUsageFromSessionLog already handles missing files, parse errors, and missing sessionId gracefully
  • Merge guards: totalTokens only updated when zero or transcript value is larger; inputTokens/outputTokens only filled when missing
  • /status is a one-shot query, not a hot path — sync file read is acceptable
  • Confirmed working: online models (zai/glm-4.7) already had usage in meta store, so includeTranscriptUsage: true has no effect on them (guards prevent overwrite)

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/openclaw-tools.session-status.test.ts (modified, +19/-0)
  • src/agents/tools/session-status-tool.ts (modified, +1/-0)
  • src/auto-reply/reply/commands-status.test.ts (modified, +83/-1)
  • src/auto-reply/reply/commands-status.ts (modified, +2/-1)

PR #55776: Agents: normalize WS usage aliases

Description (problem / solution / changelog)

Summary

  • Problem: the OpenAI-compatible WebSocket response parser still read usage from input_tokens / output_tokens only, so providers like DashScope that return prompt_tokens / completion_tokens recorded zero usage.
  • Why it matters: session transcripts and downstream usage displays lose token accounting for affected providers even though the provider returned valid usage data.
  • What changed: wired buildAssistantMessageFromResponse through the existing normalizeUsage(...) helper and added a focused regression test for prompt_tokens / completion_tokens.
  • What did NOT change (scope boundary): no provider-specific code, no UI/status rendering changes, and no changes outside the OpenAI-compatible response usage mapping path.

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 #54859
  • Related #54995

User-visible / Behavior Changes

  • OpenAI-compatible providers that report usage as prompt_tokens / completion_tokens now record non-zero usage in assistant messages instead of defaulting those fields to zero.

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: Windows 11
  • Runtime/container: source checkout
  • Model/provider: targeted unit coverage for OpenAI-compatible usage payloads (prompt_tokens / completion_tokens)
  • Integration/channel (if any): none
  • Relevant config (redacted): none

Steps

  1. Construct an OpenAI-compatible response object whose usage uses prompt_tokens, completion_tokens, and total_tokens.
  2. Pass it through buildAssistantMessageFromResponse(...).
  3. Inspect the resulting assistant message usage fields.

Expected

  • usage.input maps from prompt_tokens
  • usage.output maps from completion_tokens
  • usage.totalTokens remains populated

Actual

  • Before this change, usage.input and usage.output defaulted to 0 because the parser only read input_tokens / output_tokens.

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: existing input_tokens / output_tokens test still passes; new prompt_tokens / completion_tokens regression test passes; repo pnpm tsgo, pnpm build, and pnpm check all pass on this branch.
  • Edge cases checked: fallback still uses total_tokens when normalization returns no explicit total alias.
  • What you did not verify: a live DashScope session against a real provider account.

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) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert commit 223eee5469
  • Files/config to restore: src/agents/openai-ws-message-conversion.ts, src/agents/openai-ws-stream.test.ts
  • Known bad symptoms reviewers should watch for: usage unexpectedly zeroing for standard input_tokens / output_tokens payloads (covered by the existing test).

Risks and Mitigations

  • Risk: normalizing usage in this path could diverge from the previous direct-field behavior for providers with unusual usage payloads.
    • Mitigation: this path now reuses the same normalizeUsage(...) helper already used elsewhere, and the existing canonical usage test still passes alongside the new alias coverage.

Changed files

  • src/agents/openai-ws-connection.ts (modified, +5/-3)
  • src/agents/openai-ws-message-conversion.ts (modified, +5/-3)
  • src/agents/openai-ws-stream.test.ts (modified, +14/-0)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Summary

After upgrading OpenClaw from 2026.3.2 to 2026.3.23, /status shows Context: 0% and no token/cache info when using LM Studio backend. Works fine with Ollama and online models on the same version. Confirmed LM Studio API returns correct usage field via curl.

Steps to reproduce

  1. Run LM Studio 0.4.7 with API server on (model: qwen/qwen3.5-35b-a3b, context length: 131k)
  2. Configure OpenClaw 2026.3.23 to use LM Studio as model
  3. Send any message, then type /status
  4. Observe Context: 0/131k (0%) — no token/cache info displayed

Expected behavior

/status should show token count, context usage percentage, and cache info (e.g., Tokens: 18k/131k (14%))

<img width="765" height="351" alt="Image" src="https://github.com/user-attachments/assets/88d78d71-e2df-434a-ac6c-5516fde7a219" />

Actual behavior

/status shows Context: 0/131k (0%) with no token or cache data

<img width="770" height="297" alt="Image" src="https://github.com/user-attachments/assets/05d527c6-65d5-4cc4-a0d6-36c10f6247c7" />

OpenClaw version

2026.3.23 (ccfeecb)

Operating system

Ubuntu 24.04 (VirtualBox VM on Windows 11 host)

Install method

npm global

Model

lmstudio/qwen/qwen3.5-35b-a3b

Provider / routing chain

OpenClaw -> LM Studio 0.4.7 (local API: http://192.168.x.x:1234/v1) -> qwen/qwen3.5-35b-a3b

Additional provider/model setup details

  1. LM Studio API returns correct usage data: curl test shows "usage": {"prompt_tokens":13,"completion_tokens":10,"total_tokens":23}

  2. Same OpenClaw 3.23 works with other backends:

    • Online model (zai/glm-4.7): ✅ shows Context: 22k/205k (11%)
  3. Regression confirmed:

    • OpenClaw 2026.3.2 + LM Studio: ✅ works (see attached screenshot)
    • OpenClaw 2026.3.23 + LM Studio: ❌ broken
  4. Compaction still works (context management functional):

    • After setting context length to 16k in config, conversation triggered auto-compaction (Compactions: 2), confirming only the display layer is broken, not actual context handling

Logs, screenshots, and evidence

Impact and severity

Affected: Users running OpenClaw with LM Studio backend on version 2026.3.23

Severity: Medium (affects monitoring visibility, does not block core functionality)

Frequency: Always (100% reproducible with LM Studio; 0% with online models)

Consequence: Cannot monitor token usage and context window occupancy via /status; must rely on compaction count as indirect indicator

Additional information

Regression: Last known good version 2026.3.2, first known bad version 2026.3.13 (confirmed 2026.3.13 and 2026.3.23 both affected)

Tested versions:

  • 2026.3.2: ✅ Working
  • 2026.3.13: ❌ Broken
  • 2026.3.23: ❌ Broken

Workaround:

  • Use online models if token visibility is needed
  • Downgrade to 2026.3.2
  • Or rely on Compactions count to infer context pressure (functional despite display issue)

Additional context:

  • LM Studio API returns correct usage data (verified via curl)
  • Same OpenClaw versions work correctly with online models
  • Compaction triggers correctly in all versions (display-only issue)
  • Issue isolated to LM Studio adapter in OpenClaw

extent analysis

Fix Plan

To resolve the issue with OpenClaw 2026.3.23 not displaying token/cache info when using LM Studio backend, we need to update the LM Studio adapter in OpenClaw to correctly parse the usage field from the LM Studio API response.

Steps to Fix:

  1. Update the LM Studio adapter in OpenClaw to handle the usage field correctly.
  2. Modify the /status endpoint to display the token count, context usage percentage, and cache info based on the updated adapter.

Example Code:

// Updated LM Studio adapter
const fetchUsageData = async () => {
  const response = await fetch('http://192.168.x.x:1234/v1/usage');
  const data = await response.json();
  return data.usage;
};

// Modified /status endpoint
app.get('/status', async (req, res) => {
  const usageData = await fetchUsageData();
  const tokenCount = usageData.prompt_tokens + usageData.completion_tokens;
  const contextUsagePercentage = (tokenCount / 131k) * 100;
  const cacheInfo = `Tokens: ${tokenCount}/131k (${contextUsagePercentage}%)`;
  res.send(`Context: ${tokenCount}/131k (${contextUsagePercentage}%) - ${cacheInfo}`);
});

Verification

To verify that the fix worked, follow these steps:

  1. Update the LM Studio adapter and /status endpoint with the modified code.
  2. Restart the OpenClaw server.
  3. Send a message and type /status to check if the token count, context usage percentage, and cache info are displayed correctly.

Extra Tips

  • Ensure that the LM Studio API is returning the correct usage field data.
  • Test the updated adapter and /status endpoint with different scenarios to ensure that the fix is working as expected.
  • Consider adding error handling and logging to the updated code to improve debugging and monitoring capabilities.

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

/status should show token count, context usage percentage, and cache info (e.g., Tokens: 18k/131k (14%))

<img width="765" height="351" alt="Image" src="https://github.com/user-attachments/assets/88d78d71-e2df-434a-ac6c-5516fde7a219" />

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]: LM Studio token stats not shown in /status (regression from 3.2 to 3.23) [2 pull requests, 1 participants]