From 43fc38e46c4313648f439777966f913310cb5247 Mon Sep 17 00:00:00 2001 From: friday-james Date: Wed, 22 Apr 2026 04:29:18 -0700 Subject: [PATCH] fix(telegram): lower webhook callback timeout to 5s #16763 added `onTimeout: "return"` with `timeoutMilliseconds: 10_000` (grammY default). In practice, Telegram's webhook servers abort the read well before 10s when handler latency is LLM-bound: `getWebhookInfo` reports `last_error_message: "Read timeout expired"` and pending updates pile up, cascading into multi-minute reply lag. Reproducible A/B on identical infra (same region, same bot token): - Minimal Python echo bot: 5 back-to-back webhook RTTs 341-642ms, clean. - OpenClaw current main: intermittent Read timeout expired, 1-5 min lag. The handler still runs to completion; only the Telegram-facing ack is sooner. grammY's deployment guide suggests 5s for long-running handlers. No new config surface; minimal one-line change to the existing constant and its test assertion. If a configurable timeout is wanted, that can be a follow-up (see stale #7754). --- extensions/telegram/src/webhook.test.ts | 2 +- extensions/telegram/src/webhook.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/telegram/src/webhook.test.ts b/extensions/telegram/src/webhook.test.ts index 3c7909c835c..d36d7916530 100644 --- a/extensions/telegram/src/webhook.test.ts +++ b/extensions/telegram/src/webhook.test.ts @@ -455,7 +455,7 @@ describe("startTelegramWebhook", () => { { secretToken: TELEGRAM_SECRET, onTimeout: "return", - timeoutMilliseconds: 10_000, + timeoutMilliseconds: 5_000, }, ); expect(runtimeLog).toHaveBeenCalledWith( diff --git a/extensions/telegram/src/webhook.ts b/extensions/telegram/src/webhook.ts index eec8b7e0428..d8fb58dd29d 100644 --- a/extensions/telegram/src/webhook.ts +++ b/extensions/telegram/src/webhook.ts @@ -28,7 +28,7 @@ import { createTelegramBot } from "./bot.js"; const TELEGRAM_WEBHOOK_MAX_BODY_BYTES = 1024 * 1024; const TELEGRAM_WEBHOOK_BODY_TIMEOUT_MS = 30_000; -const TELEGRAM_WEBHOOK_CALLBACK_TIMEOUT_MS = 10_000; +const TELEGRAM_WEBHOOK_CALLBACK_TIMEOUT_MS = 5_000; const InputFileCtor: typeof grammy.InputFile = typeof grammy.InputFile === "function" ? grammy.InputFile