You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/triggering.mdx
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -869,6 +869,7 @@ The `debounce` option accepts:
869
869
-`key` - A unique string to identify the debounce group (scoped to the task)
870
870
-`delay` - Duration string specifying how long to delay (e.g., "5s", "1m", "30s")
871
871
-`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
872
873
873
874
**How it works:**
874
875
@@ -877,6 +878,52 @@ The `debounce` option accepts:
877
878
3. Once no new triggers occur within the delay duration, the run executes
878
879
4. After the run starts executing, a new trigger with the same key will create a new run
879
880
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
+
awaitsummarizeChat.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
+
880
927
**Leading vs Trailing mode:**
881
928
882
929
By default, debounce uses **leading mode** - the run executes with data from the **first** trigger.
0 commit comments