Skip to content

fix(queue): drop an owned Redis claim whose payload is gone instead of halting the reap sweep - #14481

Merged
levivannoort merged 2 commits into
mainfrom
fix/queue-redis-reap-orphan-claims
Oct 14, 2026
Merged

levivannoort merged 2 commits into
mainfrom
fix/queue-redis-reap-orphan-claims

Conversation

@levivannoort

Copy link
Copy Markdown
Member

What

Broker\Redis::reap() no longer throws on a claim that still has its owner record but whose payload is gone. Such a claim has nothing left to requeue or park, so a new abandon.lua drops it atomically: it removes the pid from the processing list, deletes the owner record and decrements the processing counter. It does that only if the owner is unchanged, no heartbeat is live and the payload really is missing. A claim whose handler still heartbeats is left to that handler, since commit already tolerates a missing payload.

Why

Appwrite Cloud, fra1 (the last region still on Redis), Sentry CLOUD-3R40: RuntimeException: Queue delivery payload is missing, 21K events, about one a minute from each of worker-functions, worker-jobs and worker-webhooks, ongoing since about Oct 7.

Two costs:

  • Noise: every reap sweep reports the same error.
  • Stranded work: the throw ends the sweep before its cursor is saved, so every sweep stops at the same orphan, and no stranded claim behind it is ever requeued. A worker that dies holding a delivery on one of those queues isn't recovered.

The orphans are claims whose payload expired while they were still owned. The existing comment allows for exactly that ("Only legacy payloads expire while processing"); only the ownerless case was handled.

Tests (RedisBrokerRecoveryTest)

test main this branch
testReapDropsAnOwnedClaimWhosePayloadIsGoneAndKeepsSweeping: two stranded claims, the first with its payload deleted. The sweep drops the orphan, requeues the second, clears the owner record and leaves the processing counter at 0 ✘ RuntimeException: Queue delivery payload is missing (Redis.php:467) ✔
testReapLeavesAPayloadlessClaimWhoseHandlerIsAlive: with a live heartbeat, the claim stays until its handler commits it ✘ same throw ✔

Run locally (phpswoole/swoole:6.2.0-php8.5-alpine, Redis 7):

  • RedisBrokerRecoveryTest 22/22; RedisRejectTest, RedisCodecTest and RedisConnectionRecoveryTest green.
  • RedisReservationTest and RedisExpiryTest fail only their Redis Cluster cases, identically on main: no cluster was running locally. RedisAuthTest/RedisClusterDsnTest need the auth Redis and the cluster from the package's compose; CI runs them.
  • Queue unit tier 150 (1 skipped, 1 incomplete, pre-existing). Pint, Rector, PHPStan (package config, max level) clean; bin/monorepo validate passes.

The new tests sit at the end of the class on purpose: PHPStan's baseline names the anonymous class in testReapToleratesAClaimSettledMidSweep by its line number, so inserting above it would shift that name and fail analysis.

After deploy (Cloud fra1)

  • CLOUD-3R40 stops getting new events.
  • The orphans in utopia-queue.processing.v1-{functions,jobs,webhooks} are cleared by the first sweep. Those deliveries were already unrecoverable; their payloads are gone.

@levivannoort levivannoort self-assigned this Oct 14, 2026
@luxor-code-review

luxor-code-review Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR extends the queue package's Redis broker with message-abandon/recovery behavior implemented as a Lua script, plus an E2E test covering broker recovery semantics.

Files Change
packages/queue/src/Broker/Redis/abandon.lua New Lua script performing the atomic abandon operation on the Redis broker.
packages/queue/src/Broker/Redis.php Wires the abandon script into the Redis broker.
packages/queue/tests/E2E/RedisBrokerRecoveryTest.php E2E test exercising broker recovery after abandon.

No issues met the reporting threshold; the change is approved.

Reviewed commit: 94dd077

@ghost

ghost commented Oct 14, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The Redis reaper now atomically abandons owned claims when their payload is gone, provided the owner is unchanged and no heartbeat is live. Recovery tests cover dropping such an orphan while continuing the sweep, and preserving a payload-less claim whose handler is still active.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
packages/queue/src/Broker/Redis.php Replaces the exception for owned payload-less claims with an atomic abandon attempt and accounts for claims that must be retained.
packages/queue/src/Broker/Redis/abandon.lua Adds guarded cleanup of the owner, processing entry, and processing counter for a payload-less, non-live claim.
packages/queue/tests/E2E/RedisBrokerRecoveryTest.php Adds coverage for continuing past an orphan and retaining a live handler's claim.

Merged main (abbb102); no changes to this PR's code since 94dd077 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/queue-redis-reap-orphan-claims (after).

Metric Before After Change
🚀 Requests/sec 217.35 220.19 ⚪ +1.3%
⏱️ Latency P50 79.93 ms 79.43 ms ⚪ -0.6%
⏱️ Latency P95 186.88 ms 180.73 ms ⚪ -3.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 79.43 180.73 13,680 220.19 -6.15
Account 149.4 270.45 720 12.27 -1.66
TablesDB 77.05 134.07 7,440 122.13 -18.99
Storage 74.06 153.59 3,600 61.11 -10.53
Functions 116.93 222.38 1,920 33.13 +19.79

Top API waits (after)

API request Max wait (ms)
account.name.update 445.24
account.prefs.update 405.01
functions.create 379.78
functions.variables.create 367.62
functions.variables.update 358.53

@levivannoort
levivannoort merged commit 868c7b6 into main Oct 14, 2026
8 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant