Expand description
Fan-out stage handling as ECS systems.
A fan_out stage (see leviath_core::blueprint::StageMode::FanOut) runs
its single inference as a split - its prompt (with the config’s
split_prompt folded in by crate::pipeline) asks the model for a JSON
array of work items. fan_out_split intercepts that response (before the
normal process_response routing), parses the items, and parks the parent in
FanOutWaiting. fan_out_collect then starts one worker per item -
bounded by max_workers concurrent workers - via the daemon-installed
FanOutSpawner, tracks them as the parent’s SubAgentChildren, and once
every worker is terminal applies the failure policy, injects a consolidated
report into the parent’s conversation, and transitions to the merge_stage
(or falls through to the stage’s normal transition).
The runtime only starts and tracks workers; resolving which blueprint a
worker runs (self-at-worker-stage, a named agent, or a capability query) is
the CLI’s job, encapsulated behind the FanOutSpawner it installs.
Structs§
- FanOut
Spawner Res - The installed
FanOutSpawner, as a world resource. Absent in a pure-runtime world (then every fan-out item fails with “no fan-out spawner installed”). - FanOut
State - The serializable form of
FanOutWaiting, written to<run_dir>/fanout.jsonso a parent interrupted mid-split resumes its merge after a restart.activecarries worker run-ids (not entities); recovery maps them back to the reloaded worker entities. - FanOut
Waiting - A parent parked while its fan-out workers run. Holds the not-yet-started
pendingitems, the currently-activeworkers, and the accumulated results. - Work
Item - One unit of work produced by a fan-out split.
Traits§
- FanOut
Spawner - Starts one worker for a fan-out work item. The implementor resolves the
worker’s blueprint (per
config’sworker_stage/worker_agent/worker_query), spawns it intoworldseeded with the work item, and returns the child entity. Parent/child linking is done byfan_out_collect, not the spawner.
Functions§
- fan_
out_ collect - Fan-out collect system (exclusive): drive each
FanOutWaitingparent - reap finished workers, start pending ones up tomax_workers, and once none remain running apply the failure policy, inject the consolidated report, and transition to the merge stage (or resolve the stage’s own transition). - fan_
out_ split - Fan-out split system (exclusive): for each
ProcessResponseagent whose current stage is a fan-out stage, consume its response as the split output - parse the work items and park the agent inFanOutWaiting(or mark itErrorif the split output isn’t a JSON array). RemovingProcessResponsehere keeps the normalprocess_responserouting from touching these agents. - parse_
work_ items - Parse a split response into work items. Tolerates markdown fences and prose by
extracting the outermost
[ … ]. (Ported from the deleted imperative engine.) - restore_
fan_ out_ waiting - Rebuild a parent’s
FanOutWaitingfrom a persistedFanOutStateand insert it, mapping each active worker’s run-id back to its reloaded entity viaresolve. Workers whose entity didn’t reload are treated as failures so the merge still completes rather than waiting forever. Used by restart recovery to resume an interrupted fan-out.