Skip to content

fix(telegram): use concurrent runner to prevent message blocking#367

Closed
Noah-Ribaudo wants to merge 1 commit intoopenclaw:mainfrom
Noah-Ribaudo:fix/telegram-concurrent-message-processing
Closed

fix(telegram): use concurrent runner to prevent message blocking#367
Noah-Ribaudo wants to merge 1 commit intoopenclaw:mainfrom
Noah-Ribaudo:fix/telegram-concurrent-message-processing

Conversation

@Noah-Ribaudo
Copy link

Summary

  • Problem: When one Telegram message handler takes a long time (e.g., a 10-minute agent timeout), ALL other messages are blocked until it completes
  • Root Cause: grammy's default bot.start() processes updates sequentially
  • Fix: Use @grammyjs/runner to process updates concurrently

The Problem

When using grammy's default long polling with bot.start(), updates are processed one at a time:

// From grammy source:
// handle updates sequentially (!)
await this.handleUpdate(update);

This means if one message handler hangs (e.g., waiting for an LLM response that times out after 10 minutes), every other message in every other chat waits in a queue behind it. The entire bot becomes unresponsive.

The Solution

The @grammyjs/runner plugin is specifically designed to solve this. It processes updates concurrently, so multiple conversations can be handled in parallel. A slow or stuck handler in one chat doesn't block handlers in other chats.

Changes

  1. Added @grammyjs/runner dependency
  2. Replaced bot.start() with run(bot) in monitor.ts
  3. Updated abort signal handling to work with the runner
  4. Added tests verifying the runner is used and responds to abort signals

Test plan

  • All existing telegram tests pass (66 tests)
  • New tests verify runner is invoked for long polling
  • New tests verify abort signal stops the runner
  • Manual testing: send multiple messages while one is processing slowly

🤖 Generated with Claude Code

## Problem

When using grammy's default `bot.start()` for long polling, updates are
processed sequentially. This means if one message handler takes a long
time (e.g., an agent with a 10-minute timeout), ALL other incoming
messages are blocked until that handler completes.

From grammy's source code:
```javascript
// handle updates sequentially (!)
await this.handleUpdate(update);
```

This caused the entire Telegram bot to become unresponsive when a single
conversation got stuck or timed out.

## Solution

Replace `bot.start()` with `@grammyjs/runner`, which processes updates
concurrently. This allows multiple conversations to be handled in
parallel, so one slow or stuck handler doesn't block others.

## Changes

- Add `@grammyjs/runner` dependency
- Replace `bot.start()` with `run(bot)` in monitor.ts
- Add tests verifying runner is used and responds to abort signals

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@steipete
Copy link
Contributor

steipete commented Jan 8, 2026

Thanks @Noah-Ribaudo! This change is already in main via commit 1a41fec (runner switch) plus follow-ups 068b187/322c5dd9. Closing as already implemented. Appreciate the contribution—happy to revisit if you still see blocking.

@steipete steipete closed this Jan 8, 2026
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
* Web: wire OAuth connections flow

* fix: pr feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments