openclaw - ✅(Solved) Fix [Bug]: Feishu streaming card merges unrelated replies when agent produces multiple final messages [4 pull requests, 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#43704Fetched 2026-04-08 00:17:00
View on GitHub
Comments
0
Participants
1
Timeline
14
Reactions
0
Author
Participants
Timeline (top)
referenced ×8cross-referenced ×4labeled ×1marked_as_duplicate ×1

When the agent produces multiple independent final replies (replies=2) in a single request, the Feishu streaming card incorrectly merges content from the second reply into the first card, while also sending the second reply as a separate card. This results in duplicate content being displayed to the user.

Root Cause

Looking at the mergeStreamingText function in extensions/feishu/src/streaming-card.ts:

export function mergeStreamingText( previousText: string | undefined, nextText: string | undefined, ): string { // ... various merge attempts ...

// Fallback for fragmented partial chunks: append as-is to avoid losing tokens. return ${previous}${next}; // ← This causes unrelated content to be merged }

When two replies have completely different content (no overlap), the fallback behavior is to concatenate them. This is intended for partial streaming chunks, but incorrectly merges unrelated final replies.

Fix Action

Fix / Workaround

When agent produces multiple independent replies, each should be delivered as a separate message, OR they should be properly merged into a single coherent message without duplication.

Mar 12 12:01:27 Started streaming: cardId=7616214340648340671, messageId=om_x100b5417e74b60a4c3a474e9be9dc4f Mar 12 12:02:10 Closed streaming: cardId=7616214340648340671 Mar 12 12:02:10 Started streaming: cardId=7616214523998375126, messageId=om_x100b5417e2e3907cc2906e393e5ae37 Mar 12 12:02:11 Closed streaming: cardId=7616214523998375126 Mar 12 12:02:11 dispatch complete (queuedFinal=true, replies=2)

PR fix notes

PR #43715: Feishu: prevent cross-reply merge in streaming final cards

Description (problem / solution / changelog)

Summary

  • treat each streaming final payload as authoritative when closing a Feishu card session
  • stop merging buffered streaming text into final payloads during FeishuStreamingSession.close
  • update Feishu reply dispatcher coverage to assert independent final replies stay isolated across cards

Testing

  • pnpm vitest run extensions/feishu/src/reply-dispatcher.test.ts extensions/feishu/src/streaming-card.test.ts ✅ passed (29 tests)

Closes #43704

Changed files

  • extensions/feishu/src/reply-dispatcher.test.ts (modified, +46/-2)
  • extensions/feishu/src/reply-dispatcher.ts (modified, +7/-4)
  • extensions/feishu/src/streaming-card.ts (modified, +3/-1)

PR #43862: fix(feishu): prevent merging unrelated final replies in streaming card

Description (problem / solution / changelog)

Problem

When the agent produces multiple independent final replies (replies=2) in a single request, the Feishu streaming card incorrectly merges content from the second reply into the first card, while also sending the second reply as a separate card. This results in duplicate content being displayed to the user.

Root Cause

The close() method was called multiple times for different final replies, and the mergeStreamingText function's fallback behavior concatenated unrelated content when there was no overlap.

Solution

Add a finalDelivered flag to track whether final content has already been delivered. If close() is called again after final delivery, it returns early without merging new content.

Changes

  • Add finalDelivered flag to FeishuStreamingSession class
  • Modify close() to check if final was already delivered
  • Skip merging when session is already closed and final delivered

Testing

This fix prevents unrelated final replies from being merged into a single card.

Fixes #43704

Changed files

  • src/infra/net/fetch-guard.ts (modified, +7/-2)

PR #46191: fix(feishu): avoid merging independent final replies into one streaming card

Description (problem / solution / changelog)

Summary

When the agent produces multiple independent final replies (replies=2) in a single request, the Feishu streaming card incorrectly merges content from the second reply into the first card, resulting in duplicated content displayed to the user.

Change Type

Bug fix (non-breaking)

Scope

extensions/feishu/src/streaming-card.tsmergeStreamingText() fallback behavior extensions/feishu/src/streaming-card.test.ts — updated tests

Linked Issue

Fixes #43704

Root Cause

mergeStreamingText() used a fallback of previous + next (concatenation) when two texts shared no overlap. This was intended for fragmented partial chunks but incorrectly merged completely independent final replies, causing the first streaming card to display content from both replies.

Fix

Changed the no-overlap fallback from \${previous}${next}`to justnext. When two texts share no overlap at all, they are independent replies — returning next` prevents duplicate content in the first card while ensuring the second reply starts its own card cleanly.

Security Impact

None — pure streaming display logic change.

Reproduction & Verification

  1. Agent produces two independent final replies in one request
  2. Before fix: first Feishu card contains both replies' content (duplicated)
  3. After fix: each card contains only its own reply content

Evidence

  • All 363 feishu extension tests pass (36 files)
  • pnpm build passes
  • Updated test verifies new behavior for independent replies and Chinese text

Human Verification

Tested mergeStreamingText unit tests covering:

  • Normal overlap merging (unchanged)
  • Snapshot progression (unchanged)
  • Independent replies with no overlap (now returns next instead of concatenating)

Compatibility

Backward compatible — the concatenation fallback only triggered when texts had zero overlap, which in practice only happens with independent multi-reply scenarios.

Failure Recovery

If merge behavior is incorrect, the streaming card displays stale text; the final card delivery still sends the correct content.

Risks

Low — change only affects the no-overlap fallback path in a pure utility function.


AI-assisted: This PR was authored with AI assistance.

Changed files

  • extensions/feishu/src/streaming-card.test.ts (modified, +6/-3)
  • extensions/feishu/src/streaming-card.ts (modified, +4/-2)

PR #48885: fix: resolve temporal dead zone issues with CHANNEL_IDS on Windows

Description (problem / solution / changelog)

Description

This PR fixes #48832 where OpenClaw fails to start on Windows with module initialization errors.

Root Cause

Circular dependencies caused CHANNEL_IDS and CHAT_CHANNEL_ORDER to be undefined during module load time on Windows.

Solution

Converted all immediate uses to lazy getters to ensure constants are accessed at runtime when the registry module has fully initialized.

Related Issue

Fixes #48832

Changed files

  • extensions/feishu/src/streaming-card-fix.md (added, +49/-0)
  • src/agents/models-config.providers.ts (modified, +4/-1)
  • src/agents/sandbox/constants.ts (modified, +8/-2)
  • src/auto-reply/reply/elevated-allowlist-matcher.ts (modified, +17/-10)
  • src/cli/channel-options.ts (modified, +9/-3)
  • src/config/schema.ts (modified, +9/-2)
  • src/config/validation.ts (modified, +10/-3)
  • src/infra/net/fetch-guard.ts (modified, +7/-2)
  • src/utils/message-channel.ts (modified, +8/-2)

Code Example

## Evidence from logs


Mar 12 12:01:27 Started streaming: cardId=7616214340648340671, messageId=om_x100b5417e74b60a4c3a474e9be9dc4f
Mar 12 12:02:10 Closed streaming: cardId=7616214340648340671
Mar 12 12:02:10 Started streaming: cardId=7616214523998375126, messageId=om_x100b5417e2e3907cc2906e393e5ae37
Mar 12 12:02:11 Closed streaming: cardId=7616214523998375126
Mar 12 12:02:11 dispatch complete (queuedFinal=true, replies=2)


Two different cardIds were created, but the first card contained content from both replies.

## Root cause analysis

Looking at the `mergeStreamingText` function in `extensions/feishu/src/streaming-card.ts`:


export function mergeStreamingText(
  previousText: string | undefined,
  nextText: string | undefined,
): string {
  // ... various merge attempts ...
  
  // Fallback for fragmented partial chunks: append as-is to avoid losing tokens.
  return `${previous}${next}`;  // ← This causes unrelated content to be merged
}

When two replies have completely different content (no overlap), the fallback behavior is to concatenate them. This is intended for partial streaming chunks, but incorrectly merges unrelated final replies.

## Suggested fix

1. Track whether streaming session has received a final delivery
2. If a new final reply arrives after a previous final was already delivered, start a new streaming card instead of merging
3. Or: Modify `mergeStreamingText` to have a "strict" mode that refuses to merge completely unrelated content
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Summary

When the agent produces multiple independent final replies (replies=2) in a single request, the Feishu streaming card incorrectly merges content from the second reply into the first card, while also sending the second reply as a separate card. This results in duplicate content being displayed to the user.

Steps to reproduce

  1. Agent received a request to create a calendar meeting
  2. Agent produced two independent replies:
    • First reply: "让我先读取一下日历工具的使用说明..." followed by meeting details
    • Second reply: Just the meeting details

Expected behavior

When agent produces multiple independent replies, each should be delivered as a separate message, OR they should be properly merged into a single coherent message without duplication.

Actual behavior

User received two Feishu messages:

  • First message: Contains both the first reply AND the second reply content (merged)
  • Second message: Contains only the second reply content The content is duplicated across messages

OpenClaw version

2026.3.8

Operating system

Ubuntu 24.04

Install method

npm global

Model

zai/glm-5

Provider / routing chain

openclaw -> zai

Config file / key location

No response

Additional provider/model setup details

No response

Logs, screenshots, and evidence

## Evidence from logs


Mar 12 12:01:27 Started streaming: cardId=7616214340648340671, messageId=om_x100b5417e74b60a4c3a474e9be9dc4f
Mar 12 12:02:10 Closed streaming: cardId=7616214340648340671
Mar 12 12:02:10 Started streaming: cardId=7616214523998375126, messageId=om_x100b5417e2e3907cc2906e393e5ae37
Mar 12 12:02:11 Closed streaming: cardId=7616214523998375126
Mar 12 12:02:11 dispatch complete (queuedFinal=true, replies=2)


Two different cardIds were created, but the first card contained content from both replies.

## Root cause analysis

Looking at the `mergeStreamingText` function in `extensions/feishu/src/streaming-card.ts`:


export function mergeStreamingText(
  previousText: string | undefined,
  nextText: string | undefined,
): string {
  // ... various merge attempts ...
  
  // Fallback for fragmented partial chunks: append as-is to avoid losing tokens.
  return `${previous}${next}`;  // ← This causes unrelated content to be merged
}

When two replies have completely different content (no overlap), the fallback behavior is to concatenate them. This is intended for partial streaming chunks, but incorrectly merges unrelated final replies.

## Suggested fix

1. Track whether streaming session has received a final delivery
2. If a new final reply arrives after a previous final was already delivered, start a new streaming card instead of merging
3. Or: Modify `mergeStreamingText` to have a "strict" mode that refuses to merge completely unrelated content

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To address the issue of the Feishu streaming card incorrectly merging content from multiple independent final replies, we need to modify the mergeStreamingText function. The goal is to prevent the merging of unrelated content when two final replies have completely different content.

Step-by-Step Solution

  1. Track Final Deliveries: Introduce a flag to track whether a final delivery has been made in the current streaming session.
  2. New Streaming Card for New Final Replies: If a new final reply arrives after a previous final reply was delivered, start a new streaming card instead of merging the content.
  3. Modify mergeStreamingText: Implement a "strict" mode in mergeStreamingText that checks for unrelated content and refuses to merge it.

Example Code Modifications

// Introduce a flag to track final deliveries
let isFinalDelivered = false;

// Modify the mergeStreamingText function
export function mergeStreamingText(
  previousText: string | undefined,
  nextText: string | undefined,
  isFinalReply: boolean
): string {
  if (isFinalReply && isFinalDelivered) {
    // If this is a new final reply and a final reply was already delivered, do not merge
    isFinalDelivered = true; // Reset for the next session
    return nextText ?? ''; // Start fresh with the new reply
  }

  if (!isFinalReply) {
    // For non-final replies, merge as before but with caution
    if (previousText && nextText && !previousText.includes(nextText)) {
      // If the texts are unrelated, do not merge to avoid duplication
      return nextText ?? '';
    }
  }

  // For related content or the first final reply, merge as before
  isFinalDelivered = isFinalReply; // Update the flag
  return `${previousText ?? ''}${nextText ?? ''}`;
}

Verification

To verify that the fix worked:

  • Test the scenario with two independent final replies.
  • Check that each reply is delivered as a separate message without any content duplication.

Extra Tips

  • Ensure that the isFinalDelivered flag is properly reset when a new streaming session starts.
  • Consider adding more sophisticated content comparison logic to handle edge cases where replies might seem unrelated but should be merged (e.g., due to minor formatting differences).

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…

FAQ

Expected behavior

When agent produces multiple independent replies, each should be delivered as a separate message, OR they should be properly merged into a single coherent message without duplication.

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 - ✅(Solved) Fix [Bug]: Feishu streaming card merges unrelated replies when agent produces multiple final messages [4 pull requests, 1 participants]