openclaw - 💡(How to fix) Fix Session history replay creates duplicate messages in web UI after session restart/migration [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#72604Fetched 2026-04-28 06:34:03
View on GitHub
Comments
1
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
commented ×1

When a session crashes and restarts (e.g., context overflow → auto-compaction → session restart), the gateway replays old conversation history into the new session. This creates duplicate messages visible in the web UI.

Root Cause

Root Cause (from source analysis)

Fix Action

Workaround

Starting a new session (new chat in web UI) stops duplicates since there is no old history to replay.

Code Example

2026-04-27T04:11:21.422Z | Boss, here's exactly what happened...
2026-04-27T04:11:21.574Z | Boss, here's exactly what happened...  (duplicate, 152ms later)

---

const connIds = new Set();
for (const connId of params.sessionEventSubscribers.getAll()) connIds.add(connId);
for (const connId of params.sessionMessageSubscribers.get(sessionKey)) connIds.add(connId);
RAW_BUFFERClick to expand / collapse

Bug Report

Version: 2026.4.24 OS: macOS 15.6 (Darwin 24.6.0, x64) Node: v25.9.0

Description

When a session crashes and restarts (e.g., context overflow → auto-compaction → session restart), the gateway replays old conversation history into the new session. This creates duplicate messages visible in the web UI.

Steps to Reproduce

  1. Have an active webchat session
  2. Session hits context overflow and gets restarted (new sessionId, same sessionKey)
  3. Gateway replays history from old session into new session
  4. Every subsequent webchat connection/reconnect triggers additional replay
  5. Messages appear duplicated in the web UI

Evidence

Session transcript shows identical assistant messages at nearly identical timestamps:

2026-04-27T04:11:21.422Z | Boss, here's exactly what happened...
2026-04-27T04:11:21.574Z | Boss, here's exactly what happened...  (duplicate, 152ms later)

At 04:31:15, 35 messages were dumped into the session in a single second — the entire previous conversation replayed.

At 04:15:20, 12 messages replayed in one second.

Impact

  • User sees every message duplicated in the web UI
  • Token usage inflated from duplicate processing
  • Session transcript grows with redundant data
  • Web UI becomes unusable for long sessions

Root Cause (from source analysis)

In server.impl-CtLS1ywt.js, createTranscriptUpdateBroadcastHandler at line ~9234:

const connIds = new Set();
for (const connId of params.sessionEventSubscribers.getAll()) connIds.add(connId);
for (const connId of params.sessionMessageSubscribers.get(sessionKey)) connIds.add(connId);

The emitSessionTranscriptUpdate in transcript-events-ofiGBxi_.js fires for each transcript write. When old session history is replayed into a new session, each replayed message triggers the transcript update handler, causing duplicate broadcasts.

Expected Behavior

Session migration/restart should NOT replay old messages into the new session transcript. Old history should be available via chat.history but not re-written as new messages.

Workaround

Starting a new session (new chat in web UI) stops duplicates since there is no old history to replay.

Environment

  • OpenClaw 2026.4.24 (cbcfdf6)
  • Channels: Discord, Telegram, Web UI
  • Gateway: local mode, loopback
  • Session experienced context overflow from a runaway tool loop (1,738 tool calls) before migration

extent analysis

TL;DR

The most likely fix involves modifying the createTranscriptUpdateBroadcastHandler to prevent duplicate broadcasts when old session history is replayed into a new session.

Guidance

  • Review the createTranscriptUpdateBroadcastHandler function in server.impl-CtLS1ywt.js to ensure it correctly handles session restarts and old history replay.
  • Consider adding a check to prevent the emitSessionTranscriptUpdate function in transcript-events-ofiGBxi_.js from firing for replayed messages.
  • Investigate the sessionEventSubscribers and sessionMessageSubscribers to ensure they are properly updated during session migration.
  • Verify that the chat.history API returns the correct conversation history without duplicates.

Example

// Potential modification to createTranscriptUpdateBroadcastHandler
const connIds = new Set();
for (const connId of params.sessionEventSubscribers.getAll()) connIds.add(connId);
for (const connId of params.sessionMessageSubscribers.get(sessionKey)) {
  if (!connIds.has(connId)) { // Check for existing connection IDs
    connIds.add(connId);
  }
}

Notes

The provided workaround of starting a new session stops duplicates, but a more permanent solution is needed to handle session restarts and old history replay.

Recommendation

Apply a workaround by modifying the createTranscriptUpdateBroadcastHandler function to prevent duplicate broadcasts, as the root cause is identified and a potential solution is proposed.

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 Session history replay creates duplicate messages in web UI after session restart/migration [1 comments, 1 participants]