Skip to content

fix(run-engine): requeue a failed restore at the run's queue position (#5104) - #5114

Closed
granbellllc-png wants to merge 1 commit into
triggerdotdev:mainfrom
granbellllc-png:fix/issue-5104-resumed-run-queue-position
Closed

granbellllc-png wants to merge 1 commit into
triggerdotdev:mainfrom
granbellllc-png:fix/issue-5104-resumed-run-queue-position

Conversation

@granbellllc-png

Copy link
Copy Markdown

Resolves #5104

Summary

When a run resumes from a checkpoint (e.g. after triggerAndWait, batchTriggerAndWait, or waitpoints), it is re-enqueued at its original queue position so waiting runs dequeue before newly triggered runs.

However, if the restore fails before execution can continue (such as a heartbeat stall, supervisor requeue due to runner crash/OOM, or transient dequeue preparation error), tryNackAndRequeue previously nacked the message with no explicit retryAt timestamp. Under default behavior, RunQueue.#callNackMessage calculated the message score as now + backoff. This caused the resumed run to lose its position in the queue, falling behind every run triggered after it—which, in busy queues with low concurrency limits, could delay the run for hours.

Solution

  1. In RunQueue.nackMessage, added keepQueuePosition?: boolean.
  2. In RunAttemptSystem.tryNackAndRequeue, passed keepQueuePosition: checkpointId !== undefined.
  3. In RunQueue.nackMessage, when keepQueuePosition is true and message.attempt <= 1 (the first requeue of a resume), retryAt is scored at message.timestamp (its original enqueue timestamp/score) rather than now + backoff.
  4. Subsequent retries (message.attempt > 1) retain standard exponential backoff, preventing tight retry loops if a restore repeatedly fails. Cold starts (without checkpointId) remain unaffected.
  5. Added unit/container regression test in restoreOutcome.test.ts verifying that a requeued restore dequeues ahead of runs triggered after it on its first retry, and applies backoff on subsequent failures.

…triggerdotdev#5104)

A run resumed from a checkpoint is re-enqueued at its original queue position, so waiting runs dequeue before new runs. When the restore fails before the run continues (heartbeat stall, supervisor requeue, or dequeue error), tryNackAndRequeue previously nacked the message with no retry time, scoring it at now + backoff. Consequently, the resumed run was placed behind newer runs that were triggered after it.

This fix:
1. Adds keepQueuePosition to RunQueue.nackMessage.
2. In tryNackAndRequeue, passes keepQueuePosition: checkpointId !== undefined.
3. On the first requeue of a checkpointed run (message.attempt <= 1), scores the message at its original timestamp instead of applying backoff. Subsequent retries retain exponential backoff to avoid tight retry loops.
4. Adds regression test in restoreOutcome.test.ts verifying that the first requeue of a restore dequeues ahead of newer runs, while subsequent failures apply backoff.
@changeset-bot

changeset-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7143a1d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

Hi @granbellllc-png, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Nov 11, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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: a resumed run whose restore fails is requeued behind newer runs

1 participant