openclaw - 💡(How to fix) Fix Bug: Context Window 显示为 unknown/0,但实际已进行大量对话 [1 comments, 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#51550Fetched 2026-04-08 01:09:44
View on GitHub
Comments
1
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1locked ×1

Code Example

📚 Context: 0/1.0m (0%)
RAW_BUFFERClick to expand / collapse

Bug Report: Context Window 显示为 0 的异常

问题描述

在 Feishu 直接对话的 session 中,session_status 显示 context window 使用量为 0,但实际上已经进行了大量对话。

环境信息

  • OpenClaw 版本: 2026.3.13
  • 模型: glm-5
  • 配置的 contextWindow: 1000000 (1M)
  • 配置的 maxTokens: 131072 (128K)
  • 渠道: Feishu 直接对话
  • 会话类型: agent:main:feishu:direct

复现步骤

  1. 在 Feishu 直接对话中与 agent 进行长时间对话
  2. 用户发送了 PDF 文件和 Excel 文件
  3. Agent 读取并分析了这些文件
  4. Agent 生成了很长的总结邮件(几万字)
  5. 进行了多次工具调用(发送邮件、修改配置等)
  6. 调用 session_status 查看 context 使用情况

实际行为

📚 Context: 0/1.0m (0%)

显示使用量为 0 tokens。

预期行为

应该显示实际使用量,至少应该有几十K tokens,因为:

  • 对话历史有几十条消息
  • 读取了 PDF 和 Excel 文件
  • 生成了很长的总结邮件内容

可能的原因

  1. Context 统计显示有延迟
  2. 只统计了用户输入,没有统计 agent 输出
  3. 文件内容被特殊处理,不计入 context 统计
  4. Gateway 重启后统计信息被重置

对话内容摘要

该 session 中包含:

  • 用户发送的 PDF 简历文件
  • 用户发送的 Excel 面试反馈文件
  • Agent 对文件的分析和总结
  • 生成的长篇候选人总结邮件
  • 多次邮件发送操作
  • 配置修改和 gateway 重启
  • 200K/500K/800K tokens 的 sub-agent 测试

影响范围

用户无法准确了解当前 session 的 context 使用情况,影响对对话长度的判断。

extent analysis

Fix Plan

To address the issue of the context window displaying as 0, we need to update the session_status calculation to accurately reflect the context usage.

Steps:

  1. Update Context Calculation: Modify the session_status function to include agent outputs and file contents in the context calculation.
  2. Handle File Contents: Ensure that file contents, such as PDF and Excel files, are properly counted towards the context usage.
  3. Prevent Gateway Reset: Implement a mechanism to persist context usage data across gateway restarts.

Example Code:

def calculate_context_usage(session):
    # Include agent outputs and file contents
    context_usage = len(session['user_inputs']) + len(session['agent_outputs'])
    for file in session['files']:
        context_usage += file['size']
    return context_usage

def update_session_status(session):
    context_usage = calculate_context_usage(session)
    session['context_usage'] = context_usage
    return session

# Example usage:
session = {
    'user_inputs': ['Hello', 'How are you?'],
    'agent_outputs': ['Hi', 'I am good'],
    'files': [{'size': 1000}, {'size': 2000}]
}
updated_session = update_session_status(session)
print(updated_session['context_usage'])

Verification

To verify the fix, perform the following steps:

  1. Test with Sample Data: Use the example code to test the calculate_context_usage function with sample session data.
  2. Check Context Usage: Verify that the context usage is accurately calculated and displayed in the session_status.
  3. Test with Gateway Restart: Restart the gateway and verify that the context usage data is persisted.

Extra Tips

  • Ensure that the calculate_context_usage function is efficient and scalable to handle large session data.
  • Consider implementing a caching mechanism to store context usage data and reduce the load on the gateway.
  • Regularly monitor and test the session_status function to prevent regressions.

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 显示为 unknown/0,但实际已进行大量对话 [1 comments, 1 participants]