Run independent reads before a join
This complete example uses no provider or external service. Save it ascalculation.ts, install matching core packages using installation, then run npx tsx calculation.ts.
inputsFrom supplies patches from transitive data ancestors and gates readiness. Each node receives its own structured clone of entry state plus those ancestor patches. Control predecessors and unrelated completed siblings do not silently supply state. Graph input and returned patches must be structured-cloneable.
Distinguish control from data
Failed or blocked predecessors block their consumers. A skipped condition can release a control join but cannot provide data. Blocked nodes appear as skipped with
workflow_dependency_blocked and make the graph fail. Complete episodes are checked before their effects: unique IDs, valid steps, references, duplicate edges, cycles in both edge types and limits. Dynamic factories are checked at entry.
Ready nodes start incrementally. maxConcurrency defaults to five nodes and maxNodes to 100 per episode; values must be positive safe integers. A nested Agent or parallel group may start its own work, so this local node ceiling does not cap aggregate provider/tool concurrency. Use recoverable graph root admission when you need one shared leaf-work ceiling.
Join owned patches predictably
Results and final joins use stable topological order with declaration-order ties. Completion timing does not choose the winning writer. Graphmerge defaults to "error": incomparable nodes writing the same key conflict even when values match. Descendants may intentionally overwrite ancestor keys. "declaration_order" uses the stable topological order to choose the later writer. Existing parallel groups retain their declaration-order default.
An ordinary node failure discards its patch, retains child diagnostics and blocks dependent work; successful independent nodes may still contribute patches. Definition, conflict and cancellation failures reject the boundary, drain already-started work and prevent downstream Workflow steps/checkpoints. Applied external effects remain applied.
Structured cloning protects state data. It does not sandbox callbacks, isolate captured resources or prove that independent nodes may safely mutate the same browser, file, database object or account. The host supplies resource ordering or locks.
Repeat complete episodes within a cap
workflow_iteration_limit. Body errors stop repetition. The cap is captured before callbacks execute. A graph factory runs once at episode entry, after previous work settles.
Factories and predicates are trusted host callbacks. Replanning here selects a complete new episode; it does not modify running nodes or execute arbitrary generated code. Per-episode and repeat limits multiply under nesting. Scoped composition has a depth limit of 64, while shared harness model/tool/token budgets bound the run. This ordinary path has no separate lifetime expansion allowance.
Grant scoped effects and handle cancellation
Graph nodes and repeat iterations appear inStepResult.executionPath, events, child session IDs and metadata.workflowExecutionPath. Segments use encodeURIComponent. A function’s controlled effect name is workflow:<executionPath>, such as workflow:calculate/left/read-left; grant that exact name under a harness. Outside scoped graph/repeat steps, legacy workflow:<step.name> names stay valid. Paths are diagnostic identity and are not remote idempotency keys.
Agent output keys remain <step.name>_output. Give independent Agent nodes distinct names or an explicit ordering/merge choice. Shared budget admission winners can depend on timing. Cancellation stops new admission, propagates to children, drains started callbacks and discards late patches; uncooperative callbacks can delay settlement. Repeats can deliberately issue effects again. Controlled Workflow does not automatically retry a rejected effect acknowledgment.
Save completed boundaries
Graph and repeat are complete top-level checkpoint boundaries. Validated continuation skips a saved completed boundary, but an unsaved graph’s effects may repeat after a crash, cancellation or failed save. Callable/factory/environment changes require a new definition version. Use ExecutionGraphRuntime for recorded Agent decisions, per-node recovery, persisted root allowances and effect reconciliation. The ordinary Workflow harness driver advertisesdurable: false. See the workflow API reference for exact graph/repeat types.