Repository navigation
Fix: PEL reaper + consumer GC to prevent leaf-worker KEDA deadlock - #22
Merged
Merged
Conversation
…KEDA deadlock - Add deleteConsumer(), gcIdleConsumers(), reapDeadLetters() to WorkQueue - leaf-job startup sweeps stale PEL entries past maxAttempts (dead-letters them with done-marker) so pendingEntriesCount drops and KEDA scales to zero - On clean exit, deleteConsumer() removes our consumer registration - gcIdleConsumers() removes orphaned consumers with 0 pending entries - 5 new unit tests covering the new methods Closes #17 Signed-off-by: Paolo Dettori <[email protected]>
pdettori
commented
Jun 29, 2026
pdettori
left a comment
Member
Author
There was a problem hiding this comment.
(Posting as a comment review — GitHub won't let an author approve their own PR. No blocking issues; this would otherwise be an APPROVE.)
Clean, focused fix for the leaf-worker KEDA deadlock. The PEL reaper + consumer GC approach is sound, the comments explain the scale-to-zero rationale well, and the new queue methods are correct. Tests hit real Redis and cover both branches of each method.
Note on CI: only the DCO check runs in this repo (passing) — the 9/9 unit-test and TypeScript typecheck claims are local-only, not enforced by a CI workflow.
One suggestion and one nit inline (neither blocking).
Assisted-By: Claude Code
…ch const - Skip ACK when xClaim returns empty (entry reclaimed by another consumer between xPendingRange inspect and xClaim) - Wrap JSON.parse in try/catch so a malformed envelope doesn't crash the startup sweep; ACK still runs to clear the stale entry - Extract REAP_BATCH=100 named const with comment explaining cross-startup drain behavior - Log warning for entries dead-lettered with unrecoverable envelope Addresses PR #22 review feedback. Signed-off-by: Paolo Dettori <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deleteConsumer(),gcIdleConsumers(),reapDeadLetters()to@sh/work-queueleaf-jobstartup sweeps stale PEL entries pastmaxAttempts→ writes failed done-markers and ACKs them sopendingEntriesCountdrops and KEDA can scale to zerodeleteConsumer()removes our consumer registration (bounds consumer list growth)gcIdleConsumers()removes orphaned consumers with 0 pending entries idle > 5 minRoot cause
When a
leaf-workerpod dies afterXREADGROUPbut beforeXACK, its entry stays in the PEL forever. KEDA'spendingEntriesCounttrigger keeps the ScaledJobACTIVE, spawning pods that find no reclaimable work (entries must be idle > 90s) and exit immediately — perpetual churn with no path to scale-to-zero.How it works now
reapDeadLetters): inspects PEL viaXPENDING RANGE, selectivelyXCLAIM+XACKentries that are both stale (idle > 90s) AND past retry limit (deliveryCount > 3). Writes afaileddone-marker so the orchestrator knows.gcIdleConsumers): removes consumers with 0 pending entries idle > 5 min (orphaned by completed/crashed pods).deleteConsumer): on the idle/success exit path, removes our consumer so it doesn't accumulate.Test plan
deleteConsumer,gcIdleConsumers,reapDeadLetters(all hit real Redis)Closes #17
Assisted-By: Claude Code