Repeat a workflow for a collection
Build a reusable folder audit, supply its items, and follow how Crewplane expands and joins the work.
1. Build a fixed child
Run one child per item
Use foreach to apply one fixed child workflow to each object in a collection. The parent run and scheduler handle every instance; the group itself has no provider, worktree, or prompt.
One child per object
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- Folder objects → Fixed child · one object each
- Fixed child → folders · instance results
- folders → summarize · ordered index
Provide ordered objects
The parent collection contains objects for src, tests, and docs. Each object becomes the item input for one instance, and this original order determines the result index order.
Reuse the child workflow
Every object is bound to the same audit-folder.task.md workflow. Each instance gets its own input and audit nodes, run by the parent scheduler within the same run.
Wait for every instance
The folders group collects the terminal child results after all instances succeed. It publishes an ordered JSON index rather than concatenating the audit text.
Summarize after the group
The summarize node depends on folders, so it waits for the group. Its prompt receives the index and can follow each descriptor to the corresponding terminal output.
Declare the child input
Save this file beside the parent workflow in .crewplane/workflows/. Configure a codex agent profile. The child accepts one object through the public input item; its fallback file lets the child run on its own.
---schema_version: "1.0"name: Audit one folderinputs: {item: item}nodes: - id: item mode: input source: "{{file:folder.json}}" - id: audit mode: parallel needs: [item] providers: [codex]--- ## auditAudit the folder described by this JSON object and report supported findings:{{item.output}} Child input and audit
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- item → audit · JSON object
Bind the item object
The child exposes item as an input. In a foreach instance it receives that instance’s JSON object; the declared file source is a fallback for running the child on its own.
Audit that item
The audit node waits for item and explicitly inserts {{item.output}} into its prompt. The provider can then inspect the folder described by that particular object.
Add a foreach group
Save this parent as .crewplane/workflows/folder-audit.task.md. It uses the same child for each folder, then gives the ordered index to summarize.
---schema_version: "1.0"name: Folder auditsnodes: - id: folders mode: foreach workflow: audit-folder.task.md item_input: item items: - {folder: src} - {folder: tests} - {folder: docs} - id: summarize mode: parallel needs: [folders] providers: [codex]--- ## folders<!-- Run the same audit for each folder. -->## summarizeUse this ordered index to read the terminal outputs and summarize the audits.Resolve each descriptor path relative to the directory containing the index at{{folders.output_path}}.{{folders.output}} Explore foreach expansion
Choose a collection and step through one parent run. This example can finish instances out of order; the group index keeps the original item order.
Choose a literal array or JSON loaded by the list input node.
Use 0 to 4 folder objects.
An artifact requires a positive cap. Omit it for a literal array to use its length.
Generated item inputs and provider nodes each use a slot while running.
Choose at least two items to make the second instance fail.
Validate the child
Preflight validates and freezes audit-folder.task.md, even if the collection is empty, before any child runs.
Fixed child: audit-folder.task.md
Each item uses the same fixed child workflow.
No child instances
folders.outputsummarizeThe waiting group uses no node slot.
Selected item
Select an item to see its object, generated nodes, and place in the index.
- Validate the child
Preflight validates and freezes audit-folder.task.md, even if the collection is empty, before any child runs.
- Resolve the collection
The collection contains 3 objects. Each object stays in its original position.
- Expand the child
Crewplane creates an instance of the fixed child for each of the 3 objects in the parent run.
- Bind items
Generated item inputs receive their objects: folders.i0.item, folders.i1.item. 2 nodes are running.
- Finish nodes
These nodes finish: folders.i0.item, folders.i1.item. Child completion order can differ from input order; 0 nodes are running.
- Start ready nodes
Ready nodes start: folders.i0.audit, folders.i1.audit. 2 nodes are running.
- Finish nodes
These nodes finish: folders.i1.audit. Child completion order can differ from input order; 1 nodes are running.
- Bind items
Generated item inputs receive their objects: folders.i2.item. 2 nodes are running.
- Finish nodes
These nodes finish: folders.i2.item. Child completion order can differ from input order; 1 nodes are running.
- Start ready nodes
Ready nodes start: folders.i2.audit. 2 nodes are running.
- Finish nodes
These nodes finish: folders.i0.audit. Child completion order can differ from input order; 1 nodes are running.
- Finish nodes
These nodes finish: folders.i2.audit. Child completion order can differ from input order; 0 nodes are running.
- Join the results
The group waits for every instance to succeed, then creates an index in input order.
- Start the summary
The summarize node can read the group index and follow its result descriptors.
- Finish nodes
These nodes finish: summarize. Child completion order can differ from input order; 0 nodes are running.
2. Choose the collection
Start with literal objects
A literal items array can be empty. Omit max_items to use the array length as the bound, or set a positive integer at least as large as the array. A smaller cap fails preflight. null is not omission.
items: - {folder: src} - {folder: tests} - {folder: docs} Literal array bounds
Read a collection from a file
To use a JSON array from a file, add an input node and replace the group fields as shown. The source must be an ancestor through needs, and an artifact reference requires a positive max_items.
You can also use the .output of an earlier foreach group as a collection. Provider output requires the findings form in the next step.
- id: folder_list mode: input source: "{{file:folders.json}}" - id: folders mode: foreach needs: [folder_list] workflow: audit-folder.task.md item_input: item items: "{{folder_list.output}}" max_items: 4 File collection
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- folders.json → folder_list · read
- folder_list → folders · needs and output
Store an array of objects
folders.json supplies the collection as JSON data. Its array order becomes the order of the eventual group index, regardless of the order in which child instances finish.
Expose the file as output
The folder_list input node reads the file and makes its raw contents available as {{folder_list.output}}. The foreach group must list it as an ancestor through needs.
Check the collection cap
The group reads the referenced array with max_items: 4. If the collection exceeds that cap, the group fails before starting children; it does not truncate the array.
Use provider findings
For a provider-generated collection, use .findings from a findings: true node with exactly one executor. In the ## plan prompt, ask for an array of folder objects in a findings block. Ordinary provider output is not a collection source.
- id: plan mode: parallel providers: [codex] findings: true - id: folders mode: foreach needs: [plan] workflow: audit-folder.task.md item_input: item items: "{{plan.findings}}" max_items: 4 Provider collection
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- plan → folders · needs and findings
Generate a collection
The plan node uses one executor and enables findings. Its prompt must request an array of folder objects in a findings block; ordinary wrapped provider output cannot serve as this collection.
Expand the findings
The group depends on plan and reads {{plan.findings}} with an explicit cap. An oversized collection fails before children start, so every accepted object receives an instance.
Bind shared inputs and parameters
Add a caller input and bind it by child input name. The caller node must be an ancestor of the group through needs. Add Use a {{param:style}} style. to the child prompt to use the shared with value.
- id: standards mode: input source: "{{file:standards.md}}" - id: folders mode: foreach needs: [standards] workflow: audit-folder.task.md item_input: item inputs: {standards: standards} with: {style: concise} items: [{folder: src}, {folder: tests}] Shared bindings
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- standards → folders · needs and inputs
- folders → Each child · shared values
Provide shared context
The parent standards input makes the standards artifact available to the group. The group lists that source in needs, establishing the required ancestor relationship.
Bind values for each instance
The inputs mapping binds the caller’s standards node to the child input, while with supplies the shared style parameter. Every instance gets the same bindings.
Combine shared and per-item data
Each child uses the common standards and concise style alongside its own item object. The workflow structure stays fixed across instances; only the bound item varies.
Understand what stays fixed
Preflight freezes and validates the child even for an empty collection. Static imports inside it can compose normally; a nested foreach is not allowed, including through imports. Child repetition metadata does not create additional runs.
Preflight and execution
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- Preflight → Items · fixed procedure
- Items → Instances · one per object
Freeze the workflow first
Preflight validates and freezes the child even when the collection is empty. The same fixed workflow applies to every item, and nested foreach is not allowed, including through imports.
Resolve bounded items
The collection provides data objects rather than new workflow definitions. Artifact-backed collections require an explicit cap, and exceeding it fails the group before any child starts.
Schedule child nodes in the parent
Each accepted object creates one child instance within the parent run. The shared scheduler counts runnable input and provider nodes against concurrency; the waiting group uses no slot.
4. Follow execution and results
Set scheduler limits
Set a finite positive settings.max_concurrent_nodes in .crewplane/config.yml. It limits how many ready nodes can run at once. Generated item inputs and provider nodes each use a slot while running; a group waiting for its children uses no slot.
settings: max_concurrent_nodes: 2 max_expanded_nodes: 100 Two separate limits
Read the ordered index
The group waits for all instances to succeed. Its {{folders.output}} is an ordered JSON index, not a concatenation of audit text. Even when instances finish in a different order, entries follow the original collection order.
Finish order and index order
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- Example finish order → Index order · join by input position
Instances can finish out of order
Different folder audits can take different amounts of time, so tests may finish before src in this example. The observed completion order does not determine index order.
Keep the input order
After all instances succeed, the group publishes entries in the original src, tests, docs order. Each entry describes terminal child results rather than embedding concatenated audit text.
Plan for empty and failed groups
An empty collection succeeds and writes [] without running a child. If a child fails, the group and its downstream consumers are blocked; independent branches may continue. Generated IDs use ordinals such as folders.i0.audit, not item fields.
Group outcomes
5. Validate, run, and resume
Check the plan
From the project root, validate the parent file, then preview its compiled plan. These commands do not run workflow nodes or write run artifacts.
crewplane validate .crewplane/workflows/folder-audit.task.mdcrewplane run --tasks .crewplane/workflows/folder-audit.task.md --dry-run Review before running
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- Validate → Dry run · then preview
Check the authored workflow
crewplane validate checks the parent workflow and its configuration before a run. It does not execute workflow nodes or write run artifacts.
Inspect the compiled plan
The dry run previews the compiled plan and any history advisory. Use it to check the intended structure before running the workflow; it does not invoke the providers.
Run and inspect
When the plan is ready, run the parent. Crewplane records the collection and expansion, individual item files, and the group result index. Inspect the group index and follow its descriptors to the terminal outputs.
crewplane run --tasks .crewplane/workflows/folder-audit.task.md Run artifacts
Hover or focus a node to preview its explanation; click to keep it.Tap a node to select its explanation.
- Collection → Expansion · record
- Expansion → Group result · join successful children
Inspect the frozen collection
The expansion artifacts include the collection and numbered item files used for the run. These records help connect each child instance back to the object it received.
Inspect expansion state
The expansion record describes the group’s expansion and completion. Each child runs within the parent run, making these records useful when inspecting or resuming the group.
Follow terminal descriptors
The group result is an ordered index of terminal child artifacts. Resolve each descriptor path relative to the directory containing the index to inspect the corresponding output.
Resume or start fresh
After a failure or cancellation, run the same command again without --force. Resume reuses eligible expansion evidence, successful nodes, and selected checkpoints after checking prerequisites and matching caller artifacts. A changed prerequisite invalidates that group’s reuse.
crewplane run --tasks .crewplane/workflows/folder-audit.task.mdcrewplane run --tasks .crewplane/workflows/folder-audit.task.md --force