Skip to content

Commit b2a9249

Browse files
durable-workflow.github.io: update v2 changes
1 parent 1898412 commit b2a9249

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/features/child-workflows.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,81 @@ When the parent is blocked on a child, Waterline shows it as a child wait rather
141141
- if that parent resume workflow task row is lost after the child-resolution event, selected-run detail stays `repair_needed`, exposes a synthetic missing workflow task with `workflow_wait_kind = child`, `child_call_id`, and `child_workflow_run_id`, and manual `repair()`, `workflow:v2:repair-pass`, or worker-loop repair recreates the same child-resolution task from typed parent history
142142
- lineage arrays expose the durable parent/child relationship alongside continue-as-new links, and child-workflow entries now carry the same `child_call_id`
143143

144+
## Parent-Close Policy
145+
146+
When a parent workflow closes — whether by completing, failing, timing out, being cancelled, or being terminated — each open child workflow is affected according to its **parent-close policy**. The policy is set per child call and controls what happens to that child when the parent run exits.
147+
148+
| Policy | Value | Behavior |
149+
|---|---|---|
150+
| Abandon | `abandon` | The child continues running independently. This is the default. |
151+
| Request Cancel | `request_cancel` | A cancel command is sent to the child when the parent closes. |
152+
| Terminate | `terminate` | A terminate command is sent to the child when the parent closes. |
153+
154+
### Setting the policy
155+
156+
Pass a `ChildWorkflowOptions` as the first argument to `child()` or `startChild()`:
157+
158+
```php
159+
use function Workflow\V2\child;
160+
use Workflow\V2\Enums\ParentClosePolicy;
161+
use Workflow\V2\Support\ChildWorkflowOptions;
162+
use Workflow\V2\Workflow;
163+
164+
final class ParentWorkflow extends Workflow
165+
{
166+
public function handle(): array
167+
{
168+
$options = new ChildWorkflowOptions(
169+
parentClosePolicy: ParentClosePolicy::RequestCancel,
170+
);
171+
172+
return child(ChildWorkflow::class, $options, 'argument1');
173+
}
174+
}
175+
```
176+
177+
The same pattern works with `startChild()` for parallel barriers:
178+
179+
```php
180+
use function Workflow\V2\all;
181+
use function Workflow\V2\startChild;
182+
use Workflow\V2\Enums\ParentClosePolicy;
183+
use Workflow\V2\Support\ChildWorkflowOptions;
184+
185+
$cancelOptions = new ChildWorkflowOptions(
186+
parentClosePolicy: ParentClosePolicy::RequestCancel,
187+
);
188+
189+
$results = all([
190+
startChild(FirstChild::class, $cancelOptions),
191+
startChild(SecondChild::class, $cancelOptions, 'arg'),
192+
]);
193+
```
194+
195+
### How it works
196+
197+
- The policy is recorded on the `workflow_links` row (`parent_close_policy`) and in the `ChildWorkflowScheduled` history event payload.
198+
- When the parent run closes for any reason, the engine queries open child links with a non-abandon policy and sends the appropriate command (cancel or terminate) to each open child.
199+
- If the child has already closed by the time the policy is enforced, no action is taken — the command is silently skipped.
200+
- Policy enforcement is best-effort: if a child command is rejected (e.g. the child is already terminal), the parent's closure is not affected.
201+
- Continue-as-new does **not** trigger parent-close policy, because the workflow instance remains active under a new run.
202+
203+
### When to use each policy
204+
205+
**Abandon** (default) is correct when children represent independent work that should complete regardless of the parent's fate — for example, a notification workflow or a cleanup task that must finish.
206+
207+
**Request Cancel** is correct when children should receive a graceful shutdown signal. The child can handle the cancellation and run compensation logic before closing.
208+
209+
**Terminate** is correct when children must stop immediately. Use this for children that are purely auxiliary to the parent and have no independent value after the parent closes.
210+
211+
### Waterline visibility
212+
213+
Waterline shows the `parent_close_policy` in:
214+
215+
- the child link entry on the parent run's lineage view
216+
- the `ChildWorkflowScheduled` timeline entry payload
217+
- the child's `CancelRequested` or `TerminateRequested` history event when policy enforcement fires, with a reason that names the parent closure
218+
144219
## Current Limitations
145220

146221
The current surface does not include:

0 commit comments

Comments
 (0)