feat: distribution simulation tests #34

Merged
zacheryasc merged 11 commits from distribution-sim-tests into master 2026-02-13 13:18:39 +00:00
Owner

Test cluster behavior in simulation.

Test cluster behavior in simulation.
zacheryasc added 11 commits 2026-02-13 13:18:21 +00:00
Add sim infrastructure for registry testing:
- Extend DistributionSnapshot with registry_size, registry_tombstone_count
- Add SimAction enum (RegisterName, RegisterNameWithActor, UnregisterName)
- Add action_schedule to DistributionSimConfig for mid-sim registry ops
- Add run_simulation_with_nodes() returning node references for assertions
- Add property checks: registry_propagation, registry_tombstones, etc.

6 registry sim tests:
- registry_name_converges_across_cluster (PASS)
- split_brain_naming_converges_after_partition_heals (IGNORED — bug)
- tombstone_propagates_when_name_owner_dies (IGNORED — bug)
- rapid_re_registration_converges_to_latest (PASS)
- simultaneous_registration_converges_deterministically (PASS)
- multiple_names_from_different_nodes_all_propagate (PASS)

BUG FOUND: SwimProbe::check_suspicion_timeouts() calls
members.declare_dead() internally before SwimNode::translate_probe_actions()
processes the DeclareDead action, so the second declare_dead() returns false
and MembershipChanged{Dead} is never emitted. This silently breaks all
death-related side effects: RT cleanup, cache invalidation, repair queue
population, and registry tombstoning.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
Bug 1 (swim/node.rs): SwimProbe::check_suspicion_timeouts() calls
members.declare_dead() before translate_probe_actions() processes the
DeclareDead action. The second declare_dead() returned false (already dead),
so MembershipChanged{Dead} was never emitted and the death was never
enqueued for dissemination. Fix: remove the redundant declare_dead() call
in translate_probe_actions since the probe already performed the mutation.

Bug 2 (swim/node.rs): apply_membership_update() — which processes piggyback
on every ping/ack/ping_req — updated the internal member list but never
emitted NodeAction::MembershipChanged. This meant DistributedNode was blind
to all state transitions learned via gossip piggyback (e.g., a dead node
refuting via incarnation bump). Fix: return MembershipChanged actions from
apply_piggyback and propagate through handle_ping/handle_ack/handle_ping_req.

Bug 3 (node.rs): DistributedNode::handle_ping/handle_ack/handle_ping_req
never processed MembershipChanged actions from SwimNode — only tick() did.
Fix: extract process_membership_changes() helper and call it from all four
message paths (tick, handle_ping, handle_ack, handle_ping_req).

Additional fixes:
- registry.rs: add re_disseminate_all() for anti-entropy on partition heal
- node.rs: call re_disseminate_all on MemberState::Alive transitions so
  registry state accumulated during partition reaches recovering nodes
- cluster_scenarios: enable dead_reprobe in 10% message loss test, since
  correct death dissemination (now working) causes cascading false deaths
  without a recovery mechanism

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
Phase 3 — lifecycle sim tests (distribution_lifecycle.rs):
- dead_node_triggers_repair_queue_and_cache_invalidation
- revived_node_has_empty_directory
- cache_shrinks_after_node_death
- routing_table_recovers_after_partition_heals
- routing_table_bounded_by_alive_count

Phase 4 — property-based sim tests (distribution_properties.rs):
- routing_table_bounded_across_configs (3 config variants)
- cache_bounded_across_configs (2 config variants)
- repair_queue_populates_on_death_with_directory_entries
- registry_eventually_consistent_across_configs (3 config variants)
- cascading_deaths_maintain_invariants

Also: update cluster_scenarios 10% message loss test to use
suspicion_timeout=60 + indirect_probes=3 + dead_reprobe=15
for resilience under correct death dissemination.

Remove diagnostic debug_registry.rs (superseded by distribution_registry.rs).

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
Two bugs found by simulation testing:

1. Suspect nodes could never recover after dissemination budget expired.
   When probing a target, the Suspect state was not re-enqueued into the
   dissemination queue (only Dead was). After budget exhaustion, the
   Suspect node never received a piggyback telling it it was suspected,
   so it could never refute via incarnation bump. Fix: re-enqueue both
   Suspect and Dead state on outgoing probes.

2. Registry entries merged before membership changes in same piggyback.
   When a message carried both a death notification and registry entries,
   the entries were merged first, then immediately tombstoned. Fix: split
   extract_registry_piggyback into unpack + deferred merge, processing
   membership changes before merging registry entries.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
Cycle 2 tests:
- explicit_unregister_propagates_to_all_nodes
- re_registration_after_tombstone_succeeds
- all_names_tombstoned_when_owner_dies
- graceful_leave_tombstones_registry_names
- piggyback_contention_both_propagate

Also:
- Add GracefulLeave variant to SimAction enum
- Fix cluster_survives_brief_message_loss config (dead_reprobe + suspicion_timeout)
- Harden split_brain test config (suspicion_timeout=200 prevents cascading false deaths)

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
New tests:
- registry_converges_despite_message_loss (30% loss window + clean convergence)
- simultaneous_kill_of_multiple_name_owners (3 name-owning nodes killed at once)
- suspected_name_owner_recovers_and_registry_survives (Suspect→Alive path)
- registry_correct_under_rapid_churn (interleaved kills + registrations + takeover)

Total: 15 registry tests, 5 lifecycle, 5 property = 25 distribution sim tests.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
New tests:
- asymmetric_partition_registry_converges_after_heal (one-way reachability)
- revived_node_re_registration_overwrites_tombstone (death + revive + takeover)
- registry_convergence_is_monotonic_in_stable_cluster (once converged, stays converged)
- large_cluster_registry_converges (15-node stress with 2 deaths)

Total: 15 registry + 5 lifecycle + 9 property = 29 distribution sim tests.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
New tests:
- partition_then_death_during_partition_then_heal (combined lifecycle scenario)
- registry_tombstones_gc_after_ttl (tombstone GC with short TTL + clock advancement)

Total: 15 registry + 7 lifecycle + 9 property = 31 new distribution sim tests.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
3 new lifecycle sim tests:
- asymmetric_one_way_block_does_not_kill_node: gossip recovery through intermediate nodes
- names_registered_during_partition_propagate_after_heal: re_disseminate_all on Alive transition
- bidirectional_suspicion_both_nodes_recover: mutual suspicion + refutation via gossip

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
4 new distribution sim tests:
- asymmetric_one_way_block_does_not_kill_node: gossip recovery through intermediates
- names_registered_during_partition_propagate_after_heal: re_disseminate_all on Alive
- bidirectional_suspicion_both_nodes_recover: mutual suspicion + refutation cycle
- three_way_partition_heals_and_converges: 9-node 3-group split recovers

35 total distribution sim tests (15 registry + 10 lifecycle + 10 property), all green.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
zacheryasc merged commit cd1816e398 into master 2026-02-13 13:18:39 +00:00
zacheryasc deleted branch distribution-sim-tests 2026-02-13 13:18:39 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: zacheryasc/swactor#34
No description provided.