Configure the vCPUs and RAM allocated to each task run, and handle out-of-memory errors gracefully.
Each Trigger.dev task run executes inside an isolated container. The machine option controls how much compute that container is allocated. Higher-spec machines increase cost but improve performance for CPU-bound or memory-intensive tasks.
You can override the machine when triggering a task — useful when the required resources depend on the payload (e.g. a large file upload or a high-data customer):
import { tasks } from "@trigger.dev/sdk";import type { heavyTask } from "./trigger/heavy-task";await tasks.trigger<typeof heavyTask>( "heavy-task", { message: "hello world" }, { machine: "large-2x" });
When a task run is killed due to exceeding the machine’s memory limit, you’ll see an error like:
TASK_PROCESS_OOM_KILLED. Your run was terminated due to exceeding the machine'smemory limit. Try increasing the machine preset in your task options or replayusing a larger machine.
Trigger.dev automatically detects the following OOM conditions:
The Node.js V8 heap limit is exceeded
The entire container process exceeds the machine’s memory limit
A child process (e.g. ffmpeg) exceeds the memory limit and exits with a non-zero code
OOM retry only triggers on out-of-memory errors. It does not permanently change the machine for new
runs — if you consistently see OOM errors, increase the machine property directly.
If your code detects it is about to run out of memory (for example, a native library signals an allocation failure), you can throw OutOfMemoryError to trigger the same OOM handling:
To diagnose OOM errors, add the ResourceMonitor helper to your project. It logs memory, CPU, and disk usage at a regular interval:
/trigger/tasks.ts
import { tasks } from "@trigger.dev/sdk";import { ResourceMonitor } from "../resourceMonitor.js";// Apply to all tasks via middlewaretasks.middleware("resource-monitor", async ({ ctx, next }) => { const resourceMonitor = new ResourceMonitor({ ctx }); if (process.env.RESOURCE_MONITOR_ENABLED === "1") { resourceMonitor.startMonitoring(10_000); // Log every 10 seconds } await next(); resourceMonitor.stopMonitoring();});
To also monitor child process memory (e.g. an ffmpeg subprocess):
const resourceMonitor = new ResourceMonitor({ ctx, processName: "ffmpeg",});
The ResourceMonitor is a helper class you add to your own project. Copy the implementation from the Trigger.dev examples repository or write a simplified version using Node.js process.memoryUsage().