Skip to Content

Replaying

A replay is a copy of a run with the same payload that runs on the current version of the environment. This is useful if something went wrong and you want to try again with your current code.

Replaying from the UI

Click the Replay button in the top right
Confirm replay settings

You can edit the payload (1) (if available) and choose the environment (2) to replay the run in.

Detecting replays in your task

You can check if a run is a replay using the context object:

export const myTask = ({
  : "my-task",
  : async (payload, {  }) => {
    if (.run.isReplay) {
      // This run is a replay of a previous run
    }
  },
});

Replaying using the SDK

You can replay a run using the SDK:

Your backend code
import {  } from "@trigger.dev/sdk";

const replayedRun = await .replay(run.id);
// { id: "run_cmv6ixfn30008ct9kegazjolu" }

The new run reuses the original run's payload, metadata, tags, queue, concurrency key, and machine. Pass options to override any of them for the new run:

Your backend code
import {  } from "@trigger.dev/sdk";

const replayedRun = await .replay(run.id, {
  : { userId: "user_456" },
  : { source: "replay" },
  : ["replayed"],
  : "large-1x",
  : "10m",
});

The options use the same names as trigger() options: payload, metadata, tags, queue, concurrencyKey, machine, version, region, delay, ttl, idempotencyKey, idempotencyKeyTTL, maxAttempts, maxDuration, and priority. If you leave out payload, metadata, tags, queue, concurrencyKey, or machine, the new run uses the original run's value. The other options fall back to the task's current defaults, and without version the replay runs on the current version (the promoted one, which isn't always the newest deploy). The replay always runs in the same environment as the original run.

A queue must already exist in the environment, and a version must be a version deployed to it. Otherwise the replay fails with an error and no run is created.

A replay starts a new run, so the API key or token you replay with needs permission to trigger the task as well as write access to the run.

The SDK serializes a payload override the same way trigger() does, so values like Date, BigInt, Map and Set reach the task with their types.

When you call trigger() or batchTrigger() on a task you receive back a run handle which has an id property. You can use that id to replay the run.

You can also access the run id from inside a run. You could write this to your database and then replay it later.

export const simpleChildTask = ({
  : "simple-child-task",
  : async (payload, {  }) => {
    // the run ID (and other useful info) is in ctx
    const runId = .run.id;
  },
});

Bulk replaying

See Bulk actions for more information.

Was this page helpful?

Last updated

Edit on GitHub

On this page