openclaw - 💡(How to fix) Fix Telegram: duplicate message_id injected into agent session during long tool calls (regression since ~2026.3.13) [2 comments, 3 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#49292Fetched 2026-04-08 00:56:52
View on GitHub
Comments
2
Participants
3
Timeline
4
Reactions
0
Timeline (top)
commented ×2closed ×1locked ×1

Root Cause

The gateway log shows telegram dedupe: skipped entries, confirming the update_id-level dedup is active. However, duplicate messages still reach the agent session. The issue appears to be:

  1. Agent processes a voice note (transcription + tool calls = 30-60s)
  2. During processing, Telegram's polling receives the same message again (possibly due to polling timeout/restart)
  3. The update_id dedup catches some but not all — especially when duplicates arrive with different update_ids but the same message_id
  4. Each duplicate is injected into the session as a new user message, triggering a new assistant response
  5. This cascading effect rapidly inflates context (voice notes with media attachments are especially large)
RAW_BUFFERClick to expand / collapse

Bug Description

Since approximately the 2026.3.13 update (installed Mar 15), Telegram messages (especially voice notes) are being delivered into agent sessions 12-13 times each when the agent is processing long-running tool calls. This causes rapid context window inflation and eventually crashes the session.

Evidence

Compared session transcripts before and after the Mar 15 update:

Session DateMax Dupes per message_idStatus
Mar 142x✅ Normal
Mar 15 (pre-update)2x✅ Normal
Mar 16 (post-update)13x❌ Regression
Mar 17 (post-update)13x❌ Regression

Specific message_ids delivered 12-13 times in the Mar 17 session:

  • 21169: 12 deliveries
  • 21180: 13 deliveries
  • 21197: 13 deliveries

The duplicates arrive in rapid succession (sub-second intervals), suggesting they bypass the existing update_id-based dedup.

Root Cause Analysis

The gateway log shows telegram dedupe: skipped entries, confirming the update_id-level dedup is active. However, duplicate messages still reach the agent session. The issue appears to be:

  1. Agent processes a voice note (transcription + tool calls = 30-60s)
  2. During processing, Telegram's polling receives the same message again (possibly due to polling timeout/restart)
  3. The update_id dedup catches some but not all — especially when duplicates arrive with different update_ids but the same message_id
  4. Each duplicate is injected into the session as a new user message, triggering a new assistant response
  5. This cascading effect rapidly inflates context (voice notes with media attachments are especially large)

Impact

  • Session crashed from ~74% context → 1.1M tokens → model fallback → frozen
  • Multiple sessions affected since Mar 16
  • Voice notes are the primary trigger (large payload + long processing time)
  • Slow response times even when session doesn't crash (agent processes same message multiple times)

Suggested Fix

Add a session-level dedup guard using message_id (Telegram's message identifier) in addition to update_id. Before injecting a user message into the agent session, check if a message with the same message_id was already injected within the last N minutes. This would catch duplicates that arrive with different update_id values.

Environment

  • OpenClaw: 2026.3.13 (61d171a)
  • Channel: Telegram (polling mode)
  • OS: macOS (arm64)
  • Node: v25.6.1

Reproduction

  1. Send a voice note via Telegram while the agent is processing a heavy task (multiple tool calls, subagent spawns)
  2. Observe the session transcript — the same message_id appears multiple times
  3. Context usage inflates rapidly

extent analysis

Fix Plan

To address the issue of duplicate Telegram messages being delivered to agent sessions, we will implement a session-level dedup guard using message_id. Here are the steps:

  • Create a cache to store recently processed message_ids with timestamps
  • Before injecting a user message into the agent session, check the cache for the message_id
  • If the message_id is found in the cache and the timestamp is within the last N minutes, skip injecting the message
  • If the message_id is not found in the cache or the timestamp is older than N minutes, add it to the cache and inject the message

Example code snippet in JavaScript:

const dedupCache = new Map();
const dedupTimeout = 5 * 60 * 1000; // 5 minutes

function isDuplicateMessage(messageId) {
  const now = Date.now();
  const cachedMessage = dedupCache.get(messageId);
  if (cachedMessage && now - cachedMessage.timestamp < dedupTimeout) {
    return true;
  }
  return false;
}

function injectMessageIntoSession(message) {
  const messageId = message.message_id;
  if (isDuplicateMessage(messageId)) {
    console.log(`Skipping duplicate message ${messageId}`);
    return;
  }
  dedupCache.set(messageId, { timestamp: Date.now() });
  // Inject message into session
}

Verification

To verify that the fix worked, send a voice note via Telegram while the agent is processing a heavy task and observe the session transcript. The same message_id should no longer appear multiple times, and context usage should not inflate rapidly.

Extra Tips

  • Adjust the dedupTimeout value based on the specific requirements of your application
  • Consider using a more robust caching mechanism, such as Redis, for production environments
  • Monitor the cache size and adjust the caching strategy as needed to prevent performance issues

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…

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 - 💡(How to fix) Fix Telegram: duplicate message_id injected into agent session during long tool calls (regression since ~2026.3.13) [2 comments, 3 participants]