openclaw - ✅(Solved) Fix [Bug] Gateway WebSocket chat stream may drop repeated consecutive characters in merged assistant text [1 pull requests, 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#63769Fetched 2026-04-10 03:41:55
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
referenced ×2commented ×1cross-referenced ×1renamed ×1

Error Message

In logs, event=agent has the correct full text first, then event=chat (state=delta/final) shows collapsed characters.

Root Cause

Likely root cause

Fix Action

Fixed

PR fix notes

PR #63994: fix(gateway): avoid collapsing repeated chars when merging assistant chat deltas

Description (problem / solution / changelog)

Fixes overlap-based dedupe in \ppendUniqueSuffix\ that removed legitimate repeated boundary characters in WebSocket \chat\ delta/final payloads when \gent\ events were correct.

  • Append incremental \delta\ with plain concatenation (upstream deltas are already incremental).
  • Keep
    esolveMergedAssistantText\ fast paths for prefix snapshots and tool-boundary segments.
  • Add \server-chat.merge.test.ts\ coverage.

Related: https://github.com/openclaw/openclaw/issues/63769

Made with Cursor

Changed files

  • extensions/qa-lab/src/multipass.runtime.ts (modified, +3/-1)
  • src/agents/pi-embedded-runner/compact.hooks.harness.ts (modified, +1/-0)
  • src/agents/pi-embedded-runner/run.overflow-compaction.harness.ts (modified, +1/-0)
  • src/commands/doctor-bootstrap-size.test.ts (modified, +16/-8)
  • src/commands/doctor-config-flow.missing-default-account-bindings.integration.test.ts (modified, +6/-6)
  • src/gateway/server-chat.merge.test.ts (added, +44/-0)
  • src/gateway/server-chat.ts (modified, +5/-10)
  • src/utils/delivery-context.test.ts (modified, +2/-1)
RAW_BUFFERClick to expand / collapse

Bug summary

When consuming OpenClaw Gateway events over WebSocket, agent stream payloads are correct, but subsequent chat delta/final payloads may drop repeated consecutive characters (digit/CJK), e.g.:

  • k0059 -> k059
  • k1119 -> k19
  • k0044 -> k04
  • 超时时间 -> 超时间

Observed behavior

In logs, event=agent has the correct full text first, then event=chat (state=delta/final) shows collapsed characters.

Likely root cause

In src/gateway/server-chat.ts, merge logic for assistant text uses overlap-based dedupe in appendUniqueSuffix():

  • checks base.endsWith(suffix)
  • then computes longest suffix/prefix overlap and slices overlap away

This heuristic removes legitimate repeated boundary characters for true incremental deltas.

Why this happens

delta from upstream is already semantically newly appended text in this path. Applying generic overlap dedupe again can wrongly collapse valid repeated characters.

Suggested fix

Keep cross-tool-boundary merge behavior, but remove overlap-dedupe from suffix append for this path:

  • use base + suffix when nextDelta exists
  • preserve existing nextText.startsWith(previousText) fast-path logic

Regression coverage

Please add/keep tests for:

  1. cross-tool-boundary segmented merge (to avoid old prefix-loss regression)
  2. repeated-boundary characters (k1119, CJK repeats) to prevent collapse

extent analysis

TL;DR

Modify the appendUniqueSuffix() function in src/gateway/server-chat.ts to remove overlap-based dedupe for delta and final payloads when nextDelta exists.

Guidance

  • Review the appendUniqueSuffix() function to understand the current merge logic and how it affects chat delta/final payloads.
  • Update the function to use base + suffix when nextDelta exists, preserving the existing fast-path logic for nextText.startsWith(previousText).
  • Verify the fix by testing cases with repeated consecutive characters (e.g., k1119, 超时时间) to ensure they are no longer collapsed.
  • Add or maintain tests for cross-tool-boundary segmented merge and repeated-boundary characters to prevent regressions.

Example

// Modified appendUniqueSuffix() function
if (nextDelta) {
  return base + suffix; // Remove overlap-based dedupe for delta and final payloads
} else {
  // Existing logic for other cases
}

Notes

This fix assumes that the nextDelta flag accurately indicates when the overlap-based dedupe should be skipped. Additional testing may be necessary to ensure the fix works correctly in all scenarios.

Recommendation

Apply the suggested fix to modify the appendUniqueSuffix() function, as it directly addresses the root cause of the issue and preserves the existing fast-path logic.

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