Skip to content

fix: ensure lazy types are loaded before reading version in save() paths#1169

Merged
stack72 merged 1 commit intomainfrom
fix/ensure-type-loaded-in-save-paths
Apr 13, 2026
Merged

fix: ensure lazy types are loaded before reading version in save() paths#1169
stack72 merged 1 commit intomainfrom
fix/ensure-type-loaded-in-save-paths

Conversation

@stack72
Copy link
Copy Markdown
Contributor

@stack72 stack72 commented Apr 13, 2026

Summary

  • Add await modelRegistry.ensureTypeLoaded(type) before modelRegistry.get(type) in YamlDefinitionRepository.save() and YamlEvaluatedDefinitionRepository.save()
  • Without this, lazy-registered types (catalog-known but not yet imported) cause get() to return undefined, silently persisting a stale typeVersion to disk
  • Follows the established fix pattern from libswamp/models/get.ts:76 and validation_service.ts:706

Closes swamp-club#90 (follow-up to swamp-club#89)

Test Plan

  • deno check passes
  • deno lint passes
  • deno fmt --check passes
  • All 4305 tests pass
  • Filed systeminit/swamp-uat#136 for missing UAT coverage of typeVersion persistence

🤖 Generated with Claude Code

modelRegistry.get() returns undefined for lazily-registered types that
haven't been imported yet. Both YamlDefinitionRepository.save() and
YamlEvaluatedDefinitionRepository.save() called get() without first
awaiting ensureTypeLoaded(), silently falling back to a potentially
stale typeVersion on the incoming Definition.

Add the missing ensureTypeLoaded() call in both save methods, matching
the established pattern in libswamp/models/get.ts and
validation_service.ts.

Closes swamp-club#90
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Clean, well-scoped bug fix that follows the established ensureTypeLoadedget pattern used throughout the codebase (e.g., libswamp/models/get.ts:76, validation_service.ts, datastores/sync.ts:71, etc.).

Blocking Issues

None.

Suggestions

  1. The existing yaml_definition_repository_test.ts doesn't cover the lazy-type typeVersion persistence path. The PR body mentions filing systeminit/swamp-uat#136 for UAT coverage, which is a reasonable approach — but a unit test asserting that save() with a lazy-registered type correctly resolves typeVersion (rather than falling back to stale data) would make this fix regression-proof at the unit level. Not blocking since the fix follows a well-tested pattern and the UAT tracking is in place.

Notes

  • DDD: Infrastructure repositories correctly depend on the domain modelRegistry — layer direction is sound.
  • Import boundary: Both files import from ../../domain/models/model.ts (domain internals), which is appropriate for infrastructure code. No libswamp boundary violation.
  • No any types, license headers present, change is minimal and focused.
  • ensureTypeLoaded accepts string | ModelType and the call sites pass ModelType — type-safe.

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial Review

Critical / High

None.

Medium

None.

Low

None.

Verdict

PASS — This is a clean, minimal 2-line fix that adds await modelRegistry.ensureTypeLoaded(type) before modelRegistry.get(type) in both YamlDefinitionRepository.save() and YamlEvaluatedDefinitionRepository.save(). It follows the established pattern from libswamp/models/get.ts:76 and validation_service.ts:706. The ensureTypeLoaded call is correctly placed after data.type assignment but before modelRegistry.get() and well before atomicWriteTextFile, so a loader failure propagates cleanly without leaving partial writes. Both files already import modelRegistry, the type parameter is ModelType which matches the string | ModelType signature, and the existing ?.version ?? data.typeVersion fallback handles the (now unlikely) undefined case. No new failure modes, no API contract changes, no concurrency concerns beyond the already-deduplicated loader promises.

@stack72 stack72 merged commit 4b7f0b3 into main Apr 13, 2026
10 checks passed
@stack72 stack72 deleted the fix/ensure-type-loaded-in-save-paths branch April 13, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant