openclaw - 💡(How to fix) Fix Bug: local Llama/OpenAI-compatible sessions can show 0% context when usage telemetry is missing [1 comments, 2 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#73990Fetched 2026-04-30 06:30:07
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Timeline (top)
commented ×1cross-referenced ×1

Local Llama / OpenAI-compatible local models can still show incorrect context usage (0%, missing usage, or stale low usage) when the model response does not provide provider usage telemetry. The status/session usage path can return no usable snapshot instead of estimating usage from the transcript.

This appears related to the previously closed context/usage issues #44184, #52219, and #54420, but the local-model display problem can still recur after updates or local dist rebuilds.

Root Cause

  • OpenClaw versions observed around 2026.4.15 local install/backport flow, and still relevant after later 2026.4.x package updates because the local workaround is overwritten by dist replacement.
  • Backend class: local Llama / OpenAI-compatible local endpoint (llama.cpp-style or openai-completions-style usage behavior)
  • Context window example: 262k
  • Surface: OpenClaw status/session context display

Fix Action

Fix / Workaround

  • OpenClaw versions observed around 2026.4.15 local install/backport flow, and still relevant after later 2026.4.x package updates because the local workaround is overwritten by dist replacement.
  • Backend class: local Llama / OpenAI-compatible local endpoint (llama.cpp-style or openai-completions-style usage behavior)
  • Context window example: 262k
  • Surface: OpenClaw status/session context display

Temporary local workaround used successfully

A local dist patch in dist/session-utils.fs-*.js fixed the display by adding a fallback in extractLatestUsageFromTranscriptChunk:

Code Example

Context: 1.1k/262k (0%)

---

1.1k/262k (0%)

---

3.3k/262k (1%)
RAW_BUFFERClick to expand / collapse

Summary

Local Llama / OpenAI-compatible local models can still show incorrect context usage (0%, missing usage, or stale low usage) when the model response does not provide provider usage telemetry. The status/session usage path can return no usable snapshot instead of estimating usage from the transcript.

This appears related to the previously closed context/usage issues #44184, #52219, and #54420, but the local-model display problem can still recur after updates or local dist rebuilds.

Environment observed

  • OpenClaw versions observed around 2026.4.15 local install/backport flow, and still relevant after later 2026.4.x package updates because the local workaround is overwritten by dist replacement.
  • Backend class: local Llama / OpenAI-compatible local endpoint (llama.cpp-style or openai-completions-style usage behavior)
  • Context window example: 262k
  • Surface: OpenClaw status/session context display

Symptom

A local Llama session with real transcript content can continue to display values like:

Context: 1.1k/262k (0%)

or remain effectively at 0% / no meaningful usage even as the transcript grows.

The practical impact is that users cannot trust the context meter for local LLM sessions, and compaction/operational decisions based on displayed context become misleading.

Local finding

When provider usage telemetry is missing or zero, the session usage extraction path can fail to mark that it saw a usable snapshot and can return null/zero-ish usage instead of a fallback estimate based on transcript content.

Temporary local workaround used successfully

A local dist patch in dist/session-utils.fs-*.js fixed the display by adding a fallback in extractLatestUsageFromTranscriptChunk:

  • If provider usage data is missing, estimate input tokens from transcript characters, e.g. estimatedChars / 3.5.
  • Mark the snapshot as seen/usable so the function does not return null solely because provider usage was absent.

After applying that local workaround and restarting the gateway, the display changed from roughly:

1.1k/262k (0%)

to a growing non-zero estimate such as:

3.3k/262k (1%)

and continued increasing as conversation content grew.

Expected behavior

For local/OpenAI-compatible providers that do not reliably return usage telemetry, OpenClaw should still provide a conservative transcript-derived context estimate rather than showing permanent zero/empty usage.

Suggested fix direction

  • Keep provider-reported usage when available and valid.
  • If usage is absent/zero but transcript content exists, fall back to a conservative transcript-character estimate.
  • Ensure the usage extractor marks the fallback snapshot as usable so status/session UI does not collapse back to 0% or null.
  • Add regression coverage for local/openai-completions-style sessions with no usage telemetry but non-empty transcript content.

extent analysis

TL;DR

Apply a fallback estimation in the session usage extraction path when provider usage telemetry is missing, using transcript content to estimate input tokens.

Guidance

  • Review the extractLatestUsageFromTranscriptChunk function in dist/session-utils.fs-*.js to ensure it handles missing provider usage data by estimating input tokens from transcript characters.
  • Verify that the function marks the snapshot as seen/usable when using the fallback estimate to prevent returning null or zero-ish usage.
  • Test the fix with local Llama sessions that do not provide usage telemetry to ensure the context meter displays a growing non-zero estimate.
  • Consider adding regression coverage for local/OpenAI-compatible sessions with no usage telemetry but non-empty transcript content.

Example

// Example fallback estimation in extractLatestUsageFromTranscriptChunk
if (providerUsageData === null || providerUsageData === 0) {
  const estimatedChars = transcriptContent.length;
  const estimatedTokens = estimatedChars / 3.5;
  // Mark the snapshot as seen/usable
  snapshot.seen = true;
  return estimatedTokens;
}

Notes

The suggested fix relies on the extractLatestUsageFromTranscriptChunk function being able to accurately estimate input tokens from transcript characters. The choice of 3.5 as the character-to-token ratio may need to be adjusted based on the specific requirements of the application.

Recommendation

Apply the workaround by modifying the extractLatestUsageFromTranscriptChunk function to include a fallback estimation when provider usage telemetry is missing, as this provides a conservative transcript-derived context estimate rather than showing permanent zero/empty usage.

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

For local/OpenAI-compatible providers that do not reliably return usage telemetry, OpenClaw should still provide a conservative transcript-derived context estimate rather than showing permanent zero/empty usage.

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 - 💡(How to fix) Fix Bug: local Llama/OpenAI-compatible sessions can show 0% context when usage telemetry is missing [1 comments, 2 participants]