Skip to content

WebUI: duplicate messages after WebSocket reconnect (v2026.3.7) #39686

@goodstark1991

Description

@goodstark1991

Bug Description

After upgrading to v2026.3.7, messages sent in Slack appear twice in the WebUI (Control UI). The issue does not affect Slack — only the WebUI shows duplicates.

Environment

  • openclaw v2026.3.7 (42a1394)
  • macOS (Darwin 25.3.0)
  • Slack channel integration (socket mode)

Steps to Reproduce

  1. Open WebUI (Control UI) connected to a Slack-bound agent session
  2. Send a message in the Slack thread
  3. Observe the message appears twice in the WebUI

Root Cause Analysis

1. Frequent WebSocket disconnections (new in v2026.3.7)

Gateway logs show the WebUI WebSocket disconnects every 30-120 seconds with code=1001:

17:05:30 [ws] webchat disconnected code=1001
17:05:30 [ws] webchat connected (v2026.3.7)
17:06:14 [ws] webchat disconnected code=1001  ← 44s later
17:06:14 [ws] webchat connected
17:07:45 [ws] webchat disconnected code=1001  ← 91s later
17:08:46 [ws] webchat disconnected code=1001  ← 61s later

Before the upgrade, WebSocket connections were stable for hours without disconnecting.

2. loadChatHistory() replaces messages without deduplication

On reconnect, onHello triggers loadChatHistory() which does:

state.chatMessages = messages.filter((message) => !isAssistantSilentReply(message));

This completely replaces the in-memory message array. If a message was already displayed via real-time push before the disconnect, it appears again after the history reload.

3. Index-based keys in chat rendering

buildChatItems() uses array-index-based keys (messageKey(tools[i], i + history.length)) instead of stable message IDs, so React/Lit cannot detect duplicates during re-render.

Suggested Fix

  1. Use message ID (or timestamp + sender hash) as dedup key in loadChatHistory()
  2. Merge fetched history with existing state.chatMessages instead of replacing
  3. Use stable message ID-based keys in buildChatItems() instead of array indices
  4. Investigate why WebSocket disconnects so frequently in v2026.3.7 (was stable pre-upgrade)

Workaround

None currently — investigating local patch options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions