What’s new in v4?
Feature | Description |
---|---|
Wait for token | Create and wait for tokens to be completed, enabling approval workflows and waiting for arbitrary external conditions. |
Wait idempotency | Skip waits if the same idempotency key is used again when using wait for, wait until, or wait for token. |
Priority | Specify a priority when triggering a task. |
Global lifecycle hooks | Register global lifecycle hooks that are executed for all runs, regardless of the task. |
onWait and onResume | Run code when a run is paused or resumed because of a wait. |
onComplete | Run code when a run completes, regardless of whether it succeeded or failed. |
onCancel | Run code when a run is cancelled. |
Hidden tasks | Create tasks that are not exported from your trigger files but can still be executed. |
Middleware & locals | The middleware system runs at the top level, executing before and after all lifecycle hooks. The locals API allows sharing data between middleware and hooks. |
useWaitToken | Use the useWaitToken hook to complete a wait token from a React component. |
ai.tool | Create an AI tool from an existing schemaTask to use with the Vercel AI SDK. |
Node.js support
Trigger.dev runs your tasks on specific Node.js versions:v3
- Node.js
21.7.3
v4
- Node.js
21.7.3
(default) - Node.js
22.16.0
(node-22
) - Bun
1.2.20
(bun
)
runtime
field in your trigger.config.ts
file.
How to migrate to v4
First read the deprecations and breaking changes sections below. We recommend the following steps to migrate to v4:- Install the v4 package.
- Run the
trigger dev
CLI command and test your tasks locally, fixing any breaking changes. - Deploy to the staging environment and test your tasks in staging, fixing any breaking changes. (this step is optional, but highly recommended)
- Once you’ve verified that v4 is working as expected, you should deploy your application backend with the updated v4 package.
- Once you’ve deployed your application backend, you should deploy your tasks to the production environment.
Once v4 is activated in your environment, there will be a period of time where old runs will
continue to execute using v3, while new runs will use v4. Because these engines use completely
different underlying queues and concurrency models, it’s possible you may have up to double the
amount of concurrently executing runs. Once the runs drain from the old run engine, the
concurrency will return to normal.
Migrate using AI
Use the prompt in the accordion below to help you migrate your v3 tasks to v4. The prompt gives good results when using Claude 4 Sonnet. You’ll need a relatively large token limit.Copy paste this prompt in full
Copy paste this prompt in full
Installation
To opt-in to using v4, you will need to update your dependencies to the latest version:@trigger.dev/*
packages to a 4.x
version.
Deprecations
We’ve deprecated the following APIs:@trigger.dev/sdk/v3
We’ve deprecated the@trigger.dev/sdk/v3
import path and moved to a new path:
handleError
and init
We’ve renamed the handleError
hook to catchError
to better reflect that it can catch and react to errors. handleError
will be removed in a future version.
init
was previously used to initialize data used in the run function:
locals
API and middleware. See the Improved middleware and locals section for more details.
toolTask
We’ve deprecated thetoolTask
function, which created both a Trigger.dev task and a tool compatible with the Vercel AI SDK:
toolTask
function with the ai.tool
function, which creates an AI tool from an existing schemaTask
. See the ai.tool page for more details.
Breaking changes
Queue changes
Previously, it was possible to specify a queue name of a queue that did not exist, along with a concurrency limit. The queue would then be created “on-demand” with the specified concurrency limit. If the queue did exist, the concurrency limit of the queue would be updated to the specified value:queue
function:
concurrencyKey
you can specify the queue
and concurrencyKey
like this:
concurrencyKey
, a new queue will be created using the concurrencyLimit
from the queue. This allows you to have a queue per user.
Lifecycle hooks
We’ve changed the function signatures of the lifecycle hooks to be more consistent and easier to use, by unifying all the parameters into a single object that can be destructured. Previously, hooks received a payload as the first argument and then an additional object as the second argument:Context changes
We’ve made a few small changes to thectx
object:
ctx.attempt.id
andctx.attempt.status
have been removed.ctx.attempt.number
is still available.ctx.task.exportName
has been removed (since we no longer require tasks to be exported to be triggered).
BatchTrigger changes
ThebatchTrigger
function no longer returns a runs
list directly. In v3, you could access the runs directly from the batch handle:
batch.retrieve()
method to get the batch with its runs:
OpenTelemetry
We are now using newer versions of the OpenTelemetry packages. This means that if you’re using custom exporters you may need to update the packages:Package | Previous Version | New Version | Change Type |
---|---|---|---|
@opentelemetry/api-logs | 0.52.1 | 0.203.0 | Major update |
@opentelemetry/exporter-logs-otlp-http | 0.52.1 | 0.203.0 | Major update |
@opentelemetry/exporter-trace-otlp-http | 0.52.1 | 0.203.0 | Major update |
@opentelemetry/instrumentation | 0.52.1 | 0.203.0 | Major update |