Repository navigation
fix(telegram): webhook updates survive crashes and restarts via durable spooling - #98806
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 8:43 PM ET / 00:43 UTC. Summary PR surface: Source +599, Tests +385. Total +984 across 6 files. Reproducibility: yes. for a source-level path: current main sends 200 before durable persistence or awaiting bot.handleUpdate, while the PR moves persistence before ACK. I did not run a live Telegram crash/restart reproduction in this read-only review. Review metrics: 2 noteworthy metrics.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land a maintainer-reviewed version after redacted live Telegram proof shows webhook updates persist before ACK, replay after restart or transient failure, and do not duplicate delivery in the real transport path. Do we have a high-confidence way to reproduce the issue? Yes for a source-level path: current main sends 200 before durable persistence or awaiting bot.handleUpdate, while the PR moves persistence before ACK. I did not run a live Telegram crash/restart reproduction in this read-only review. Is this the best way to solve the issue? Yes for the fix shape: reusing the shared SQLite ingress queue and shared retry policy is narrower than an ad hoc webhook sidecar queue. It still needs maintainer review and live Telegram proof because the delivery semantics are user-visible. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c49714f7b6d2. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +599, Tests +385. Total +984 across 6 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
084d339 to
17d69eb
Compare
|
Landed via rebase onto main.
|
Closes #98777
What Problem This Solves
Fixes an issue where Telegram webhook mode silently and permanently lost updates: the handler acked 200 to Telegram before any persistence, so a gateway crash, restart, deploy, or even a transient processing failure (DB lock, provider error) during an in-flight update dropped it forever — Telegram saw the 200 and never redelivers. Three sibling webhook-mode gaps are fixed with it: a single transient network blip during startup
getMefailed the whole account start (burning the supervisor's cumulative restart budget), the webhook bot's HTTP transport was never closed (leaking keep-alive sockets on every restart — the same class as #68128, fixed for polling only), and the generic 120 req/min pre-auth rate limit throttled Telegram's own authenticated delivery on busy bots, growingpending_update_countuntil Telegram dropped old updates.Why This Change Was Made
Webhook mode now uses the same durability model as polling: the parsed update is written to the SQLite ingress spool before the 200 ack (a spool write failure returns non-200 so Telegram redelivers — that is the contract), and a webhook drain replays spooled updates through the bot with per-lane ordering, claim refresh, capped exponential backoff, and age-gated dead-lettering, including recovery of leftover updates on startup. Enqueue-time duplicate detection makes Telegram's own webhook retries idempotent. Rather than duplicating polling's retry policy, it is extracted into a shared
spooled-update-retry-policy.tsconsumed by both drains — including the age-gate semantics from 55d31be (over-limit updates keep retrying at the 3-minute cap and only tombstone once 24h old), now applied to webhook too. Startupbot.init()retries transient errors with the existing webhook retry classifier (401 stays fatal); the webhook owns its transport and closes it exactly once on shutdown and on startup failure (evicted probe-cache transports are closed as well); and the request path validates the Telegram secret first, so only failed secret guesses consume the abuse rate-limit budget — the pinned security contracts (constant-time compare, single-header enforcement, connection close on 401, body-size limits) are unchanged.User Impact
Webhook-mode Telegram accounts no longer lose messages across restarts, deploys, or transient failures — updates survive durably and replay, matching polling-mode reliability. Accounts come up cleanly after reboots instead of dying on the first network blip, long-running gateways stop leaking sockets on webhook restarts, and busy bots no longer have their own traffic rate-limited into growing delivery backlogs.
Evidence
webhook.test.ts, +313 lines): update spooled before ack and redelivered after a transient processing failure; non-200 when the spool write fails; leftover spooled updates drained on startup; young over-limit updates stay pending while >24h-old ones dead-letter (age-gate parity); transientgetMethen success starts the account while 401 stays fatal; transport closed exactly once on shutdown and startup failure (plusprobe.test.tsfor evicted transports); authenticated request storm passes while unauthenticated storm still 429s.extensions/telegram/src/polling-session.test.tsis unchanged frommainand passes against the shared policy module — polling behavior is identical by its own tests, including the age-gate tests from 55d31be.main:pnpm tsgo:extensionspass;node scripts/run-vitest.mjsonwebhook.test.ts,probe.test.ts,polling-session.test.ts— 114 tests pass;node scripts/run-oxlint.mjson touched files clean; repo autoreview (branch mode vsorigin/main) clean.