Skip to content

Telegram polling crashes gateway with unhandled fetch errors #1851

@haymovie

Description

@haymovie

Description

The Telegram provider causes the entire gateway to crash when network errors occur during getUpdates polling. The error manifests as:

Unhandled promise rejection: TypeError: fetch failed
    at node:internal/deps/undici/undici:13510:13
    at processTicksAndRejections (node:internal/process/task_queues:105:5)

Root Cause

In src/telegram/monitor.ts, the error handling only catches and retries 409 conflicts (when another bot instance is polling). All other errors, including network failures, are rethrown and crash the gateway:

// Lines 151-157 in monitor.ts
if (!isGetUpdatesConflict(err)) {
  throw err;  // <-- This crashes the gateway on network errors
}

Expected Behavior

Network errors (fetch failures, timeouts, DNS issues) should be caught and retried with backoff, similar to how 409 conflicts are handled. The gateway should not crash due to transient network issues.

Reproduction

  1. Start the gateway with Telegram enabled
  2. The gateway crashes approximately 30-60 seconds after Telegram provider starts
  3. Error message: TypeError: fetch failed

Environment

  • OS: Windows 11
  • Node.js: v22.x
  • Clawdbot version: 2026.1.20

Suggested Fix

Add network error handling to the catch block in monitorTelegramProvider:

const isNetworkError = (err: unknown) => {
  if (!err || typeof err !== 'object') return false;
  const message = String((err as { message?: string }).message ?? '');
  return message.includes('fetch failed') || 
         message.includes('ECONNREFUSED') ||
         message.includes('ETIMEDOUT') ||
         message.includes('ENOTFOUND');
};

// In the catch block:
if (!isGetUpdatesConflict(err) && !isNetworkError(err)) {
  throw err;
}
// Retry with backoff for both conflicts and network errors

Workaround

Disable Telegram in clawdbot.json:

"plugins": {
  "entries": {
    "telegram": { "enabled": false }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions