Skip to content

fix(queue): drop the retried job's old payload when retry() requeues it - #14524

Merged
HarshMN2345 merged 5 commits into
mainfrom
fix-queue-retry-payload
Oct 29, 2026
Merged

HarshMN2345 merged 5 commits into
mainfrom
fix-queue-retry-payload

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Broker\Redis::retry() requeued each failed job under a fresh pid but left the payload under the old pid (<namespace>.jobs.<queue>.<pid>). Nothing references that pid once it leaves the failed list, and with the default jobTtl of 0 it never expires, so every queue-retry run grew Redis memory by one payload per retried job.

retry.lua now takes the old payload key as an optional third key and deletes it in the same atomic step that moves the job from the failed list to the ready queue, as reclaim.lua already does for reap(). Payloads of jobs parked on the dead list are kept, since the dead list still references them.
A failed job whose stored payload the codec cannot decode is now parked on the dead list instead of having its pid dropped and its payload orphaned.

Verified:

  • retry.lua against Redis 7: requeue removes the old payload, parking keeps it, an expired entry is dropped from the failed list, a stale pid is a no-op
  • queue unit tier, PHPStan and Pint: left to CI after the merge with main

Closes #14491

@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Add the WRONGTYPE guard sibling scripts have (requeue.lua:3) — The new requeue.lua calls LPUSH/DEL with no key-type validation, while every sibling script in packages/queue/src/Broker/Redis/ (reclaim.lua:3-7, settle.lua:7-11, claim.lua, abandon.lua) rejects unexpected key types with a WRONGTYPE error before mutating anything.

This small PR touches the queue package's Redis broker, adjusting the requeue.lua script so requeueing a job back onto the ready list is guarded against WRONGTYPE errors when the target key has unexpected contents. No API surface or other subsystems are affected.

Files Change
packages/queue/src/Broker/Redis/requeue.lua Adds a type guard to the requeue Lua script so it tolerates unexpected key types instead of erroring mid-requeue.
packages/queue/src/Broker/Redis.php Broker-side wiring for the updated requeue script.

Reviewed commit: 931cd0f

@ghost

ghost commented Oct 15, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The still-open test-coverage finding about asserting deletion of the old payload remains unresolved.

Redis retry now moves failed jobs to the ready or dead list through a Lua script that checks the current failed-list tail and performs the transition with old-payload cleanup. Failed entries whose payload is missing are removed, while entries with payloads that the codec cannot decode are retained on the dead list for inspection.

Latest changes: The newest commits couple failed-list removal with requeueing or dead-lettering, guard the transition against a changed tail entry, and validate destination list types before mutation.

Verdict New comments Fixed Still open
💬 Commented 0 0 1

[!NOTE]

Newer commits exist (`8886a58`) and will be reviewed. This review is of `9b01b3d` and does not approve it.
Fix with agent prompt
### Issue 1
packages/queue/src/Broker/Redis.php:523-526
**Assert retry removes the old payload**

The existing `RedisBrokerRecoveryTest::testRetryRequeuesARejectedMessageWithItsAttemptCount` verifies the replacement is readable, but not that the original `jobs.*.<pid>` key is gone. A regression that omits this deletion would still pass the current retry coverage.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 2
File Change
packages/queue/src/Broker/Redis.php Uses the retry script for guarded failed-list transitions and counts only jobs successfully requeued.
packages/queue/src/Broker/Redis/retry.lua Checks list key types and the failed-list tail before moving an entry and deleting the old payload.
⏳ Still open from earlier reviews · 1

Merged main (c0b34bb); no changes to this PR's code since 9b01b3d · 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 A · Looks good to merge. Summary

Comment thread packages/queue/src/Broker/Redis.php Outdated
Comment on lines +523 to +526
$this->script($this->commands, 'requeue', [
"{$queue->namespace}.queue.{$queue->name}",
"{$queue->namespace}.jobs.{$queue->name}.{$pid}",
], [$this->retryPayload($queue, $job)]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Assert retry removes the old payload

The existing RedisBrokerRecoveryTest::testRetryRequeuesARejectedMessageWithItsAttemptCount verifies the replacement is readable, but not that the original jobs.*.<pid> key is gone. A regression that omits this deletion would still pass the current retry coverage.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/queue/src/Broker/Redis.php
Line: 523-526

Comment:
**Assert retry removes the old payload**

The existing `RedisBrokerRecoveryTest::testRetryRequeuesARejectedMessageWithItsAttemptCount` verifies the replacement is readable, but not that the original `jobs.*.<pid>` key is gone. A regression that omits this deletion would still pass the current retry coverage.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • 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 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-queue-retry-payload (after).

Metric Before After Change
🚀 Requests/sec 213.81 215.58 ⚪ +0.8%
⏱️ Latency P50 79.59 ms 81.91 ms ⚪ +2.9%
⏱️ Latency P95 190.78 ms 184.9 ms ⚪ -3.1%
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 81.91 184.9 13,680 215.58 -5.89
Account 152.2 277.86 720 12.05 -14.4
TablesDB 80.35 145.79 7,440 120.27 +3.52
Storage 72.93 168.63 3,600 59.8 -18.22
Functions 113.74 216.58 1,920 32.49 -33.8

Top API waits (after)

API request Max wait (ms)
account.name.update 416.82
account.prefs.update 399.43
functions.create 389.89
functions.variables.update 349.36
storage.buckets.create 323.24

@HarshMN2345
HarshMN2345 merged commit 0f1e945 into main Oct 29, 2026
66 checks passed
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.

🐛 Bug Report: queue-retry requeues a copy under a new job ID and never deletes the original payload, which stays in Redis without a TTL

2 participants