Skip to content

fix(telegram): survive transient getUpdates errors and stop per-send cache rewrites - #98775

Merged
obviyus merged 2 commits into
mainfrom
codex/fix-telegram-cache-transport
Jul 1, 2026
Merged

obviyus merged 2 commits into
mainfrom
codex/fix-telegram-cache-transport

Conversation

@obviyus

@obviyus obviyus commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #98772
Closes #98773

What Problem This Solves

Fixes two Telegram channel stability defects found in a full subsystem audit:

  1. Resolves a problem where any transient Telegram Bot API error on getUpdates (429, 500, 502 — including 502s with HTML bodies) crashed the account's polling session. Because the gateway supervisor counts restart attempts cumulatively, routine Telegram degradations eventually disabled the channel permanently until a manual restart. This was a regression from the isolated-ingress migration: the retired grammY polling path retried these errors internally for up to an hour.
  2. Fixes an issue where every outbound Telegram message rewrote the entire sent-message cache (up to 10,000 entries) to SQLite as individual synchronous transactions. On busy bots this stalled the gateway event loop, showing up as spurious "polling stall detected" restarts and lock contention with the ingress spool on the shared state DB.

Why This Change Was Made

The ingress worker now classifies Bot API server errors (5xx) and rate limits (429) as retryable, honoring parameters.retry_after before falling back to the existing exponential backoff, and parses non-2xx bodies defensively so a 502 HTML page becomes a status-bearing retryable error instead of a fatal JSON.parse crash. 401/404 stay fatal (bad token) and 409 still propagates to the parent session, which owns webhook-conflict recovery. The classifier is shared with the webhook registration path, which already had this behavior (pure refactor there, no behavior change). The sent-message cache now persists only the newly recorded entry — keys were already content-addressed — relying on per-entry TTL and store-side caps for expiry.

The worker runtime was extracted into an injectable function (module-level side effects gated behind a workerData marker) so the retry behavior is directly testable.

User Impact

Telegram accounts survive Telegram-side outages and rate limiting instead of dying permanently, and 429 retry_after hints are respected on the polling path. Busy bots no longer degrade the whole gateway as their daily send volume grows; spurious stall-watchdog restarts from event-loop blocking disappear.

Known bound, not a bug: an extreme retry_after (e.g. 3600s) makes the worker sleep past the parent stall watchdog, which restarts the session — an acceptable upper bound that converges.

Evidence

  • New regression tests in extensions/telegram/src/telegram-ingress-worker.runtime.test.ts: 429-with-retry_after retries after the hinted delay; 500/502 retry with backoff; 502 HTML body (JSON parse failure) retries; 401 and 409 still propagate to the parent.
  • extensions/telegram/src/send.test.ts now asserts exactly one persisted entry per recorded sent message.
  • Validation: pnpm tsgo:extensions pass; node scripts/run-vitest.mjs on all touched test files — 204 tests pass (send, network-errors, ingress-worker runtime); repo autoreview clean.
  • Combined-merge validation with the sibling spool PR (codex/fix-telegram-spool): conflict-free octopus merge, pnpm tsgo:extensions pass, 403/403 tests across all six touched test files.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: L maintainer Maintainer-authored PR labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 6:20 PM ET / 22:20 UTC.

Summary
The branch updates Telegram sent-message cache persistence to register only the new row and refactors the isolated ingress worker runtime to retry Bot API 429/5xx/non-JSON 5xx getUpdates failures with focused tests.

PR surface: Source +108, Tests +208. Total +316 across 8 files.

Reproducibility: yes. at source level: current main rewrites every cached sent-message row on each send and current isolated getUpdates handling rethrows 429/5xx/non-JSON failures because the retry gate does not classify them as recoverable. I did not run a live Telegram degradation replay in this read-only review.

Review metrics: 2 noteworthy metrics.

  • Sent-message persistence writes: full live-cache rewrite removed; 1 new row registered per send. This is the central hot-path performance claim behind the linked cache-stall bug.
  • Retryable Bot API classes: 2 added: 429 and 5xx. This changes isolated polling availability behavior for Telegram-side rate limits and server errors.

Stored data model
Persistent data-model change detected: persistent cache schema: extensions/telegram/src/send.test.ts, serialized state: extensions/telegram/src/telegram-ingress-worker.runtime.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #98775
Summary: This PR is the active candidate fix for the two linked Telegram bugs; older/open Telegram transient-recovery PRs overlap only part of the getUpdates behavior and do not cover the cache rewrite bug.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • Maintainer should decide whether targeted worker-runtime tests are enough or request a redacted live/terminal getUpdates retry probe.
  • [P2] Clear or explicitly waive the unrelated-looking current CI failures before merge.

Risk before merge

  • [P1] Telegram maintainer notes prefer real Telegram proof for transport/retry changes; this review found targeted tests and validation text, but no live Telegram degradation replay.
  • [P1] The PR intentionally allows very large retry_after values to be bounded by the parent stall watchdog/session restart rather than adding a local cap, so maintainers should accept that operational tradeoff before merge.
  • [P1] Current CI is unstable, but the sampled failures are outside the touched Telegram surface and should clear or be waived through the normal merge gate rather than becoming a patch finding here.

Maintainer options:

  1. Request live Telegram retry proof
    Ask for redacted live or terminal proof that a transient getUpdates 429/5xx condition retries without killing the Telegram account before merge.
  2. Accept targeted tests and the watchdog bound
    Maintainers can land with the new worker-runtime tests while explicitly accepting that extreme retry_after values converge through the parent stall watchdog restart.

Next step before merge

  • [P1] Protected maintainer label plus availability proof and retry_after tradeoff means the next action is maintainer merge/proof judgment, not an automated repair branch.

Security
Cleared: No concrete security or supply-chain concern was found; the diff changes Telegram TypeScript runtime error handling, cache persistence, and tests without new dependencies, scripts, permissions, or credential handling.

Review details

Best possible solution:

Land this bounded Telegram retry/cache repair after maintainer acceptance of the transport-proof gap and retry_after bound, then let the linked issues close through the merged PR.

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

Yes, at source level: current main rewrites every cached sent-message row on each send and current isolated getUpdates handling rethrows 429/5xx/non-JSON failures because the retry gate does not classify them as recoverable. I did not run a live Telegram degradation replay in this read-only review.

Is this the best way to solve the issue?

Yes: the PR fixes the implicated owner boundaries by keeping retry classification in the Telegram worker/network-error layer and narrowing cache persistence to the one new entry. The remaining question is merge proof depth and operational acceptance, not a different implementation layer.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR addresses Telegram channel availability failures that can permanently disable polling after routine Bot API degradation.
  • merge-risk: 🚨 availability: Merging changes whether transient Telegram Bot API failures stay inside the worker retry loop or propagate into account/session restarts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The contributor real-behavior gate is not applied to this maintainer-labeled PR; the PR has targeted tests and validation text, while live Telegram outage/rate-limit proof remains a maintainer risk reducer.
Evidence reviewed

PR surface:

Source +108, Tests +208. Total +316 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 232 124 +108
Tests 3 210 2 +208
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 442 126 +316

What I checked:

Likely related people:

  • obviyus: Prior merged history ties this person to isolated-ingress error-code propagation and 409 recovery on the same worker boundary, and this branch changes the adjacent retry behavior. (role: recent Telegram ingress contributor; confidence: high; commits: 4a3d06ee3785, d4819948f37d, c82e50d3f55d; files: extensions/telegram/src/telegram-ingress-worker.runtime.ts, extensions/telegram/src/telegram-ingress-worker.ts, extensions/telegram/src/polling-session.ts)
  • samzong: The merged Telegram reaction ownership cache work touched sent-message-cache.ts and send.test.ts, which are the central cache files changed by this PR. (role: sent-message cache feature contributor; confidence: high; commits: 0e0ad692b5fe; files: extensions/telegram/src/sent-message-cache.ts, extensions/telegram/src/send.test.ts)
  • steipete: History points to storage/runtime refactor work around plugin-state persistence, which is the synchronous store contract implicated by the cache rewrite behavior. (role: adjacent storage/runtime contributor; confidence: medium; commits: 1da9a5a5f3c4; files: src/plugin-state/plugin-state-store.sqlite.ts)
  • Peter Lee: Current shallow/grafted blame attributes the central cache loop and worker runtime lines to a broad recent commit, but the commit topic is not Telegram-specific, so this is weak routing evidence. (role: recent current-line contributor; confidence: low; commits: 85f7834852d3; files: extensions/telegram/src/sent-message-cache.ts, extensions/telegram/src/telegram-ingress-worker.runtime.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: 🐚 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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 1, 2026
@obviyus
obviyus force-pushed the codex/fix-telegram-cache-transport branch from c82e50d to 84ee4a6 Compare July 1, 2026 22:21
@obviyus
obviyus merged commit 5a10a29 into main Jul 1, 2026
87 checks passed
@obviyus
obviyus deleted the codex/fix-telegram-cache-transport branch July 1, 2026 22:24
@obviyus

obviyus commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Landed via rebase onto main.

  • Scoped tests: node scripts/run-vitest.mjs extensions/telegram/src/send.test.ts extensions/telegram/src/network-errors.test.ts extensions/telegram/src/telegram-ingress-worker.runtime.test.ts — 204 passed.
  • Typecheck: pnpm tsgo:extensions attempted, but pnpm stalled fetching @openai/codex-0.142.4-darwin-arm64.tgz; no TypeScript result reached.
  • Changelog: release-owned; not edited for this normal PR.
  • Land commit: 84ee4a6
  • Merge commit: 5a10a29

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

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant