Phase 0: Replay and snapshot reconstruction #56

Merged
erikinkinen merged 3 commits from 0-replay-and-snapshot-reconstruction into main 2026-03-03 10:43:49 +01:00
Owner

Summary

Implements replay and snapshot reconstruction for event-log history (#15), so state can be reconstructed strictly from history and compared deterministically against live state.

Closes #15.

What Changed

Replay APIs (aes::io)

Added to io/include/aes/io/event_log.hpp:

  • core::Result<sim::Engine> replay_event_log_jsonl(const std::string &path);
  • core::Result<sim::Engine> replay_event_log_jsonl_until(const std::string &path, std::uint64_t t);
  • core::Error verify_replay_matches_live_state(const sim::Engine &live, const std::string &path);

Full Replay

  • Implemented replay from validated JSONL log records into a fresh sim::Engine.
  • Reconstructs time, history, stores, and adjacency indices through event replay.
  • Restores ID generator cursors for resume-capable snapshots.

Replay-Until-Time

  • Added inclusive replay until logical tick t.
  • Enforces strict bounds:
    • t == 0 -> Errc::OutOfRange
    • t > log_size -> Errc::OutOfRange
  • Returns snapshot with time == t and history.size() == t.

Live-State Verification

  • Added deterministic replay-vs-live comparison:
    • compares time
    • history IDs and events
    • subjects, objects, edges
    • outgoing/incoming indices
    • next ID cursors
  • Excludes seed from equality scope by design.
  • Validates both states via validate_graph.
  • Returns Errc::InvariantViolation on first semantic mismatch with explicit message.

Supporting Changes

  • core/include/aes/core/ids.hpp:
    • added next_object_value(), next_edge_value(), next_event_value()
    • added reset_next_values(...)
  • io/CMakeLists.txt:
    • linked aes_io publicly against aes_sim.

Tests

Added/extended replay coverage in tests/event_log_replay_tests.cpp:

  • full replay reconstruction success
  • empty-log replay behavior
  • replay error propagation (parse/io)
  • replay-until success (mid-log snapshot)
  • replay-until strict bound failures (t=0, t>size)
  • ID cursor restoration checks
  • verify replay matches live state success/failure
  • seed exclusion verification

Validation

Ran:

  • cmake --build _build
  • ctest --test-dir _build --output-on-failure

Result:

  • 24/24 tests passed.
## Summary Implements replay and snapshot reconstruction for event-log history (`#15`), so state can be reconstructed strictly from history and compared deterministically against live state. Closes #15. ## What Changed ### Replay APIs (`aes::io`) Added to `io/include/aes/io/event_log.hpp`: - `core::Result<sim::Engine> replay_event_log_jsonl(const std::string &path);` - `core::Result<sim::Engine> replay_event_log_jsonl_until(const std::string &path, std::uint64_t t);` - `core::Error verify_replay_matches_live_state(const sim::Engine &live, const std::string &path);` ### Full Replay - Implemented replay from validated JSONL log records into a fresh `sim::Engine`. - Reconstructs `time`, `history`, stores, and adjacency indices through event replay. - Restores ID generator cursors for resume-capable snapshots. ### Replay-Until-Time - Added inclusive replay until logical tick `t`. - Enforces strict bounds: - `t == 0` -> `Errc::OutOfRange` - `t > log_size` -> `Errc::OutOfRange` - Returns snapshot with `time == t` and `history.size() == t`. ### Live-State Verification - Added deterministic replay-vs-live comparison: - compares `time` - history IDs and events - subjects, objects, edges - outgoing/incoming indices - next ID cursors - Excludes `seed` from equality scope by design. - Validates both states via `validate_graph`. - Returns `Errc::InvariantViolation` on first semantic mismatch with explicit message. ### Supporting Changes - `core/include/aes/core/ids.hpp`: - added `next_object_value()`, `next_edge_value()`, `next_event_value()` - added `reset_next_values(...)` - `io/CMakeLists.txt`: - linked `aes_io` publicly against `aes_sim`. ## Tests Added/extended replay coverage in `tests/event_log_replay_tests.cpp`: - full replay reconstruction success - empty-log replay behavior - replay error propagation (parse/io) - replay-until success (mid-log snapshot) - replay-until strict bound failures (`t=0`, `t>size`) - ID cursor restoration checks - verify replay matches live state success/failure - seed exclusion verification ## Validation Ran: - `cmake --build _build` - `ctest --test-dir _build --output-on-failure` Result: - `24/24` tests passed.
erikinkinen added this to the Phase 0 milestone 2026-03-03 10:40:23 +01:00
Phase 0: Verify replay matches live state (#15)
All checks were successful
ci / smoke (push) Successful in 12s
clang-format / check-format (push) Successful in 8s
markdownlint / markdown-lint (push) Successful in 10s
ci / smoke (pull_request) Successful in 12s
clang-format / check-format (pull_request) Successful in 8s
markdownlint / markdown-lint (pull_request) Successful in 10s
489c4701f4
Sign in to join this conversation.
No reviewers
No milestone
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
erikinkinen/AES!56
No description provided.