Repository navigation
Description
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_untilbecomes 19:24:24.000 - 20:28: still
Delayedwithqueued_atnull; 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:
- 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. - The debounce trigger calls
rescheduleDelayedRun. It updatesdelayUntiland callsworker.reschedule(id, delayUntil), which isZADD XXon that same, in-flight id. enqueueDelayedRuntakes the run lock after the reschedule, seesrun.delayUntil > now, and returns early ("the rescheduled worker job will handle it").- 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.ackItemalready 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
nik1062 commentedon Dec 4, 2026
Hi! I'd like to investigate and fix this debounce/reschedule race condition—could you please assign it to me? I'll trace
enqueueDelayedRunvs trailing debounce rescheduling whendelayUntilmoves while the job is in flight, ensure the run is re-enqueued for the updateddelayUntilinstead of staying stuck inDELAYED, and add regression tests for the concurrent reschedule window.