openclaw - 💡(How to fix) Fix [Bug]: WebChat 会话消息丢失 - Token消耗存在但消息记录消失 [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#51497Fetched 2026-04-08 01:10:22
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×2commented ×1cross-referenced ×1

Code Example

# QClaw 会话消息丢失 Bug 报告

## 问题描述

用户在 QClaw WebChat 界面中的多条消息在会话中凭空消失,但 Token 消耗记录显示这些消息确实被处理过。

## 证据

### 事件 1: 2026-03-21 (今天)

**会话 ID**: `663ae372-2c69-4417-a607-c45210c35489`
**文件路径**: `C:\Users\daishigong\.qclaw\agents\main\sessions\663ae372-2c69-4417-a607-c45210c35489.jsonl`

- **会话创建时间**: `2026-03-21T06:24:12.757Z` (北京时间 14:24)
- **第一条记录的消息**: `2026-03-21T06:56:58` (北京时间 14:56)
- **缺失时段**:32 分钟的消息历史
- **用户报告**: Token 消耗约 227,098,但消息列表为空
- **当前文件大小**: 59,088 bytes

用户反馈:"你还不承认删除和清空了我提交的任务吗?"

### 事件 2: 2026-03-20 (昨天 - 相同问题)

**会话 ID**: `7188da16-9e0c-40b5-855e-2293741d4952`
**文件路径**: `C:\Users\daishigong\.qclaw\agents\main\sessions\7188da16-9e0c-40b5-855e-2293741d4952.jsonl`

- **会话创建时间**: `2026-03-20T13:09:15.118Z` (北京时间 21:09)
- **第一条记录的消息**: `2026-03-20T13:55:19` (北京时间 21:55)
- **缺失时段**:46 分钟的消息历史
- **文件大小**: 509,734 bytes (较大,说明有其他消息被记录)

用户反馈:"你把我的这个会话任务全删除了?"

## 技术分析

### 日志文件结构

JSONL 文件格式正确,包含:
- `type: "session"` - 会话元数据
- `type: "model_change"` - 模型切换
- `type: "thinking_level_change"` - 思考级别
- `type: "message"` - 用户/助手消息

### 可能的原因

1. **写入延迟/缓冲问题**: 消息可能被缓存在内存中,但未及时写入磁盘
2. **会话重启/重连**: 用户断开重连时,内存中的消息丢失
3. **前端与后端同步问题**: WebChat 前端显示消息,但后端未持久化
4. **会话文件覆盖**: 某种情况下文件被截断或覆盖

### 影响

- 用户无法回顾之前的对话内容
- 用户提交的任务/指令丢失
- Token 已消耗但无记录,影响用户体验和信任

## 复现步骤

无法确定确切复现步骤,但模式显示:
1. 用户开始新会话
2. 进行对话/任务
3. 一定时间后(30-45分钟),早期的消息从记录中消失
4. Token 消耗统计保留,证明消息确实存在过

## 建议

1. **增加写入确认机制**: 确保每条消息都被持久化
2. **添加消息序列号**: 检测是否有消息丢失
3. **实现 WAL (Write-Ahead Logging)**: 先写日志再处理
4. **前端消息缓存恢复**: 从前端恢复可能丢失的消息

## 环境信息

- **OpenClaw 版本**: 2026.3.13 (61d171a)
- **运行环境**: Windows_NT 10.0.19042 (x64)
- **Node.js**: v22.21.1
- **渠道**: webchat
- **时区**: Asia/Shanghai

---

**报告时间**: 2026-03-21 15:03 (北京时间)
**报告来源**: https://github.com/mydaisg
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Summary

问题描述

用户在 QClaw WebChat 界面中的多条消息在会话中凭空消失,但 Token 消耗记录显示这些消息确实被处理过。此问题已连续两天发生。

证据

事件 1: 2026-03-21

会话 ID: 663ae372-2c69-4417-a607-c45210c35489 文件路径: C:\Users\daishigong\.qclaw\agents\main\sessions\663ae372-2c69-4417-a607-c45210c35489.jsonl

  • 会话创建时间: 2026-03-21T06:24:12.757Z (北京时间 14:24)
  • 第一条记录的消息: 2026-03-21T06:56:58 (北京时间 14:56)
  • 缺失时段: 约 32 分钟的消息历史
  • 用户报告: Token 消耗约 227,098,但消息列表为空
  • 当前文件大小: 59,088 bytes

用户反馈:"你还不承认删除和清空了我提交的任务吗?"

事件 2: 2026-03-20 (昨天 - 相同问题)

会话 ID: 7188da16-9e0c-40b5-855e-2293741d4952 文件路径: C:\Users\daishigong\.qclaw\agents\main\sessions\7188da16-9e0c-40b5-855e-2293741d4952.jsonl

  • 会话创建时间: 2026-03-20T13:09:15.118Z (北京时间 21:09)
  • 第一条记录的消息: 2026-03-20T13:55:19 (北京时间 21:55)
  • 缺失时段: 约 46 分钟的消息历史
  • 文件大小: 509,734 bytes (较大,说明有其他消息被记录)

用户反馈:"你把我的这个会话任务全删除了?"

技术分析

日志文件结构

JSONL 文件格式正确,包含:

  • type: "session" - 会话元数据
  • type: "model_change" - 模型切换
  • type: "thinking_level_change" - 思考级别
  • type: "message" - 用户/助手消息

可能的原因

  1. 写入延迟/缓冲问题: 消息可能被缓存在内存中,但未及时写入磁盘
  2. 会话重启/重连: 用户断开重连时,内存中的消息丢失
  3. 前端与后端同步问题: WebChat 前端显示消息,但后端未持久化
  4. 会话文件覆盖: 某种情况下文件被截断或覆盖

影响

  • 用户无法回顾之前的对话内容
  • 用户提交的任务/指令丢失
  • Token 已消耗但无记录,影响用户体验和信任
  • 用户对 AI 产生误解(以为是 AI 删除了消息)

Steps to reproduce

复现步骤

无法确定确切复现步骤,但模式显示:

  1. 用户开始新会话
  2. 进行对话/任务
  3. 一定时间后(30-45分钟),早期的消息从记录中消失
  4. Token 消耗统计保留,证明消息确实存在过

Expected behavior

影响

  • 用户无法回顾之前的对话内容
  • 用户提交的任务/指令丢失
  • Token 已消耗但无记录,影响用户体验和信任
  • 建议

  1. 增加写入确认机制: 确保每条消息都被持久化
  2. 添加消息序列号: 检测是否有消息丢失
  3. 实现 WAL (Write-Ahead Logging): 先写日志再处理
  4. 前端消息缓存恢复: 从前端恢复可能丢失的消息

Actual behavior

QCLaw v0.1.13

OpenClaw version

  • OpenClaw 版本: 2026.3.13 (61d171a)

Operating system

Windows_NT 10.0.19042 (x64)

Install method

  • Node.js: v22.21.1

Model

Qclaw

Provider / routing chain

Qclaw chat

Additional provider/model setup details

环境信息

  • OpenClaw 版本: 2026.3.13 (61d171a)
  • 运行环境: Windows_NT 10.0.19042 (x64)
  • Node.js: v22.21.1
  • 渠道: webchat
  • 时区: Asia/Shanghai

Logs, screenshots, and evidence

# QClaw 会话消息丢失 Bug 报告

## 问题描述

用户在 QClaw WebChat 界面中的多条消息在会话中凭空消失,但 Token 消耗记录显示这些消息确实被处理过。

## 证据

### 事件 1: 2026-03-21 (今天)

**会话 ID**: `663ae372-2c69-4417-a607-c45210c35489`
**文件路径**: `C:\Users\daishigong\.qclaw\agents\main\sessions\663ae372-2c69-4417-a607-c45210c35489.jsonl`

- **会话创建时间**: `2026-03-21T06:24:12.757Z` (北京时间 14:24)
- **第一条记录的消息**: `2026-03-21T06:56:58` (北京时间 14:56)
- **缺失时段**: 约 32 分钟的消息历史
- **用户报告**: Token 消耗约 227,098,但消息列表为空
- **当前文件大小**: 59,088 bytes

用户反馈:"你还不承认删除和清空了我提交的任务吗?"

### 事件 2: 2026-03-20 (昨天 - 相同问题)

**会话 ID**: `7188da16-9e0c-40b5-855e-2293741d4952`
**文件路径**: `C:\Users\daishigong\.qclaw\agents\main\sessions\7188da16-9e0c-40b5-855e-2293741d4952.jsonl`

- **会话创建时间**: `2026-03-20T13:09:15.118Z` (北京时间 21:09)
- **第一条记录的消息**: `2026-03-20T13:55:19` (北京时间 21:55)
- **缺失时段**: 约 46 分钟的消息历史
- **文件大小**: 509,734 bytes (较大,说明有其他消息被记录)

用户反馈:"你把我的这个会话任务全删除了?"

## 技术分析

### 日志文件结构

JSONL 文件格式正确,包含:
- `type: "session"` - 会话元数据
- `type: "model_change"` - 模型切换
- `type: "thinking_level_change"` - 思考级别
- `type: "message"` - 用户/助手消息

### 可能的原因

1. **写入延迟/缓冲问题**: 消息可能被缓存在内存中,但未及时写入磁盘
2. **会话重启/重连**: 用户断开重连时,内存中的消息丢失
3. **前端与后端同步问题**: WebChat 前端显示消息,但后端未持久化
4. **会话文件覆盖**: 某种情况下文件被截断或覆盖

### 影响

- 用户无法回顾之前的对话内容
- 用户提交的任务/指令丢失
- Token 已消耗但无记录,影响用户体验和信任

## 复现步骤

无法确定确切复现步骤,但模式显示:
1. 用户开始新会话
2. 进行对话/任务
3. 一定时间后(30-45分钟),早期的消息从记录中消失
4. Token 消耗统计保留,证明消息确实存在过

## 建议

1. **增加写入确认机制**: 确保每条消息都被持久化
2. **添加消息序列号**: 检测是否有消息丢失
3. **实现 WAL (Write-Ahead Logging)**: 先写日志再处理
4. **前端消息缓存恢复**: 从前端恢复可能丢失的消息

## 环境信息

- **OpenClaw 版本**: 2026.3.13 (61d171a)
- **运行环境**: Windows_NT 10.0.19042 (x64)
- **Node.js**: v22.21.1
- **渠道**: webchat
- **时区**: Asia/Shanghai

---

**报告时间**: 2026-03-21 15:03 (北京时间)
**报告来源**: https://github.com/mydaisg

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To address the issue of missing messages in the QClaw WebChat interface, we will implement the following steps:

  1. Increase write confirmation mechanism: Ensure every message is persisted by implementing a write confirmation callback.
  2. Add message sequence numbers: Detect missing messages by assigning a sequence number to each message.
  3. Implement Write-Ahead Logging (WAL): Write messages to a log before processing to prevent data loss.
  4. Recover messages from frontend cache: Recover potential lost messages from the frontend cache.

Example Code (Node.js):

// Import required modules
const fs = require('fs');
const logger = require('./logger');

// Define a function to write messages to a file with confirmation
function writeMessageToFile(message, filePath) {
  fs.appendFile(filePath, JSON.stringify(message) + '\n', (err) => {
    if (err) {
      logger.error(`Error writing message to file: ${err}`);
    } else {
      logger.info(`Message written to file: ${message}`);
    }
  });
}

// Define a function to implement Write-Ahead Logging (WAL)
function writeMessageToLog(message) {
  // Write message to log before processing
  logger.info(`Writing message to log: ${message}`);
  // Process message
  processMessage(message);
}

// Define a function to recover messages from frontend cache
function recoverMessagesFromCache(cache) {
  // Recover potential lost messages from cache
  const recoveredMessages = cache.get('messages');
  if (recoveredMessages) {
    logger.info(`Recovered messages from cache: ${recoveredMessages}`);
    // Write recovered messages to file
    recoveredMessages.forEach((message) => {
      writeMessageToFile(message, 'recovered_messages.jsonl');
    });
  }
}

Verification

To verify the fix, follow these steps:

  1. Start a new conversation in the QClaw WebChat interface.
  2. Send multiple messages and wait for 30-45 minutes.
  3. Check the conversation history to ensure all messages are present.
  4. Verify that the Token consumption statistics match the number of messages sent.
  5. Repeat steps 1-4 multiple times to ensure the issue is resolved.

Extra Tips

  • Regularly review and monitor the conversation history to detect any potential issues.
  • Consider implementing a message queue to handle high volumes of messages and prevent data loss.
  • Ensure that the Write-Ahead Logging (WAL) mechanism is properly configured and functioning correctly.

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