Skip to content

fix(run-engine): treat delay=0 as immediate retry, not exhausted retries - #5162

Closed
okxint wants to merge 3 commits into
triggerdotdev:mainfrom
okxint:fix/retry-delay-zero-treated-as-no-retry
Closed

okxint wants to merge 3 commits into
triggerdotdev:mainfrom
okxint:fix/retry-delay-zero-treated-as-no-retry

Conversation

@okxint

@okxint okxint commented Nov 27, 2026

Copy link
Copy Markdown

calculateNextRetryDelay() returns undefined when retries are exhausted and a number (including 0) when a retry should occur.

Two guards in retrying.ts used !delay to check for no more retries, but this coerces 0 to false, so a task configured with an immediate retry (delay = 0ms) gets incorrectly failed instead of retried.

OOM retry path (line 70):

// Before
if (!delay) {

// After
if (delay === undefined) {

General retry path (line 183):

// Before
if (!nextDelay) {

// After
if (nextDelay === undefined) {

This matches how calculateNextRetryDelay signals "no retry" (by returning undefined) vs "retry immediately" (returning 0).

okxint added 2 commits October 9, 2026 15:21
Multiplying Date.getTime() by 1_000_000 as a float before converting
to BigInt causes IEEE 754 precision loss once the product exceeds
Number.MAX_SAFE_INTEGER (~9007T, which ms * 1e6 hits around 2255 AD).

The correct pattern already exists in convertDateToNanoseconds():
  BigInt(date.getTime()) * BigInt(1_000_000)

Apply it consistently to the three call sites that still use the
float-multiply pattern (getNowInNanoseconds, calculateDurationFromStart,
and the runEngineHandlers retry-event recordEvent call).
…for cancelled runs

booleanHelpersFromRunStatus omitted CANCELED from failedStatuses, so realtime run shapes returned isCompleted: false and isFailed: false for cancelled runs. The REST API presenter correctly sets both to true. Consumers checking run.isCompleted to gate teardown logic silently skipped cancelled runs.
@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7f7d24a

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

@github-actions

Copy link
Copy Markdown
Contributor

Hi @okxint, 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 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 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

calculateNextRetryDelay() returns undefined when retries are exhausted
and a number (including 0) when a retry should happen. The !delay guard
was coercing 0 to false, causing runs configured with an immediate retry
(delay of 0ms) to be treated as having no retries left and failed
prematurely.

Switch to explicit undefined checks in both the OOM retry path and the
general retry path.

@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 found 5 potential issues.

Devin Review

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.

🔍 Three unrelated fixes in one PR

The PR describes zero-delay retries but also changes trace timestamps and Realtime status helpers. The contribution guide requires one issue per PR.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

const delay = calculateNextRetryDelay(oomResult.retrySettings, attemptNumber ?? 1);

if (!delay) {
if (delay === undefined) {

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.

🔴 Immediate OOM retries exceed attempt limits

When a run reaches its per-run limit and runs out of memory, retryOutcomeFromCompletion can still schedule a zero-delay retry. retryOOMOnMachine uses the task’s retry settings instead of the run’s attempt limit. The extra attempt runs on the fallback machine.

Learn more

The trigger service passes the caller’s maxAttempts to the engine. Dequeue preserves that per-run limit and saves the task’s original retry settings separately. The OOM lookup reads only the task settings, and the ordinary attempt-limit check runs after the OOM branch has already returned. Previously a zero delay stopped that branch before it could use the wrong limit. Now attempt completion requeues the run on the fallback machine.

Example: Deploy a task with retry.maxAttempts: 3, minTimeoutInMs: 0, and an OOM fallback machine. Trigger it with { maxAttempts: 1 } and let the first attempt run out of memory. The engine queues a second attempt instead of ending the run.

Recommended fix: Include the run’s maxAttempts in retryOOMOnMachine’s existing read and use it as the effective attempt limit when present, without discarding the valid zero delay. Add an engine test that compares an immediate OOM retry with and without a one-attempt override.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

const waitingStatuses = ["WAITING"];
const executingStatuses = ["DEQUEUED", "EXECUTING"];
const failedStatuses = ["FAILED", "CRASHED", "SYSTEM_FAILURE", "EXPIRED", "TIMED_OUT"];
const failedStatuses = ["FAILED", "CRASHED", "SYSTEM_FAILURE", "EXPIRED", "TIMED_OUT", "CANCELED"];

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.

🟡 Canceled runs reported as failures

When a subscriber receives a canceled run, booleanHelpersFromRunStatus now emits isFailed: true alongside isCancelled: true. The Realtime run contract treats cancellation separately from failure.

Learn more

subscribeToRun delivers run objects with status helpers, and the Realtime contract lists failure statuses separately from cancellation. RunSubscription closes based on finishedAt, not isFailed, so marking the run failed is not necessary to close its subscription.

Example: Cancel a run while subscribed to it. The final update reports status: "CANCELED", isCancelled: true, and now isFailed: true, so a subscription that routes failed runs to a failure handler also routes cancellations there.

Recommended fix: Keep CANCELED out of failedStatuses. If the intended behavior is to mark canceled runs complete, add cancellation to the isCompleted expression separately and update its documentation.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

const waitingStatuses = ["WAITING"];
const executingStatuses = ["DEQUEUED", "EXECUTING"];
const failedStatuses = ["FAILED", "CRASHED", "SYSTEM_FAILURE", "EXPIRED", "TIMED_OUT"];
const failedStatuses = ["FAILED", "CRASHED", "SYSTEM_FAILURE", "EXPIRED", "TIMED_OUT", "CANCELED"];

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.

🔍 Missing changeset for Realtime status

The package changelog has no changeset for the Realtime status change. The release-note rules require one for user-visible package behavior.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

type: fix
---

Fix OTLP trace timestamps losing precision for runs after approximately 2255 AD. Timestamps are now computed with full 64-bit integer arithmetic.

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.

🔍 Misleading date in timestamp release note

The old timestamp conversion already rounds some present-day dates. The fix affects server-generated event times, not incoming OTLP timestamps.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

1 participant