Skip to main content
← Back to list
01Issue
BugShippedSwamp CLIPublic
Assigneeszack

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

  1. swamp repo init in an empty directory.
  2. Create 500 command/shell definitions named s000..s499 under models/command/shell/.
  3. Create workflows under workflows/workflow-<name>.yaml with 40 model_method steps each, each with a distinct modelIdOrName (for example s003, s014, s025, ...) and methodName: execute.
  4. 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.
02Bog Flow
✓OPEN✓TRIAGED✓IN PROGRESS✓SHIPPED+ 1 MOREASSIGNED+ 1 MORELINKED+ 3 MOREPR_LINKED+ 1 MORESESSION_SUMMARIZED

Shipped

11/19/2026, 6:25:37 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
zack assigned zack11/19/2026, 5:33:53 PM
zack linked sibling of #490311/19/2026, 5:38:45 PM

Sign in to post a ripple.