Skip to content

fix(telegram): answer callback queries before sequentialize delays them - #92800

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
liuhao1024:fix/telegram-callback-pre-sequentialize-answer
Jun 14, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
liuhao1024:fix/telegram-callback-pre-sequentialize-answer

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Summary

Telegram callback queries (inline button presses) have a ~15s server-side timeout for answerCallbackQuery. When an agent turn is already processing for the same chat/topic, grammY's sequentialize middleware queues the callback update. By the time the callback_query handler runs and calls answerCallbackQuery, the timeout has expired and the user sees a stuck loading spinner on the button.

The fix adds a middleware registered before sequentialize that answers callback queries immediately, bypassing the queue. The existing answer in the callback_query handler is idempotent and remains as a fallback.

Root cause

In extensions/telegram/src/bot-core.ts, the middleware stack order is:

  1. updateTracker (line 216)
  2. sequentialize (line 252) — queues updates by chat/topic key
  3. Raw update logger (line 257)
  4. callback_query handler (registered via registerTelegramHandlers at line 429) — calls answerCallbackQuery

When an agent turn is processing for chat X, sequentialize queues all subsequent updates for chat X — including callback queries. The answerCallbackQuery call inside the handler is delayed until the agent turn completes, often exceeding Telegram's 15s timeout.

Fix

Add a bot.use() middleware before sequentialize (line 252) that detects callback queries and answers them immediately via fire-and-forget bot.api.answerCallbackQuery(callback.id). This runs before the queue, so the answer reaches Telegram within the timeout window regardless of agent turn duration.

1 file changed, 12 insertions(+).

Real behavior proof

  • Behavior addressed: Telegram callback queries time out when an agent turn is queued behind sequentialize for the same chat/topic
  • Environment tested: macOS, OpenClaw local build from upstream/main (commit 6cb72371)
  • Steps run after the patch:
    1. Verified the middleware is registered before sequentialize via grep -n
    2. Ran node scripts/run-vitest.mjs run extensions/telegram/src/bot-handlers.runtime.test.ts — 4/4 passed
    3. Ran node scripts/run-vitest.mjs run extensions/telegram/src/bot.test.ts — 77/77 passed
    4. Ran pnpm build — succeeded
  • Evidence after fix:
$ grep -n 'Answer callback queries immediately' extensions/telegram/src/bot-core.ts
252:  // Answer callback queries immediately before sequentialize queues them behind
254:  // for answerCallbackQuery; if an agent turn is already processing, sequentialize
259:      void bot.api.answerCallbackQuery(callback.id).catch(() => {});

$ node scripts/run-vitest.mjs run extensions/telegram/src/bot-handlers.runtime.test.ts
 Test Files  1 passed (1)
      Tests  4 passed (4)

$ node scripts/run-vitest.mjs run extensions/telegram/src/bot.test.ts
 Test Files  1 passed (1)
      Tests  77 passed (77)

$ pnpm build
✓ built in 522ms
  • Observed result after fix: Callback queries are answered before sequentialize queues them. The existing answer in the handler is idempotent and serves as a fallback. No new test failures introduced (8 pre-existing failures in bot.create-telegram-bot.test.ts are unrelated — confirmed by running the same tests on upstream/main without the change).
  • What was not tested: Live Telegram bot interaction (requires running gateway with Telegram bot token). The fix is a middleware ordering change that is structurally verifiable via code inspection and test suite.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 13, 2026
@clawsweeper

clawsweeper Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 13, 2026, 6:39 PM ET / 22:39 UTC.

Summary
The PR adds a pre-sequentialize Telegram middleware that fire-and-forgets answerCallbackQuery before queued callback processing reaches the existing handler.

PR surface: Source +12. Total +12 across 1 file.

Reproducibility: yes. source-reproducible: current main registers sequentialize before the callback handler, ordinary callbacks share the chat/topic sequential key, and grammY runner waits before invoking downstream middleware. I did not run a live Telegram client reproduction in this read-only review.

Review metrics: 1 noteworthy metric.

  • Callback answer sites: 1 added, 1 existing retained. The early acknowledgement is added while the existing handler acknowledgement remains, so reviewers need to check duplicate Bot API calls before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Mark successful early callback acknowledgements on the context and skip the existing handler-level answerCallbackQuery, with focused middleware-order coverage.
  • [P1] Add redacted live Telegram proof showing an inline callback clears while same-chat/topic work is queued.
  • After updating the PR body with proof, rely on automatic ClawSweeper re-review or ask a maintainer to comment @clawsweeper re-review if it does not run.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body supplies grep/build/unit-test output but no live Telegram callback observation; add redacted Desktop/bot-to-bot/log proof, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.

Mantis proof suggestion
A native Telegram callback recording would directly show whether inline button loading clears while the same chat/topic queue is busy. A maintainer can ask Mantis to capture proof by posting a new PR comment that starts with the OpenClaw Mantis account mention, followed by:

telegram desktop proof: verify an inline button callback clears immediately while an OpenClaw Telegram agent turn is still queued for the same chat/topic.

Risk before merge

  • [P1] The PR changes visible Telegram callback timing without live Telegram proof; the PR body only reports grep/build/unit tests and says live Telegram interaction was not tested.
  • [P1] The branch adds an early Telegram API answer while retaining the handler-level answer, so a successful early acknowledgement can still lead to a second Bot API request and avoidable callback-answer errors.

Maintainer options:

  1. Fix duplicate acknowledgement before merge (recommended)
    After a successful early answer, tag the context and skip the existing handler-level answerCallbackQuery, then add focused middleware-order coverage.
  2. Require live Telegram proof
    Ask for redacted Telegram Desktop, bot-to-bot QA, terminal/live output, logs, or a recording showing the inline-button spinner clears while a same-chat/topic turn is busy.
  3. Accept duplicate API calls
    Maintainers could intentionally accept the extra callback-answer request and logging risk, but that should be an explicit transport decision.

Next step before merge

  • [P1] The remaining blockers are a narrow code correction plus contributor or maintainer live Telegram proof, not a standalone automated repair lane.

Security
Cleared: The diff only changes Telegram runtime middleware and does not touch dependencies, workflows, secrets, package metadata, or supply-chain-sensitive execution paths.

Review findings

  • [P2] Skip the handler answer after an early callback ack — extensions/telegram/src/bot-core.ts:259
Review details

Best possible solution:

Keep the pre-sequentialize acknowledgement shape, but mark successful early acknowledgements and skip the handler-level fallback before merging, with focused regression coverage and redacted live Telegram proof.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: current main registers sequentialize before the callback handler, ordinary callbacks share the chat/topic sequential key, and grammY runner waits before invoking downstream middleware. I did not run a live Telegram client reproduction in this read-only review.

Is this the best way to solve the issue?

No for this branch as written. Pre-sequentialize acknowledgement is the right layer, but the branch should also prevent the downstream duplicate answer and supply live Telegram proof before merge.

Full review comments:

  • [P2] Skip the handler answer after an early callback ack — extensions/telegram/src/bot-core.ts:259
    This new pre-sequentialize answer still falls through to the existing callback_query handler, which calls answerCallbackQuery again for the same callback. That turns every successful early acknowledgement into a second Bot API request and can log avoidable callback-answer failures; the related prior implementation at fix(telegram): answer callback query before sequentialize to prevent timeout #90381 handled this by marking the context and skipping the fallback.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2f57352eaa66.

Label changes

Label changes:

  • add merge-risk: 🚨 availability: The diff can double Telegram callback acknowledgement API calls and produce avoidable API errors under normal callback use.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body supplies grep/build/unit-test output but no live Telegram callback observation; add redacted Desktop/bot-to-bot/log proof, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is mock_only, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.
  • remove proof: 🎥 video: Current real behavior proof evidence kind is none.

Label justifications:

  • P2: This is a focused Telegram channel bug fix for a visible inline-button workflow with limited blast radius.
  • merge-risk: 🚨 availability: The diff can double Telegram callback acknowledgement API calls and produce avoidable API errors under normal callback use.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body supplies grep/build/unit-test output but no live Telegram callback observation; add redacted Desktop/bot-to-bot/log proof, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. This changes visible Telegram inline-button callback behavior that can be demonstrated in a short Telegram Desktop or live transport recording.
Evidence reviewed

PR surface:

Source +12. Total +12 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 12 0 +12
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 12 0 +12

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/telegram/src/bot.create-telegram-bot.test.ts -- -t callback_query.
  • [P1] node scripts/run-vitest.mjs extensions/telegram/src/bot.test.ts -- -t callback_query.
  • [P1] Live Telegram Desktop, bot-to-bot QA, terminal/live output, logs, or recording proof that a callback button clears while a same-chat/topic agent turn is busy.

What I checked:

Likely related people:

  • obviyus: Current-line blame for the present Telegram bot-core, handler, and sequential-key files points to Ayaan Zaidi's recent split commit, and recent history includes adjacent Telegram bot-core work. (role: recent area contributor; confidence: high; commits: 84cbaf1832dd, 547cc0f10903; files: extensions/telegram/src/bot-core.ts, extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/sequential-key.ts)
  • Vincent Koc: Recent history around callback_query includes multiple Telegram callback retry and fast-status fixes near this handler surface. (role: recent callback contributor; confidence: medium; commits: 3034adfdb34a, 77f1ea0de813, 88111453cb76; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot.create-telegram-bot.test.ts)
  • steipete: History around Telegram sequential-key extraction and callback-adjacent tests includes Peter Steinberger commits that shaped the current queueing boundary. (role: sequential-key and test-history contributor; confidence: medium; commits: 192915110307, 03755f8463a5, f749365b1ce2; files: extensions/telegram/src/sequential-key.ts, extensions/telegram/src/bot.create-telegram-bot.test.ts)
  • Lucenx9: Recent callback-query work adjusted callback update error handling and tests near the same handler surface. (role: recent callback error-handling contributor; confidence: medium; commits: d8b18f1d96ac, 90b8f3fba20c; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot.create-telegram-bot.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 13, 2026
@clawsweeper
clawsweeper Bot temporarily deployed to qa-live-shared June 13, 2026 22:41 Inactive
@openclaw-mantis

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: Mantis captured native Telegram Desktop before/after GIFs for an inline model button press while a chat turn was pending.

Main screenshot This PR screenshot
Baseline native Telegram Desktop screenshot Candidate native Telegram Desktop screenshot
Main This PR
Baseline native Telegram Desktop proof GIF Candidate native Telegram Desktop proof GIF

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-desktop/pr-92800/run-27481248393-1/index.json

@vincentkoc vincentkoc self-assigned this Jun 14, 2026
liuhao1024 and others added 2 commits June 14, 2026 08:21
Telegram has a ~15s server-side timeout for answerCallbackQuery. When an
agent turn is already processing for the same chat/topic, grammY's
sequentialize middleware queues the callback update. By the time the
callback_query handler runs and calls answerCallbackQuery, the timeout
has expired and the user sees a stuck loading spinner on the button.

Answer the callback query in a middleware registered before sequentialize
so the response is immediate regardless of queue depth. The existing
answer in the callback_query handler is idempotent and remains as a
fallback.

Fixes openclaw#42156
@vincentkoc
vincentkoc force-pushed the fix/telegram-callback-pre-sequentialize-answer branch from 6cb7237 to 999a1e8 Compare June 14, 2026 00:26
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 14, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jun 14, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer fixup pushed and ready to land.

What changed:

  • Acknowledges Telegram callback queries before per-chat/topic sequentialize can queue the handler behind an active turn.
  • Carries the in-flight answerCallbackQuery promise on the grammY context so the downstream handler reuses it, retries only after early-answer failure, and does not double-answer successful callbacks.
  • Adds a regression that holds a same-chat sequentialize lane busy and proves the callback is acknowledged before the handler runs.

Proof:

  • node scripts/run-vitest.mjs extensions/telegram/src/bot.create-telegram-bot.test.ts -- -t "answers callback queries before same-chat sequentialize delays handlers|sequentializes updates by chat and thread|routes callback_query payloads as messages"
  • node scripts/run-vitest.mjs extensions/telegram/src/bot.test.ts extensions/telegram/src/bot-handlers.runtime.test.ts
  • node_modules/.bin/oxfmt --check extensions/telegram/src/bot-core.ts extensions/telegram/src/bot-handlers.runtime.ts extensions/telegram/src/callback-query-answer-state.ts extensions/telegram/src/bot.create-telegram-bot.test.ts
  • git diff --check origin/main...HEAD
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main → clean, no accepted/actionable findings
  • Azure Crabbox cbx_cba20c462ad5 / silver-barnacle, Standard_D4ads_v6: OPENCLAW_TESTBOX=1 node scripts/crabbox-wrapper.mjs run --provider azure --class Standard_D4ads_v6 --idle-timeout 90m --ttl 240m --timing-json -- env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 corepack pnpm check:changed → exit 0, lanes extensions, extensionTests, lease stopped.

Proof gap:

  • Live Telegram Desktop/burner-account proof was not run because openclaw-telegram-user-crabbox-proof is not installed in this shell. The source-level queue behavior and Telegram plugin tests cover the changed ordering and fallback path.

Source SHA: 999a1e8

@vincentkoc
vincentkoc merged commit 4c3c0ff into openclaw:main Jun 14, 2026
222 of 234 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants