Repository navigation
feat(core): state machine legality + effect sandwich (E2) - #16
Merged
Merged
Conversation
- state.rs: explicit legal transition table (can_transition) per architecture §5; illegal moves are errors, never panics - storage.rs: commit() validates CAS + legality before writing a single byte; replay enforces the same table (tampered logs rejected at open) - Record::State gains a 'snapshot' flag: compact() writes a materialized state record, not an illegal transition; backward compatible (serde default) - machine.rs (new): effect sandwich driver — begin (intent + pending cell + pc→Executing, one atomic commit) / settle_ok / settle_err / finish, with ReplaySafety contracts (idempotent/guarded/never) persisted in the intent payload - Deterministic resume: reads only the durable pending cell, resolves to Clean / ReExecute / Fail - 8 new tests incl. crash-at-each-sandwich-point determinism proof: resumed durable state == no-crash reference run
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
Addresses cora review round 2 (both findings valid): - begin() refuses when the pending cell is already set (one sandwich at a time; the cell is the crash sentinel and must never be overwritten) - settle_ok/settle_err verify the handle matches the pending cell's intentId before settling (catches wrong-handle and double-settle) - new StorageError::Effect variant for sandwich invariant violations - 3 regression tests: double-begin, wrong-handle settle, double-settle
This was referenced Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements E2 — state machine (issue #2).
StorageError::IllegalTransition, never panic, and never write a bytecompact()now writes asnapshotstate record so compacted files stay replayablemachinemodule: the three-layer effect sandwich (begin→ effect →settle_ok/settle_err) withReplaySafetycontractsresume()reads only the durablependingcell →Clean/ReExecute/Failbegin()refuses while a pending cell is set;settle_*verify the handle matches the pending cell (no double-settle, no wrong-handle settle)Why
The JSONL log from E1 is only crash-safe if program-counter steps are constrained to the legal transition table — otherwise a torn or hand-edited file could silently move the machine anywhere. E2 makes the table an enforced invariant at both write time and replay time, and gives tool effects a durable intent/settlement sandwich so a crash mid-effect resumes deterministically instead of guessing.
Testing
open()Closes #2