fix(telegram): drain ingress with native queue claims#96912
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 26, 2026, 5:25 PM ET / 21:25 UTC. Summary PR surface: Source +68, Tests +228. Total +296 across 6 files. Reproducibility: yes. at source level. Current main preserves the PID-reuse live-owner predicate and the linked issue reports durable Telegram claimed/pending backlogs; I did not run a live Telegram replay in this read-only review. Review metrics: 1 noteworthy metric.
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:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge only after maintainers explicitly accept the queue selector API and Telegram-scoped recovery, or revise the selectors behind a private seam while keeping broader startup recovery tracked separately. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main preserves the PID-reuse live-owner predicate and the linked issue reports durable Telegram claimed/pending backlogs; I did not run a live Telegram replay in this read-only review. Is this the best way to solve the issue? Mostly yes. Queue-native claiming is a maintainable fix shape for the Telegram drain path, but the SDK API expansion and scope versus broader startup recovery need maintainer acceptance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 29680046801d. Label changesLabel justifications:
Evidence reviewedPR surface: Source +68, Tests +228. Total +296 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
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@openclaw-mantis telegram desktop proof: verify a PID-reused stale Telegram ingress claim is recovered and queued messages drain in update order. |
|
Clarifying the recovery scope after the latest changes: This is intentionally Telegram-scoped for recovery because Telegram is the only current production user of the queue claim/drain flow. The shared queue changes are generic and reusable for future channels; WhatsApp uses the same SQLite queue today, but only as an accept/complete/release journal, so there is no equivalent stale claim drain path to recover there yet. So this is not a global startup sweep, but it does fix the Telegram claimed-row PID-reuse deadlock in the path that currently owns that behavior. |
1526324 to
58e228b
Compare
|
Superseded by the consolidated canonical fix in #97118. #97118 now contains this PR's four queue-native claim/PID-reuse commits, preserves Dallin Romney's authorship, and adds the stalled-drain heartbeat/lease fix from the companion implementation. Keeping both PRs open would split one Telegram delivery fix across two competing drain paths. The combined branch passed 99 focused tests, Testbox-through-Crabbox |
What Problem This Solves
Fixes #90945.
Telegram isolated ingress stores Bot API updates in the shared SQLite
channel_ingress_eventsqueue. The deadlock had two parts: Telegram selected pending rows outside the queue's native claim flow, and staleclaimedrows could survive a restart when the recorded owner PID was reused by the new process. In containers this commonly means PID 1, so a dead claim could look live forever and block later same-lane updates.This branch is rebased on the merged #96962 claim-refresh fix. It keeps that liveness/lease behavior and adds the separate queue-selection/PID-reuse fix.
Why This Change Was Made
Telegram now asks the shared ingress queue to atomically
claimNextthe next eligible update, using the queue's existing claim token for complete/release/fail operations. The queue selection skips blocked lanes while preserving Telegram update-id ordering.The queue claim path also blocks lanes from claimed rows in the same candidate snapshot. That preserves the old per-update ordering invariant if a sibling drainer claims an earlier same-lane row between Telegram's pending snapshot and
claimNext.The stale claimed-row fix stays in Telegram's existing drain recovery path: a claim with this process's PID but a different Telegram process owner id is no longer treated as another live process. The normal stale-claim recovery releases that row back to pending, so the original inbound update is handled before later same-lane updates instead of being failed or skipped.
This keeps recovery local to Telegram's drain loop instead of adding a gateway startup sweep.
User Impact
Telegram users should see stuck isolated-ingress updates drain again without manual SQLite edits. Restarted or recovered Telegram sessions can release PID-reused stale claims, reclaim the original update, skip genuinely live blocked lanes, preserve active claim refresh from #96962, and continue unrelated lanes.
Evidence
node scripts/run-vitest.mjs extensions/telegram/src/telegram-ingress-spool.test.ts extensions/telegram/src/polling-session.test.ts src/channels/message/ingress-queue.test.ts(81Telegram tests,16queue tests passed)node scripts/run-oxlint.mjs extensions/telegram/src/polling-session.ts extensions/telegram/src/telegram-ingress-spool.ts extensions/telegram/src/telegram-ingress-spool.test.ts extensions/telegram/src/polling-session.test.ts src/channels/message/ingress-queue.ts src/channels/message/ingress-queue.test.tspnpm exec oxfmt --check --threads=1 extensions/telegram/src/polling-session.ts extensions/telegram/src/telegram-ingress-spool.ts extensions/telegram/src/telegram-ingress-spool.test.ts extensions/telegram/src/polling-session.test.ts src/channels/message/ingress-queue.ts src/channels/message/ingress-queue.test.tsgit diff --check origin/main...HEAD.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main(clean after fixing the concurrent same-lane claim race it found)