Repository navigation
fix(zalo): prevent webhook message loss after acknowledgment - #110630
Conversation
… append OA webhooks acked before detached processing behind a 5-minute in-memory guard, and Zalo does not retry (silent loss). Raw webhook JSON now appends durably (event_id = Bot API message.message_id, lane per chat.id) before the 200; failed appends answer 400/500 so nothing acks unpersisted. Dispatch runs through the core drain with serialized admissions across append backoff, deferred claims held through shutdown until adoption, retry/dead-letter classification, and 30d/20k tombstones replacing the deleted 5min/5k guard after its parity test. Webhook and polling transports stay mutually exclusive; no twin scenario exists across the four received-event types. Autoreview scanner false-positive on deleted-line token field references; full manual review performed (ack ordering, dual-transport exclusivity, eleven-test matrix). Part of the #109657 fleet program (wave 3).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14fcb8859a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const eventId = nonEmptyString(message?.message_id); | ||
| if (!eventId) { | ||
| throw new ZaloWebhookPayloadError("Zalo webhook message is missing message.message_id."); |
There was a problem hiding this comment.
Acknowledge ignored non-message Zalo webhooks
When Zalo sends a valid webhook event with an event_name but no message (the Bot webhook docs mark message optional, and monitor.webhook.test.ts still exercises { event_name: "message.unsupported.received" } as a 200), this throws during admission; handleZaloWebhookRequest maps ZaloWebhookPayloadError to HTTP 400, so Zalo will retry events OpenClaw previously acked and ignored. Gate durable enqueue to supported message events and acknowledge ignored/no-message event types instead of rejecting them.
Useful? React with 👍 / 👎.
| drain.dispose(); | ||
| await drainTask; | ||
| // A pump may have been between prune and drain when the first dispose ran. | ||
| drain.dispose(); |
There was a problem hiding this comment.
Keep the drain owner live until deferred work settles
Because createChannelIngressDrain.dispose() deregisters the live owner and removes active lane state, doing it here before waiting for activeDeliveries/deferredClaims lets a replacement Zalo ingress in the same process recover the still-claimed row while the old delivery is still adopting or abandoning. That can redeliver the same webhook and produce duplicate replies during a channel restart/shutdown; keep the drain alive until active and deferred work settles, then dispose it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6481b01660
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await queue.enqueue( | ||
| facts.eventId, | ||
| { version: ZALO_WEBHOOK_SPOOL_VERSION, rawEvent }, | ||
| { receivedAt, laneKey: facts.laneKey }, |
There was a problem hiding this comment.
Preserve replay scope beyond message_id
When two valid events for the same Zalo account share a message.message_id but come from different chats or senders, this durable enqueue now keys only on facts.eventId; the channel ingress queue is unique by queue/event id, so the second event is treated as a duplicate and is never delivered. The previous replay guard scoped the key by path/account/event/chat/sender/message id, and the deleted tests covered different-chat/sender collisions, so include the chat/sender scope in the durable event id instead of using the bare message id.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…w#110630) * fix(zalo): adopt durable ingress drain with ack gated on raw-envelope append OA webhooks acked before detached processing behind a 5-minute in-memory guard, and Zalo does not retry (silent loss). Raw webhook JSON now appends durably (event_id = Bot API message.message_id, lane per chat.id) before the 200; failed appends answer 400/500 so nothing acks unpersisted. Dispatch runs through the core drain with serialized admissions across append backoff, deferred claims held through shutdown until adoption, retry/dead-letter classification, and 30d/20k tombstones replacing the deleted 5min/5k guard after its parity test. Webhook and polling transports stay mutually exclusive; no twin scenario exists across the four received-event types. Autoreview scanner false-positive on deleted-line token field references; full manual review performed (ack ordering, dual-transport exclusivity, eleven-test matrix). Part of the openclaw#109657 fleet program (wave 3). * refactor(zalo): keep webhook runtime exports private * test(zalo): use managed temp directories
…w#110630) * fix(zalo): adopt durable ingress drain with ack gated on raw-envelope append OA webhooks acked before detached processing behind a 5-minute in-memory guard, and Zalo does not retry (silent loss). Raw webhook JSON now appends durably (event_id = Bot API message.message_id, lane per chat.id) before the 200; failed appends answer 400/500 so nothing acks unpersisted. Dispatch runs through the core drain with serialized admissions across append backoff, deferred claims held through shutdown until adoption, retry/dead-letter classification, and 30d/20k tombstones replacing the deleted 5min/5k guard after its parity test. Webhook and polling transports stay mutually exclusive; no twin scenario exists across the four received-event types. Autoreview scanner false-positive on deleted-line token field references; full manual review performed (ack ordering, dual-transport exclusivity, eleven-test matrix). Part of the openclaw#109657 fleet program (wave 3). * refactor(zalo): keep webhook runtime exports private * test(zalo): use managed temp directories
The Zalo Bot API consumes each polled update on response (getUpdates has no offset or confirm parameter), so a crash or restart between the poll response and dispatch completion permanently loses the message. Route polling through the same durable ingress the webhook transport uses (openclaw#110630), including durable-after-stop admission for the shutdown race, while keeping current ready/recovering status and partial-delivery recovery behavior. PR openclaw#110803
The Zalo Bot API consumes each polled update on response (getUpdates has no offset or confirm parameter), so a crash or restart between the poll response and dispatch completion permanently loses the message. Route polling through the same durable ingress the webhook transport uses (openclaw#110630), including durable-after-stop admission for the shutdown race, while keeping current ready/recovering status and partial-delivery recovery behavior. The polling ingress drains serially (startLimit=1): the pre-journal loop dispatched one update at a time in poll order, so the journaled path keeps that user-visible delivery contract and only closes the crash-loss window. The webhook fan-out limit stays the default for the webhook transport. Co-Authored-By: Claude <[email protected]>
…w#110630) * fix(zalo): adopt durable ingress drain with ack gated on raw-envelope append OA webhooks acked before detached processing behind a 5-minute in-memory guard, and Zalo does not retry (silent loss). Raw webhook JSON now appends durably (event_id = Bot API message.message_id, lane per chat.id) before the 200; failed appends answer 400/500 so nothing acks unpersisted. Dispatch runs through the core drain with serialized admissions across append backoff, deferred claims held through shutdown until adoption, retry/dead-letter classification, and 30d/20k tombstones replacing the deleted 5min/5k guard after its parity test. Webhook and polling transports stay mutually exclusive; no twin scenario exists across the four received-event types. Autoreview scanner false-positive on deleted-line token field references; full manual review performed (ack ordering, dual-transport exclusivity, eleven-test matrix). Part of the openclaw#109657 fleet program (wave 3). * refactor(zalo): keep webhook runtime exports private * test(zalo): use managed temp directories
Related: #109657
What Problem This Solves
Fixes an issue where Zalo webhook users could lose incoming messages when detached processing failed after the webhook had already returned success. The previous replay guard was also process-local, so it could not recover accepted work after restart.
Why This Change Was Made
Zalo now appends the raw webhook envelope durably before returning HTTP 200, using the Bot API message ID for deduplication and the chat ID for lane serialization. Delivery then adopts the shared durable ingress drain contract for bounded retries, dead-letter handling, shutdown safety, restart recovery, and durable tombstones; polling and webhook transports remain mutually exclusive.
User Impact
Accepted Zalo webhook messages now survive process interruption and retry through the shared ingress lifecycle without duplicate visible replies. Failed persistence does not acknowledge the webhook.
Evidence
The whole-branch autoreview bundle scanner rejected deleted-line token-field references as secret-like content before model invocation. The mechanical follow-up diff received a clean autoreview, and the full branch received a manual evidence-map review across Zalo entry points, core drain ownership, sibling channel drains, and focused tests; no message-loss, duplicate-reply, or data-corruption defect was found.