openclaw - 💡(How to fix) Fix Context counter shows 0/200k with LiteLLM proxy — compaction never triggers [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#52235Fetched 2026-04-08 01:13:53
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
1
Timeline (top)
commented ×1

Error Message

Context stays at 0 permanently. Auto-compaction never triggers. Eventually the session hits the actual context limit and fails with an API error instead of compacting gracefully.

Root Cause

OpenClaw may not be reading or accumulating the usage field from LiteLLM proxy responses into the session context counter. This could be because:

  1. Token counting relies on a different mechanism (e.g., local tiktoken) that doesn't work for litellm/* model IDs
  2. The usage response format from LiteLLM has extra fields that cause parsing issues
  3. Context size is tracked differently for non-native providers

Code Example

{
  "usage": {
    "completion_tokens": 10,
    "prompt_tokens": 9,
    "total_tokens": 19,
    "completion_tokens_details": { "text_tokens": 10 },
    "prompt_tokens_details": { "cached_tokens": 0, "cache_creation_tokens": 0 }
  }
}

---

{
  "agents": {
    "defaults": {
      "compaction": { "mode": "default" }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Environment

  • OpenClaw: 2026.3.13 (61d171a)
  • Model: litellm/claude-opus-4-6 via LiteLLM proxy (localhost:4000)
  • OS: Debian 13 (arm64, Raspberry Pi 5)

Problem

/status always shows Context: 0/200k (0%) and Compactions: 0, even after long conversations with extensive tool use.

Expected behavior

Context counter should accumulate tokens from API responses and trigger auto-compaction when nearing the model's context window.

Actual behavior

Context stays at 0 permanently. Auto-compaction never triggers. Eventually the session hits the actual context limit and fails with an API error instead of compacting gracefully.

Investigation

LiteLLM proxy does return usage in the response:

{
  "usage": {
    "completion_tokens": 10,
    "prompt_tokens": 9,
    "total_tokens": 19,
    "completion_tokens_details": { "text_tokens": 10 },
    "prompt_tokens_details": { "cached_tokens": 0, "cache_creation_tokens": 0 }
  }
}

Verified with a direct curl request to localhost:4000/v1/chat/completions. The usage fields are present and correct.

Compaction config

{
  "agents": {
    "defaults": {
      "compaction": { "mode": "default" }
    }
  }
}

Hypothesis

OpenClaw may not be reading or accumulating the usage field from LiteLLM proxy responses into the session context counter. This could be because:

  1. Token counting relies on a different mechanism (e.g., local tiktoken) that doesn't work for litellm/* model IDs
  2. The usage response format from LiteLLM has extra fields that cause parsing issues
  3. Context size is tracked differently for non-native providers

extent analysis

Fix Plan

To resolve the issue of the context counter not accumulating tokens, we need to modify the OpenClaw code to correctly parse and accumulate the usage field from LiteLLM proxy responses.

Step-by-Step Solution

  1. Update the token counting mechanism: Ensure that the token counting mechanism is compatible with the litellm/* model IDs. This might involve modifying the code to use the usage field from the LiteLLM proxy responses.
  2. Parse the usage response format: Verify that the code can correctly parse the usage response format from LiteLLM, including the extra fields.
  3. Accumulate tokens: Update the code to accumulate the tokens from the usage field into the session context counter.

Example Code Changes

# Assuming the response from LiteLLM proxy is stored in the 'response' variable
usage = response.json()['usage']
total_tokens = usage['total_tokens']

# Accumulate tokens into the session context counter
session_context_counter += total_tokens

Configuration Changes

No changes are required to the compaction configuration.

Verification

To verify that the fix worked, monitor the context counter and compaction triggers after applying the changes. The context counter should now accumulate tokens correctly, and auto-compaction should trigger when nearing the model's context window.

Extra Tips

  • Ensure that the LiteLLM proxy is configured correctly and returning the expected usage field in the responses.
  • Verify that the OpenClaw code is correctly parsing and accumulating the tokens from the usage field.
  • Test the changes with different model IDs and conversation scenarios to ensure that the fix is robust.

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

Context counter should accumulate tokens from API responses and trigger auto-compaction when nearing the model's context window.

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 Context counter shows 0/200k with LiteLLM proxy — compaction never triggers [1 comments, 2 participants]