Skip to content

Commit 627da6b

Browse files
ericallamclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 6270380 commit 627da6b

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎docs/runs/max-duration.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Runs have no maximum duration. You set a default `maxDuration` for your project
88

99
Trigger is built for long running AI agents and workflows and we have seen Trigger.dev users with runs lasting more than six months.
1010

11-
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.
11+
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.
1212

1313
You must set a default maxDuration in your `trigger.config.ts` file, which will apply to all tasks unless overridden:
1414

@@ -33,14 +33,14 @@ You can set the `maxDuration` for a run in the following ways:
3333

3434
## How it works
3535

36-
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:
36+
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:
3737

38-
- `wait.for` calls
38+
- `wait.for` and `wait.until` calls longer than 5 seconds (shorter waits run in-process and count towards it)
3939
- `triggerAndWait` calls
4040
- `batchTriggerAndWait` calls
4141
- `wait.forToken` calls
4242

43-
You can inspect the CPU time of a task inside the run function with our `usage` utility:
43+
You can inspect the execution time of a task inside the run function with our `usage` utility:
4444

4545
```ts /trigger/max-duration.ts
4646
import { task, usage } from "@trigger.dev/sdk";
@@ -51,7 +51,7 @@ export const maxDurationTask = task({
5151
run: async (payload: any, { ctx }) => {
5252
let currentUsage = usage.getCurrent();
5353

54-
currentUsage.compute.attempt.durationMs; // The CPU time in milliseconds since the start of this attempt
54+
currentUsage.compute.attempt.durationMs; // Execution time in milliseconds since the start of this attempt, excluding paused waits
5555
},
5656
});
5757
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
In the Trigger.dev Cloud we automatically pause execution of tasks when they are waiting for
22
longer than a few seconds.
33

4-
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.
4+
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.
55

66
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.

0 commit comments

Comments
 (0)