# Compose subgraphs, batches, waits, and recovery

## When to use

Use this task when a graph must reuse a child workflow, process a collection, pause for time or an external event, or survive process restart. Stop before adding durability if retrying the whole short-lived request is cheaper and safe.

## Inspect first

- Find the existing graph identity, business key, child graph registry, and collection boundaries.
- Identify every wait correlation key and event idempotency key.
- Separate “resume this execution” from “repeat this external effect.”
- Read Chapters [10](/en/v/0.9.8-RC1/10-reuse-with-subgraphs), [11](/en/v/0.9.8-RC1/11-batch-and-iteration), [12](/en/v/0.9.8-RC1/12-waiting-for-the-world), and [13](/en/v/0.9.8-RC1/13-durable-execution) only as needed.

## Required inputs

Obtain the parent-visible child result, collection size and ordering requirement, wait timeout, correlation identity, duplicate-event policy, restart requirement, persistence owner, and acceptable effect recovery semantics.

## Implementation path

1. Use a subgraph only when the child has a stable input/output boundary; keep its internal node outputs private.
2. Choose sequential or parallel collection execution from ordering, rate, and effect constraints.
3. Use `wait` for a direct signal or duration and `await` for externally correlated events.
4. Bind execution identity and correlation keys to stable business data.
5. Add durable stores only for state that must survive process loss: execution, checkpoints, waits, work items, and graph definitions.
6. Prove suspend, signal/event delivery, resume, duplicate delivery, timeout, and cold recovery as separate observations.

## MUST / SHOULD / MAY

- **MUST** use stable business identity for correlation and recovery.
- **MUST** make duplicate delivery harmless or explicitly rejected.
- **MUST** treat a persisted checkpoint and an external side effect as different facts.
- **SHOULD** keep subgraph scope isolated unless parent visibility is required and reviewed.
- **SHOULD** bound parallel collection work by downstream capacity.
- **MAY** use in-memory stores for tests; do not present them as restart evidence.

## Failure patterns

- Flatly reading a subgraph output: consume its declared aggregate result instead of leaking child internals.
- Using an execution id as an external webhook contract: introduce a stable business correlation key.
- Resuming after a crash and repeating a charge: add an idempotency key or reconciliation step at the effect boundary.
- Claiming durability from one engine instance: create a second engine/runtime instance against shared persisted state.

## Validation

Run a focused suspend/resume test, then a duplicate-event test, then a cold-recovery test with a new engine instance. Run target-module tests after the focused cases. Report persistence evidence and external-effect evidence separately.

## Evidence

- [Composition and subgraphs](/en/v/0.9.8-RC1/10-reuse-with-subgraphs)
- [Waiting and correlation](/en/v/0.9.8-RC1/12-waiting-for-the-world)
- [Durable execution](/en/v/0.9.8-RC1/13-durable-execution)
- [Effects and idempotency reference](/agent/en/v/0.9.8-RC1/reference/effects-and-idempotency.md)
