Relationships
↔ sibling #4903#4902 workflow validate and workflow run re-scan models/ once per distinct step behavior (O(steps x definition files) file opens)
Opened by zack · 11/19/2026· Shipped 11/19/2026
Summary
swamp workflow validate and swamp workflow run re-read the definition files under models/ once per distinct behavior a workflow's steps use. Each step that names a behavior (modelIdOrName) is resolved with findDefinitionByIdOrName, which calls YamlDefinitionRepository.findByNameGlobal. In the CLI no name index is attached, so every lookup of a name not seen before in the process walks models/ in sorted order, parsing YAML until the name matches. Cost is O(distinct step behaviors x definition files). This has the same shape as swamp-club#4895, which fixed behavior search --json.
Measurements
Scratch repo: 500 command/shell definitions (models/command/shell/s000.yaml .. s499.yaml, run: echo ok) and five workflows of 40 steps each. Each step names a different behavior, spread across the 500. Counted successful openat calls on models/**/*.yaml with strace -f -e trace=openat, using swamp 20261118.223849.0-sha.c2530f0f:
| Command | models/ YAML opens | Wall time |
|---|---|---|
swamp workflow validate wf0 --json (one 40-step workflow) |
8,820 | |
swamp workflow validate --json (all 5 workflows) |
43,117 | 1.5s |
swamp workflow run wf0 --json (succeeds) |
18,060 | 1.4s |
workflow run makes about two walks per step: validation, then the execution-time lookup (execution_service.ts around lines 2174, 3693, 8589 and 9467 call findDefinitionByIdOrName / findByNameGlobal). Repeated names are cheap, because findByNameGlobal records a path hint for each name it finds. Only names new to the process pay for a walk.
At 800 definitions, a 50-step workflow would cost roughly 20k opens per validate and about twice that per run.
Reproduction
swamp repo initin an empty directory.- Create 500
command/shelldefinitions nameds000..s499undermodels/command/shell/. - Create workflows under
workflows/workflow-<name>.yamlwith 40model_methodsteps each, each with a distinctmodelIdOrName(for examples003,s014,s025, ...) andmethodName: execute. strace -f -e trace=openat -o ol.log swamp workflow validate wf0 --json >/dev/null, then count lines matching/models/.*\.yaml"(excluding ENOENT). The count is far above 500.
Expected
Resolving a workflow's step behaviors should read each definition file at most about once per invocation, as serve already does through its definition name index.
Possible directions
- Build or attach a name index in the CLI once a command is about to resolve more than a handful of distinct names (workflow validate and run know the full step list up front).
- Or record a name hint for every file the first walk parses, not only the file it stops at, so later lookups become single reads.
Shipped
Click a lifecycle step above to view its details.