The Webhook Returned 503. What Should We Retry?
In a Cycles regression test, the webhook transport returns HTTP 503 on the only allowed attempt. We deliberately corrupt the subscription row so the worker cannot update its failure count. It saves the delivery outcome for recovery. We repair the row, then deny the Redis write that would queue the failure alert. Once recovery has the permissions it needs, what should it retry?
The endpoint has already answered. Sending the webhook again would spend an HTTP attempt after this delivery had exhausted its retry budget. Walking away would leave the operator looking at a stale failure count and waiting for an alert. The job that still needs doing is entirely inside Redis.
What the webhook worker knows after a 503
The test delivers a tenant.created event. The same dispatch code handles a subscription that listens for a budget crossing a threshold. Cycles sends its endpoint a signed POST. If the endpoint returns 503 and the delivery has attempts left, the worker can schedule another attempt with backoff. On the final attempt, the work changes. The worker has to record the failed delivery, update the subscription's health, and queue a failure event. If this failure takes the subscription over its disable threshold, the worker also has to record that change and queue a second event. Webhook delivery contract
Ordinarily the worker finishes those writes directly. If finalization fails after the HTTP call, it tries to save a checkpoint on the delivery row. That checkpoint records which subscription was contacted and the outcome the worker still needs to account for. A row can already say FAILED and still carry a checkpoint. For the next worker, the checkpoint means there is bookkeeping to finish.
Where the Redis writes went wrong
In version 0.1.25.31, the finalization script ran its writes one after another, on the normal path and during recovery alike. Its first four writes were enough to explain the failure. Its outbox stored each event payload under its own key. A sorted set of task IDs told the publisher which payloads to pick up.
| Step | Write | What remained after Redis denied step 3 |
|---|---|---|
| 1 | Set the delivery to FAILED and clear the checkpoint. | The delivery looked finished. |
| 2 | Store the failure event's task payload. | The payload existed in Redis. |
| 3 | Add the task ID to the pending sorted set. | The publisher had no scheduled entry for the payload. |
| 4 | Update subscription health. | This step never ran. The failure count kept its old value. |
Redis ran the script without another client interleaving a command. But when Redis refused the sorted-set write, the first two writes stayed applied. The next worker could read a finished delivery, while the publisher, reading its own queue, could find nothing to publish. Both were reading exactly what the first worker had written. Previous finalization script
How recovery finishes without another POST
In 0.1.25.32, the terminal script verifies the worker still owns the claim, checks the delivery and subscription against the versions it read, and builds the list of writes this result requires. On Redis 7 and later it checks the worker's permission for each planned write against its target key with redis.acl_check_cmd. If any check fails, the script exits before the first write. Redis Lua API
Once permissions are in place, the worker can use the checkpoint to finish. It restores any delivery-history entry moved by a subscription change, queues the required events, writes subscription health, then saves the final delivery row and clears the checkpoint as its last write. If someone changed the delivery's subscription in the meantime, the saved checkpoint still identifies the subscription whose endpoint answered. Terminal write implementation
Redis 6 lacks that permission check. A command denial there can leave earlier writes applied, so we documented the commands the worker needs for each key, including the history indexes it touches after a subscription change. Terminal delivery ACL checklist
What the regression test counts
The test uses a real Redis 7 instance and a mock HTTP transport so we can count sends. We start recovery with a saved 503, an active subscription, and ten consecutive failures already recorded. In one run we deny the sorted-set write that schedules the alert. In another we allow the outbox writes but deny the write to subscription health.
In both runs the checkpoint survives byte for byte. The subscription stays at ten failures, the failure task is absent, and the pending outbox stays empty. Once recovery runs with the required permissions, the test checks four outcomes.
- The failure count advances from 10 to 11.
- The subscription becomes disabled.
- The events for
system.webhook_delivery_failedandwebhook.disabledboth exist under their expected IDs. - The transport was called once across the original attempt and recovery.
That final assertion matters. A test that looked only at the finished Redis rows could pass even if recovery made an unnecessary second POST. Regression test
There is still a window between the endpoint handling a request and the worker saving its outcome. A crash in that window can leave the next worker unable to tell whether the endpoint acted. Cycles webhooks have at-least-once delivery semantics, and receivers still need to deduplicate by event ID. Receiver-side idempotency patterns
When reviewing a queue worker, pick the line immediately after its outbound call and imagine the process restarting there. What durable evidence tells the next worker where to resume?
Further reading
- Webhook event delivery protocol covers the wire contract for senders and receivers.
- Cycles Events Server 0.1.25.32 release notes summarize the recovery changes and upgrade requirements.