Skip to content

fix(telegram): keep messages queued after handler timeouts - #169202

Merged
obviyus merged 5 commits into
openclaw:mainfrom
diregoblin:fix/telegram-pending-ingress-retry-20261011
Oct 14, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
diregoblin:fix/telegram-pending-ingress-retry-20261011

Conversation

@diregoblin

@diregoblin diregoblin commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Related: #127229 (the pending-update retry variant)

What Problem This Solves

Fixes Telegram messages disappearing when a slow ingress handler times out and its retry is mistaken for an already completed duplicate.

User Impact

Timed-out messages remain retryable and are processed once before their queued followers. Completed duplicates remain suppressed. No configuration, schema, retention, retry-budget, permission, or protocol changes are required.

Why This Change Was Made

The existing tracker distinguishes pending from completed duplicates, and middleware records the corresponding retryable or skipped outcome. The shared drain still owns retries and FIFO ordering.

This retains @diregoblin's fix and regression while removing the broader missing-outcome fallback change and its separate test. The regression uses the existing withinTest cancellation helper, as in #170943, so a cancelled test releases its held turn before cleanup joins it.

Production delta against the merge base: +21/-4. Tests and support: +97/-5. Total: 127 changed lines, down from 186. The production growth represents the missing pending outcome, not new state or a second retry owner.

No overlap with Pash/Sarah changes.

Community evidence: Discord records 1552978751803883622 and 1552978923665621144 describe prolonged typing without a reply. The canonical issue also contains historical variants outside this focused repair.

Evidence

Real Telegram Test Server, Convex-leased TDLib user, built Gateway; baseline 923e59a01e20549965381a1e72a471762981db9d, final candidate 4d38a28bd39c6836388c2f8f28af6643ca0da93b.

Both refs received a real voice note followed four seconds later by uniquely marked text. The local OpenAI-compatible transcription fixture delayed its first request 45 seconds and returned subsequent requests immediately. Both used the existing OPENCLAW_TELEGRAM_SPOOLED_HANDLER_TIMEOUT_MS=30000, implemented in the Telegram drain and documented in extensions/telegram/AGENTS.md.

Run Observed native Telegram replies
Baseline, slow transcription Only OPENCLAW_E2E_FOLLOWER_169202 at 51.45s; no voice reply during the 100s recording
Final candidate, same slow transcription OPENCLAW_E2E_VOICE_169202 at 52.58s, then OPENCLAW_E2E_FOLLOWER_169202 at 53.60s; each once
Fast transcription control, earlier production-identical candidate Voice at 7.31s, follower at 8.44s; each once, no ingress timeout
Final candidate, real OpenAI gpt-5-mini plus fast transcription Voice at 15.15s, follower at 16.14s; real HTTPS provider requests and native replies observed

The model fixture acknowledges each new user marker in order; it does not invent a voice acknowledgment when the voice input is absent. Baseline model input contained only the follower; candidate inputs contained the voice and follower once each, in order.

Sanitized shipped diagnostic evidence:

BASE
claim→adoption stalled for event <voice> after 30001ms; applying retry policy
spooled update <voice> failed; keeping for retry
telegram dedupe: skipped update <voice>
telegram ingress: update <voice> completed without a recorded processing outcome

HEAD
telegram dedupe: skipped update <voice>
spooled update <voice> failed; keeping for retry: Telegram update processing is still pending
[voice subsequently processed, followed by the queued text]

The worker-backed regression fails on baseline because the expected pending voice and follower rows are already gone. Final candidate: 30 focused tests passed across tracker and ingress-coalescing suites in 30.79s; the new regression body took 2.96s. Formatting, focused lint and the runtime build passed.

Cancellation proof held the regression's downstream gate, then let the actual Vitest 10-second timeout abort its test signal. The held-gate and completed-cleanup receipts were both observed; the runner exited with only the intended test timeout and no hook timeout. The transient fault injection was removed before normal tests and the build.

The previous production-identical head's hosted CI passed; final-head CI and review are requested after this cancellation-only follow-up. All live leases were released and temporary credential files removed.

Merge danger: two-way door for future processing; reverting restores the old dedupe behavior. Neither this fix nor a revert can recover payloads already scrubbed by the old behavior. Blast radius is Telegram ingress duplicate classification and retry ordering only.

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S labels Oct 11, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR keeps Telegram retries pending until their original handlers settle, while continuing to suppress completed duplicates.

Example: A voice note takes 45 seconds to transcribe with a 30-second ingress timeout, followed four seconds later by text.

  • Before: The voice retry is falsely completed and only OPENCLAW_E2E_FOLLOWER_169202 receives a reply.
  • After: OPENCLAW_E2E_VOICE_169202 receives one reply, followed by one reply to OPENCLAW_E2E_FOLLOWER_169202.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong shipped-entry-point proof and no remaining findings; the overall tier reflects a focused partial repair of the broader linked issue, rather than a need to expand this PR.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The exact candidate's built Gateway exercised real Telegram Test Server ingress with a 45-second transcription fault and 30-second watchdog; supplied sanitized diagnostics and native reply results show retained retries and voice-before-follower delivery once each.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A Telegram message can disappear without reaching an agent turn or receiving a reply when its retry encounters the still-pending original handler.
Reason: The focused repair has clear user value and strong live evidence; Related correctly limits its scope to one variant of the broader linked issue.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes Telegram message loss still present on main, and the prior test-cancellation finding is resolved; no actionable findings remain.

Priority: P1
Reviewed head: 4d38a28bd39c6836388c2f8f28af6643ca0da93b

Before merge

None.

Findings

None.

Agent review details

How this fits together

Telegram polling and webhook ingress persist updates in SQLite; the shared drain sends them through Telegram middleware and uses recorded processing outcomes to retain retries or complete queue rows.

flowchart TD
  A[Telegram updates] --> B[Durable ingress queue]
  B --> C[Shared drain]
  C --> D[Telegram update tracker]
  D --> E[Sequential middleware]
  E --> F[Agent turn]
  D --> G[Processing outcome]
  F --> G
  G --> B
Loading

Technical review

Best possible solution:

Land the focused tracker classification repair while leaving broader historical variants with their canonical issue.

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

Current-main source establishes the pending-duplicate-to-completion path, corroborated by official-release reports and supplied baseline Gateway diagnostics; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs classification at the existing Telegram tracker and carries that fact through the existing processing frame, preserving shared retry policy and participant settlement ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6dc4f1b5cf54.

Provenance checked

  • Tracker duplicate classification changes intended behavior with a stated reason (c130ceb: Per-ID acceptance replaced a global watermark to allow delayed cross-lane spool replays while suppressing restored offsets and exact previously accepted IDs.)
  • Duplicate middleware early return changes intended behavior with a stated reason (7c79f0a: Centralize update-offset tracking and suppress duplicate dispatch; the PR retains suppression while recording whether the duplicate is pending or terminal.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced production change: The pinned introduced diff adds a pending rejection reason and records failed-retryable for pending duplicates versus skipped for completed duplicates; it leaves retry policy and participant settlement ownership intact. (extensions/telegram/src/bot-core.ts:155, 4d38a28bd39c)
  • Current-main failure remains: Current main rejects accepted pending IDs as accepted-watermark and returns from middleware without recording an outcome; the existing drain completes updates without an outcome or deferred participant. (extensions/telegram/src/bot-update-tracker.ts:177, 6dc4f1b5cf54)
  • Canonical official-release reports: In telegram: watchdog-released durable update is falsely tombstoned before transport tracker settles #127229, travellingsoldier85 traces pending tracker rejection on official 2026.9.1 webhook ingress, PaGrom reports slow-transcription loss on 2026.9.4, and cablackmon supplies the same loss signature on 2026.9.7.
  • Exact-head shipped-entry-point evidence: The full PR body supplies built-Gateway Telegram Test Server baseline/candidate results and sanitized diagnostics: baseline loses the voice input, while the exact candidate retains its pending retry and replies to voice then text once each; fast controls also succeed. (4d38a28bd39c)
  • Prior cancellation finding resolved: Compared with the previously reviewed head, waits while the downstream gate is held now use withinTest with the Vitest signal, and setup waits occur inside the gate-release try/finally; the body also records an actual timeout probe completing cleanup without a hook timeout. (extensions/telegram/src/telegram-ingress-coalescing.e2e.test.ts:215, 4d38a28bd39c)
  • Feature history and original intent: The history spans tracker centralization, per-ID cross-lane replay protection, transport refactors, and the renamed media-group/coalescing regression. The original centralization diff encountered an unavailable historical blob; GitHub independently confirms that commit added the tracker. Current-main blame verifies retained lines authored by Peter Steinberger and Ayaan Zaidi. (extensions/telegram/src/bot-update-tracker.ts:50, 6dc4f1b5cf54)

Likely related people:

  • Peter Steinberger: Raw commit 7c79f0a adds extensions/telegram/src/bot-update-tracker.ts:49 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7c79f0ac9cda; files: extensions/telegram/src/bot-update-tracker.ts)
  • Ayaan Zaidi: Raw commit c130ceb adds extensions/telegram/src/bot-update-tracker.ts:95 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c130ceb5e158; files: extensions/telegram/src/bot-update-tracker.ts)

PR surface

Source +17, Tests +92. Total +109 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 21 4 +17
Tests 3 97 5 +92
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 118 9 +109

Review metrics

Metric Value Why it matters
Production versus test growth Production +21/-4; tests and support +97/-5 The production growth adds the missing processing-outcome distinction without another state or retry owner; the regression checks retained payloads, FIFO delivery, completed dedupe, and cancellation cleanup.

Root-cause cluster

Relationship: partial_overlap
Canonical: #127229
Summary: This PR repairs the canonical report's pending-tracker retry variant without claiming to resolve every historical trigger or acknowledgement concern.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The repaired workflow silently loses accepted Telegram messages, supported by official-release reports and baseline/candidate live evidence.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-11T15:51:27.473Z sha 76c3e43 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-14T22:20:48.062Z sha 5f835c8 :: needs changes before merge. :: [P2] Release the held regression turn when the test is cancelled

Reviewed October 14, 2026, 6:54 PM ET / 22:54 UTC (Revision 3).

@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 14, 2026
@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 14, 2026
@obviyus
obviyus merged commit 6d624f3 into openclaw:main Oct 14, 2026
124 of 127 checks passed
@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Landed in 6d624f3. Thanks @diregoblin! Verified on the Telegram Test Server: a voice note whose transcription outlasts the handler timeout is now answered instead of dropped.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…169202)

fix(telegram): keep timed-out updates for retry instead of dropping them

When a Telegram update's handler ran past the spooled-handler timeout (for example, a voice note waiting on slow speech transcription), the retry found the original handler still pending. The duplicate tracker treated that as already completed, the middleware recorded no outcome, and the drain marked the update done and removed it. The voice note was never answered, and users saw long typing with no reply. A still-pending original now keeps the update queued for retry, so it is processed once and later messages keep their order.

Proof: Telegram Test Server with a real user and a built Gateway, a 30s handler timeout and a transcriber whose first call takes 45s. On main the voice note was dropped after the timeout. With this change the bot replied to the voice note and then to the follow-up text, once each, in order. Fast-transcriber and real-provider controls are unchanged. This matches Discord reports of Telegram typing with no reply.

Related to openclaw#127229. Thanks @diregoblin.

Co-authored-by: Ayaan Zaidi <[email protected]>
@diregoblin
diregoblin deleted the fix/telegram-pending-ingress-retry-20261011 branch October 15, 2026 11:45
RomneyDa pushed a commit that referenced this pull request Oct 16, 2026
fix(telegram): keep timed-out updates for retry instead of dropping them

When a Telegram update's handler ran past the spooled-handler timeout (for example, a voice note waiting on slow speech transcription), the retry found the original handler still pending. The duplicate tracker treated that as already completed, the middleware recorded no outcome, and the drain marked the update done and removed it. The voice note was never answered, and users saw long typing with no reply. A still-pending original now keeps the update queued for retry, so it is processed once and later messages keep their order.

Proof: Telegram Test Server with a real user and a built Gateway, a 30s handler timeout and a transcriber whose first call takes 45s. On main the voice note was dropped after the timeout. With this change the bot replied to the voice note and then to the follow-up text, once each, in order. Fast-transcriber and real-provider controls are unchanged. This matches Discord reports of Telegram typing with no reply.

Related to #127229. Thanks @diregoblin.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 6d624f3)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
…169202)

fix(telegram): keep timed-out updates for retry instead of dropping them

When a Telegram update's handler ran past the spooled-handler timeout (for example, a voice note waiting on slow speech transcription), the retry found the original handler still pending. The duplicate tracker treated that as already completed, the middleware recorded no outcome, and the drain marked the update done and removed it. The voice note was never answered, and users saw long typing with no reply. A still-pending original now keeps the update queued for retry, so it is processed once and later messages keep their order.

Proof: Telegram Test Server with a real user and a built Gateway, a 30s handler timeout and a transcriber whose first call takes 45s. On main the voice note was dropped after the timeout. With this change the bot replied to the voice note and then to the follow-up text, once each, in order. Fast-transcriber and real-provider controls are unchanged. This matches Discord reports of Telegram typing with no reply.

Related to openclaw#127229. Thanks @diregoblin.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 6d624f3)
(cherry picked from commit c09a6dd)

Co-authored-by: RomneyDa <[email protected]>
amittell added a commit to amittell/openclaw that referenced this pull request Nov 11, 2026
…claim hold

telegram-ingress-coalescing.e2e.test.ts > "keeps a timed-out update
retryable while its original middleware is still waiting" fails on the
stack, on 3eefd13 and on the deployed 11.1 carry (eee763b), and
passes on bare v2026.11.2. Upstream added it with openclaw#169202 (6d624f3,
2026-10-15). There the stall watchdog re-queues a timed-out update as
pending with handler-timeout while its original middleware still waits,
and the retry records "Telegram update processing is still pending"
until the original returns.

The fork carries upstream openclaw#132409 (closed upstream unmerged; carried
since da9b206fc93, now through 1e127ad). Its stall watchdog
(ingress-drain-watchdog.ts) releases the timed-out claim only once the
original dispatch has quiesced (beforeRetryRelease ->
waitForQuiescenceOrStop). The test pinned openclaw#169202's in-between state, so
it cannot pass with openclaw#132409. Alex chose to keep openclaw#132409, so the
upstream test is replaced by a pin of the fork's behavior, marked FORK
DIVERGENCE (openclaw#132409): "holds a timed-out update's claim until its
original middleware returns, then retries it once".

The pin lives in a new fork-only file,
extensions/telegram/src/telegram-ingress-claim-hold.e2e.test.ts, with the
subset of the coalescing harness a text-only case needs (the same mocks,
fixture and import order). The upstream file was already over the
1,000-line test cap at the tag (1,014 counted lines, so oxlint max-lines
fails on it). Moving the replaced case out brings it to 928, and later
upstream merges of that file only see the case removed.

The assertions are what an instrumented run measured on the stack:
- at 300 s the watchdog has fired, and 802 is still claimed with
  attempts 0 and no lastError. It is not pending and not failed.
- 803, admitted then, stays pending behind it, and 802 is not handed to
  handleUpdate again.
- after 801 finishes and the drain runs, handleUpdate has seen 802, 802,
  803 (the original, then the one retry), and the downstream turns are
  "busy turn", "deliver this later", "deliver after the retry".
- nothing is left pending, claimed or failed, both updates are
  tombstoned, and a redelivered 802 is skipped.

The same measurement shows no message loss: the update is processed
once, and in order.

Proof (M4, Node 26.12.1, node scripts/run-vitest.mjs run --config
test/vitest/vitest.e2e.config.ts <file>), on 1daeda2 plus this commit:
- telegram-ingress-coalescing.e2e.test.ts 20/20 passed.
  telegram-ingress-claim-hold.e2e.test.ts 1/1 passed.
- Red check (throwaway commit): with the watchdog's quiescence wait
  skipped (env toggle), the pin fails at the 300 s assertion, because 802
  is already pending with lastError "Channel ingress claim->adoption
  stalled for event 802 ... (handler-timeout)". Without the toggle it
  passes.
- Gates: check-line-cap-ratchet --base v2026.11.2 rc 0, run-oxlint on
  both files rc 0, check-test-mock-exports --base v2026.11.2 rc 0 (the
  new file's three isolating mocks carry mock-isolation reasons),
  tsgo:extensions:test rc 0, and oxfmt --check on both files rc 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants