Skip to content

Feishu replies disappear from webchat after compaction rotation (buildSuccessorEntries drops assistant messages) #76729

@njuboy11

Description

@njuboy11

Description

After compaction with truncateAfterCompaction: true, assistant messages are dropped from the rotated session transcript. This causes:

  1. The Feishu (or any channel) reply briefly appears in webchat/Control UI (written by appendSessionTranscriptMessage before compaction)
  2. When compaction rotates the session file via rotateTranscriptFileAfterCompaction, buildSuccessorEntries marks all messages before firstKeptEntryId as "removedIds" — including assistant replies
  3. The rotated session now has: [user_msg_1], [compaction summary], [user_msg_2] — with NO assistant reply between them
  4. The webchat UI refreshes and shows user messages consecutively without the reply
  5. When the agent reads the session, it sees two unanswered user messages and processes them as one combined turn

Reproduction Steps

  1. Send a message via any channel (e.g. Feishu)
  2. Agent generates a reply — it appears in webchat temporarily
  3. Session exceeds compaction threshold (token count or maxActiveTranscriptBytes)
  4. Compaction runs → shouldRotateCompactionTranscript returns truerotateTranscriptFileAfterCompaction creates new session file
  5. In the new session file, the assistant reply is gone
  6. Send a second message — agent processes both messages together (sees no intermediate reply)

Root Cause

In compaction-successor-transcript-ZByj7D6a.js, function buildSuccessorEntries:

for (const entry of allEntries) 
    if (summarizedBranchIds.has(entry.id) && entry.type === "message" 
        || staleStateEntryIds.has(entry.id) 
        || duplicateUserMessageIds.has(entry.id)) 
        removedIds.add(entry.id);

All messages before firstKeptEntryId are removed, regardless of role (user or assistant). User messages tend to survive because they are referenced by firstKeptEntryId, but the assistant replies to those user messages are dropped.

Session stats from the bug reproduction:

  • Before compaction: user=8, assistant=167, total=556 entries, 1088KB
  • After compaction rotation: user=6, assistant=30, total=278 entries, 455KB
  • 137 assistant messages lost (82% reduction)

Impact

  • All channels that share the embedded PI session experience this bug
  • Users see replies "disappear" from webchat
  • Multiple user messages get batched together as one LLM call
  • Queue mode (steer/queue) can compound the issue by processing multiple items together

Suggested Fix

In buildSuccessorEntries, when determining which messages to remove, preserve the last assistant reply that precedes each surviving user message. This ensures that the rotated transcript maintains conversational structure (user → assistant → user → assistant) rather than collapsing into consecutive user messages.

Alternatively, ensure that compaction rotation preserves all assistant messages that are direct replies to surviving user messages.

Environment

  • OpenClaw v2026.5.2
  • compaction.truncateAfterCompaction: true
  • compaction.maxActiveTranscriptBytes: 10mb
  • Feishu channel + webchat/Control UI

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    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