openclaw - 💡(How to fix) Fix Telegram: duplicate session race condition when messages arrive during session initialization [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#49023Fetched 2026-04-08 00:49:35
View on GitHub
Comments
2
Participants
3
Timeline
2
Reactions
0
Author
Timeline (top)
commented ×2

When two Telegram messages arrive in quick succession (within ~2-3 seconds), the gateway spawns duplicate sessions for the same chat, resulting in duplicate responses to the user.

Error Message

12:54:48 WARN tools.profile (coding) allowlist contains unknown entries...

Root Cause

Root Cause (suspected)

Fix Action

Workaround

None currently. Users see duplicate responses to their messages.

Code Example

12:53:55 INFO  autoSelectFamily=true (default-node22)     ← session 1 init
12:53:55 INFO  dnsResultOrder=ipv4first (default-node22)
12:54:46 INFO  telegram sendMessage ok chat=XXX message=6734  ← response from session 1
12:54:47 INFO  telegram sendMessage ok chat=XXX message=6735  ← duplicate from session 2
12:54:48 WARN  tools.profile (coding) allowlist contains unknown entries...
RAW_BUFFERClick to expand / collapse

Description

When two Telegram messages arrive in quick succession (within ~2-3 seconds), the gateway spawns duplicate sessions for the same chat, resulting in duplicate responses to the user.

Root Cause (suspected)

Message 1 arrives → gateway begins session initialization (DNS resolution, network setup, tools profile loading — takes 2-5 seconds). Message 2 arrives during this window → gateway sees no active session for the chat yet → spawns a second session with both messages queued. Both sessions then independently process the full message queue, sending duplicate replies.

Evidence from gateway log

12:53:55 INFO  autoSelectFamily=true (default-node22)     ← session 1 init
12:53:55 INFO  dnsResultOrder=ipv4first (default-node22)
12:54:46 INFO  telegram sendMessage ok chat=XXX message=6734  ← response from session 1
12:54:47 INFO  telegram sendMessage ok chat=XXX message=6735  ← duplicate from session 2
12:54:48 WARN  tools.profile (coding) allowlist contains unknown entries...

Pattern repeats consistently when user sends messages within the session initialization window (~2-5s).

Expected Behavior

The gateway should claim/lock a session for a chat ID as soon as the first message is dispatched, before initialization completes. Subsequent messages for the same chat should queue into the pending session rather than spawning a new one.

Environment

  • OpenClaw version: 2026.3.9
  • Channel: Telegram (long-polling mode)
  • macOS, Node 25.8.1
  • Gateway running as launchd service (ai.openclaw.dev)

Workaround

None currently. Users see duplicate responses to their messages.

extent analysis

Fix Plan

To prevent duplicate sessions, we need to implement a locking mechanism for chat sessions. Here are the steps:

  • Introduce a sessionLocks map to store chat IDs as keys and a boolean indicating whether a session is being initialized.
  • When a new message arrives, check the sessionLocks map for an existing lock for the chat ID.
  • If a lock is found, queue the new message to the existing session.
  • If no lock is found, create a new lock, initialize a new session, and queue the message.

Example code snippet:

const sessionLocks = new Map();

// When a new message arrives
if (sessionLocks.has(chatId)) {
  // Queue the message to the existing session
  const session = getSession(chatId);
  session.queueMessage(message);
} else {
  // Create a new lock and initialize a new session
  sessionLocks.set(chatId, true);
  const session = initializeSession(chatId);
  session.queueMessage(message);
  // Remove the lock when the session is fully initialized
  session.once('initialized', () => {
    sessionLocks.delete(chatId);
  });
}

Verification

To verify the fix, test the following scenarios:

  • Send two messages in quick succession (within 2-3 seconds) and check that only one response is sent.
  • Send multiple messages in a row and check that the responses are not duplicated.
  • Check the gateway logs for any errors or warnings related to session initialization or message queuing.

Extra Tips

  • Consider implementing a timeout for session initialization to prevent locks from being held indefinitely.
  • Review the tools.profile warning and ensure that the allowlist is properly configured to prevent any issues with session initialization.

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