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

Relationships

↔ sibling #4902

#4903 behavior validate re-scans models/ once per distinct expression model reference (O(references x definition files) file opens)

Opened by zack · 11/19/2026· Shipped 11/19/2026

Summary

swamp behavior validate (with no name, so every definition is validated) re-reads the definition files under models/ once for each distinct behavior referenced from an expression. validateAll in src/libswamp/models/validate.ts first lists every definition with findAllGlobal. Then, for each definition, DefaultModelValidationService resolves every model.<name> reference by calling definitionRepo.findByNameGlobal (validateModelPathReference and namesModel in src/domain/models/validation_service.ts, around lines 1189 and 1285). In the CLI no name index is attached, and the findAllGlobal walk records no name hints. So each name new to the process walks models/ in sorted order, parsing YAML until it matches. Cost is O(distinct referenced behaviors x definition files), though the full listing at the start has already parsed every file once. This has the same shape as swamp-club#4895 (fixed for behavior search --json) and swamp-club#4902 (workflow validate/run).

Measurements

Scratch repo: 500 command/shell definitions (s000..s499). Each has run: echo followed by a model.sNNN.definition.globalArguments expression that references one other definition, spread across the 500. Every definition validates cleanly. 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 behavior validate --json, definitions cross-referencing 125,750 3.9s
swamp behavior validate --json, same 500 definitions without references 500
swamp behavior validate s250 --json (single, one reference) ~1,000

That is about 250 reads per file: one partial walk per distinct reference.

Reproduction

  1. swamp repo init in an empty directory.
  2. Create 500 command/shell definitions s000..s499 under models/command/shell/. Give each a methods.execute.arguments.run whose expression references a different definition (for example model.s261.definition.globalArguments inside the usual expression braces).
  3. strace -f -e trace=openat -o ol.log swamp behavior validate --json >/dev/null, then count lines matching /models/.*\.yaml" (excluding ENOENT). Compare with the same repo after removing the references.

Expected

Validating every definition should read each definition file about once. The full listing validateAll already does holds every definition, so reference checks can be answered from it, or from a name index built during that walk.

Possible directions

  • Answer reference lookups during validateAll from the findAllGlobal result (a name map), or have that walk record a name hint for every file it parses, so each later findByNameGlobal is a single read.
  • A shared CLI-side name index would also cover swamp-club#4902.
02Bog Flow
✓OPEN✓TRIAGED✓IN PROGRESS✓SHIPPED+ 1 MOREASSIGNED+ 9 MOREREVIEW+ 10 MOREPR_LINKED+ 2 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:54 PM
zack linked sibling of #490211/19/2026, 5:38:45 PM

Sign in to post a ripple.