Skip to content

Telegram direct replies can duplicate because accumulated assistantTexts are emitted as separate messages after context-engine maintenance #79621

@nonzeroclaw

Description

@nonzeroclaw

Summary

Telegram direct chats can receive multiple bot messages from a single assistant turn. This appears to be real outbound duplication, not just client/UI duplication.

Environment

  • OpenClaw: 2026.5.3-1
  • macOS arm64
  • Telegram provider enabled
  • Gateway running normally
  • Installed package verified clean against the published openclaw@2026.5.3-1 tarball: same 8500, changed 0, missing 0, extra 0

Evidence

Gateway logs show real outbound Telegram send clusters to the same direct chat immediately after context-engine turn maintenance is queued.

Example pattern:

[context-engine] deferred turn maintenance queued ... sessionKey=agent:main:telegram:direct:...
[telegram] sendMessage ok ... message=...
[telegram] sendMessage ok ... message=...
[telegram] sendMessage ok ... message=...

Observed clusters included 2–5 Telegram messages from one turn window.

Leading cause

In the active stock bundle:

dist/pi-embedded-CElEZtBc.js

the answer selection path builds reply text from all non-empty assistant text blocks:

const answerTexts = ... hasAssistantTextPayload ? nonEmptyAssistantTexts : ...

Then each text is pushed into replyItems, which appear to be delivered as separate Telegram messages.

This means if a run accumulates multiple visible assistant text blocks — e.g. progress/commentary/final, or leaked internal/context-maintenance text — Telegram receives multiple messages instead of only the final user-facing answer.

Related leakage

Context-engine maintenance notices also appear in next-turn runtime context, e.g.:

Background task update: Context engine turn maintenance. Deferred maintenance is still running.
Background task done: Context engine turn maintenance ... Rewrote 0 transcript entries and freed 0 bytes.

This may be contributing to accumulated visible text / re-emission behavior.

Expected behavior

For direct Telegram delivery, a single assistant turn should deliver only the final user-facing reply item, unless explicit multi-message/media behavior is requested.

Internal maintenance/status/runtime-context text should never be routed into user-visible Telegram output.

Actual behavior

A single assistant turn can produce multiple Telegram sendMessage calls, causing duplicate/multi-part messages in the user’s direct chat.

Notes

A prior local emergency hotfix that selected only the last accumulated assistant text appeared to reduce this, but it was against a content-hashed installed dist bundle and was later orphaned by package refresh/restart. Current clean stock 2026.5.3-1 still contains the duplicate-prone logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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