@@ -45,9 +45,13 @@ Each retry:
4545- Returns cached results for completed steps
4646- Re-executes the failed step
4747
48- ## Exponential Backoff
48+ ## Retry Policy
49+
50+ Both steps and workflows use the same retry policy shape. A retry policy
51+ controls exponential backoff — how long to wait between retries, how fast delays
52+ grow, and when to stop retrying.
4953
50- Failed workflows are rescheduled with increasing delays :
54+ With the defaults, retry delays look like this :
5155
5256| Attempt | Delay |
5357| ------- | --------- |
@@ -58,28 +62,58 @@ Failed workflows are rescheduled with increasing delays:
5862| 5 | ~ 8s |
5963| ... | ... |
6064
61- This prevents overwhelming external services during outages.
65+ This prevents overwhelming external services during outages. Retries continue
66+ until canceled, until ` deadlineAt ` is reached (or the next retry would pass it),
67+ or until ` maximumAttempts ` is exhausted.
6268
63- By default, retries continue until canceled or until ` deadlineAt ` is reached (or
64- the next retry would pass it). If ` maximumAttempts ` is configured, the workflow
65- is also marked ` failed ` once that limit is reached.
69+ Retry policies have the following fields:
6670
67- ## Retry Policy
71+ | Field | Default | Description |
72+ | -------------------- | ---------- | --------------------------------------------------- |
73+ | ` initialInterval ` | ` "1s" ` | Delay before the first retry after a failed attempt |
74+ | ` backoffCoefficient ` | ` 2 ` | Multiplier applied to each subsequent retry delay |
75+ | ` maximumInterval ` | ` "100s" ` | Upper bound for retry delay |
76+ | ` maximumAttempts ` | ` Infinity ` | Maximum attempts, including the initial one |
77+
78+ ### Step Retry Policy
79+
80+ Each ` step.run(...) ` can define its own retry policy. If you omit ` retryPolicy ` ,
81+ OpenWorkflow uses the defaults shown above.
82+
83+ ``` ts
84+ await step .run (
85+ {
86+ name: " call-api" ,
87+ retryPolicy: {
88+ initialInterval: " 500ms" ,
89+ backoffCoefficient: 2 ,
90+ maximumInterval: " 30s" ,
91+ maximumAttempts: 5 ,
92+ },
93+ },
94+ async () => {
95+ // step logic
96+ },
97+ );
98+ ```
99+
100+ ### Workflow Retry Policy
68101
69- Retry behavior is configured per workflow using ` retryPolicy ` in the workflow
70- spec:
102+ Workflow-level ` retryPolicy ` applies to non-step failures — for example, missing
103+ workflow definitions or errors thrown outside ` step.run ` . If you omit
104+ ` retryPolicy ` (or individual fields), OpenWorkflow uses the same defaults.
71105
72106``` ts
73107import { defineWorkflow } from " openworkflow" ;
74108
75- export const chargeCustomer = defineWorkflow (
109+ defineWorkflow (
76110 {
77111 name: " charge-customer" ,
78112 retryPolicy: {
79- initialInterval: " 1s " ,
113+ initialInterval: " 500ms " ,
80114 backoffCoefficient: 2 ,
81- maximumInterval: " 100s " ,
82- maximumAttempts: Infinity ,
115+ maximumInterval: " 30s " ,
116+ maximumAttempts: 5 ,
83117 },
84118 },
85119 async ({ step }) => {
@@ -88,15 +122,6 @@ export const chargeCustomer = defineWorkflow(
88122);
89123```
90124
91- ` retryPolicy ` is optional. Any omitted fields use defaults.
92-
93- | Field | Description |
94- | -------------------- | ----------------------------------------------------- |
95- | ` initialInterval ` | Delay before the first retry after a failed attempt |
96- | ` backoffCoefficient ` | Multiplier applied to each subsequent retry delay |
97- | ` maximumInterval ` | Upper bound for retry delay |
98- | ` maximumAttempts ` | Maximum total attempts, including the initial attempt |
99-
100125## What Triggers a Retry
101126
102127Retries happen when:
0 commit comments