Skip to content

fix(zalo): prevent webhook message loss after acknowledgment - #110630

Merged
steipete merged 3 commits into
mainfrom
claude/ingress-zalo
Jul 18, 2026
Merged

steipete merged 3 commits into
mainfrom
claude/ingress-zalo

Conversation

@steipete

@steipete steipete commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

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.

steipete added 2 commits July 18, 2026 11:46
… 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).
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: zalo Channel integration: zalo labels Jul 18, 2026
@steipete steipete self-assigned this Jul 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Jul 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +83 to +85
const eventId = nonEmptyString(message?.message_id);
if (!eventId) {
throw new ZaloWebhookPayloadError("Zalo webhook message is missing message.message_id.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +353 to +356
drain.dispose();
await drainTask;
// A pump may have been between prune and drain when the first dispose ran.
drain.dispose();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +311 to +314
await queue.enqueue(
facts.eventId,
{ version: ZALO_WEBHOOK_SPOOL_VERSION, rawEvent },
{ receivedAt, laneKey: facts.laneKey },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@steipete
steipete merged commit 0ac69b9 into main Jul 18, 2026
113 of 115 checks passed
@steipete
steipete deleted the claude/ingress-zalo branch July 18, 2026 11:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

coder-master-0915 pushed a commit to coder-master-0915/openclaw that referenced this pull request Jul 18, 2026
…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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
…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
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Aug 16, 2026
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
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Sep 2, 2026
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]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: zalo Channel integration: zalo docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant