Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ffb13392d3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Greptile SummaryThis PR adds a disk-backed webhook queue to survive Telegram gateway restarts — a well-scoped solution to a real message-loss problem. Payloads are persisted atomically before processing, deferred work (media groups, text fragments, inbound debounce) delays dequeue until the full logical operation completes, and replay on startup is ordered and deduplicated. Verified findings:
The core persistence and replay logic is solid — atomic writes, TTL cleanup, correct deferred-work tracking, and replay-before-listen ordering are all well-implemented. The three findings above are edge-case issues: one is a restart-window race condition, two are API design improvements that would prevent latent bugs if the code is reused across multiple channels. Confidence Score: 3/5
Last reviewed commit: ffb1339 |
|
Closing for rework. Will resubmit with fixes. |
Summary
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Messages received during a gateway restart window are now replayed on next startup instead of being silently dropped. No new config required -- the queue directory (
webhook-queue/inside the state dir) is created automatically.Security Impact (required)
Repro + Verification
Environment
Steps
openclaw gateway restart)Expected
Actual (before this PR)
Evidence
Attach at least one:
New test suites:
src/infra/webhook-queue.test.ts(13 tests): enqueue/dequeue lifecycle, replay ordering, deduplication, TTL cleanup, malformed file handling, orphaned tmp cleanup, idempotent dequeue, timestamp tie-breakingsrc/telegram/webhook.test.ts(1 new test): verifies dequeue fires whenonUpdateProcessedcallback triggersHuman Verification (required)
Review Conversations
Compatibility / Migration
Failure Recovery (if this breaks)
Risks and Mitigations
.tmpfiles are cleaned up during replay. Entries older than 1 hour are deleted during replay.Architecture
Three layers:
Queue module (
src/infra/webhook-queue.ts): Generic channel-agnostic enqueue/dequeue/replay with atomic writes, TTL cleanup, dedup, and deterministic ordering.Webhook integration (
src/telegram/webhook.ts): Validates secret before enqueuing. Enqueues before Grammy handler. Dequeues viaonUpdateProcessedcallback. Replays pending entries on startup before accepting new webhooks.Deferred-work tracking (
src/telegram/bot.ts,bot-handlers.ts): TheonUpdateProcessedcallback only fires after all deferred work (media group assembly, text fragment concatenation, inbound debounce flush) has settled. Handlers register promises viaregisterDeferredWork(updateId, promise). The bot middleware awaits all registered promises for an update_id before callingonUpdateProcessed.AI Disclosure
AI-assisted (Claude). Fully tested and reviewed.
Resubmission of #40056 (closed for clean commit history).