Skip to content

[2026.5.18] Compaction safeguard causes duplicate messages on sessions_send interactions #84139

Description

@MarkMa84

Bug Description

When compaction triggers during an active sessions_send exchange between two agents, the compaction safeguard replays the session branch messages after recovery, causing the same interaction to be sent twice to the target agent.

Example scenario:

  1. Agent PM sends a sessions_send to 小蜂 (this agent)
  2. 小蜂 processes and replies with a simple emoji 🐝
  3. 小蜂 sends sessions_send reply back to PM
  4. Compaction triggers at this moment
  5. After compaction recovery, the safeguard replays the session branch → 小蜂 sends another 🐝 to PM
  6. Result: PM receives 🐝 twice

Steps to Reproduce

  1. Have two agents exchange messages via sessions_send
  2. Wait for compaction to trigger during the exchange (context积累到阈值)
  3. Observe that the message sent during the recovery period appears twice in the target session

Expected Behavior

Each sessions_send interaction should be delivered exactly once. Compaction should not cause duplicate delivery of messages that were already sent.

Actual Behavior

Messages delivered via sessions_send are duplicated after compaction recovery. The safeguard appears to replay the session branch containing the sessions_send interaction, causing duplicate delivery.

Gateway Log

21:07:40 [ws] ⇄ res ✓ agent.wait 8153ms conn=8d3cc9d1…d1ab id=193b25a2…6716
21:07:40 [agent:nested] session=agent:pm:main run=f2b16e7b-02d8-44fd-9248-47b5e1dd3c41 channel=webchat 🐝
21:07:48 [ws] ⇄ res ✓ agent.wait 8299ms conn=565514c9…c6bb id=fec29339…f5cd
21:07:51 [compaction-safeguard] Compaction safeguard: using session branch messages after compaction preparation omitted real conversation content.
21:07:51 [agent:nested] session=agent:main:main run=e8352a29-4146-4a65-8c57-c8dcdc19a4a1 channel=webchat 🐝
21:08:19 [ws] ⇄ res ✓ agent.wait 60001ms conn=c4ad3534…96e0 id=130ae42b…45f7

Key line: Compaction safeguard: using session branch messages after compaction preparation omitted real conversation content.

The safeguard falls back to branch messages when real content is omitted during compaction preparation, but this replay includes already-sent sessions_send interactions.

Environment

  • OS: macOS Darwin 25.4.0 (arm64)
  • OpenClaw: 2026.5.18 (50a2481)
  • Node: v25.9.0
  • Model: minimax/MiniMax-M2.7
  • Compaction provider: compaction-weighted 1.0.0

Additional Context

  • This only affects inter-agent sessions_send interactions, not direct user↔agent messages
  • The duplication is 偶发 — only triggers when compaction hits during an active exchange
  • User reports it as acceptable as a known system-layer issue if fix is low priority
  • Related: fix: clear cross-run messaging-tool sent-text state after every compaction #80285 fix: clear cross-run messaging-tool sent-text state after every compaction (may be related but different issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.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

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions