interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

branch main Branches Tags History

synapse / docs / B4_REVISION_STATES.md

96 lines · 24697 bytes Raw Blame History Source

B4: Revision State Machine

ADR 0003 section 9 step B4 (issue aien-dev/synapse#28). Section 5.3 ("States") and need N14: a revision is Private (visible only to its owner's delegation chain) or Draft (visible within Read scope), then Proposed, then Verified (every claim and required action discharged on its exact tree), then Canonical (promoted by quorum, immutable). Revisions never change state backwards; replacing one creates a new revision and an obsolescence marker (B1). Builds on B1 (revisions, admission witnesses, chain dominance) and F1 (capability chains).

Code: crates/synapse-core/src/revision_state.rs (RevisionState, the order rule, the owner-move rule), crates/synapse-auth/src/state_move.rs (SignedStateMove: the mover's signed statement and its check against the chain leaf, issue #89), crates/synapse-store/src/revision.rs (state in the ledger, visibility, moves), crates/synapse-store/src/{lib,codec}.rs (WAL kind 9, replay, checkpoint), crates/synapse-api/src/lib.rs (advance_revision_state, read_revision). Tests: unit tests in crates/synapse-core/src/revision_state.rs, crates/synapse-auth/src/state_move.rs, and crates/synapse-store/src/revision.rs (b4_tests, including the b89_ tests), crates/synapse-store/tests/b4_revision_states.rs (with the shared real-F1-link fixture tests/common/mod.rs), crates/synapse-api/tests/b4_revision_states.rs. Evidence: evidence/b4-revision-states/.

1. Model and invariants

2. Operations

OperationStoreAPI (F1 chained request)
Moveadvance_revision_state(state_move: SignedStateMove, now_ms) -> WalSeqadvance_revision_state(req, now_ms): capability Propose; payload = RevisionStateMovePayload (built with RevisionStateMovePayload::sign_new); chain = the request's chain; mover key = the request's agent key; leaf link = the request chain's leaf
Readget_revision_visible_to(repo, id, viewer), change_status_visible_to(repo, change_id, viewer)read_revision(req, now_ms): capability Read; payload = the 32-byte ChangesetId; every mutation path of the revision must be in the leaf's path scope, otherwise ChangesetNotFound
Server-side readget_revision(repo, id), change_status(repo, change_id) (unfiltered)through store()

Move check order: to == Canonical (CanonicalOutsidePromotionQueue), then the mover signature and leaf binding (AuthSignatureInvalid: a payload signed by another key, over another chain, state, or time, or with a flipped bit), then visibility (ChangesetNotFound), then owner chain (AuthChainNotDominant), then the owner-move rule (RevisionStateMoveInvalid). A store still writing v1 JSON records refuses moves with EnvelopeVersionUnsupported, as for B1 records. Nothing is written on a refusal.

3. Canonical binary layout (principle P5)

All integers little-endian; str = u32 len | UTF-8; trailing bytes refused.

4. Acceptance

Acceptance (issue #28)Test
Over random operation sequences no revision moves backwardsb4_property_random_operation_sequences_never_move_a_revision_backwards (store: 12 seeded cases of 40 random admissions, joins, moves by any chain to any state, reopens, and checkpoint-compact-reopens, checked against a model, under the EveryCommit and group-commit fsync policies); b4_property_forged_record_sequences_never_move_a_revision_backwards (ledger: 200 seeded cases of 60 raw records including forged moves, rebuilt from the log); b4_replay_refuses_a_forged_move_to_verified; b4_property_random_move_sequences_never_move_backwards (core: 2000 cases of 32 moves)
A Private revision is invisible to every key outside its owner chainb4_private_revision_is_invisible_to_every_key_outside_its_owner_chain (read, change status, parent, marker, and move, for the delegation tree and 200 random chains, after replay and a checkpoint); b4_api_private_revision_is_invisible_outside_its_owner_chain_with_real_f1_chains; joins: b4_joining_identical_content_grants_no_ownership_of_a_private_revision (also after replay and a checkpoint), b4_api_joining_identical_content_grants_no_ownership_of_a_private_revision
Any move to Canonical outside the promotion queue is refusedb4_any_move_to_canonical_outside_the_promotion_queue_is_refused; b4_api_move_to_canonical_outside_the_promotion_queue_is_refused (including a grant with Publish and CanonicalViaPromotionQueue); b4_owner_moves_never_reach_verified_or_canonical
Acceptance (issue #89)Test
A forged or resealed kind 9 record with a bad signature or a non-leaf signer changes nothing on replayb89_forged_owner_move_resealed_in_the_wal_changes_nothing_on_replay (a broken-signature and a validly-signed-by-another-key owner move written through the store's own framing: torn-tail recovery keeps both as counted no-ops, strict recovery refuses the store with RevisionStateMoveUnverified, both before and after checkpoint and compaction); the ledger property test now mixes both forgeries into its 200 cases and checks the replay report; b89_api_state_moves_must_be_signed_by_the_request_agent (API: a payload signed by another key, over another chain, state, or time, or with a flipped bit, is AuthSignatureInvalid and writes nothing)
A legitimate signed move round-trips write, replay, checkpoint, and compaction, and the state root covers itb89_signed_owner_move_round_trips_replay_checkpoint_and_compaction; b89_state_root_record_digest_covers_the_signature_fields
Review of PR #100: a torn-tail store can be compacted back into one strict recovery acceptsb89_torn_tail_compaction_drops_unverified_moves_so_strict_recovery_accepts_the_store (red on 30353d6: red-green/b89-red-compaction.txt)
Review of PR #100: verify() alone accepts a forger-minted leaf link; the owner rule refuses itb89_a_forger_minted_leaf_link_verifies_but_never_owns_a_revision (a self-minted root link and a self-appended link under the owner chain both verify; plan_move refuses both with AuthChainNotDominant and replay keeps them as no-ops; fails if ownership is widened to descendant chains)
Strict codec: malformed or truncated records refused typedb4_state_move_records_round_trip_and_malformed_bytes_are_refused_typed (signed layout: every cut, trailing bytes, unknown tag, the #88 layout, a malformed leaf link); the API payload loop in b4_api_* (empty, 33-byte #88 payload, bad tag, 104 and 106 bytes); crates/synapse-auth/src/state_move.rs unit tests (a move signed by the leaf verifies for root and derived chains; a flipped bit, another signer, a link that is not the chain leaf, and a link of another repository are refused)

Also: b4_state_move_records_round_trip_and_malformed_bytes_are_refused_typed, b4_state_tags_round_trip_and_unknown_tags_are_not_states, b4_every_allowed_move_raises_the_rank_and_every_other_pair_is_refused. The B1 prune tests now share the orchestrator's revision (Private -> Draft) before checking that other chains are refused for dominance, since a Private revision is now unknown to them.

Red before green: each acceptance test was run against the B4 commit with one mutation that removes the behaviour it proves (evidence/b4-revision-states/red-green/red.txt), and fails; green.txt holds the passing runs. The join tests (review of PR #88) were committed before their fix and fail on the earlier implementation (red-join.txt); so was the replay test b4_replay_refuses_a_forged_move_to_verified (red-replay.txt). Issue #89: b89_forged_owner_move_resealed_in_the_wal_changes_nothing_on_replay fails on the #88 head cf3879f, where a resealed unsigned owner move publishes a Private revision on replay (red-green/b89-red.txt); b89-green.txt holds the passing runs on this branch; the review fixes have b89-red-compaction.txt and b89-green-review.txt.

5. Limits and deviations

6. Revision seal (issue #101)

Code: crates/synapse-store/src/seal.rs (RevisionSeal, RevisionSealKey, the head and signature), crates/synapse-store/src/revision.rs (checking at replay, sealing on write, compaction), crates/synapse-store/src/codec.rs (the trailer), crates/synapse-store/src/lib.rs (open_sealed, strict refusal). Tests: the s101_ tests in crates/synapse-store/src/revision.rs.

Limits: