Skip to content

bug: debounced run stays DELAYED forever when a trigger reschedules it while its enqueueDelayedRun job is in flight #5176

Backlog

Description

@ubrimah

Provide environment information

Trigger.dev Cloud, production environment. @trigger.dev/sdk and CLI 4.5.12, runtime node-22. The bug is server-side, so local envinfo output is not relevant.

Describe the bug

A run was triggered with debounce (mode: "trailing", delay: "2s"). A second trigger with the same debounce key arrived almost exactly as the first delay expired. The second trigger was accepted: the run's payload was replaced (trailing mode) and delayUntil moved about one second later.

The run then never left DELAYED. queued_at stayed null, and over an hour later it was still Delayed with delay_until in the past, until we cancelled it. The caller got no error.

Expected: the run is enqueued at the new delayUntil.

Timeline (UTC, 2026-12-03):

  • 19:24:20.936: run created by the first debounced trigger (due ≈ 19:24:22.94)
  • ≈ 19:24:22.5 to 22.9: second trigger with the same key; delay_until becomes 19:24:24.000
  • 20:28: still Delayed with queued_at null; cancelled by hand

In the same project, plain delay runs work. So did earlier debounced runs whose second trigger arrived well before expiry.

Reproduction repo

None. This is a server-side timing race: the second trigger has to land between the dequeue and the ack of the run's enqueueDelayedRun worker job.

To reproduce

await myTask.trigger(payloadA, { debounce: { key: "k", delay: "2s", mode: "trailing" }, idempotencyKey: "a", concurrencyKey: "x" });
// about 2 s later, as close to the first delay's expiry as possible:
await myTask.trigger(payloadB, { debounce: { key: "k", delay: "2s", mode: "trailing" }, idempotencyKey: "b", concurrencyKey: "x" });

Repeat with the second trigger timed around the expiry. Occasionally the run stays DELAYED permanently.

Suggested fix

Suspected mechanism, from internal-packages/run-engine/src/engine/systems/delayedRunSystem.ts and packages/redis-worker/src/queue.ts:

  1. The enqueueDelayedRun:<runId> job comes due and is dequeued. The dequeue script keeps the same id in the sorted set with a visibility-timeout score.
  2. The debounce trigger calls rescheduleDelayedRun. It updates delayUntil and calls worker.reschedule(id, delayUntil), which is ZADD XX on that same, in-flight id.
  3. enqueueDelayedRun takes the run lock after the reschedule, sees run.delayUntil > now, and returns early ("the rescheduled worker job will handle it").
  4. The worker acks the job by id (ZREM + HDEL). That deletes the entry the reschedule just re-armed, so nothing is left to enqueue the run.

Possible fixes:

  • Version the job on reschedule, for example a new deduplicationKey, so the in-flight ack becomes a no-op. ackItem already supports this.
  • Give each schedule its own job id.
  • Re-arm the job after the early return.

A periodic sweep for DELAYED runs whose delayUntil is well past would also catch any other lost wakeup.

Additional information

We now catch these stranded runs with our own watchdog. We can share the affected run ID privately if that helps.

Activity

  1. nik1062 commented on Dec 4, 2026

    @nik1062

    Hi! I'd like to investigate and fix this debounce/reschedule race condition—could you please assign it to me? I'll trace enqueueDelayedRun vs trailing debounce rescheduling when delayUntil moves while the job is in flight, ensure the run is re-enqueued for the updated delayUntil instead of staying stuck in DELAYED, and add regression tests for the concurrent reschedule window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions