Skip to content

[codex] harden Telegram transient recovery - #97270

Closed
ghitafilali wants to merge 2 commits into
openclaw:mainfrom
ghitafilali:codex/telegram-transient-recovery
Closed

ghitafilali wants to merge 2 commits into
openclaw:mainfrom
ghitafilali:codex/telegram-transient-recovery

Conversation

@ghitafilali

@ghitafilali ghitafilali commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenClaw can stay locally healthy while Telegram appears unresponsive when Telegram Bot API calls fail in two different transient ways:

  • Bot API HTTP 5xx responses from polling/setup paths crossed the isolated Telegram worker boundary as fatal server errors, causing ingress exits and supervisor backoff.
  • Slow or hanging provider sends could outlive the outbound message gateway client default timeout. The caller would abandon the request at 10s even though Telegram send handling is bounded at 60s, leaving ambiguous delivery state and no visible proof in the source chat.

The fix classifies Telegram Bot API HTTP 5xx responses as recoverable for polling/setup/control-plane contexts while keeping non-idempotent send context conservative. It also aligns the outbound message gateway default timeout with bounded provider sends, so callers receive the provider success/failure instead of an early local gateway timeout.

Summary

  • classify Telegram Bot API HTTP 5xx responses as recoverable for polling/setup/control-plane contexts
  • keep send context conservative to avoid duplicate visible messages
  • increase the outbound message gateway default timeout from 10s to 75s
  • document the Bad Gateway troubleshooting behavior for Telegram polling/startup instability

Evidence

  • Focused regression: pnpm exec vitest run extensions/telegram/src/network-errors.test.ts passes: 53 tests
  • Focused timeout contract: pnpm exec vitest run src/infra/outbound/message-gateway-options.test.ts passes: 3 tests
  • Local observed failure pattern: gateway health remained live, but Telegram logs repeated Bad Gateway | Telegram ingress worker exited with code 1 after Bot API timeouts/502s
  • Local proof after applying the same classifier hotpatch earlier in the incident: safe gateway restart, Telegram account connected, and openclaw message send --channel telegram ... --json returned ok: true with a Telegram message id
  • Follow-up local proof for the timeout alignment: the installed hotpatch changed the visible failure from GatewayTransportError: gateway timeout after 10000ms to the provider-level OutboundDeliveryError: Network request for sendMessage failed! after the bounded provider timeout
  • Sanitized token-specific probe evidence: dummy/fake-token Telegram getMe probes returned immediately, while the configured real bot token established TLS and then timed out with zero bytes. This points to a Telegram-side/token-specific provider hang; the PR keeps OpenClaw behavior bounded and diagnosable rather than wedged or ambiguous.
  • Local pnpm check:changed from the earlier PR pass did not execute checks because the delegated Blacksmith Testbox crabbox binary failed its own sanity check before running

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 27, 2026
@clawsweeper

clawsweeper Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 28, 2026, 5:31 PM ET / 21:31 UTC.

Summary
The PR classifies Telegram Bot API 5xx errors as recoverable outside send paths, raises the outbound message gateway default timeout to 75 seconds, adds focused tests, and documents Telegram Bad Gateway troubleshooting.

PR surface: Source +9, Tests +23, Docs +1. Total +33 across 5 files.

Reproducibility: yes. at source level: current main preserves Bot API error_code on getUpdates failures, then exits polling when the classifier returns false for 5xx; current outbound message gateway options also time out at 10 seconds while Telegram text sends are bounded at 60 seconds. A live 502 replay was not run in this read-only review.

Review metrics: 1 noteworthy metric.

  • Outbound gateway default timeout: 1 changed: 10,000 ms -> 75,000 ms. This default affects how long outbound message callers wait before surfacing a local gateway timeout.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🐚 platinum hermit
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

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

Rank-up moves:

  • [P2] Correct the command-menu 5xx troubleshooting claim or add a tested command-menu retry path.

Risk before merge

  • [P2] The outbound message gateway default now lets callers wait up to 75 seconds instead of 10 seconds; existing scripts or operators relying on the shorter local timeout may observe longer blocking before a local timeout.

Maintainer options:

  1. Accept the longer bounded default
    Maintainers can accept the 75-second default because it aligns gateway callers with bounded provider sends, while noting the longer wait in release context.
  2. Narrow the longer wait
    If the broader default is not acceptable, keep the global 10-second behavior and pass a longer timeout only through the Telegram outbound path that needs it.

Next step before merge

  • [P2] A narrow docs repair can make the troubleshooting claim match the runtime without changing the intended Telegram recovery behavior.

Security
Cleared: No concrete security or supply-chain concern was found in the TypeScript retry/timeout logic, tests, and documentation diff.

Review findings

  • [P2] Align the command-menu 5xx troubleshooting claim — docs/channels/telegram.md:1024
Review details

Best possible solution:

Keep the classifier and timeout alignment, but correct the troubleshooting sentence so it only promises retries for paths the implementation actually retries unless command-menu retry is intentionally added and tested.

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

Yes, at source level: current main preserves Bot API error_code on getUpdates failures, then exits polling when the classifier returns false for 5xx; current outbound message gateway options also time out at 10 seconds while Telegram text sends are bounded at 60 seconds. A live 502 replay was not run in this read-only review.

Is this the best way to solve the issue?

No, not as submitted: the runtime classifier and timeout changes are the right owner-boundary fix, but the docs currently promise command-menu 5xx retry behavior that the implementation does not provide.

Full review comments:

  • [P2] Align the command-menu 5xx troubleshooting claim — docs/channels/telegram.md:1024
    The new bullet says command-menu setup paths retry server 5xx responses, but command-menu sync only retries BOT_COMMANDS_TOO_MUCH; other setMyCommands failures are thrown out of the loop and then logged by the top-level catch. Please remove command-menu setup from this recovery promise, or implement and test that retry path.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR addresses a broken Telegram channel workflow where transient Bot API failures can interrupt ingress and obscure outbound delivery state for real users.
  • merge-risk: 🚨 compatibility: Changing the outbound message gateway default timeout can alter existing caller and operator expectations during upgrades.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body, comments, and passed proof check include redacted live operational output showing the hotpatched behavior and provider-level timeout result after the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body, comments, and passed proof check include redacted live operational output showing the hotpatched behavior and provider-level timeout result after the fix.
Evidence reviewed

PR surface:

Source +9, Tests +23, Docs +1. Total +33 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 10 1 +9
Tests 2 24 1 +23
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 35 2 +33

Acceptance criteria:

  • [P1] git diff --check.
  • [P1] pnpm docs:check-mdx.

What I checked:

Likely related people:

  • obviyus: Recent commits centralized Telegram error classification and carried Bot API error codes across the isolated ingress worker boundary. (role: recent Telegram classifier and ingress-boundary contributor; confidence: high; commits: a956ab848146, 4a3d06ee3785; files: extensions/telegram/src/network-errors.ts, extensions/telegram/src/telegram-ingress-worker.runtime.ts)
  • steipete: Commit c8d458d introduced the existing outbound message gateway timeout clamp that this PR changes. (role: outbound timeout history owner; confidence: medium; commits: c8d458d13d7b; files: src/infra/outbound/message-gateway-options.ts)
  • miorbnli: Recent Telegram work changed idempotent retry contexts for delete and reaction paths, adjacent to the PR's context-sensitive retry classifier behavior. (role: recent adjacent Telegram retry contributor; confidence: medium; commits: ce15f348bbc4; files: extensions/telegram/src/network-errors.ts, extensions/telegram/src/send.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.

@ghitafilali

Copy link
Copy Markdown
Contributor Author

Additional repro/context for the triage label:

  • Gateway health remained live (/health OK, no queued/running tasks), so this was not a gateway process outage.
  • Telegram logs repeated deleteWebhook failed with a recoverable network error; continuing to polling, followed by Bad Gateway | Telegram ingress worker exited with code 1.
  • That sequence points at getUpdates returning a Bot API server-side 5xx after webhook cleanup had already continued into polling.
  • The patch keeps 5xx retryable for polling/setup/control-plane contexts only; send context intentionally remains false in the new regression test so visible messages are not blindly duplicated.
  • Local proof after applying the same classifier hotpatch: safe gateway restart, Telegram account connected, and openclaw message send --channel telegram ... --json returned ok: true with Telegram message id 7200.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 27, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P1 High-priority user-facing bug, regression, or broken workflow. labels Jun 27, 2026
@ghitafilali ghitafilali changed the title [codex] recover Telegram polling from Bot API 5xx [codex] harden Telegram transient recovery Jun 27, 2026
@ghitafilali

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated the PR with the second root-cause fix from the same incident: outbound message gateway timeout now waits long enough for bounded provider sends, preventing ambiguous 10s local gateway timeouts when Telegram itself is still timing out. Focused tests passing locally:

  • pnpm exec vitest run extensions/telegram/src/network-errors.test.ts
  • pnpm exec vitest run src/infra/outbound/message-gateway-options.test.ts

@clawsweeper

clawsweeper Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Re-checking this PR because the visible status appears stale after the second root-cause fix.

Current live PR state I verified:

  • PR head: 553175f45f095ca7708f38187fe05b27fdf1df5a
  • Merge state: clean / mergeable
  • Checks: no failures; current-head CI and real behavior proof are passing, with older cancelled runs appearing to be superseded duplicates
  • Current labels still include status: 🔁 re-review loop
  • The durable ClawSweeper verdict marker in the main review comment still points at the older 45703e7798752bd21dc5e29ed5c064c61696f974 SHA, even though the PR now also includes the outbound message gateway timeout fix

Re-assessment from today: I do not see a new code change needed in this PR. The latest local "not getting replies" investigation showed Telegram ingress/egress working and the final receipt delivered; that symptom is a separate long-running detached-ingest progress/receipt visibility issue, not a recurrence of the Telegram transient recovery bug fixed here.

Please refresh the review verdict and labels against the current head SHA.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. labels Jun 28, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: [codex] harden Telegram transient recovery This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: XS stale Marked as stale due to inactivity status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant