Skip to content

Commit d27396d

Browse files
committed
chore(docs): cover maxDelay debounce option
1 parent b221719 commit d27396d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/triggering.mdx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ The `debounce` option accepts:
869869
- `key` - A unique string to identify the debounce group (scoped to the task)
870870
- `delay` - Duration string specifying how long to delay (e.g., "5s", "1m", "30s")
871871
- `mode` - Optional. Controls which trigger's data is used: `"leading"` (default) or `"trailing"`
872+
- `maxDelay` - Optional. Maximum total time from the first trigger before the run must execute
872873

873874
**How it works:**
874875

@@ -877,6 +878,52 @@ The `debounce` option accepts:
877878
3. Once no new triggers occur within the delay duration, the run executes
878879
4. After the run starts executing, a new trigger with the same key will create a new run
879880

881+
**Limiting total delay with `maxDelay`:**
882+
883+
By default, continuous triggers can delay execution indefinitely. The `maxDelay` option sets an upper bound on the total delay from the first trigger, ensuring the run eventually executes even with constant activity.
884+
885+
```ts
886+
await summarizeChat.trigger(
887+
{ conversationId: "123" },
888+
{
889+
debounce: {
890+
key: "conversation-123",
891+
delay: "10s", // Wait 10s after each message
892+
maxDelay: "5m", // But always run within 5 minutes of first trigger
893+
},
894+
}
895+
);
896+
```
897+
898+
This is useful for scenarios like:
899+
900+
- Summarizing AI chat threads that need periodic updates even during active conversations
901+
- Syncing data that should happen regularly despite continuous changes
902+
- Any case where you want debouncing but also guarantee timely execution
903+
904+
**Timeline example with `maxDelay`:**
905+
906+
Consider `delay: "5s"` and `maxDelay: "30s"` with triggers arriving every 2 seconds:
907+
908+
| Time | Event | Result |
909+
| :--- | :--- | :--- |
910+
| 0s | Trigger 1 | Run A created, scheduled for 5s |
911+
| 2s | Trigger 2 | Run A rescheduled to 7s |
912+
| 4s | Trigger 3 | Run A rescheduled to 9s |
913+
| ... | ... | ... |
914+
| 26s | Trigger 14 | Run A rescheduled to 31s |
915+
| 28s | Trigger 15 | Would reschedule to 33s, but exceeds maxDelay (30s). Run A executes, Run B created |
916+
| 30s | Trigger 16 | Run B rescheduled to 35s |
917+
918+
Without `maxDelay`, continuous triggers would prevent the run from ever executing. With `maxDelay: "30s"`, execution is guaranteed within 30 seconds of the first trigger.
919+
920+
<Note>
921+
The `maxDelay` value is evaluated from each trigger call, not stored with the original run. This
922+
means if you pass different `maxDelay` values for the same debounce key, each trigger uses its own
923+
`maxDelay` to check against the original run's creation time. For consistent behavior, use the
924+
same `maxDelay` value for all triggers with the same debounce key.
925+
</Note>
926+
880927
**Leading vs Trailing mode:**
881928

882929
By default, debounce uses **leading mode** - the run executes with data from the **first** trigger.

0 commit comments

Comments
 (0)