Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Assertion Reference

All macros live in moonpool_sim (also through the moonpool facade with the sim feature). Accounting lives in moonpool-assertions, a dependency-free crate with a heap table by default and a MAP_SHARED table under exploration. No macro panics. A violated always-style assertion records a failure for the current seed, and the report lists it.

Macro Summary

MacroFormKindFails the seed whenGuides the explorer
assert_always!(cond, msg) or (cond, msg, { "k" => v, .. })Alwayscond is false, or the site never ranNo
assert_always_or_unreachable!(cond, msg) or (cond, msg, {..})AlwaysOrUnreachablecond is falseNo
assert_sometimes!(cond, msg)Sometimescoverage miss: ran, never trueYes: first pass
assert_reachable!(msg)Reachablecoverage miss: never reachedYes: first pass
assert_unreachable!(msg) or (msg, {..})Unreachablereached at allNo
assert_always_greater_than!(val, thresh, msg [, {..}])NumericAlwaysval > thresh is falseNo
assert_always_greater_than_or_equal_to!sameNumericAlwaysval >= thresh is falseNo
assert_always_less_than!sameNumericAlwaysval < thresh is falseNo
assert_always_less_than_or_equal_to!sameNumericAlwaysval <= thresh is falseNo
assert_sometimes_greater_than!(val, thresh, msg)NumericSometimescoverage miss: val > thresh never trueYes: watermark
assert_sometimes_greater_than_or_equal_to!sameNumericSometimescoverage missYes: watermark
assert_sometimes_less_than!sameNumericSometimescoverage missYes: watermark
assert_sometimes_less_than_or_equal_to!sameNumericSometimescoverage missYes: watermark
assert_sometimes_all!(msg, [(name, bool), ..])BooleanSometimesAllcoverage miss: never all true at onceYes: frontier, combination
assert_sometimes_each!(msg, [(key, val), ..]) or (msg, [identity..], [quality..])bucket tablenever (no contract)Yes: bucket, quality

Rules that apply to every macro:

  • msg is any Display value. It identifies the site, so keep it stable and unique.
  • Numeric values go through to_i64_saturating, so any integer type works.
  • The detail map { "k" => v, .. } prints [ASSERTION FAILED] msg (seed=N) | k=v ... on failure only. Values must implement Display.
  • assert_sometimes_each! takes at most 6 identity keys per site (MAX_EACH_KEYS). The quality list is optional.

Numeric Watermarks

Every numeric site keeps one watermark, the best value seen for its direction:

Macro familyWatermark tracks
assert_always_greater_than[_or_equal_to]!the minimum value (the worst case)
assert_always_less_than[_or_equal_to]!the maximum value (the worst case)
assert_sometimes_greater_than[_or_equal_to]!the maximum value
assert_sometimes_less_than[_or_equal_to]!the minimum value

Always-style watermarks are reporting only. An improvement on a NumericSometimes watermark is a WatermarkImprovement discovery, so the explorer branches from it.

Discovery Kinds

The accounting layer fires on_discovery(kind, state_id) at most once per distinct discovery across every process that shares the table. The DiscoveryKind values and the macros that produce them:

KindProduced byExplorer priority
WatermarkImprovementa NumericSometimes watermark movesprogress (2)
FrontierAdvancemore assert_sometimes_all! facts true at once than beforeprogress (2)
BucketQualityan assert_sometimes_each! bucket’s quality value improvesprogress (2)
BucketFirsta new assert_sometimes_each! identity bucketstructured novelty (1)
BooleanCombinationa new partial truth combination in assert_sometimes_all!structured novelty (1)
SometimesPassfirst pass of assert_sometimes! or assert_reachable!coverage (0)

Contract Validation

validate_assertion_contracts() returns (always_violations, coverage_violations) after the campaign:

KindAlways violationCoverage violation
Alwaysfail_count > 0, or the site was never evaluated (must_hit)
AlwaysOrUnreachablefail_count > 0
Unreachablepass_count > 0
NumericAlwaysfail_count > 0
Sometimesevaluated at least once, never passed
Reachablenever reached
NumericSometimesevaluated, never passed
BooleanSometimesAllfrontier < frontier_target

Table integrity counts as an always violation: dropped slot allocations, dropped bucket allocations, a slot conflict or a bucket conflict (two messages hashing to one slot). SimulationReport.dropped_assertion_allocations reports the dropped count.

Coverage violations do not fail a FixedCount campaign by themselves. They stop UntilCoverageStable from converging, and the report prints them.

Table Limits

ConstantValueMeaning
MAX_ASSERTION_SLOTS2048distinct assertion sites per campaign
MAX_EACH_BUCKETS256distinct assert_sometimes_each! identity buckets
MAX_EACH_KEYS6identity keys per assert_sometimes_each! call

Bucket a coarse vocabulary (phase, role, floor), not identifiers (node id, slot number).

Probe Macros

moonpool-assertions exports two lightweight probes for library code that must not depend on moonpool-sim:

MacroFormEquivalent
reachable!reachable!("msg")assert_reachable!
sometimes!sometimes!(cond, "msg")assert_sometimes!

moonpool-sim re-exports them as moonpool_sim::reachable and moonpool_sim::sometimes.

ItemWherePurpose
assertion_results() -> BTreeMap<String, AssertionStats>moonpool_simper-message { total_checks, successes }
reset_assertion_results()moonpool_simclear the table (the runner does this per campaign)
has_always_violations(), reset_always_violations()moonpool_simthe per-run always flag
validate_assertion_contracts()moonpool_simthe rules above
AssertKind, AssertCmpmoonpool_assertions, re-exportedthe kind and comparison enums
AssertionDetailmoonpool_sim reportmsg, kind, pass_count, fail_count, watermark, frontier, frontier_target, combinations_seen, status
AssertionStatusmoonpool_sim reportFail, Miss, Pass
BucketSiteSummarymoonpool_sim reportmsg, buckets_discovered, total_hits per sometimes_each site
SimulationReport.assertion_detailsreportone AssertionDetail per slot
SimulationReport.bucket_summariesreportone BucketSiteSummary per site
SimulationReport.assertion_violationsreportalways-style violations found by validation
SimulationReport.coverage_violationsreportsometimes-style misses

Where to Use Which

SituationMacro
An invariant that must hold on every evaluationassert_always!
An invariant on a path that may never run under some seedsassert_always_or_unreachable!
A branch the chaos must reach (retry, timeout, recovery)assert_sometimes! or assert_reachable!
A branch that must never runassert_unreachable!
A bound (queue depth, latency, replica lag)assert_always_less_than! and friends
Depth the explorer should push (level reached, slots decided)assert_sometimes_greater_than!
Several facts that must coincide at least onceassert_sometimes_all!
Coverage per identity with a quality valueassert_sometimes_each!

See Assertions: Finding Bugs for the narrative and The Frontier Controller for how discoveries drive exploration.