From 627da6b6e89c989352597169d216cc83f72ecd0b Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Thu, 3 Dec 2026 15:54:19 +0000 Subject: [PATCH] docs: clarify wait billing and what maxDuration measures Token and child-run waits are never billed; the 5 second rule only applies to wait.for/wait.until (over 5s is free, 5s or less billed in full). maxDuration compares wall time minus paused waits, not CPU time, so awaited network calls count. Co-Authored-By: Claude Opus 5.5 --- docs/runs/max-duration.mdx | 10 +++++----- docs/snippets/paused-execution-free.mdx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/runs/max-duration.mdx b/docs/runs/max-duration.mdx index babe321996c..613d29c771e 100644 --- a/docs/runs/max-duration.mdx +++ b/docs/runs/max-duration.mdx @@ -8,7 +8,7 @@ Runs have no maximum duration. You set a default `maxDuration` for your project Trigger is built for long running AI agents and workflows and we have seen Trigger.dev users with runs lasting more than six months. -The `maxDuration` parameter sets a maximum compute time limit for tasks. When a task exceeds this duration, it will be automatically stopped. This helps prevent runaway tasks and manage compute resources effectively. +The `maxDuration` parameter limits how long a task can execute. When a task exceeds this duration, it will be automatically stopped. This helps prevent runaway tasks and manage compute resources effectively. You must set a default maxDuration in your `trigger.config.ts` file, which will apply to all tasks unless overridden: @@ -33,14 +33,14 @@ You can set the `maxDuration` for a run in the following ways: ## How it works -The `maxDuration` is set in seconds, and is compared to the CPU time elapsed since the start of a single execution (which we call [attempts](/runs#attempts)) of the task. The CPU time is the time that the task has been actively running on the CPU, and does not include time spent waiting during the following: +The `maxDuration` is set in seconds, and is compared to the execution time of a single attempt (see [attempts](/runs#attempts)) of the task. Execution time is the wall-clock time since the attempt started, minus any time the run was paused. It includes time spent awaiting network calls such as LLM responses. It does not include time spent paused during the following: -- `wait.for` calls +- `wait.for` and `wait.until` calls longer than 5 seconds (shorter waits run in-process and count towards it) - `triggerAndWait` calls - `batchTriggerAndWait` calls - `wait.forToken` calls -You can inspect the CPU time of a task inside the run function with our `usage` utility: +You can inspect the execution time of a task inside the run function with our `usage` utility: ```ts /trigger/max-duration.ts import { task, usage } from "@trigger.dev/sdk"; @@ -51,7 +51,7 @@ export const maxDurationTask = task({ run: async (payload: any, { ctx }) => { let currentUsage = usage.getCurrent(); - currentUsage.compute.attempt.durationMs; // The CPU time in milliseconds since the start of this attempt + currentUsage.compute.attempt.durationMs; // Execution time in milliseconds since the start of this attempt, excluding paused waits }, }); ``` diff --git a/docs/snippets/paused-execution-free.mdx b/docs/snippets/paused-execution-free.mdx index 6372d1f783b..db948ad213d 100644 --- a/docs/snippets/paused-execution-free.mdx +++ b/docs/snippets/paused-execution-free.mdx @@ -1,6 +1,6 @@ In the Trigger.dev Cloud we automatically pause execution of tasks when they are waiting for longer than a few seconds. -When triggering and waiting for subtasks, the parent is checkpointed and while waiting does not count towards compute usage. When waiting for a time period (`wait.for` or `wait.until`), a wait longer than 5 seconds does not count towards compute usage. +When triggering and waiting for subtasks (`triggerAndWait`, `batchTriggerAndWait`) or waiting on a [waitpoint token](/wait-for-token) (`wait.forToken`), the run is checkpointed and the wait does not count towards compute usage, however long it lasts. When waiting for a time period (`wait.for` or `wait.until`), a wait longer than 5 seconds does not count towards compute usage at all, and a wait of 5 seconds or less is billed in full. Free compute isn't the same as freed concurrency: the concurrency slot is only released once we've snapshotted the machine and shut it down. For `wait.for` and `wait.until` that happens 60 seconds into the wait, so anything shorter stays `EXECUTING` and holds its slot for the whole wait. \ No newline at end of file