Skip to content

Guard config contracts at startup#11

Merged
gphiIIips merged 2 commits into
mainfrom
test/config-fallback-contracts
Jun 12, 2026
Merged

Guard config contracts at startup#11
gphiIIips merged 2 commits into
mainfrom
test/config-fallback-contracts

Conversation

@gphiIIips

@gphiIIips gphiIIips commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Make 41 existing literal typed-store fallback values explicit in PARAMETERS.
  • Add centralized startup config validation in src/config_validation.rs, called once before Simulation::new.
  • Record validation status in startup logs, run metadata, and the compact [report] line.
  • Extend Fast Guardrails with runtime validation tests.

Why

Silent fallback values and malformed config values are scientifically risky: a missing or invalid parameter can change model behavior without the operator realizing it. This PR makes the currently used literal defaults auditable and adds a startup boundary that stops unambiguous invalid config before timestep 0.

Runtime Behavior

  • Default mode is strict.
  • On success, startup logs show [config-validation] PASSED: 0 error(s), 0 warning(s), mode=strict.
  • Hard errors block the run before Simulation::new, write failed run metadata where possible, print a [report] status=config_validation_failed ..., and exit with code 2.
  • AMR_CONFIG_VALIDATION=warn allows explicit non-production continuation while preserving the failed validation status in logs/metadata/report output.

Hard errors currently cover:

  • literal get_global_param keys missing from PARAMETERS;
  • required get_required keys missing from PARAMETERS;
  • literal get_or_default(map, "...") keys missing from PARAMETERS;
  • non-finite values;
  • out-of-range probability-style values;
  • negative values for clearly non-negative parameter families.

Warnings currently cover:

  • boolean-style flags set to values other than 0.0 or 1.0, because runtime treats >0.5 as true.

Scope

  • Production model transition logic is not touched.
  • Existing model behavior should be unchanged when config is valid.
  • Dynamic per-entity fallback patterns remain intentionally allowed.

Validation

  • cargo check --all-targets
  • cargo test --test config_validation -- --nocapture
  • cargo test --test config_invariants -- --nocapture
  • cargo test --test probability_invariants -- --nocapture
  • cargo test --test determinism -- --nocapture
  • cargo test --test csv_invariants -- --nocapture
  • cargo test --test dimension_invariants -- --nocapture
  • rustfmt --check src/main.rs src/observability.rs src/config_validation.rs tests/config_invariants.rs tests/config_validation.rs tests/csv_invariants.rs tests/determinism.rs tests/dimension_invariants.rs tests/probability_invariants.rs
  • git diff --check

Runner Smoke

  • JID: 20260612T001542-58395
  • Overrides: population_size=1000, time_steps=200, CalibrationMode::Partial, seed 123456789
  • Result: success
  • Startup validation line: [config-validation] PASSED: 0 error(s), 0 warning(s), mode=strict
  • Simulation run ID: 870119
  • Summary hash: f5a194b21e63bfcc58d95ba91c7b35649c3158667752dc48f9a40bebb7263299

@gphiIIips gphiIIips changed the title Guard literal config fallbacks Guard config contracts at startup Jun 11, 2026
@gphiIIips gphiIIips merged commit ff3df72 into main Jun 12, 2026
1 check passed
@gphiIIips gphiIIips deleted the test/config-fallback-contracts branch June 12, 2026 00:52
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