How a Deferred Webhook Stalled Every Tenant
A randomized test was draining 720 webhook deliveries from 12 tenants through the Cycles Events Service (cycles-server-events). In each 400 ms cycle, a chaos thread picked a subscription and deleted its signing secret for 150 ms, so some deliveries had to wait before they could be signed. After 160 deliveries, dispatch stopped for every tenant.
Nothing was broken in an obvious way. The pending, processing, retry, sending and ready queues were empty, and one scheduler thread sat in a blocking pop on an empty list. Five deliveries from one tenant were still listed in that tenant's queue, each marked as waiting to resume, and none of them was in any queue a worker reads. Each of the five was also first in the order list of a different shared subscription, and every remaining tenant had deliveries for those subscriptions waiting behind them. Issue #203
The first attempts that had been sent were in order. The scheduler had stopped making progress. This post covers how the race was found, what fixed it in 0.1.25.33, and why a second change now lets woken deliveries go ahead of new traffic. The per-tenant design itself is described in One Slow Webhook Receiver Stalled Every Tenant.
Why one webhook deferral could stall every tenant
In the per-tenant scheduler, each tenant has a FIFO of its deliveries, and each subscription has an order list across tenants. A delivery is sent only when it is first in both. A system subscription receives events from many tenants, so its order list mixes them.
A worker that cannot send yet, for example because the signing secret is not readable, defers the delivery before any HTTP request. The deferred delivery keeps its place, and its followers wait behind it. That is what keeps first attempts in order, and it is safe as long as one condition holds: every parked delivery has some event that will wake it. When the head finishes, its acknowledgement pushes the next delivery in the tenant FIFO back into admission. That push is the follower's only wakeup.
If that wakeup is lost, the follower stays parked. It holds no send claim, so stale-claim recovery does not see it. It still heads its subscription's order list, so other tenants' deliveries to that subscription stay parked too. A tenant with work for other subscriptions can still progress, but when the stranded deliveries head enough shared subscriptions, as in this run, a single lost wakeup stalls the whole fleet.
Finding a race that hid under MONITOR
The test that found it was new. The verification for PR #189 had run a randomized drain of 720 deliveries with retargets and deferrals, but that test was never committed. A new version, opened as a draft PR with a deferral-only mode, stalled in four consecutive runs one afternoon. It then passed five times, and did not reproduce in three more runs with Redis MONITOR attached, with the same code and configuration. A minimal test of one deferred head with two followers on other subscriptions passed every time. Issue #203
MONITOR streams the command traffic Redis executes back to a client. It slowed Redis enough that it plausibly hid the race, although five unmonitored runs passed as well. The trace that exposed it came from a test-only subclass of the queue repository instead. TracingDeliveryQueueRepository overrides the queue operations and records selected call completions, with their thread, delivery, claim and result, in memory without adding Redis commands. With it attached, the race still occurred. It records when each Java call completes, which can differ from the order Redis executed the commands, so the trace narrows the race without proving the order on its own. PR #204 · Redis MONITOR
The lost wakeup
A deferred head resumes through its own lane, so its tenant's next delivery can hold a send claim at the same time. Inside the handler, the two are serialized through the tenant FIFO. The losing interleaving, with resumed head P and follower F:
| Step | What happens | State afterward |
|---|---|---|
| 1 | F finds P still first in the tenant FIFO, so F's handler will return RETAIN and park F. | F still owns its send claim. |
| 2 | P finishes. Its acknowledgement advances the tenant FIFO and pushes F into admission. | That push is F's only wakeup. |
| 3 | Admission picks up the wakeup, sees that F still owns its send claim, and drops it as a duplicate. | No wakeup is queued for F. |
| 4 | F's RETAIN acknowledgement parks it with a resume marker. | Nothing will wake F. |
Each step is correct when checked alone. Dropping a duplicate admission is how the worker avoids sending a delivery twice. The bug is in the gap between steps 3 and 4: the duplicate check assumed the delivery that owned the claim would publish its own next step, and the RETAIN path did not.
The step-by-step reproduction is followerParkedWhileItsWakeupWasDroppedIsWokenByItsOwnRetainAck, which drives the four steps directly against Redis. It failed before the fix.
The fix: the parked delivery publishes its own wakeup
In 0.1.25.33, when the send-stage handler returns RETAIN, its acknowledgement checks whether that delivery is now first in its tenant FIFO. For a waiting follower, being first means its predecessor already finished, so its wakeup was either queued or dropped. If no readmission is in flight and no retry is scheduled, the same Lua script that parks the delivery also publishes the wakeup. When the original wakeup is still queued, the in-flight marker prevents a second copy. PR #204 · Why Cycles uses Redis Lua
The order of writes in that script matters. The wakeup is written to dispatch:pending before the readmission marker is set and before the claim and lane are released. If that write is rejected, for example by a Redis ACL that denies LPUSH, the claim and the lane are still in place, no marker is left behind, and the acknowledgement can be retried. If the marker were written first, a rejected push would leave a marker with no wakeup behind it, and the retried acknowledgement would see the marker and skip the wakeup it still owed. A test acknowledges through an ACL user denied only LPUSH and checks that the acknowledgement fails cleanly and then succeeds as the normal user. That test fails if the two writes are swapped.
With the fix, five randomized seeds that removed signing secrets for 300 ms of every 400 ms, with 30 to 40 deferrals each, all drained. Seed 3, run with the same settings before the fix, stalled permanently.
Woken deliveries now go ahead of new traffic
With the stall gone, every randomized run still showed one fleet-wide pause of 19 to 39 seconds, starting one to three seconds in, during which no delivery reached SUCCESS. This was a delay, not a loss: the deliveries drained on their own. The stall watchdog showed retargeted and retried heads waiting in dispatch:pending behind about 357 entries not yet admitted for the first time, admitted at roughly 25 a second. Producers add new deliveries to one end of that list with LPUSH, and workers consume from the other end with BLMOVE ... RIGHT. Every readmission also used LPUSH, so a readmitted delivery that still held its place waited behind the whole backlog, and so did its tenant and its subscription's order list. Issue #205 · Redis BLMOVE
In 0.1.25.33, such a readmission goes to the consuming end with RPUSH when it is the only copy of that delivery in the admission pipeline. Three worker scripts share one Lua function for that check. The excerpt below is from v0.1.25.33:
local function front_eligible(id, pending)
return redis.call('HEXISTS', 'dispatch:sending:subscriptions', 'order:' .. id) == 1
and redis.call('HEXISTS', 'dispatch:send:members', id) == 0
and redis.call('HEXISTS', 'dispatch:sending:claim_owner', id) == 0
and redis.call('SISMEMBER', 'dispatch:send:readmitting', id) == 0
and not redis.call('ZSCORE', 'dispatch:recovery:staged', id)
and not redis.call('LPOS', 'dispatch:processing', id)
and not redis.call('LPOS', pending, id)
endIn order, it requires a subscription order entry, no send lane, no send claim, no readmission already in flight, and no copy staged by recovery, mid-admission or already pending. A wakeup of a parked follower also requires that no retry is scheduled. The second-to-last condition reads dispatch:processing directly, because a delivery sits there between BLMOVE and claim registration. Any other copy could change the delivery's state before the front copy is consumed, so any other copy disqualifies the front. PR #206
The change covers readmissions that used to go to the back. Stale-processing recovery and admission replay already restored work to the consuming end. The split for the rest:
| Readmission | Where it goes | Why |
|---|---|---|
| Woken follower, resumed deferral, due retry that was never sent, detached resume restored by stale-send recovery | Front, if the check passes | Its tenant and its subscription's order list are waiting for it. |
| Retarget to a different subscription | Back | It gives up its positions and takes new ones on admission. |
| Retry of a request that was already sent | Back | It also takes new positions. Order is guaranteed only for first attempts. |
| Delivery with no subscription order entry | Back | Admission order is its only order on a shared subscription. |
| The wakeup that fixes the stall | Back | It is written before the lane is removed later in the same script, so it must not jump ahead of a live lane. |
On seed 20261201, the largest pause in the first 30 seconds went from 28.7 s to 5.1–5.2 s. On seed 3 it went from 21.8 s to about 5 s, with one run at 14.4 s. Total drain time is not claimed to have improved. The randomized runs are noisy, and the later pauses of 10 to 15 seconds match overlapping five-second deferral windows rather than queue order.
Upgrading from 0.1.25.32 to 0.1.25.33
The release changes no Redis keys and no command names, but three things matter during this rollout. Fleets on older releases also have the earlier steps in the upgrade guide: from 0.1.25.31, the terminal-delivery ACL check that came with 0.1.25.32; from 0.1.25.30 or earlier, also stopping older senders before starting workers that write checkpoints. Events 0.1.25.33 release · Deploying the Events Service
Check per-key ACL grants first. The new check reads dispatch:send:members with HEXISTS and dispatch:recovery:staged with ZSCORE. Namespace grants already cover them. An ACL that restricts commands per key needs both before the new workers start.
Older workers can still strand a head. Each upgraded worker publishes its own wakeup, but a 0.1.25.32 worker's RETAIN path does not, so the race remains possible until the last older worker exits. A rolling upgrade from 0.1.25.32 keeps first-send order: a new worker gives up front priority when an older worker's copy or marker exists.
Upgrading does not wake heads that are already stranded. The sign is deliveries that stay PENDING while a dispatch:ordering:tenant:{tenant} list persists and nothing is sent. The release ships a repair script for one list. It readmits the list's head only if dispatch:ordering:members maps that delivery to the list, the head has a resume marker, and it has no send lane, send or processing claim, processing-list entry, pending entry, recovery staging, scheduled retry or readmission in flight. It then pushes the head to the consuming end of dispatch:pending with RPUSH, sets the readmission marker and returns the delivery ID. An immediate second run for the same head returns nil.
redis-cli --scan --pattern 'dispatch:ordering:tenant:*' | while read -r fifo; do
redis-cli --eval tools/repair/readmit-stranded-tenant-head.lua "$fifo"
doneAdd your connection and authentication flags to both commands. The script also needs TYPE on the staged key and the membership command for that key's type. Run it after every worker is upgraded, so an older worker cannot strand the same tenant again. Repair script
The takeaway
- Test progress, not only order. An order check alone would have passed on the stalled run, because nothing was ever sent out of order. The randomized test now fails if the queues do not drain within its budget, and a watchdog dumps Redis state and the queue trace while a pause is live.
- Give every parked item an owner for its wakeup. The bug came from two components that each assumed the other would publish the next step. Now the acknowledgement that parks a delivery checks whether a wakeup is still owed.
- Commit the randomized test. A verification run that is not committed checks one moment. Once committed with a deferral mode, it found a race the earlier run did not.
- Trace in process for timing races. With
MONITORattached the race did not reproduce. An in-memory trace of queue calls added no Redis commands and caught it. - Order writes so a rejected write is retryable. Publishing the wakeup before setting the marker or releasing the claim turns an ACL denial into a failed acknowledgement that can be retried, instead of a silent strand.
Webhook allowlist grammar and IPv6 matching
The previous post said the governance spec gave an example allowlist pattern but no glob grammar, so the admin and events matchers had to be kept in step by hand, and that they still differed on equivalent IPv6 spellings. That gap is closed. Governance spec 0.1.25.45 defines the allowed_url_patterns grammar, with shared test vectors, and Admin 0.1.25.58 compares bracketed IPv6 literals in canonical form, as the events worker does. The spec still allows normalization differences for URLs outside its portable URL form. Governance changelog · Conformance vectors at governance 0.1.25.45