openclaw - 💡(How to fix) Fix Bug: Context Window shows unknown/0 despite extensive conversation [3 comments, 3 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#51551Fetched 2026-04-08 01:09:42
View on GitHub
Comments
3
Participants
3
Timeline
3
Reactions
0
Author
Timeline (top)
commented ×3

Root Cause

Should display actual usage, at least tens of thousands of tokens, because:

  • Conversation history contains dozens of messages
  • PDF files were read and processed
  • Long summary content was generated
  • Multiple tool calls were made

Code Example

📚 Context: 0/1.0m (0%)

---

│ agent:main:feishu:direct:ou_ad4… │ direct │ 1m ago │ glm-5-fp8 │ unknown/1000k (?%)
RAW_BUFFERClick to expand / collapse

Bug Report: Context Window Shows 0 Despite Extensive Conversation

Problem Description

In a Feishu direct message session, session_status and openclaw status show context window usage as unknown or 0, even after extensive conversation with large file processing.

Environment

  • OpenClaw version: 2026.3.13
  • Model: glm-5
  • Configured contextWindow: 1000000 (1M)
  • Configured maxTokens: 131072 (128K)
  • Channel: Feishu direct message
  • Session type: agent:main:feishu:direct

Reproduction Steps

  1. Start a conversation with the agent via Feishu direct message
  2. User sends a big PDF file (> 1M)
  3. Agent reads and analyzes these files
  4. Agent generates a long summary (several thousand words)
  5. Multiple tool calls
  6. Run session_status or openclaw status to check context usage

Actual Behavior

📚 Context: 0/1.0m (0%)

or

│ agent:main:feishu:direct:ou_ad4… │ direct │ 1m ago │ glm-5-fp8 │ unknown/1000k (?%) │

Shows usage as 0 or unknown tokens.

Expected Behavior

Should display actual usage, at least tens of thousands of tokens, because:

  • Conversation history contains dozens of messages
  • PDF files were read and processed
  • Long summary content was generated
  • Multiple tool calls were made

Possible Causes

  1. Context statistics display has a delay
  2. Only counting user input, not counting agent output
  3. File content is handled specially, not counted in context statistics
  4. Statistics were reset after Gateway restart

Session Content Summary

The session contains:

  • User-sent PDF file
  • Agent's analysis and summary of files
  • Generated long summary
  • Configuration modifications and gateway restart

Impact

Users cannot accurately understand the current session's context usage, affecting judgment of conversation length and remaining capacity.

Additional Notes

The configured contextWindow: 1000000 is correctly read from ~/.openclaw/openclaw.json, but the runtime usage statistics from Gateway appear to be broken or not tracking properly.

extent analysis

Fix Plan

To address the issue of context window usage showing 0 or unknown despite extensive conversation, we need to modify the way context statistics are tracked and displayed.

Step-by-Step Solution:

  1. Update OpenClaw Configuration: Ensure that the contextWindow and maxTokens are correctly set in ~/.openclaw/openclaw.json. For example:
    {
      "contextWindow": 1000000,
      "maxTokens": 131072
    }
  2. Modify Context Tracking: Update the code to count both user input and agent output towards the context statistics. This might involve modifying the session_status and openclaw status commands to accurately reflect the total tokens used.
  3. Handle File Content: Adjust the handling of file content to include it in the context statistics. This could involve adding the file size (in tokens) to the total context usage when a file is processed.
  4. Prevent Statistics Reset: Ensure that context statistics are not reset after a Gateway restart. This might involve storing the statistics in a persistent storage that survives restarts.

Example Code Snippet (Python):

def update_context_statistics(session_id, tokens_used):
    # Load current statistics
    stats = load_statistics(session_id)
    
    # Update statistics
    stats['context_usage'] += tokens_used
    
    # Save updated statistics
    save_statistics(session_id, stats)

def load_statistics(session_id):
    # Load from persistent storage
    # For simplicity, assume a dictionary stored in a file
    try:
        with open(f'{session_id}_stats.json', 'r') as file:
            return json.load(file)
    except FileNotFoundError:
        return {'context_usage': 0}

def save_statistics(session_id, stats):
    # Save to persistent storage
    with open(f'{session_id}_stats.json', 'w') as file:
        json.dump(stats, file)

Verification

To verify that the fix worked, follow these steps:

  • Start a new conversation via Feishu direct message.
  • Send a large file (> 1M) and have the agent process it.
  • Generate a long summary.
  • Make multiple tool calls.
  • Run session_status or openclaw status to check the context usage.
  • The output should now accurately reflect the total tokens used, including both user input and agent output, and should not reset after a Gateway restart.

Extra Tips

  • Regularly review and update the contextWindow and maxTokens configurations to ensure they meet the needs of your conversations.
  • Consider implementing a mechanism to alert users when the context usage approaches the maximum allowed, to prevent unexpected truncation of conversations.
  • Ensure that all components involved in tracking and displaying context statistics are updated and compatible with each other to avoid version conflicts.

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…

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: Context Window shows unknown/0 despite extensive conversation [3 comments, 3 participants]