Skip to content

fix(openclaw): prevent duplicate replies from late chat events#1844

Merged
piorpua merged 1 commit intomainfrom
fix/issue-1281
Mar 29, 2026
Merged

fix(openclaw): prevent duplicate replies from late chat events#1844
piorpua merged 1 commit intomainfrom
fix/issue-1281

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • After handleEndTurn() resets currentStreamMsgId to null, late-arriving chat.event delta/final events would create a new msg_id and re-emit the same content as a "new" message
  • Added a turnActive flag to OpenClawAgent that blocks chat event processing after turn completion
  • Flag is set true in sendMessage() and false in handleEndTurn()

Related Issues

Closes #1281

Test Plan

  • Unit tests: 5 new tests covering normal flow, late delta prevention, double final prevention, multi-turn flow, and pre-sendMessage guard
  • Type check passes (tsc --noEmit)
  • Lint and format pass

After handleEndTurn() resets currentStreamMsgId to null, late-arriving
chat.event delta/final events would create a new msg_id and re-emit
the same content, causing users to see duplicate replies in the
OpenClaw gateway channel.

Add a turnActive flag that is set to true when sendMessage() starts a
new turn and reset to false in handleEndTurn(). handleChatEvent() now
returns early when turnActive is false, preventing any late events
from generating duplicate content messages.
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

Code Review:fix(openclaw): prevent duplicate replies from late chat events (#1844)

变更概述

本 PR 在 OpenClawAgent 中新增 turnActive 布尔标志位,作为 handleChatEvent() 的前置守卫,阻止 handleEndTurn() 重置状态后迟到的 chat.event 事件创建新的 msg_id 并重发相同内容。改动涉及 src/process/agent/openclaw/index.ts(+13 行)以及新增测试文件 tests/unit/openClawAgentDuplicate.test.ts(237 行)。


方案评估

结论:✅ 方案合理

标志位生命周期清晰(sendMessage() 置 true → handleEndTurn() 置 false),早返回放在 session 过滤检查之后,符合现有防护链的逻辑顺序。方案最小化修改,未引入额外状态或抽象,与项目现有架构完全一致。Layer 3 fallback(fetchAndEmitHistoryFallback)的异步 .finally() 调用 handleEndTurn() 可能与新一轮 sendMessage() 产生竞态,但该竞态早于本 PR 就已存在,本次改动未引入新风险。


问题清单

未发现需报告的问题。代码逻辑正确,边界情况覆盖完整,测试充分,lint baseline 中唯一警告(第 285 行 await in loop)为改动前已有的存量问题。


汇总

无问题。

结论

批准合并 — 修复方案简洁正确,5 个针对性测试覆盖了所有关键边界情况,无阻塞性问题。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

CONCLUSION: APPROVED
IS_CRITICAL_PATH: false
PR_NUMBER: 1844

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua merged commit cb95b1a into main Mar 29, 2026
17 checks passed
@piorpua piorpua deleted the fix/issue-1281 branch March 29, 2026 09:10
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

单条消息收到重复回复 (Duplicate replies for single message)

2 participants