fix: prevent ghost media from debounce buffer flatMap

When multiple messages arrive within the debounce window, the flush handler
was using entries.flatMap(e => e.allMedia) which merged media from ALL
buffered entries. This caused images from a previous photo message to
ghost-attach to subsequent text-only messages.

Fix: Use only the last entry's allMedia, matching how last.ctx is already
used as the authoritative context for the flushed message.

Fixes #46655
This commit is contained in:
thejavadude 2026-03-18 20:48:56 -04:00
parent 002cc07322
commit b56105f608

View File

@ -305,8 +305,11 @@ export function createTelegramInboundBufferRuntime(params: {
const combinedText = entries
.map((entry) => entry.msg.text ?? entry.msg.caption ?? "")
.filter(Boolean)
.join("\n");
const combinedMedia = entries.flatMap((entry) => entry.allMedia);
.join("
");
// Fix: only use last entry's media to prevent ghost attachments from debounce buffer
// See: https://github.com/openclaw/openclaw/issues/46655
const combinedMedia = entries.at(-1)?.allMedia ?? [];
if (!combinedText.trim() && combinedMedia.length === 0) {
return;
}