Repository navigation
Description
Upstream issue draft — OpenClaw
Repo: https://github.com/openclaw/openclaw/issues/new
Title: answerCallbackQuery timeout cluster on Telegram bots — late ACK because callback handler awaits model response
Summary
When a Telegram user presses an inline-keyboard button on a bot deployed via OpenClaw, the bot's callback handler invokes the model before sending answerCallbackQuery. On any model with mean latency > 15 s (every locally-served LLM in our deployment, and most reasoning-mode candidates), the ACK arrives late and Telegram rejects it with HTTP 400:
[telegram] answerCallbackQuery failed: ... (400: Bad Request: query is too old and response timeout expired or query ID is invalid)
Empirically observed on openclaw 2026.5.2 (8b2a6e5) running on macOS 25.4.0 / arm64 with qwen2.5:14b (mean 27.7 s) — 13 callback-query timeouts in a single 3.5-hour window on 2026-05-09 06:05–09:36 EDT, all on bot chat_id=8667951543.
The associated sendMessage call usually succeeds — so the user sees the bot reply, but the spinning "Loading…" indicator on the inline keyboard never resolves. UX glitch, not data loss.
Symptom
2026-05-09T06:05:12.418-04:00 [telegram] answerCallbackQuery failed: callback_query_id=...; chat=8667951543: 400 Bad Request: query is too old and response timeout expired or query ID is invalid
[bot] sendMessage chat_id=8667951543 length=487 ← model reply arrives ~22s after button press; succeeds
Root cause (analysis)
The callback dispatch flow in bot-Ce301bOE.js appears to be:
- Telegram delivers
callback_queryto bot. - Bot invokes model with the query payload.
- Bot waits for model's full response.
- Bot calls
answerCallbackQuery(text=<model_response_first_line>). - Bot calls
sendMessage(text=<model_response_full>).
Step 4's text comes from the model, so it has to wait for step 3. Telegram's hard limit on callback_query ID validity is ~15 s; any model whose mean latency exceeds that window will routinely fail step 4.
Proposed fix
Standard Telegram bot pattern: ACK the callback BEFORE invoking the model.
// Pseudocode
async function handleCallbackQuery(query) {
// 1. Acknowledge immediately, with empty text or a "Loading…" toast.
await telegram.answerCallbackQuery(query.id, { text: "" });
// 2. NOW invoke the model.
const reply = await agent.process(query.data);
// 3. Send reply via sendMessage (or editMessageText if the original message
// should be updated in place).
await telegram.sendMessage(query.message.chat.id, reply);
}This separates the callback ACK (which has a 15s deadline) from the model response (which can take as long as it needs).
Alternatives considered
- Set
cache_timeonanswerCallbackQuery— limited; Telegram still enforces the ~15s validity on the original callback ID regardless of cache_time. - Avoid callback-query interactions for high-latency replies — workaround, not fix; user-facing UX still requires inline keyboards for some flows.
- Switch to a faster model — independently desirable but does not solve the root issue (the 15s deadline is a hard Telegram limit, no local model reliably fits inside it).
Environment
openclaw 2026.5.2 (8b2a6e5)- macOS 25.4.0 (Darwin 25.4.0) / arm64 / Mac Mini M4 Pro
- Models tested:
qwen2.5:14b(Q4_K_M, mean 27.7s); reproduced on every locally-served LLM ≥14B - Telegram bot library: bundled (no override)
What I'd expect
answerCallbackQuery returns 200 OK consistently regardless of how long the model takes. The inline-keyboard "Loading…" indicator resolves within 1–2 seconds of the button press.
Workaround in place
None directly — the user sees the spinning indicator linger but the bot reply still arrives via sendMessage. Tracked locally as Operational #6 in docs/18-chatbot-improvement-plan.md.
Attachments / extra detail available on request
- Gateway log excerpts spanning the 13-error cluster on 2026-05-09 06:05–09:36 EDT
- Latency distribution across all 26 prompts × 3 trials × n=4 candidate models from
ci/runs/agent-bench-2026-05-09-1333-phase5-q5-incumbent.mdand siblings — confirms no locally-served LLM fits inside 15s consistently
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon May 10, 2026
Thanks for the context here. I did a careful shell check against current
main, and this is already implemented.Close as implemented on current main: the Telegram callback handler now sends
answerCallbackQueryimmediately, before the callback path reaches agent/model dispatch. The proof commit is present onmain/origin/mainbut is not contained in a release tag I could verify.I found the merged PR that appears to have closed this: #80113: Detect Docker Playwright Chromium.
So I’m closing this as already implemented rather than keeping a duplicate issue open.
Review details
Best possible solution:
Keep the current Telegram-layer early-ACK behavior and let the next release carry it; any future report should include logs from a build after the proof commit if callback ACKs still expire.
Do we have a high-confidence way to reproduce the issue?
No for current main. Source inspection shows
answerCallbackQueryis awaited at callback entry before the raw callback fallback reachesrunInboundReplyTurn, so the reported late-ACK path no longer reproduces in current source.Is this the best way to solve the issue?
Yes. The current implementation is the narrow Telegram-owned fix: ACK the callback immediately and process the callback payload afterward without adding core behavior or configuration.
Security review:
Security review: This is an issue triage review with no proposed patch and no security-sensitive report.
What I checked:
callback_queryhandler builds ananswerCallbackQueryfunction and awaits it immediately, before callback data parsing, authorization, plugin interactive dispatch, managed select handling, native command fallback, or agent/model processing. (extensions/telegram/src/bot-handlers.runtime.ts:1488, 15b26be8daf0)processMessageWithReplyChain; that path delegates todispatchTelegramMessageandrunInboundReplyTurn, so the model turn is downstream of the early ACK. (extensions/telegram/src/bot-handlers.runtime.ts:2124, 15b26be8daf0)dispatchTelegramMessageawaitsrunInboundReplyTurn, confirming this is the slower agent/model path and it is reached only after the callback handler's early ACK. (extensions/telegram/src/bot-message-dispatch.ts:1147, 15b26be8daf0)answerCallbackQuery, which protects the callback ACK behavior across authorized and unauthorized flows. (extensions/telegram/src/bot.create-telegram-bot.test.ts:725, 15b26be8daf0)answerCallbackQuerycall and comment, points at proof commit082c932e94b6c3b8efa7fb299298181f7c0616ac. (extensions/telegram/src/bot-handlers.runtime.ts:1480, 082c932e94b6)git showreports proof commit082c932e94b6c3b8efa7fb299298181f7c0616accommitted at2026-05-10T11:37:37+05:30. (082c932e94b6)Likely related people:
git blameattributes the current Telegram callback handler and downstream dispatch wrapper lines to the proof commit that contains the early ACK behavior. (role: current implementation provenance; confidence: high; commits: 082c932e94b6; files:extensions/telegram/src/bot-handlers.runtime.ts,extensions/telegram/src/bot-message-dispatch.ts)extensions/telegram/src/bot-message-dispatch.test.ts, making this a useful routing candidate for follow-up validation if the behavior regresses. (role: recent adjacent area contributor; confidence: medium; commits: d1d97eb8caa9; files:extensions/telegram/src/bot-message-dispatch.test.ts)Codex review notes: model gpt-5.5, reasoning high; reviewed against 15b26be8daf0; fix evidence: merged PR #80113, commit 082c932e94b6, main fix timestamp 2026-05-10T11:37:37+05:30.