interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

B2: undo, discard and revoke as logged operations, with a digest of what each change shows

closed 6414ec8c57fc20ad #113 · opened 2026-10-18 17:29 UTC · closed 2026-10-29 18:59 UTC

Imported from GitHub aien-dev/synapse#113, by drakestapleton

Base 2f06c455a5af8a5db7e0230c3692f08db21f61f2 · Head 8c68955f1e230f37df3daecb4b61a9237071849d

drakestapleton wrote on 2026-10-18 17:29 UTC

Closes #30.

What

  • WAL kind 12 records for undo (whole change or one actor's work), plain discard, final discard and revocation.
  • A view (the visible heads of each change) computed from the log, with a Merkle digest.
  • API: undo (needs the Undo capability), discard (needs Propose), operator revoke_link.
  • Compaction keeps kind 12 records. Design note docs/B2_OPERATION_VIEWS.md.

Evidence (worker run, verified by the desk before merge)

  • CARGO_TARGET_DIR=~/workspace/targets/syn-30 cargo test --workspace --locked --no-fail-fast: 410 passed, 0 failed; clippy -D warnings and fmt clean.
  • 14 of 14 deliberate code breakages turn tests red (evidence/b2-operation-views/).

Not covered

  • No undo window and no garbage collection (K1).
  • The policy enforcer's grants and revocations are not rebuilt when the store reopens.
  • Kind 12 records carry no agent signature; they rely on the #101 seal.
  • README per-step index lives in #106.
  • Small textual conflict with B3 (revision.rs test helpers, core lib.rs refusal codes); the second to merge is rebased by the desk.

🤖 Generated with Claude Code

drakestapleton wrote on 2026-10-29 18:59 UTC

Closing in org cleanup (Drake, 2026-10-29): abandoned: no activity in 11 days (>= 7 days), merge conflicts with base, failing checks with no follow-up. Reopen if still needed.

Apply it

git checkout -b patch-6414ec8c57fc20ad 2f06c455a5af8a5db7e0230c3692f08db21f61f2
curl -fsSL https://interplane.io/drakestapleton/synapse/patches/6414ec8c57fc20ad.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/synapse
113
8c68955f1e230f37df3daecb4b61a9237071849d
{"kind":"github-import","owner":"aien-dev","repo":"synapse","number":113,"url":"https://github.com/aien-dev/synapse/pull/113","export_sha256":"1c576073d3642d6130bfff61541dda3d27f03618b9224cb72ff5d1ad6d163116","imported_utc":"2026-11-18T16:39:09Z"}

Changes

diff --git a/crates/synapse-api/src/lib.rs b/crates/synapse-api/src/lib.rs
index f41f7de..1fd703c 100644
--- a/crates/synapse-api/src/lib.rs
+++ b/crates/synapse-api/src/lib.rs
@@ -21,7 +21,7 @@ use synapse_core::{
 use synapse_core::{ChainPath, ChangeId, ChangesetEnvelopeV2, ObsolescenceMarker, RevisionState};
 use synapse_store::{
     AdmissionAuthority, CompactionReport, FsyncPolicy, IngestOutcome, RecoveryPolicy, ReviewRecord,
-    RevisionOutcome, StoreLimits, StoredChangeset, StoredRevision, SynapseStore,
+    RevisionOutcome, StoreLimits, StoredChangeset, StoredRevision, SynapseStore, ViewOutcome,
 };
 
 mod advisory;
@@ -318,6 +318,94 @@ impl RevisionStateMovePayload {
     }
 }
 
+/// Request payload for [`SynapseService::undo`] (ADR 0003 B2): `target u64 | 0` for a whole
+/// undo, or `target u64 | 1 | chain path` (core `ChainPath` encoding) to undo only the
+/// operations of that actor chain and the chains below it.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct UndoPayload {
+    pub target: WalSeq,
+    pub actor: Option<ChainPath>,
+}
+
+impl UndoPayload {
+    pub fn encode(&self) -> Vec<u8> {
+        let mut buf = Vec::with_capacity(9 + 1 + 32 * 4);
+        buf.extend_from_slice(&self.target.0.to_le_bytes());
+        match &self.actor {
+            None => buf.push(0),
+            Some(a) => {
+                buf.push(1);
+                a.encode_into(&mut buf);
+            }
+        }
+        buf
+    }
+
+    /// The one encoding above; anything else is `EnvelopeMalformed`.
+    pub fn decode(bytes: &[u8]) -> SynapseResult<Self> {
+        let malformed = || {
+            SynapseError::new(
+                RefusalCode::EnvelopeMalformed,
+                "undo payload must be target u64 | 0, or target u64 | 1 | chain path",
+            )
+        };
+        if bytes.len() < 9 {
+            return Err(malformed());
+        }
+        let (target, rest) = bytes.split_at(8);
+        let target = WalSeq(u64::from_le_bytes(
+            target.try_into().map_err(|_| malformed())?,
+        ));
+        let actor = match (rest[0], &rest[1..]) {
+            (0, []) => None,
+            (1, chain) => Some(ChainPath::decode(chain).map_err(|_| malformed())?),
+            _ => return Err(malformed()),
+        };
+        Ok(Self { target, actor })
+    }
+}
+
+/// Request payload for [`SynapseService::discard`] (ADR 0003 B2), exactly 33 bytes:
+/// `changeset_id [32] | final u8 (0 plain, 1 final)`.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct DiscardPayload {
+    pub changeset_id: ChangesetId,
+    pub final_discard: bool,
+}
+
+impl DiscardPayload {
+    pub const LEN: usize = 33;
+
+    pub fn encode(&self) -> Vec<u8> {
+        let mut buf = Vec::with_capacity(Self::LEN);
+        buf.extend_from_slice(&self.changeset_id.0);
+        buf.push(u8::from(self.final_discard));
+        buf
+    }
+
+    /// Exactly 33 bytes with a final flag of 0 or 1; anything else is `EnvelopeMalformed`.
+    pub fn decode(bytes: &[u8]) -> SynapseResult<Self> {
+        let malformed = || {
+            SynapseError::new(
+                RefusalCode::EnvelopeMalformed,
+                "discard payload must be changeset_id [32] | final u8 (0 or 1)",
+            )
+        };
+        if bytes.len() != Self::LEN {
+            return Err(malformed());
+        }
+        let final_discard = match bytes[32] {
+            0 => false,
+            1 => true,
+            _ => return Err(malformed()),
+        };
+        Ok(Self {
+            changeset_id: ChangesetId(bytes[..32].try_into().map_err(|_| malformed())?),
+            final_discard,
+        })
+    }
+}
+
 /// Exact path index mapping repository paths to touching `ChangesetId`s. Trees live in the
 /// service's shared [`TreeStore`].
 #[derive(Debug, Default)]
@@ -750,6 +838,80 @@ impl SynapseService {
         self.store.advance_revision_state(state_move, now_ms)
     }
 
+    /// Undo (ADR 0003 B2) under an F1 delegation chain granting `Undo`. `req.payload` is an
+    /// [`UndoPayload`]. The store applies the undo rules: a target not before the undo is
+    /// `UndoTargetInvalid`, an undo reaching a revocation or a final discard is
+    /// `UndoIrreversible`, and an undo reaching an operation of an actor chain the request's
+    /// chain does not dominate is `AuthChainNotDominant`. Undo moves references only.
+    pub fn undo(&mut self, req: &ChainedRequest, now_ms: u64) -> SynapseResult<ViewOutcome> {
+        let p = UndoPayload::decode(&req.payload)?;
+        self.auth.authorize_chain(
+            BoundaryKind::Api,
+            "undo",
+            &self.repo_id,
+            Capability::Undo,
+            req,
+            self.store.committed_seq().next(),
+            now_ms,
+        )?;
+        let chain = admission_authority(req)?.chain;
+        self.store
+            .record_undo(self.repo_id.clone(), p.target, p.actor, chain, now_ms)
+    }
+
+    /// Discard a revision (ADR 0003 B2), plain (undoable) or final (never undone), under an
+    /// F1 delegation chain granting `Propose`. `req.payload` is a [`DiscardPayload`]. The
+    /// store requires the chain to own the revision (`AuthChainNotDominant`) and refuses a
+    /// revision already finally discarded (`DiscardInvalid`).
+    pub fn discard(&mut self, req: &ChainedRequest, now_ms: u64) -> SynapseResult<ViewOutcome> {
+        let p = DiscardPayload::decode(&req.payload)?;
+        self.auth.authorize_chain(
+            BoundaryKind::Api,
+            "discard",
+            &self.repo_id,
+            Capability::Propose,
+            req,
+            self.store.committed_seq().next(),
+            now_ms,
+        )?;
+        let chain = admission_authority(req)?.chain;
+        self.store.record_discard(
+            self.repo_id.clone(),
+            p.changeset_id,
+            p.final_discard,
+            chain,
+            now_ms,
+        )
+    }
+
+    /// Revoke the leaf link of `revoked` on behalf of the chain `by` (operator path, ADR 0003
+    /// B2): the revocation is written to the operation log as a fact no undo reaches, and the
+    /// policy enforcer refuses every chain through the link for requests at that sequence or
+    /// later. `by` must be or dominate `revoked` (`AuthChainNotDominant`); a link the
+    /// enforcer never granted is `AuthChainBroken`. Both checks run before anything is
+    /// written.
+    pub fn revoke_link(
+        &mut self,
+        revoked: ChainPath,
+        by: ChainPath,
+        now_ms: u64,
+    ) -> SynapseResult<ViewOutcome> {
+        let leaf = synapse_auth::LinkDigest(*revoked.links().last().ok_or_else(|| {
+            SynapseError::new(RefusalCode::AuthChainBroken, "revoke: empty chain")
+        })?);
+        if self.auth.unallocated_quota(&leaf).is_none() {
+            return Err(SynapseError::new(
+                RefusalCode::AuthChainBroken,
+                "cannot revoke a link never granted",
+            ));
+        }
+        let out = self
+            .store
+            .record_revocation(self.repo_id.clone(), revoked, by, now_ms)?;
+        self.auth.revoke_link(leaf, out.wal_seq)?;
+        Ok(out)
+    }
+
     /// Read an envelope v2 revision (ADR 0003 B4) under an F1 delegation chain granting
     /// `Read`. `req.payload` is the 32-byte `ChangesetId`. A revision the chain may not see
     /// is `ChangesetNotFound`, exactly like an unknown one: another owner's `Private`
diff --git a/crates/synapse-api/tests/b2_operation_views.rs b/crates/synapse-api/tests/b2_operation_views.rs
new file mode 100644
index 0000000..8d1cb84
--- /dev/null
+++ b/crates/synapse-api/tests/b2_operation_views.rs
@@ -0,0 +1,377 @@
+//! ADR 0003 step B2 through the API with real signed F1 capability chains: authority `A`
+//! grants orchestrator `O` (`Read`, `Propose`, `Undo`); `O` delegates worker `W` (`Read`,
+//! `Propose`, `Undo`) and worker `V` (`Read`, `Propose`, no `Undo`).
+
+use ed25519_dalek::SigningKey;
+use sha2::{Digest, Sha256};
+use std::path::{Path, PathBuf};
+use synapse_api::{DiscardPayload, SynapseService, TreeTarget, UndoPayload};
+use synapse_auth::{
+    Capability, CapabilityChain, CapabilityLink, ChainQuotas, ChainedRequest, ChangeScope,
+    LinkCaveats, OperationSet, PathScope, ReferenceKind, ReferenceScope, RequestScope, ROOT_PARENT,
+};
+use synapse_core::{
+    encode_did_key_ed25519, BlobDigest, ChainPath, ChangeId, ChangesetEnvelopeV2, ChangesetId,
+    FileMode, GitOid, IdempotencyKey, MutationOp, PathMutation, RefusalCode, RepoId,
+    RevisionContent, TreeDigest, WalSeq,
+};
+use synapse_store::{FsyncPolicy, RecoveryPolicy, RevisionOutcome, StoreLimits, ViewOutcome};
+
+const NOW: u64 = 2_000;
+
+type Agent = (SigningKey, CapabilityChain);
+
+fn link_nonces(dir: &Path) -> impl FnMut() -> [u8; 32] {
+    let seed = dir.to_string_lossy().into_owned();
+    let mut issued = 0u32;
+    move || {
+        issued += 1;
+        let mut h = Sha256::new();
+        h.update(seed.as_bytes());
+        h.update(issued.to_le_bytes());
+        h.finalize().into()
+    }
+}
+
+fn repo() -> RepoId {
+    RepoId::new("aien-spark/synapse").unwrap()
+}
+
+fn pk(k: &SigningKey) -> [u8; 32] {
+    k.verifying_key().to_bytes()
+}
+
+fn chain_path(a: &Agent) -> ChainPath {
+    ChainPath::new(a.1.link_digests().iter().map(|d| d.0).collect()).unwrap()
+}
+
+fn caveats(ops: &[Capability], share: u64) -> LinkCaveats {
+    LinkCaveats {
+        operations: OperationSet::from_capabilities(ops),
+        paths: PathScope::whole_repository(),
+        references: ReferenceScope::from_kinds(&[ReferenceKind::OwnDrafts]),
+        changes: ChangeScope::any(),
+        quotas: ChainQuotas {
+            max_ops_per_window: (1_000 / share) as u32,
+            window_duration_ms: 60_000,
+            storage_bytes: (1 << 30) / share,
+            footprint_paths: (1 << 20) / share,
+            max_bytes_per_op: 1 << 20,
+        },
+        issued_at_ms: 1_000,
+        expires_at_ms: 100_000,
+    }
+}
+
+struct Fx {
+    svc: SynapseService,
+    base: TreeDigest,
+    o: Agent,
+    w: Agent,
+    v: Agent,
+    nonce: u8,
+}
+
+impl Fx {
+    fn new(name: &str) -> Self {
+        let dir: PathBuf = std::env::temp_dir().join(format!(
+            "synapse-b2-api-{name}-{}-{}",
+            std::process::id(),
+            std::time::SystemTime::now()
+                .duration_since(std::time::UNIX_EPOCH)
+                .unwrap()
+                .as_nanos()
+        ));
+        let mut svc = SynapseService::open(
+            &dir,
+            repo(),
+            FsyncPolicy::EveryCommit,
+            RecoveryPolicy::StrictFailClosed,
+            StoreLimits {
+                wal_prealloc_bytes: 64 * 1024,
+                ..Default::default()
+            },
+        )
+        .unwrap();
+        let a = SigningKey::from_bytes(&[1; 32]);
+        let key = |n: u8| SigningKey::from_bytes(&[n; 32]);
+        let (o, w, v) = (key(2), key(3), key(4));
+        svc.auth_mut()
+            .register_repo_authority(repo(), encode_did_key_ed25519(&pk(&a)));
+        let rpu = [Capability::Read, Capability::Propose, Capability::Undo];
+        let rp = [Capability::Read, Capability::Propose];
+        let mut nonce = link_nonces(&dir);
+        let root_o =
+            CapabilityLink::issue(&a, ROOT_PARENT, nonce(), repo(), pk(&o), caveats(&rpu, 1));
+        let link_w = CapabilityLink::issue(
+            &o,
+            root_o.digest(),
+            nonce(),
+            repo(),
+            pk(&w),
+            caveats(&rpu, 4),
+        );
+        let link_v = CapabilityLink::issue(
+            &o,
+            root_o.digest(),
+            nonce(),
+            repo(),
+            pk(&v),
+            caveats(&rp, 4),
+        );
+        let co = CapabilityChain::new(vec![root_o]);
+        let (cw, cv) = (co.extended(link_w), co.extended(link_v));
+        for c in [&co, &cw, &cv] {
+            svc.auth_mut().grant_link(c, WalSeq(0), NOW).unwrap();
+        }
+        let base_oid = GitOid([0x0B; 20]);
+        svc.register_base_tree(
+            base_oid,
+            vec![("README.md".into(), FileMode::Regular644, b"base".to_vec())],
+        )
+        .unwrap();
+        let base = svc
+            .tree_digest(TreeTarget::BaseGitCommit(base_oid), None)
+            .unwrap();
+        Self {
+            svc,
+            base,
+            o: (o, co),
+            w: (w, cw),
+            v: (v, cv),
+            nonce: 0,
+        }
+    }
+
+    fn request(
+        &mut self,
+        who: &Agent,
+        cap: Capability,
+        scope: RequestScope,
+        payload: Vec<u8>,
+    ) -> ChainedRequest {
+        self.nonce += 1;
+        ChainedRequest::sign_new(
+            &who.0,
+            who.1.clone(),
+            repo(),
+            cap,
+            scope,
+            [self.nonce; 32],
+            NOW,
+            payload,
+        )
+    }
+
+    /// `who` submits a revision of change `change` writing `body` to `src/lib.rs`.
+    fn submit(&mut self, who: &Agent, change: u8, body: &[u8]) -> Result<ChangesetId, RefusalCode> {
+        let c = ChangeId([change; 16]);
+        let content = RevisionContent {
+            change_id: c,
+            base_tree: self.base,
+            parents: vec![],
+            mutations: vec![PathMutation {
+                path: "src/lib.rs".into(),
+                op: MutationOp::Upsert {
+                    mode: FileMode::Regular644,
+                    blob_digest: BlobDigest::compute(body),
+                    size_bytes: body.len() as u64,
+                },
+            }],
+            intent_summary: "implement the task".into(),
+        };
+        let mut idem = [change; 32];
+        idem[1] = self.nonce;
+        let env = ChangesetEnvelopeV2::sign_new(&who.0, repo(), content, IdempotencyKey(idem), NOW);
+        let scope = RequestScope {
+            paths: vec!["src/lib.rs".into()],
+            reference: None,
+            join_change: Some(c),
+        };
+        let req = self.request(who, Capability::Propose, scope, env.encode());
+        let blobs = vec![(BlobDigest::compute(body), body.to_vec())];
+        match self
+            .svc
+            .submit_revision(&req, &blobs, NOW)
+            .map_err(|e| e.code)?
+        {
+            RevisionOutcome::Admitted { changeset_id, .. } => Ok(changeset_id),
+            other => panic!("expected an admission, got {other:?}"),
+        }
+    }
+
+    fn undo(
+        &mut self,
+        who: &Agent,
+        cap: Capability,
+        target: WalSeq,
+        actor: Option<&Agent>,
+    ) -> Result<ViewOutcome, RefusalCode> {
+        let payload = UndoPayload {
+            target,
+            actor: actor.map(chain_path),
+        }
+        .encode();
+        let req = self.request(who, cap, RequestScope::default(), payload);
+        self.svc.undo(&req, NOW).map_err(|e| e.code)
+    }
+
+    fn discard(
+        &mut self,
+        who: &Agent,
+        id: ChangesetId,
+        final_discard: bool,
+    ) -> Result<ViewOutcome, RefusalCode> {
+        let payload = DiscardPayload {
+            changeset_id: id,
+            final_discard,
+        }
+        .encode();
+        let req = self.request(who, Capability::Propose, RequestScope::default(), payload);
+        self.svc.discard(&req, NOW).map_err(|e| e.code)
+    }
+
+    fn seq(&self) -> WalSeq {
+        self.svc.store().committed_seq()
+    }
+
+    fn heads(&self, change: u8) -> Vec<ChangesetId> {
+        self.svc
+            .store()
+            .view(&repo())
+            .heads
+            .get(&ChangeId([change; 16]))
+            .map(|h| h.iter().copied().collect())
+            .unwrap_or_default()
+    }
+}
+
+/// `undo` needs a chain granting `Undo` (`AuthCapabilityDenied` otherwise, nothing written);
+/// with it, an undo restores the view of the target and undoing it gives the view back.
+#[test]
+fn b2_api_undo_requires_the_undo_capability() {
+    let mut fx = Fx::new("cap");
+    let (w, v) = (fx.w.clone(), fx.v.clone());
+    let t = fx.seq();
+    let rv = fx.submit(&v, 0x31, b"v attempt").unwrap();
+    let seq = fx.seq();
+    assert_eq!(
+        fx.undo(&v, Capability::Undo, t, Some(&v)).unwrap_err(),
+        RefusalCode::AuthCapabilityDenied
+    );
+    assert_eq!(
+        fx.undo(&v, Capability::Propose, t, Some(&v)).unwrap_err(),
+        RefusalCode::AuthCapabilityDenied
+    );
+    assert_eq!(fx.seq(), seq, "nothing written");
+    assert_eq!(fx.heads(0x31), vec![rv]);
+
+    let t = fx.seq();
+    let rw = fx.submit(&w, 0x32, b"w attempt").unwrap();
+    let before = fx.svc.store().view_at(&repo(), t).digest(&repo());
+    let out = fx.undo(&w, Capability::Undo, t, Some(&w)).unwrap();
+    assert_eq!(out.view_digest, before);
+    assert_eq!(fx.heads(0x32), Vec::<ChangesetId>::new());
+    assert_eq!(fx.heads(0x31), vec![rv]);
+    fx.undo(&w, Capability::Undo, WalSeq(out.wal_seq.0 - 1), None)
+        .unwrap();
+    assert_eq!(fx.heads(0x32), vec![rw]);
+    // Malformed payloads are refused typed.
+    let req = fx.request(&w, Capability::Undo, RequestScope::default(), vec![1, 2, 3]);
+    assert_eq!(
+        fx.svc.undo(&req, NOW).unwrap_err().code,
+        RefusalCode::EnvelopeMalformed
+    );
+}
+
+/// Undoing another actor's work needs a chain that dominates that actor's: the sibling `W`
+/// may not undo `V`'s revision, the orchestrator `O` may. A discard needs the owner chain.
+#[test]
+fn b2_api_undo_and_discard_of_another_actor_need_a_dominating_chain() {
+    let mut fx = Fx::new("dominance");
+    let (o, w, v) = (fx.o.clone(), fx.w.clone(), fx.v.clone());
+    let t = fx.seq();
+    let rv = fx.submit(&v, 0x41, b"v attempt").unwrap();
+    assert_eq!(
+        fx.undo(&w, Capability::Undo, t, None).unwrap_err(),
+        RefusalCode::AuthChainNotDominant
+    );
+    assert_eq!(
+        fx.undo(&w, Capability::Undo, t, Some(&v)).unwrap_err(),
+        RefusalCode::AuthChainNotDominant
+    );
+    assert_eq!(
+        fx.discard(&w, rv, false).unwrap_err(),
+        RefusalCode::AuthChainNotDominant
+    );
+    assert_eq!(fx.heads(0x41), vec![rv]);
+    fx.undo(&o, Capability::Undo, t, Some(&v)).unwrap();
+    assert_eq!(fx.heads(0x41), Vec::<ChangesetId>::new());
+}
+
+/// A plain discard is undoable; a final discard is a fact: an undo reaching it is
+/// `UndoIrreversible` even for the orchestrator, and the revision cannot be discarded again.
+#[test]
+fn b2_api_final_discard_can_never_be_undone() {
+    let mut fx = Fx::new("discard");
+    let (o, w) = (fx.o.clone(), fx.w.clone());
+    let rw = fx.submit(&w, 0x51, b"w attempt").unwrap();
+    let t = fx.seq();
+    fx.discard(&w, rw, false).unwrap();
+    assert_eq!(fx.heads(0x51), Vec::<ChangesetId>::new());
+    fx.undo(&w, Capability::Undo, t, None).unwrap();
+    assert_eq!(fx.heads(0x51), vec![rw]);
+    let t = fx.seq();
+    fx.discard(&w, rw, true).unwrap();
+    assert_eq!(
+        fx.undo(&o, Capability::Undo, t, None).unwrap_err(),
+        RefusalCode::UndoIrreversible
+    );
+    assert_eq!(
+        fx.discard(&w, rw, false).unwrap_err(),
+        RefusalCode::DiscardInvalid
+    );
+    assert_eq!(fx.svc.store().view(&repo()).discarded.get(&rw), Some(&true));
+}
+
+/// A revocation is written to the operation log as a fact and enforced on requests: the
+/// revoked worker's next request is `AuthGrantRevoked`, and an undo reaching the revocation
+/// is `UndoIrreversible`. Only a dominating chain may revoke; a link never granted is
+/// `AuthChainBroken`; neither refusal writes anything.
+#[test]
+fn b2_api_revocation_is_a_fact_and_is_enforced() {
+    let mut fx = Fx::new("revoke");
+    let (o, w, v) = (fx.o.clone(), fx.w.clone(), fx.v.clone());
+    let t = fx.seq();
+    fx.submit(&w, 0x61, b"w attempt").unwrap();
+    let seq = fx.seq();
+    assert_eq!(
+        fx.svc
+            .revoke_link(chain_path(&w), chain_path(&v), NOW)
+            .unwrap_err()
+            .code,
+        RefusalCode::AuthChainNotDominant
+    );
+    let never = ChainPath::new(vec![[0xAB; 32]]).unwrap();
+    assert_eq!(
+        fx.svc
+            .revoke_link(never.clone(), never, NOW)
+            .unwrap_err()
+            .code,
+        RefusalCode::AuthChainBroken
+    );
+    assert_eq!(fx.seq(), seq, "nothing written");
+    fx.svc
+        .revoke_link(chain_path(&w), chain_path(&o), NOW)
+        .unwrap();
+    assert_eq!(
+        fx.submit(&w, 0x62, b"after revocation").unwrap_err(),
+        RefusalCode::AuthGrantRevoked
+    );
+    assert_eq!(
+        fx.undo(&o, Capability::Undo, t, None).unwrap_err(),
+        RefusalCode::UndoIrreversible
+    );
+    // V is untouched.
+    fx.submit(&v, 0x63, b"v attempt").unwrap();
+}
diff --git a/crates/synapse-core/src/lib.rs b/crates/synapse-core/src/lib.rs
index 9966ad3..ff89024 100644
--- a/crates/synapse-core/src/lib.rs
+++ b/crates/synapse-core/src/lib.rs
@@ -137,6 +137,14 @@ pub enum RefusalCode {
     /// it needs: the change's creating chain for a prune, or for a rewrite or split either the
     /// creating chain or the chain that first admitted the replaced revision (step B1).
     AuthChainNotDominant,
+    /// An undo names a target that is not an earlier operation of the undo window (ADR 0003
+    /// section 5.4, step B2).
+    UndoTargetInvalid,
+    /// An undo would reach a fact that can never be undone: a revocation or a final discard
+    /// (later also canonical promotions, accepted receipts, erasures; step B2).
+    UndoIrreversible,
+    /// A discard names a revision that is already finally discarded (step B2).
+    DiscardInvalid,
     /// An obsolescence marker names an unknown revision, a revision of another change, itself
     /// as its own successor, or would close a cycle of markers (step B1).
     ObsolescenceMarkerInvalid,
diff --git a/crates/synapse-store/src/codec.rs b/crates/synapse-store/src/codec.rs
index 74247ca..9c71200 100644
--- a/crates/synapse-store/src/codec.rs
+++ b/crates/synapse-store/src/codec.rs
@@ -18,6 +18,7 @@
 //! huge length is refused without allocating it.
 
 use super::*;
+use crate::operation::ViewOperation;
 use synapse_auth::CapabilityLink;
 use synapse_core::{FileMode, GitOid, PathMutation};
 
@@ -42,6 +43,10 @@ pub const DOMAIN_CHECKPOINT_CONTENT_V2: &[u8] = b"SYNAPSE_CHECKPOINT_CONTENT_V2\
 pub const DOMAIN_CHECKPOINT_ROOT_V2: &[u8] = b"SYNAPSE_CHECKPOINT_ROOT_V2\0";
 /// Domain tag of `SynapseStore::state_root_digest` (unchanged from v1).
 pub const DOMAIN_STATE_ROOT_V1: &[u8] = b"SYNAPSE_STATE_ROOT_V1\0";
+/// View operation tags inside a kind 12 `ViewOperationRecorded` record (B2).
+const VIEW_OP_UNDO: u8 = 1;
+const VIEW_OP_DISCARD: u8 = 2;
+const VIEW_OP_REVOKE: u8 = 3;
 
 /// Which encoding a WAL record payload uses (declared by the frame header flags).
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -364,6 +369,47 @@ pub fn encode_record(record: &WalRecord) -> SynapseResult<Vec<u8>> {
             put_chain(&mut w, chain)?;
             w.u64(*admitted_at_ms);
         }
+        WalRecord::ViewOperationRecorded {
+            op,
+            chain,
+            recorded_at_ms,
+        } => {
+            match op {
+                ViewOperation::Undo {
+                    repo_id,
+                    target,
+                    actor,
+                } => {
+                    w.u8(VIEW_OP_UNDO);
+                    w.repo(repo_id)?;
+                    w.u64(target.0);
+                    match actor {
+                        None => w.u8(0),
+                        Some(a) => {
+                            w.u8(1);
+                            put_chain(&mut w, a)?;
+                        }
+                    }
+                }
+                ViewOperation::Discard {
+                    repo_id,
+                    changeset_id,
+                    final_discard,
+                } => {
+                    w.u8(VIEW_OP_DISCARD);
+                    w.repo(repo_id)?;
+                    w.raw(&changeset_id.0);
+                    w.u8(u8::from(*final_discard));
+                }
+                ViewOperation::Revoke { repo_id, revoked } => {
+                    w.u8(VIEW_OP_REVOKE);
+                    w.repo(repo_id)?;
+                    put_chain(&mut w, revoked)?;
+                }
+            }
+            put_chain(&mut w, chain)?;
+            w.u64(*recorded_at_ms);
+        }
     }
     Ok(w.0)
 }
@@ -786,6 +832,69 @@ pub fn decode_record(bytes: &[u8], cap: u64) -> Result<WalRecord, CodecRefusal>
             chain: r.embedded("chain path", ChainPath::decode)?,
             admitted_at_ms: r.u64()?,
         },
+        12 => {
+            let at = r.pos;
+            let op = match r.u8()? {
+                VIEW_OP_UNDO => {
+                    let repo_id = r.repo()?;
+                    let target = WalSeq(r.u64()?);
+                    let at = r.pos;
+                    let actor = match r.u8()? {
+                        0 => None,
+                        1 => Some(r.embedded("chain path", ChainPath::decode)?),
+                        tag => {
+                            return Err(CodecRefusal::UnknownTag {
+                                at,
+                                field: "undo actor",
+                                tag,
+                            })
+                        }
+                    };
+                    ViewOperation::Undo {
+                        repo_id,
+                        target,
+                        actor,
+                    }
+                }
+                VIEW_OP_DISCARD => {
+                    let repo_id = r.repo()?;
+                    let changeset_id = ChangesetId(r.array()?);
+                    let at = r.pos;
+                    let final_discard = match r.u8()? {
+                        0 => false,
+                        1 => true,
+                        tag => {
+                            return Err(CodecRefusal::UnknownTag {
+                                at,
+                                field: "final discard",
+                                tag,
+                            })
+                        }
+                    };
+                    ViewOperation::Discard {
+                        repo_id,
+                        changeset_id,
+                        final_discard,
+                    }
+                }
+                VIEW_OP_REVOKE => ViewOperation::Revoke {
+                    repo_id: r.repo()?,
+                    revoked: r.embedded("chain path", ChainPath::decode)?,
+                },
+                tag => {
+                    return Err(CodecRefusal::UnknownTag {
+                        at,
+                        field: "view operation",
+                        tag,
+                    })
+                }
+            };
+            WalRecord::ViewOperationRecorded {
+                op,
+                chain: r.embedded("chain path", ChainPath::decode)?,
+                recorded_at_ms: r.u64()?,
+            }
+        }
         tag => {
             return Err(CodecRefusal::UnknownTag {
                 at,
@@ -1144,7 +1253,7 @@ impl CheckpointState {
                 let tag_at = r.pos + 4 + 1;
                 let bytes = r.bytes()?;
                 let record = decode_record(&bytes, r.cap)?;
-                if !matches!(record.kind_byte(), 7..=9 | 11) {
+                if !matches!(record.kind_byte(), 7..=9 | 11 | 12) {
                     return Err(CodecRefusal::UnknownTag {
                         at: tag_at,
                         field: "revision record kind",
diff --git a/crates/synapse-store/src/lib.rs b/crates/synapse-store/src/lib.rs
index 08411db..49ee529 100644
--- a/crates/synapse-store/src/lib.rs
+++ b/crates/synapse-store/src/lib.rs
@@ -32,6 +32,9 @@ mod a1_tests;
 pub mod codec;
 #[cfg(test)]
 mod group_tests;
+mod operation;
+#[cfg(test)]
+mod operation_tests;
 mod revision;
 pub mod segment;
 #[cfg(test)]
@@ -40,6 +43,10 @@ mod shared;
 pub mod wal2;
 
 pub use codec::{CheckpointChain, CheckpointState, CodecRefusal, RecordCodec};
+pub use operation::{
+    UndoFault, View, ViewOperation, ViewOutcome, ViewReplayReport, DOMAIN_VIEW_HEADS_V1,
+    DOMAIN_VIEW_V1,
+};
 pub use revision::{
     verify_revision_log, AdmissionAuthority, ChangeStatus, RecordedMarker, RevisionOutcome,
     StateMoveReplayReport, StoredRevision, DOMAIN_STATE_ROOT_REVISIONS_V1,
@@ -342,6 +349,14 @@ pub enum WalRecord {
         chain: ChainPath,
         admitted_at_ms: u64,
     },
+    /// An operation on the references of one repository (undo, plain or final discard,
+    /// revocation) by `chain` at server time `recorded_at_ms` (ADR 0003 B2). Binary codec only.
+    #[serde(skip)]
+    ViewOperationRecorded {
+        op: crate::operation::ViewOperation,
+        chain: ChainPath,
+        recorded_at_ms: u64,
+    },
 }
 
 impl WalRecord {
@@ -357,6 +372,7 @@ impl WalRecord {
             Self::ObsolescenceRecorded { .. } => 8,
             Self::RevisionStateMoved { .. } => 9,
             Self::DerivedRevisionAdmitted { .. } => 11,
+            Self::ViewOperationRecorded { .. } => 12,
         }
     }
 
@@ -2167,7 +2183,8 @@ impl SynapseStore {
                 self.revisions.apply(seq, record);
             }
             record @ (WalRecord::ObsolescenceRecorded { .. }
-            | WalRecord::RevisionStateMoved { .. }) => self.revisions.apply(seq, record),
+            | WalRecord::RevisionStateMoved { .. }
+            | WalRecord::ViewOperationRecorded { .. }) => self.revisions.apply(seq, record),
             record @ WalRecord::DerivedRevisionAdmitted { .. } => {
                 for digest in record.upsert_blobs() {
                     self.blob_first_visible_seq.entry(digest).or_insert(seq);
diff --git a/crates/synapse-store/src/operation.rs b/crates/synapse-store/src/operation.rs
new file mode 100644
index 0000000..70b72dc
--- /dev/null
+++ b/crates/synapse-store/src/operation.rs
@@ -0,0 +1,644 @@
+//! Operation views and undo, plain and final discard (ADR 0003 section 5.4, section 9 step B2).
+//!
+//! * **Operations.** Every revision record in the WAL is an operation with an actor chain:
+//!   an admission (kinds 7 and 11), an obsolescence marker (kind 8), a state move (kind 9),
+//!   and the view operations of WAL kind 12 ([`ViewOperation`]): undo, plain and final
+//!   discard, and capability revocation.
+//! * **View.** The references of one repository: for every change, its visible heads (an
+//!   admitted revision that no marker names as predecessor and no discard names), the
+//!   discarded revisions, and conflict data (a marker or discard whose revision is not in the
+//!   view). Its digest is a two-level Merkle root ([`View::digest`]), so two views compare in
+//!   one step. Revision states (B4) are facts of the revision, not references: they are not in
+//!   the view and undo never moves a state backwards.
+//! * **Undo.** An undo to operation `T` disables every later operation of the repository
+//!   (whole undo) or every later operation whose actor chain descends from a given chain
+//!   (per-actor undo). An operation is in effect when no undo in effect disables it, which is
+//!   well defined because an undo only reaches earlier operations: undoing an undo re-enables
+//!   what it disabled, so undo is undoable, and a whole undo to `T` gives back the exact view
+//!   of `T`. Undo changes references only; no object is deleted.
+//! * **Who may undo what.** The undoer's chain must be, or dominate, the actor chain of every
+//!   operation the undo reaches (`AuthChainNotDominant`). Facts are never undone: an undo
+//!   that reaches a revocation or a final discard is refused (`UndoIrreversible`). Canonical
+//!   promotions, accepted receipts and erasures join this list when E1, E2 and M2 create them.
+//! * **Replay.** The effect of every kind 12 operation is a pure function of the log: an undo
+//!   that reaches an operation its actor may not undo, a discard by a chain that does not own
+//!   the revision, or a revocation by a chain that does not dominate the revoked link changes
+//!   nothing on replay and is counted in [`ViewReplayReport`], so a record written without the
+//!   store cannot undo someone else's work.
+
+use crate::WalRecord;
+use sha2::{Digest, Sha256};
+use std::collections::{BTreeMap, BTreeSet};
+use synapse_core::{
+    ChainPath, ChangeId, ChangesetId, RefusalCode, RepoId, SynapseError, SynapseResult, WalSeq,
+};
+
+/// Domain tag of [`View::digest`].
+pub const DOMAIN_VIEW_V1: &[u8] = b"SYNAPSE_VIEW_V1\0";
+/// Domain tag of the per-change leaf of a view digest.
+pub const DOMAIN_VIEW_HEADS_V1: &[u8] = b"SYNAPSE_VIEW_HEADS_V1\0";
+
+/// An operation on the references of one repository (WAL kind 12).
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum ViewOperation {
+    /// Restore the view of operation `target` (`WalSeq(0)`: before any operation), either
+    /// whole or, with `actor`, only for the operations whose actor chain is or descends from
+    /// `actor`.
+    Undo {
+        repo_id: RepoId,
+        target: WalSeq,
+        actor: Option<ChainPath>,
+    },
+    /// Remove a revision from the view. A plain discard stays undoable; a final discard is
+    /// the owner's choice to give up undo and can never be undone.
+    Discard {
+        repo_id: RepoId,
+        changeset_id: ChangesetId,
+        final_discard: bool,
+    },
+    /// Revoke the leaf link of `revoked` (a fact: never undone).
+    Revoke { repo_id: RepoId, revoked: ChainPath },
+}
+
+impl ViewOperation {
+    pub fn repo_id(&self) -> &RepoId {
+        match self {
+            ViewOperation::Undo { repo_id, .. }
+            | ViewOperation::Discard { repo_id, .. }
+            | ViewOperation::Revoke { repo_id, .. } => repo_id,
+        }
+    }
+
+    /// Canonical bytes of the operation for the state-root record digest: tag, repository
+    /// (`u64` length + bytes), then the fields in declaration order, chains in their core
+    /// encoding with a `u64` length.
+    pub(crate) fn digest_bytes(&self) -> Vec<u8> {
+        fn put_repo(out: &mut Vec<u8>, repo: &RepoId) {
+            out.extend_from_slice(&(repo.as_str().len() as u64).to_le_bytes());
+            out.extend_from_slice(repo.as_str().as_bytes());
+        }
+        fn put_chain(out: &mut Vec<u8>, chain: &ChainPath) {
+            let mut buf = Vec::new();
+            chain.encode_into(&mut buf);
+            out.extend_from_slice(&(buf.len() as u64).to_le_bytes());
+            out.extend_from_slice(&buf);
+        }
+        let mut out = Vec::new();
+        match self {
+            ViewOperation::Undo {
+                repo_id,
+                target,
+                actor,
+            } => {
+                out.push(1);
+                put_repo(&mut out, repo_id);
+                out.extend_from_slice(&target.0.to_le_bytes());
+                match actor {
+                    None => out.push(0),
+                    Some(a) => {
+                        out.push(1);
+                        put_chain(&mut out, a);
+                    }
+                }
+            }
+            ViewOperation::Discard {
+                repo_id,
+                changeset_id,
+                final_discard,
+            } => {
+                out.push(2);
+                put_repo(&mut out, repo_id);
+                out.extend_from_slice(&changeset_id.0);
+                out.push(u8::from(*final_discard));
+            }
+            ViewOperation::Revoke { repo_id, revoked } => {
+                out.push(3);
+                put_repo(&mut out, repo_id);
+                put_chain(&mut out, revoked);
+            }
+        }
+        out
+    }
+}
+
+/// The references of one repository at one point of its operation log.
+#[derive(Debug, Clone, Default, PartialEq, Eq)]
+pub struct View {
+    /// Visible heads of every change that has one.
+    pub heads: BTreeMap<ChangeId, BTreeSet<ChangesetId>>,
+    /// Discarded revisions; `true` for a final discard.
+    pub discarded: BTreeMap<ChangesetId, bool>,
+    /// Operations in effect whose revision is not in the view (a per-actor undo removed the
+    /// admission a later marker or discard of another actor names): recorded, never dropped.
+    pub conflicts: BTreeSet<WalSeq>,
+}
+
+impl View {
+    /// `SHA-256(DOMAIN_VIEW_V1 || repo || u64 n || (change_id || leaf)* || u64 n ||
+    /// (changeset_id || final u8)* || u64 n || seq*)`, where `leaf` is
+    /// `SHA-256(DOMAIN_VIEW_HEADS_V1 || u64 n || head*)` with heads ascending.
+    pub fn digest(&self, repo: &RepoId) -> [u8; 32] {
+        let mut h = Sha256::new();
+        h.update(DOMAIN_VIEW_V1);
+        h.update((repo.as_str().len() as u64).to_le_bytes());
+        h.update(repo.as_str().as_bytes());
+        h.update((self.heads.len() as u64).to_le_bytes());
+        for (change, heads) in &self.heads {
+            let mut leaf = Sha256::new();
+            leaf.update(DOMAIN_VIEW_HEADS_V1);
+            leaf.update((heads.len() as u64).to_le_bytes());
+            for id in heads {
+                leaf.update(id.0);
+            }
+            h.update(change.0);
+            h.update(leaf.finalize());
+        }
+        h.update((self.discarded.len() as u64).to_le_bytes());
+        for (id, final_discard) in &self.discarded {
+            h.update(id.0);
+            h.update([u8::from(*final_discard)]);
+        }
+        h.update((self.conflicts.len() as u64).to_le_bytes());
+        for seq in &self.conflicts {
+            h.update(seq.0.to_le_bytes());
+        }
+        h.finalize().into()
+    }
+}
+
+/// Kind 12 operations that replay found changing nothing, by reason. A live store writes none
+/// of them, so every count is a record written without the store.
+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
+pub struct ViewReplayReport {
+    pub undo_refused: u64,
+    pub discard_refused: u64,
+    pub revoke_refused: u64,
+}
+
+/// Why an undo is refused (the admission check and the replay rule are the same function).
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum UndoFault {
+    /// The target is not before the undo.
+    TargetInvalid,
+    /// The undo reaches a revocation or a final discard at this sequence.
+    Irreversible(WalSeq),
+    /// The undo reaches an operation at this sequence whose actor chain the undoer does not
+    /// dominate.
+    NotDominant(WalSeq),
+}
+
+impl UndoFault {
+    pub fn into_error(self) -> SynapseError {
+        match self {
+            UndoFault::TargetInvalid => SynapseError::new(
+                RefusalCode::UndoTargetInvalid,
+                "undo target must be an earlier operation of the window",
+            ),
+            UndoFault::Irreversible(seq) => SynapseError::new(
+                RefusalCode::UndoIrreversible,
+                format!("undo reaches operation {seq}, a revocation or final discard, which can never be undone"),
+            ),
+            UndoFault::NotDominant(seq) => SynapseError::new(
+                RefusalCode::AuthChainNotDominant,
+                format!("undo reaches operation {seq} of an actor chain the undoer does not dominate"),
+            ),
+        }
+    }
+}
+
+#[derive(Debug, Clone)]
+enum OpKind {
+    Admit {
+        change: ChangeId,
+        id: ChangesetId,
+    },
+    Marker {
+        pred: ChangesetId,
+        succs: Vec<ChangesetId>,
+    },
+    StateMove,
+    Undo {
+        target: WalSeq,
+        filter: Option<ChainPath>,
+    },
+    Discard {
+        id: ChangesetId,
+        final_discard: bool,
+    },
+    Revoke {
+        revoked: ChainPath,
+    },
+}
+
+#[derive(Debug, Clone)]
+struct Op {
+    seq: WalSeq,
+    actor: ChainPath,
+    kind: OpKind,
+}
+
+impl Op {
+    fn is_fact(&self) -> bool {
+        matches!(
+            self.kind,
+            OpKind::Revoke { .. }
+                | OpKind::Discard {
+                    final_discard: true,
+                    ..
+                }
+        )
+    }
+}
+
+/// The operations of `repo` in `log` (revision records in sequence order).
+fn ops_of(log: &[(WalSeq, WalRecord)], repo: &RepoId) -> Vec<Op> {
+    let mut ops = Vec::new();
+    for (seq, record) in log {
+        let (r, actor, kind) = match record {
+            WalRecord::RevisionAdmitted {
+                envelope, chain, ..
+            } => (
+                &envelope.attestation.repo_id,
+                chain,
+                OpKind::Admit {
+                    change: envelope.content.change_id,
+                    id: envelope.attestation.changeset_id,
+                },
+            ),
+            WalRecord::DerivedRevisionAdmitted { derived, chain, .. } => (
+                &derived.attestation.repo_id,
+                chain,
+                OpKind::Admit {
+                    change: derived.content.change_id,
+                    id: derived.attestation.output_changeset,
+                },
+            ),
+            WalRecord::ObsolescenceRecorded { marker, chain, .. } => (
+                &marker.repo_id,
+                chain,
+                OpKind::Marker {
+                    pred: marker.predecessor,
+                    succs: marker.successors.clone(),
+                },
+            ),
+            WalRecord::RevisionStateMoved { state_move, .. } => {
+                (&state_move.repo_id, &state_move.chain, OpKind::StateMove)
+            }
+            WalRecord::ViewOperationRecorded { op, chain, .. } => (
+                op.repo_id(),
+                chain,
+                match op {
+                    ViewOperation::Undo { target, actor, .. } => OpKind::Undo {
+                        target: *target,
+                        filter: actor.clone(),
+                    },
+                    ViewOperation::Discard {
+                        changeset_id,
+                        final_discard,
+                        ..
+                    } => OpKind::Discard {
+                        id: *changeset_id,
+                        final_discard: *final_discard,
+                    },
+                    ViewOperation::Revoke { revoked, .. } => OpKind::Revoke {
+                        revoked: revoked.clone(),
+                    },
+                },
+            ),
+            _ => continue,
+        };
+        if r == repo {
+            ops.push(Op {
+                seq: *seq,
+                actor: actor.clone(),
+                kind,
+            });
+        }
+    }
+    ops
+}
+
+/// The operations an undo at `undo_seq` by `undoer` to `target`, filtered to `filter`,
+/// reaches (indices into `ops`), or why it is refused.
+fn undo_reach(
+    ops: &[Op],
+    undo_seq: WalSeq,
+    undoer: &ChainPath,
+    target: WalSeq,
+    filter: Option<&ChainPath>,
+) -> Result<Vec<usize>, UndoFault> {
+    if target >= undo_seq {
+        return Err(UndoFault::TargetInvalid);
+    }
+    let mut reach = Vec::new();
+    for (i, op) in ops.iter().enumerate() {
+        if op.seq <= target || op.seq >= undo_seq {
+            continue;
+        }
+        if filter.is_some_and(|f| !f.dominates(&op.actor)) {
+            continue;
+        }
+        if op.is_fact() {
+            return Err(UndoFault::Irreversible(op.seq));
+        }
+        if !undoer.dominates(&op.actor) {
+            return Err(UndoFault::NotDominant(op.seq));
+        }
+        reach.push(i);
+    }
+    Ok(reach)
+}
+
+/// The chain of the first admission of `id` before index `before`, if any.
+fn first_admitter(ops: &[Op], id: ChangesetId, before: usize) -> Option<&ChainPath> {
+    ops[..before].iter().find_map(|op| match op.kind {
+        OpKind::Admit { id: a, .. } if a == id => Some(&op.actor),
+        _ => None,
+    })
+}
+
+/// Whether each operation of `ops` is in effect, and the replay report. An operation is in
+/// effect unless an undo in effect reaches it; undos only reach earlier operations, so one
+/// pass from the newest operation decides each one after every undo that could reach it.
+fn effective(ops: &[Op]) -> (Vec<bool>, ViewReplayReport) {
+    let mut report = ViewReplayReport::default();
+    let mut valid = vec![true; ops.len()];
+    let mut reaches: Vec<Vec<usize>> = vec![Vec::new(); ops.len()];
+    for (i, op) in ops.iter().enumerate() {
+        match &op.kind {
+            OpKind::Undo { target, filter } => {
+                match undo_reach(ops, op.seq, &op.actor, *target, filter.as_ref()) {
+                    Ok(r) => reaches[i] = r,
+                    Err(_) => {
+                        valid[i] = false;
+                        report.undo_refused += 1;
+                    }
+                }
+            }
+            OpKind::Discard { id, .. }
+                if !first_admitter(ops, *id, i).is_some_and(|c| op.actor.dominates(c)) =>
+            {
+                valid[i] = false;
+                report.discard_refused += 1;
+            }
+            OpKind::Revoke { revoked } if !op.actor.dominates(revoked) => {
+                valid[i] = false;
+                report.revoke_refused += 1;
+            }
+            _ => {}
+        }
+    }
+    let mut on = valid;
+    for j in (0..ops.len()).rev() {
+        if on[j] {
+            for &k in &reaches[j] {
+                on[k] = false;
+            }
+        }
+    }
+    (on, report)
+}
+
+/// The view of `repo` after every operation of `log` up to and including `upto`.
+pub(crate) fn view_at(log: &[(WalSeq, WalRecord)], repo: &RepoId, upto: WalSeq) -> View {
+    let ops: Vec<Op> = ops_of(log, repo)
+        .into_iter()
+        .filter(|op| op.seq <= upto)
+        .collect();
+    fold(&ops)
+}
+
+fn fold(ops: &[Op]) -> View {
+    let (on, _) = effective(ops);
+    let mut admitted: BTreeMap<ChangesetId, ChangeId> = BTreeMap::new();
+    let mut markers: Vec<(WalSeq, ChangesetId, &[ChangesetId])> = Vec::new();
+    let mut discards: Vec<(WalSeq, ChangesetId, bool)> = Vec::new();
+    for (op, _) in ops.iter().zip(&on).filter(|(_, on)| **on) {
+        match &op.kind {
+            OpKind::Admit { change, id } => {
+                admitted.entry(*id).or_insert(*change);
+            }
+            OpKind::Marker { pred, succs } => markers.push((op.seq, *pred, succs)),
+            OpKind::Discard { id, final_discard } => discards.push((op.seq, *id, *final_discard)),
+            OpKind::StateMove | OpKind::Undo { .. } | OpKind::Revoke { .. } => {}
+        }
+    }
+    let mut view = View::default();
+    let mut hidden: BTreeSet<ChangesetId> = BTreeSet::new();
+    for (seq, pred, succs) in &markers {
+        hidden.insert(*pred);
+        if !admitted.contains_key(pred) || succs.iter().any(|s| !admitted.contains_key(s)) {
+            view.conflicts.insert(*seq);
+        }
+    }
+    for (seq, id, final_discard) in &discards {
+        hidden.insert(*id);
+        let e = view.discarded.entry(*id).or_insert(false);
+        *e |= *final_discard;
+        if !admitted.contains_key(id) {
+            view.conflicts.insert(*seq);
+        }
+    }
+    for (id, change) in &admitted {
+        if !hidden.contains(id) {
+            view.heads.entry(*change).or_default().insert(*id);
+        }
+    }
+    view
+}
+
+/// Replay report of the kind 12 operations of every repository in `log`.
+pub(crate) fn replay_report(log: &[(WalSeq, WalRecord)]) -> ViewReplayReport {
+    let repos: BTreeSet<RepoId> = log
+        .iter()
+        .filter_map(|(_, r)| match r {
+            WalRecord::ViewOperationRecorded { op, .. } => Some(op.repo_id().clone()),
+            _ => None,
+        })
+        .collect();
+    let mut total = ViewReplayReport::default();
+    for repo in repos {
+        let (_, r) = effective(&ops_of(log, &repo));
+        total.undo_refused += r.undo_refused;
+        total.discard_refused += r.discard_refused;
+        total.revoke_refused += r.revoke_refused;
+    }
+    total
+}
+
+/// Admission check of an undo at `undo_seq`: the same rule replay applies.
+pub(crate) fn check_undo(
+    log: &[(WalSeq, WalRecord)],
+    repo: &RepoId,
+    undo_seq: WalSeq,
+    undoer: &ChainPath,
+    target: WalSeq,
+    filter: Option<&ChainPath>,
+) -> SynapseResult<()> {
+    undo_reach(&ops_of(log, repo), undo_seq, undoer, target, filter)
+        .map(|_| ())
+        .map_err(UndoFault::into_error)
+}
+
+/// Admission check of a discard: the revision was admitted in `repo` and `chain` is, or
+/// dominates, the chain of its first admission; a revision already finally discarded is
+/// refused.
+pub(crate) fn check_discard(
+    log: &[(WalSeq, WalRecord)],
+    repo: &RepoId,
+    id: ChangesetId,
+    chain: &ChainPath,
+) -> SynapseResult<()> {
+    let ops = ops_of(log, repo);
+    let owner = first_admitter(&ops, id, ops.len()).ok_or_else(|| {
+        SynapseError::new(
+            RefusalCode::ChangesetNotFound,
+            format!("revision {id} is not admitted in {repo}"),
+        )
+    })?;
+    if !chain.dominates(owner) {
+        return Err(SynapseError::new(
+            RefusalCode::AuthChainNotDominant,
+            format!("only the owner chain of revision {id} or one dominating it may discard it"),
+        ));
+    }
+    if fold(&ops).discarded.get(&id) == Some(&true) {
+        return Err(SynapseError::new(
+            RefusalCode::DiscardInvalid,
+            format!("revision {id} is already finally discarded"),
+        ));
+    }
+    Ok(())
+}
+
+/// A recorded view operation: where it landed and the repository view right after it.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct ViewOutcome {
+    pub wal_seq: WalSeq,
+    /// [`View::digest`] of the repository after the operation.
+    pub view_digest: [u8; 32],
+    /// Operations in effect whose revision is no longer in the view (see [`View::conflicts`]).
+    pub conflicts: BTreeSet<WalSeq>,
+}
+
+impl crate::SynapseStore {
+    /// Record an undo of `repo_id` to operation `target` under `chain` at server time
+    /// `now_ms`: whole, or with `actor` only the operations whose actor chain is or descends
+    /// from `actor`. Refused, with nothing written: a target not before the undo
+    /// (`UndoTargetInvalid`), an undo reaching a revocation or a final discard
+    /// (`UndoIrreversible`), or an operation whose actor chain `chain` does not dominate
+    /// (`AuthChainNotDominant`). The check runs against the sequence the record is written
+    /// at (`WalSequenceGap` if another writer took it).
+    pub fn record_undo(
+        &mut self,
+        repo_id: RepoId,
+        target: WalSeq,
+        actor: Option<ChainPath>,
+        chain: ChainPath,
+        now_ms: u64,
+    ) -> SynapseResult<ViewOutcome> {
+        self.check_writable()?;
+        self.check_binary_codec()?;
+        let at = self.committed_seq().next();
+        check_undo(
+            self.revisions.log(),
+            &repo_id,
+            at,
+            &chain,
+            target,
+            actor.as_ref(),
+        )?;
+        let op = ViewOperation::Undo {
+            repo_id,
+            target,
+            actor,
+        };
+        self.append_view_operation(op, chain, now_ms, at)
+    }
+
+    /// Record a plain (undoable) or final (never undone) discard of revision `changeset_id`
+    /// under `chain`. Refused: a revision not admitted in `repo_id` (`ChangesetNotFound`), a
+    /// chain that is not and does not dominate the chain of its first admission
+    /// (`AuthChainNotDominant`), a revision already finally discarded (`DiscardInvalid`).
+    pub fn record_discard(
+        &mut self,
+        repo_id: RepoId,
+        changeset_id: ChangesetId,
+        final_discard: bool,
+        chain: ChainPath,
+        now_ms: u64,
+    ) -> SynapseResult<ViewOutcome> {
+        self.check_writable()?;
+        self.check_binary_codec()?;
+        let at = self.committed_seq().next();
+        check_discard(self.revisions.log(), &repo_id, changeset_id, &chain)?;
+        let op = ViewOperation::Discard {
+            repo_id,
+            changeset_id,
+            final_discard,
+        };
+        self.append_view_operation(op, chain, now_ms, at)
+    }
+
+    /// Record the revocation of the leaf link of `revoked` by `chain` in the operation log of
+    /// `repo_id`: a fact no undo can reach. `chain` must be or dominate `revoked`
+    /// (`AuthChainNotDominant`). Enforcing the revocation on requests is the policy
+    /// enforcer's job (`synapse-api` revokes the link there at the same sequence).
+    pub fn record_revocation(
+        &mut self,
+        repo_id: RepoId,
+        revoked: ChainPath,
+        chain: ChainPath,
+        now_ms: u64,
+    ) -> SynapseResult<ViewOutcome> {
+        self.check_writable()?;
+        self.check_binary_codec()?;
+        if !chain.dominates(&revoked) {
+            return Err(SynapseError::new(
+                RefusalCode::AuthChainNotDominant,
+                "only the revoked chain or one dominating it may revoke its leaf link",
+            ));
+        }
+        let at = self.committed_seq().next();
+        let op = ViewOperation::Revoke { repo_id, revoked };
+        self.append_view_operation(op, chain, now_ms, at)
+    }
+
+    /// The current view of `repo_id` (B2): references only, a fold over the operation log.
+    pub fn view(&self, repo_id: &RepoId) -> View {
+        view_at(self.revisions.log(), repo_id, self.committed_seq())
+    }
+
+    /// The view of `repo_id` right after operation `seq` (the view an undo to `seq` restores).
+    pub fn view_at(&self, repo_id: &RepoId, seq: WalSeq) -> View {
+        view_at(self.revisions.log(), repo_id, seq)
+    }
+
+    /// Kind 12 records that change nothing on replay, by reason. All zero for a log written
+    /// only by stores.
+    pub fn view_replay_report(&self) -> ViewReplayReport {
+        replay_report(self.revisions.log())
+    }
+
+    fn append_view_operation(
+        &mut self,
+        op: ViewOperation,
+        chain: ChainPath,
+        now_ms: u64,
+        at: WalSeq,
+    ) -> SynapseResult<ViewOutcome> {
+        let repo = op.repo_id().clone();
+        let record = WalRecord::ViewOperationRecorded {
+            op,
+            chain,
+            recorded_at_ms: now_ms,
+        };
+        let wal_seq = self.append_revision_record(record, &[], Some(at))?;
+        let view = self.view(&repo);
+        Ok(ViewOutcome {
+            wal_seq,
+            view_digest: view.digest(&repo),
+            conflicts: view.conflicts,
+        })
+    }
+}
diff --git a/crates/synapse-store/src/operation_tests.rs b/crates/synapse-store/src/operation_tests.rs
new file mode 100644
index 0000000..11e687b
--- /dev/null
+++ b/crates/synapse-store/src/operation_tests.rs
@@ -0,0 +1,521 @@
+//! B2 (issue #30): operation views, undo, plain and final discard, revocation as a fact.
+
+use crate::codec::{decode_record, encode_record, CodecRefusal};
+use crate::revision::b4_tests::{body, key_of, open, path, repo, temp_dir, SplitMix64};
+use crate::{AdmissionAuthority, RecoveryPolicy, SynapseStore, ViewOperation, WalRecord};
+use std::collections::BTreeMap;
+use synapse_core::{
+    BlobDigest, ChangeId, ChangesetEnvelopeV2, ChangesetId, FileMode, IdempotencyKey, MutationOp,
+    ObsolescenceMarker, PathMutation, RefusalCode, RevisionContent, TreeDigest, WalSeq,
+};
+
+const STRICT: RecoveryPolicy = RecoveryPolicy::StrictFailClosed;
+/// Root chain: dominates both actors.
+const ROOT: &[u8] = &[1];
+const ALICE: &[u8] = &[1, 2];
+const BOB: &[u8] = &[1, 3];
+
+/// Admit revision `n` of change `change` under the chain (and key) `owner`.
+fn admit(s: &mut SynapseStore, owner: &[u8], n: u32, change: u8) -> ChangesetId {
+    let b = body(n);
+    let content = RevisionContent {
+        change_id: ChangeId([change; 16]),
+        base_tree: TreeDigest([0x7E; 32]),
+        parents: vec![],
+        mutations: vec![PathMutation {
+            path: "src/lib.rs".into(),
+            op: MutationOp::Upsert {
+                mode: FileMode::Regular644,
+                blob_digest: BlobDigest::compute(&b),
+                size_bytes: b.len() as u64,
+            },
+        }],
+        intent_summary: "implement the task".into(),
+    };
+    let mut idem = [0u8; 32];
+    idem[..4].copy_from_slice(&n.to_le_bytes());
+    idem[4] = change;
+    let envelope =
+        ChangesetEnvelopeV2::sign_new(&key_of(owner), repo(), content, IdempotencyKey(idem), 1_000);
+    let id = envelope.changeset_id();
+    let authority = AdmissionAuthority {
+        chain: path(owner),
+        change_scope: Vec::new(),
+    };
+    s.admit_revision(
+        envelope,
+        &[(BlobDigest::compute(&b), b.to_vec())],
+        authority,
+        5_000,
+    )
+    .unwrap();
+    id
+}
+
+fn rewrite(s: &mut SynapseStore, owner: &[u8], change: u8, pred: ChangesetId, succ: ChangesetId) {
+    let m = ObsolescenceMarker::sign_new(
+        &key_of(owner),
+        repo(),
+        ChangeId([change; 16]),
+        pred,
+        vec![succ],
+        6_000,
+    );
+    s.record_obsolescence(m, path(owner), 6_000).unwrap();
+}
+
+fn digest(s: &SynapseStore) -> [u8; 32] {
+    s.view(&repo()).digest(&repo())
+}
+
+fn heads(s: &SynapseStore, change: u8) -> Vec<ChangesetId> {
+    s.view(&repo())
+        .heads
+        .get(&ChangeId([change; 16]))
+        .map(|h| h.iter().copied().collect())
+        .unwrap_or_default()
+}
+
+fn undo(
+    s: &mut SynapseStore,
+    target: WalSeq,
+    actor: Option<&[u8]>,
+    by: &[u8],
+) -> synapse_core::SynapseResult<crate::ViewOutcome> {
+    s.record_undo(repo(), target, actor.map(path), path(by), 7_000)
+}
+
+/// The owner chain of each of the three actors.
+fn actor(i: u64) -> &'static [u8] {
+    [ROOT, ALICE, BOB][i as usize]
+}
+
+/// Acceptance 1 (property): random sequences of admissions, rewrites, plain and final
+/// discards, revocations, whole and per-actor undos and undos of undos. Every whole undo to
+/// `T` that is admitted gives back exactly the view digest of `T`; every refused operation
+/// writes nothing and leaves the view unchanged; replay, `checkpoint_and_compact`, and a
+/// strict reopen give back the digest of every point of the log.
+#[test]
+fn b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction() {
+    let mut rng = SplitMix64(0xB2_0030);
+    let mut checked_undos = 0u32;
+    let mut refused = 0u32;
+    for round in 0..6u32 {
+        let dir = temp_dir(&format!("b2-prop-{round}"));
+        let mut s = open(&dir, STRICT).unwrap();
+        let mut at: BTreeMap<u64, [u8; 32]> = BTreeMap::new();
+        at.insert(0, digest(&s));
+        // (owner index, change, changeset) of every admission, in order.
+        let mut revs: Vec<(u64, u8, ChangesetId)> = Vec::new();
+        let mut n = 0u32;
+        for _ in 0..40 {
+            let before = (s.committed_seq(), digest(&s));
+            let pick = rng.below(16);
+            let result: Result<(), RefusalCode> = match pick {
+                0..=4 => {
+                    let who = 1 + rng.below(2);
+                    let change = (10 * who + rng.below(2)) as u8;
+                    n += 1;
+                    let id = admit(&mut s, actor(who), round * 1_000 + n, change);
+                    revs.push((who, change, id));
+                    Ok(())
+                }
+                5..=6 => {
+                    // Rewrite an earlier revision of a change into a later one (no cycles).
+                    let k = rng.below(revs.len().max(1) as u64) as usize;
+                    match revs.get(k).copied() {
+                        Some((who, change, pred)) => {
+                            match revs[k + 1..].iter().find(|r| r.1 == change) {
+                                Some(&(_, _, succ)) => {
+                                    rewrite(&mut s, actor(who), change, pred, succ);
+                                    Ok(())
+                                }
+                                None => Ok(()),
+                            }
+                        }
+                        None => Ok(()),
+                    }
+                }
+                7..=8 => match revs.get(rng.below(revs.len().max(1) as u64) as usize) {
+                    Some(&(who, _, id)) => s
+                        .record_discard(repo(), id, rng.below(6) == 0, path(actor(who)), 7_000)
+                        .map(|_| ())
+                        .map_err(|e| e.code),
+                    None => Ok(()),
+                },
+                9 => {
+                    if rng.below(3) == 0 {
+                        s.record_revocation(repo(), path(&[1, 2, 9]), path(ROOT), 7_000)
+                            .map(|_| ())
+                            .map_err(|e| e.code)
+                    } else {
+                        Ok(())
+                    }
+                }
+                _ => {
+                    let last = s.committed_seq().0;
+                    let target = WalSeq(rng.below(last + 1));
+                    let (by, filter) = match rng.below(4) {
+                        0 => (ROOT, None),
+                        1 => (ALICE, Some(ALICE)),
+                        2 => (BOB, Some(BOB)),
+                        _ => (actor(rng.below(3)), None),
+                    };
+                    match undo(&mut s, target, filter, by) {
+                        Ok(out) => {
+                            if filter.is_none() {
+                                assert_eq!(
+                                    out.view_digest, at[&target.0],
+                                    "a whole undo to {target} must restore the view of {target}"
+                                );
+                                checked_undos += 1;
+                            }
+                            at.insert(out.wal_seq.0, digest(&s));
+                            // Undo is undoable: undoing the undo restores the view before it.
+                            if rng.below(2) == 0 {
+                                let prev = WalSeq(out.wal_seq.0 - 1);
+                                let back = undo(&mut s, prev, None, ROOT).unwrap();
+                                assert_eq!(back.view_digest, at[&prev.0]);
+                                at.insert(back.wal_seq.0, back.view_digest);
+                                checked_undos += 1;
+                            }
+                            Ok(())
+                        }
+                        Err(e) => Err(e.code),
+                    }
+                }
+            };
+            match result {
+                Ok(()) => {
+                    at.insert(s.committed_seq().0, digest(&s));
+                }
+                Err(code) => {
+                    refused += 1;
+                    assert!(
+                        matches!(
+                            code,
+                            RefusalCode::UndoIrreversible
+                                | RefusalCode::AuthChainNotDominant
+                                | RefusalCode::DiscardInvalid
+                        ),
+                        "unexpected refusal {code:?}"
+                    );
+                    assert_eq!(
+                        (s.committed_seq(), digest(&s)),
+                        before,
+                        "a refusal writes nothing"
+                    );
+                }
+            }
+        }
+        let check = |s: &SynapseStore| {
+            for (seq, d) in &at {
+                assert_eq!(
+                    &s.view_at(&repo(), WalSeq(*seq)).digest(&repo()),
+                    d,
+                    "view of {seq}"
+                );
+            }
+            assert_eq!(s.view_replay_report(), crate::ViewReplayReport::default());
+        };
+        check(&s);
+        drop(s);
+        let mut s = open(&dir, STRICT).unwrap();
+        check(&s);
+        s.checkpoint_and_compact(8_000).unwrap();
+        check(&s);
+        drop(s);
+        check(&open(&dir, STRICT).unwrap());
+        let _ = std::fs::remove_dir_all(&dir);
+    }
+    assert!(checked_undos >= 20, "only {checked_undos} undos checked");
+    assert!(refused >= 5, "only {refused} refusals exercised");
+}
+
+/// A per-actor undo disables only the operations of that actor (and the chains below it);
+/// another actor's later work stays, and a marker of another actor that names an undone
+/// revision is reported as conflict data instead of being dropped.
+#[test]
+fn b2_per_actor_undo_leaves_other_actors_intact() {
+    let dir = temp_dir("b2-per-actor");
+    let mut s = open(&dir, STRICT).unwrap();
+    let a1 = admit(&mut s, ALICE, 1, 20);
+    let t = s.committed_seq();
+    let b1 = admit(&mut s, BOB, 2, 30);
+    let a2 = admit(&mut s, ALICE, 3, 20);
+    rewrite(&mut s, ALICE, 20, a1, a2);
+    let b2 = admit(&mut s, BOB, 4, 30);
+    rewrite(&mut s, BOB, 30, b1, b2);
+    assert_eq!(heads(&s, 20), vec![a2]);
+    assert_eq!(heads(&s, 30), vec![b2]);
+
+    let out = undo(&mut s, t, Some(ALICE), ALICE).unwrap();
+    assert_eq!(heads(&s, 20), vec![a1], "Alice's later work is undone");
+    assert_eq!(heads(&s, 30), vec![b2], "Bob's work is untouched");
+    assert!(out.conflicts.is_empty());
+
+    // Undo Alice's first admission too: Bob's rewrite of Bob's change is still fine, and
+    // undoing all of Alice's work from the start leaves only Bob's view.
+    undo(&mut s, WalSeq(0), Some(ALICE), ALICE).unwrap();
+    assert_eq!(heads(&s, 20), Vec::<ChangesetId>::new());
+    assert_eq!(heads(&s, 30), vec![b2]);
+    // Undo of the undo by the root gives Alice's state back.
+    let prev = WalSeq(s.committed_seq().0 - 1);
+    undo(&mut s, prev, None, ROOT).unwrap();
+    assert_eq!(heads(&s, 20), vec![a1]);
+    let _ = std::fs::remove_dir_all(&dir);
+}
+
+/// A per-actor undo that removes an admission another actor's later marker names keeps the
+/// marker in effect and reports it as conflict data in the view instead of dropping it.
+#[test]
+fn b2_per_actor_undo_records_conflicts_with_other_actors_markers() {
+    let dir = temp_dir("b2-conflict");
+    let mut s = open(&dir, STRICT).unwrap();
+    // The root creates change 40; Alice (below the root) joins it; the root rewrites its
+    // revision into Alice's.
+    let r1 = admit(&mut s, ROOT, 1, 40);
+    let t = s.committed_seq();
+    let a1 = admit(&mut s, ALICE, 2, 40);
+    rewrite(&mut s, ROOT, 40, r1, a1);
+    let marker_seq = s.committed_seq();
+    assert_eq!(heads(&s, 40), vec![a1]);
+    // The root undoes only Alice's work: her admission goes, the root's marker stays.
+    let out = undo(&mut s, t, Some(ALICE), ROOT).unwrap();
+    assert_eq!(heads(&s, 40), Vec::<ChangesetId>::new());
+    assert_eq!(
+        out.conflicts.iter().copied().collect::<Vec<_>>(),
+        vec![marker_seq]
+    );
+    assert_eq!(s.view(&repo()).conflicts, out.conflicts);
+    // Undoing that undo resolves the conflict; no object was ever deleted.
+    let prev = WalSeq(out.wal_seq.0 - 1);
+    let back = undo(&mut s, prev, None, ROOT).unwrap();
+    assert!(back.conflicts.is_empty());
+    assert_eq!(heads(&s, 40), vec![a1]);
+    assert!(s.get_revision(&repo(), a1).is_ok());
+    let _ = std::fs::remove_dir_all(&dir);
+}
+
+/// Facts are never undone: an undo that reaches a revocation or a final discard is refused
+/// with `UndoIrreversible` and writes nothing; an undo that stops after the fact, or a
+/// per-actor undo whose filter excludes it, is admitted. A finally discarded revision cannot
+/// be discarded again.
+#[test]
+fn b2_undo_of_a_revocation_or_a_final_discard_is_refused() {
+    let dir = temp_dir("b2-facts");
+    let mut s = open(&dir, STRICT).unwrap();
+    let a1 = admit(&mut s, ALICE, 1, 20);
+    let before_final = s.committed_seq();
+    s.record_discard(repo(), a1, true, path(ALICE), 7_000)
+        .unwrap();
+    let after_final = s.committed_seq();
+    let seq = s.committed_seq();
+    let err = undo(&mut s, before_final, None, ROOT).unwrap_err();
+    assert_eq!(err.code, RefusalCode::UndoIrreversible, "{err:?}");
+    assert_eq!(s.committed_seq(), seq, "nothing written");
+    let err = undo(&mut s, before_final, Some(ALICE), ALICE).unwrap_err();
+    assert_eq!(err.code, RefusalCode::UndoIrreversible);
+    let err = s
+        .record_discard(repo(), a1, false, path(ALICE), 7_000)
+        .unwrap_err();
+    assert_eq!(err.code, RefusalCode::DiscardInvalid);
+
+    let b1 = admit(&mut s, BOB, 2, 30);
+    s.record_revocation(repo(), path(&[1, 3, 7]), path(BOB), 7_000)
+        .unwrap();
+    let err = undo(&mut s, after_final, None, ROOT).unwrap_err();
+    assert_eq!(err.code, RefusalCode::UndoIrreversible);
+    // Bob's per-actor undo to before his revision reaches his revocation: refused too.
+    let err = undo(&mut s, after_final, Some(BOB), BOB).unwrap_err();
+    assert_eq!(err.code, RefusalCode::UndoIrreversible);
+    // A revocation needs a chain that dominates the revoked one.
+    let err = s
+        .record_revocation(repo(), path(&[1, 2, 7]), path(BOB), 7_000)
+        .unwrap_err();
+    assert_eq!(err.code, RefusalCode::AuthChainNotDominant);
+    // Alice's per-actor undo after her final discard (filter excludes Bob's revocation).
+    let a2 = admit(&mut s, ALICE, 3, 21);
+    undo(&mut s, after_final, Some(ALICE), ALICE).unwrap();
+    assert_eq!(heads(&s, 21), Vec::<ChangesetId>::new());
+    assert_eq!(heads(&s, 30), vec![b1]);
+    assert_eq!(s.view(&repo()).discarded.get(&a1), Some(&true));
+    let _ = a2;
+    let _ = std::fs::remove_dir_all(&dir);
+}
+
+/// An undo that reaches an operation of an actor chain the undoer does not dominate is
+/// refused (`AuthChainNotDominant`), whole or per-actor; so is a discard by a chain that does
+/// not own the revision. A target at or after the undo is `UndoTargetInvalid`.
+#[test]
+fn b2_undo_by_a_non_dominating_chain_is_refused() {
+    let dir = temp_dir("b2-dominance");
+    let mut s = open(&dir, STRICT).unwrap();
+    let a1 = admit(&mut s, ALICE, 1, 20);
+    admit(&mut s, BOB, 2, 30);
+    let seq = s.committed_seq();
+    let err = undo(&mut s, WalSeq(0), None, BOB).unwrap_err();
+    assert_eq!(err.code, RefusalCode::AuthChainNotDominant);
+    let err = undo(&mut s, WalSeq(0), Some(ALICE), BOB).unwrap_err();
+    assert_eq!(err.code, RefusalCode::AuthChainNotDominant);
+    let err = s
+        .record_discard(repo(), a1, false, path(BOB), 7_000)
+        .unwrap_err();
+    assert_eq!(err.code, RefusalCode::AuthChainNotDominant);
+    let err = s
+        .record_discard(repo(), ChangesetId([9; 32]), false, path(ROOT), 7_000)
+        .unwrap_err();
+    assert_eq!(err.code, RefusalCode::ChangesetNotFound);
+    let err = undo(&mut s, WalSeq(seq.0 + 1), None, ROOT).unwrap_err();
+    assert_eq!(err.code, RefusalCode::UndoTargetInvalid);
+    assert_eq!(s.committed_seq(), seq, "nothing written");
+    // Bob may undo his own work, and the root may undo anyone's.
+    undo(&mut s, WalSeq(0), Some(BOB), BOB).unwrap();
+    undo(&mut s, WalSeq(0), None, ROOT).unwrap();
+    assert!(s.view(&repo()).heads.is_empty());
+    let _ = std::fs::remove_dir_all(&dir);
+}
+
+/// Kind 12 records written without the store (an undo of another actor's work, an undo
+/// reaching a final discard, a discard by a non-owner, a revocation by a non-dominating
+/// chain) change nothing on replay and are counted by reason.
+#[test]
+fn b2_forged_view_operations_change_nothing_on_replay() {
+    let dir = temp_dir("b2-forged");
+    let mut s = open(&dir, STRICT).unwrap();
+    let a1 = admit(&mut s, ALICE, 1, 20);
+    let a2 = admit(&mut s, ALICE, 2, 21);
+    s.record_discard(repo(), a2, true, path(ALICE), 7_000)
+        .unwrap();
+    let honest = digest(&s);
+    let forged = |op: ViewOperation, by: &[u8]| WalRecord::ViewOperationRecorded {
+        op,
+        chain: path(by),
+        recorded_at_ms: 7_000,
+    };
+    let undo_other = forged(
+        ViewOperation::Undo {
+            repo_id: repo(),
+            target: WalSeq(0),
+            actor: None,
+        },
+        BOB,
+    );
+    let undo_fact = forged(
+        ViewOperation::Undo {
+            repo_id: repo(),
+            target: WalSeq(0),
+            actor: Some(path(ALICE)),
+        },
+        ALICE,
+    );
+    let discard_other = forged(
+        ViewOperation::Discard {
+            repo_id: repo(),
+            changeset_id: a1,
+            final_discard: false,
+        },
+        BOB,
+    );
+    let revoke_other = forged(
+        ViewOperation::Revoke {
+            repo_id: repo(),
+            revoked: path(ALICE),
+        },
+        BOB,
+    );
+    for r in [undo_other, undo_fact, discard_other, revoke_other] {
+        s.append_revision_record(r, &[], None).unwrap();
+    }
+    let check = |s: &SynapseStore| {
+        assert_eq!(digest(s), honest, "forged kind 12 records change nothing");
+        assert_eq!(heads(s, 20), vec![a1]);
+        let r = s.view_replay_report();
+        assert_eq!(
+            (r.undo_refused, r.discard_refused, r.revoke_refused),
+            (2, 1, 1)
+        );
+    };
+    check(&s);
+    drop(s);
+    let mut s = open(&dir, STRICT).unwrap();
+    check(&s);
+    s.checkpoint_and_compact(8_000).unwrap();
+    drop(s);
+    check(&open(&dir, STRICT).unwrap());
+    let _ = std::fs::remove_dir_all(&dir);
+}
+
+/// The kind 12 codec round-trips every operation, refuses unknown operation and flag tags,
+/// and the state root digest covers every field.
+#[test]
+fn b2_kind_12_codec_round_trips_and_refuses_unknown_tags() {
+    let ops = [
+        ViewOperation::Undo {
+            repo_id: repo(),
+            target: WalSeq(7),
+            actor: None,
+        },
+        ViewOperation::Undo {
+            repo_id: repo(),
+            target: WalSeq(0),
+            actor: Some(path(ALICE)),
+        },
+        ViewOperation::Discard {
+            repo_id: repo(),
+            changeset_id: ChangesetId([3; 32]),
+            final_discard: true,
+        },
+        ViewOperation::Revoke {
+            repo_id: repo(),
+            revoked: path(&[1, 2, 9]),
+        },
+    ];
+    let mut digests = std::collections::BTreeSet::new();
+    for op in ops {
+        let record = WalRecord::ViewOperationRecorded {
+            op,
+            chain: path(ROOT),
+            recorded_at_ms: 9_000,
+        };
+        let bytes = encode_record(&record).unwrap();
+        assert_eq!(decode_record(&bytes, 1 << 20).unwrap(), record);
+        assert!(digests.insert(crate::revision::record_digest(&record)));
+    }
+    let record = WalRecord::ViewOperationRecorded {
+        op: ViewOperation::Undo {
+            repo_id: repo(),
+            target: WalSeq(1),
+            actor: None,
+        },
+        chain: path(ROOT),
+        recorded_at_ms: 9_000,
+    };
+    let bytes = encode_record(&record).unwrap();
+    // Layout: codec version, kind, op tag.
+    let tag_at = 2;
+    assert_eq!(bytes[tag_at], 1);
+    let mut bad = bytes.clone();
+    bad[tag_at] = 4;
+    assert!(matches!(
+        decode_record(&bad, 1 << 20),
+        Err(CodecRefusal::UnknownTag {
+            field: "view operation",
+            tag: 4,
+            ..
+        })
+    ));
+    // The actor flag follows repository (u32 len + bytes) and target (u64).
+    let flag_at = tag_at + 1 + 4 + repo().as_str().len() + 8;
+    assert_eq!(bytes[flag_at], 0);
+    let mut bad = bytes;
+    bad[flag_at] = 2;
+    assert!(matches!(
+        decode_record(&bad, 1 << 20),
+        Err(CodecRefusal::UnknownTag {
+            field: "undo actor",
+            tag: 2,
+            ..
+        })
+    ));
+}
diff --git a/crates/synapse-store/src/revision.rs b/crates/synapse-store/src/revision.rs
index ad5305b..c44b049 100644
--- a/crates/synapse-store/src/revision.rs
+++ b/crates/synapse-store/src/revision.rs
@@ -150,7 +150,7 @@ pub(crate) struct RevisionLedger {
 }
 
 /// Digest of one revision record over its canonical core encodings.
-fn record_digest(record: &WalRecord) -> [u8; 32] {
+pub(crate) fn record_digest(record: &WalRecord) -> [u8; 32] {
     let mut h = Sha256::new();
     h.update([record.kind_byte()]);
     let mut chain = Vec::new();
@@ -214,6 +214,18 @@ fn record_digest(record: &WalRecord) -> [u8; 32] {
             h.update(&chain);
             h.update(admitted_at_ms.to_le_bytes());
         }
+        WalRecord::ViewOperationRecorded {
+            op,
+            chain: c,
+            recorded_at_ms,
+        } => {
+            let o = op.digest_bytes();
+            h.update((o.len() as u64).to_le_bytes());
+            h.update(&o);
+            c.encode_into(&mut chain);
+            h.update(&chain);
+            h.update(recorded_at_ms.to_le_bytes());
+        }
         _ => {}
     }
     h.finalize().into()
@@ -439,6 +451,9 @@ impl RevisionLedger {
                     }
                 }
             }
+            // B2: view operations change no revision; they only join the log (the view is a
+            // fold over it, `operation::view_at`).
+            WalRecord::ViewOperationRecorded { .. } => {}
             _ => return,
         }
         self.log.push((seq, record));
@@ -1146,7 +1161,7 @@ impl crate::SynapseStore {
             .ok_or_else(|| not_found(format!("change {change_id} not found")))
     }
 
-    fn check_binary_codec(&self) -> SynapseResult<()> {
+    pub(crate) fn check_binary_codec(&self) -> SynapseResult<()> {
         if self.codec == crate::RecordCodec::JsonV1 {
             return Err(SynapseError::new(
                 RefusalCode::EnvelopeVersionUnsupported,
@@ -1163,7 +1178,7 @@ impl crate::SynapseStore {
     /// before anything is written, and a frame that lands at another sequence anyway is not
     /// applied and poisons the store (`WalSequenceGap` in both cases), so a record is never
     /// admitted at a sequence it was not checked at. Real checks in every build profile.
-    fn append_revision_record(
+    pub(crate) fn append_revision_record(
         &mut self,
         record: WalRecord,
         blobs: &[(BlobDigest, &[u8])],
@@ -1234,7 +1249,7 @@ fn sequence_mismatch(checked_at: WalSeq, seq: WalSeq, written: bool) -> Option<S
 }
 
 #[cfg(test)]
-mod b4_tests {
+pub(crate) mod b4_tests {
     use super::*;
     use crate::{AdmissionAuthority, FsyncPolicy, RecoveryPolicy, StoreLimits, SynapseStore};
     use ed25519_dalek::SigningKey;
@@ -1245,10 +1260,10 @@ mod b4_tests {
     };
     use synapse_core::{FileMode, PathMutation, TreeDigest};
 
-    struct SplitMix64(u64);
+    pub(crate) struct SplitMix64(pub(crate) u64);
 
     impl SplitMix64 {
-        fn next(&mut self) -> u64 {
+        pub(crate) fn next(&mut self) -> u64 {
             self.0 = self.0.wrapping_add(0x9E37_79B9_7F4A_7C15);
             let mut z = self.0;
             z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
@@ -1256,12 +1271,12 @@ mod b4_tests {
             z ^ (z >> 31)
         }
 
-        fn below(&mut self, n: u64) -> u64 {
+        pub(crate) fn below(&mut self, n: u64) -> u64 {
             self.next() % n
         }
     }
 
-    fn repo() -> RepoId {
+    pub(crate) fn repo() -> RepoId {
         RepoId::new("aien-spark/synapse").unwrap()
     }
 
@@ -1277,7 +1292,7 @@ mod b4_tests {
     }
 
     /// The key presenting the chain with label path `labels`.
-    fn key_of(labels: &[u8]) -> SigningKey {
+    pub(crate) fn key_of(labels: &[u8]) -> SigningKey {
         SigningKey::from_bytes(&derived("key", labels))
     }
 
@@ -1324,7 +1339,7 @@ mod b4_tests {
     }
 
     /// Link digests of the chain with label path `labels`; label prefixes are ancestors.
-    fn path(labels: &[u8]) -> ChainPath {
+    pub(crate) fn path(labels: &[u8]) -> ChainPath {
         ChainPath::new(
             chain_of(labels)
                 .link_digests()
@@ -1374,7 +1389,7 @@ mod b4_tests {
         }
     }
 
-    fn body(n: u32) -> [u8; 4] {
+    pub(crate) fn body(n: u32) -> [u8; 4] {
         n.to_le_bytes()
     }
 
@@ -1545,7 +1560,7 @@ mod b4_tests {
         assert_eq!(report.unverified(), 0);
     }
 
-    fn temp_dir(name: &str) -> PathBuf {
+    pub(crate) fn temp_dir(name: &str) -> PathBuf {
         let nanos = std::time::SystemTime::now()
             .duration_since(std::time::UNIX_EPOCH)
             .unwrap()
@@ -1556,7 +1571,7 @@ mod b4_tests {
         dir
     }
 
-    fn open(dir: &PathBuf, policy: RecoveryPolicy) -> SynapseResult<SynapseStore> {
+    pub(crate) fn open(dir: &PathBuf, policy: RecoveryPolicy) -> SynapseResult<SynapseStore> {
         let limits = StoreLimits {
             wal_prealloc_bytes: 64 * 1024,
             ..Default::default()
diff --git a/crates/synapse-store/tests/a1_malformed_corpus.rs b/crates/synapse-store/tests/a1_malformed_corpus.rs
index c90fbcd..ed4bfce 100644
--- a/crates/synapse-store/tests/a1_malformed_corpus.rs
+++ b/crates/synapse-store/tests/a1_malformed_corpus.rs
@@ -162,6 +162,8 @@ fn length_fields(record: &WalRecord, bin: &[u8]) -> Vec<usize> {
         | WalRecord::DerivedRevisionAdmitted { .. } => vec![2],
         // repo_id length first (ADR 0003 B4).
         WalRecord::RevisionStateMoved { .. } => vec![2],
+        // View operation tag, then repo_id length (ADR 0003 B2).
+        WalRecord::ViewOperationRecorded { .. } => vec![3],
     }
 }
 
diff --git a/docs/B2_OPERATION_VIEWS.md b/docs/B2_OPERATION_VIEWS.md
new file mode 100644
index 0000000..f694ec5
--- /dev/null
+++ b/docs/B2_OPERATION_VIEWS.md
@@ -0,0 +1,85 @@
+# B2: Operation views, undo, plain and final discard
+
+ADR 0003 section 9 step B2 (issue aien-dev/synapse#30), section 5.4 "Operation log and undo": every repository has an operation log, every operation produces a view, undo restores an earlier view, and facts are never undone.
+
+Code: `crates/synapse-store/src/operation.rs` (operations, view fold, undo rules, store API), `crates/synapse-store/src/codec.rs` (WAL kind 12), `crates/synapse-store/src/revision.rs` (record digest, ledger log), `crates/synapse-api/src/lib.rs` (`undo`, `discard`, `revoke_link`, `UndoPayload`, `DiscardPayload`). Tests: `crates/synapse-store/src/operation_tests.rs` (`b2_*`), `crates/synapse-api/tests/b2_operation_views.rs` (`b2_api_*`). Evidence: `evidence/b2-operation-views/`.
+
+## 1. Model
+
+* **Operation log.** The revision records already in the WAL are operations with an actor chain: admissions (kinds 7 and 11), obsolescence markers (kind 8), state moves (kind 9). B2 adds WAL kind 12, `ViewOperationRecorded`, carrying a `ViewOperation`: `Undo { target, actor }`, `Discard { changeset_id, final_discard }`, `Revoke { revoked }`, with the actor chain and the server time. No separate log is kept: the log is the WAL, so replay, checkpoints and compaction carry it like every other revision record.
+* **View.** The references of one repository after an operation: for every change, its visible heads (an admitted revision in effect that no marker in effect names as predecessor and no discard in effect names), the discarded revisions (`true` for a final discard), and conflict data. `View::digest` is a two-level Merkle root (`SYNAPSE_VIEW_V1`, per change `SYNAPSE_VIEW_HEADS_V1`), so two views compare in one step. `SynapseStore::view`, `view_at(seq)`.
+* **Revision states (B4) are not references.** They stay facts of the revision; undo never moves a state backwards and the view does not contain them. `ChangeStatus` stays the object history (every revision and marker ever admitted).
+
+## 2. Rules
+
+* **Undo.** An undo to operation `T` disables every operation of the repository after `T` (whole undo), or only those whose actor chain is or descends from `actor` (per-actor undo). An operation is in effect unless an undo in effect disables it. An undo only reaches earlier operations, so one pass from the newest operation decides every operation after every undo that could reach it.
+  * A whole undo to `T` gives back exactly the view of `T`.
+  * Undoing an undo (an undo to the operation just before it) re-enables what it disabled, so undo is undoable.
+  * Undo changes references only. No object, blob or record is deleted.
+* **Who may undo what.** The undoer's chain must be, or dominate, the actor chain of every operation the undo reaches (`AuthChainNotDominant`). Through the API the request chain must also grant `Undo` (`AuthCapabilityDenied`).
+* **Facts are never undone.** An undo that reaches a revocation or a final discard is refused (`UndoIrreversible`). An undo that stops after the fact, or a per-actor undo whose filter excludes it, is fine.
+* **Discard.** A discard removes a revision from the view. Only a chain that owns the revision (is or dominates the chain of its first admission) may discard it (`AuthChainNotDominant`); an unknown revision is `ChangesetNotFound`. A plain discard is undoable. A final discard is the owner's choice to give up undo; a revision already finally discarded cannot be discarded again (`DiscardInvalid`). Through the API a discard needs `Propose`.
+* **Revocation.** `SynapseService::revoke_link(revoked, by, now)` is the operator path. Checks, in order, before anything is written:
+  * `by` must be or dominate `revoked` (`AuthChainNotDominant`).
+  * The leaf link must have been granted (`AuthChainBroken`).
+
+  The store then writes the revocation as a kind 12 fact. The policy enforcer revokes the leaf link at that same sequence, so every chain through it is `AuthGrantRevoked` from then on.
+* **Conflicts are data.** A per-actor undo can remove an admission that another actor's later marker or discard names. That operation stays in effect and its sequence is listed in `View::conflicts` (and `ViewOutcome::conflicts`); nothing is dropped. Undoing the undo resolves it.
+* **Admission equals replay.** The store checks an undo against the sequence it is written at (`checked_at`, `WalSequenceGap` otherwise) with the same function replay uses. A kind 12 record written without the store has no effect on replay, and `view_replay_report` counts it by reason. Such records are:
+  * an undo reaching an operation its actor may not undo, or reaching a fact;
+  * a discard by a non-owner;
+  * a revocation by a chain that does not dominate the revoked link.
+
+## 3. Kind 12 layout
+
+`codec v2 | kind 12 | op | chain path (u32 len | core encoding) | recorded_at_ms u64`, with `op`:
+
+* `1 | repo str | target u64 | 0` or `1 | repo str | target u64 | 1 | chain path` (undo, whole or per actor)
+* `2 | repo str | changeset_id [32] | final u8 (0 or 1)` (discard)
+* `3 | repo str | chain path` (revocation)
+
+An unknown operation tag, actor flag, or final flag is `UnknownTag`. Checkpoints accept kind 12 in the revision section. The state-root record digest covers every field (`ViewOperation::digest_bytes`). Kind 12 needs the binary codec: a store still writing v1 JSON refuses it (`EnvelopeVersionUnsupported`), like every envelope v2 record.
+
+## 4. Acceptance
+
+| Acceptance (issue #30) | Test |
+|---|---|
+| Undo to `T` restores the exact view digest of `T` (property, across replay and compaction) | `b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction`: 6 rounds of 40 random admissions, rewrites, plain and final discards, revocations, whole and per-actor undos, and undos of undos. Every admitted whole undo and every undo of an undo matches the recorded digest. Every refusal writes nothing. All recorded digests still match after reopen, after `checkpoint_and_compact`, and after a strict reopen. |
+| Undo is undoable | Property above; `b2_per_actor_undo_leaves_other_actors_intact`; `b2_api_undo_requires_the_undo_capability` |
+| Per-actor undo leaves other actors intact | `b2_per_actor_undo_leaves_other_actors_intact`, `b2_per_actor_undo_records_conflicts_with_other_actors_markers` |
+| Undo of a revocation or final discard is refused | `b2_undo_of_a_revocation_or_a_final_discard_is_refused`, `b2_api_final_discard_can_never_be_undone`, `b2_api_revocation_is_a_fact_and_is_enforced` |
+| Undo of another actor's work needs a dominating chain | `b2_undo_by_a_non_dominating_chain_is_refused`, `b2_api_undo_and_discard_of_another_actor_need_a_dominating_chain` |
+
+Also covered:
+
+* `b2_forged_view_operations_change_nothing_on_replay`: four forged kind 12 records, counted by reason, survive compaction as no-ops.
+* `b2_kind_12_codec_round_trips_and_refuses_unknown_tags`.
+
+Red before green: `evidence/b2-operation-views/red-green/red.txt` holds 14 mutations from `run.sh`, one per behaviour, and each turns its tests red. `green.txt` holds the passing runs.
+
+The 14 behaviours:
+
+* undo effect;
+* the fact rule;
+* undo dominance;
+* the actor filter;
+* replay discard check and replay revocation check;
+* conflict data;
+* final discard repeat;
+* store revocation dominance;
+* record digest coverage;
+* checkpoint kinds;
+* ledger log;
+* the API `Undo` capability;
+* API revocation enforcement.
+
+## 5. Limits and deviations
+
+* **No window or GC.** ADR 0003 bounds the undo window per owner and lets K1 GC release objects outside it. Neither exists yet: any earlier sequence is a valid target and nothing is released (K1).
+* **Grants and revocations are not rebuilt at open.** The policy enforcer's grant table lives in memory, as before B2. The kind 12 revocation fact is durable in the WAL, but a reopened `SynapseService` does not yet re-apply it to the enforcer.
+* **No agent signature in the record.** A kind 12 record carries the actor chain but no agent signature over the operation. The API request is signed and verified at admission, but replay cannot check the signer. The replay rules make a forged record a no-op only when its chain may not perform it; a forged record naming a chain that may perform it is indistinguishable. Kinds 7, 8, 9 and 11 carry a signature replay can verify; kind 12 does not, so the WAL seal from #101 (`open_sealed`) is what protects it, and a signed operation statement is follow-up work.
+* **Re-admission of an undone revision.** Submitting the same envelope again returns its first admission (B1 idempotency), which stays undone in the view. To restore it, undo the undo.
+* **Conflicts are computed, not stored.** Conflict data is recomputed from the log by every view fold.
+* **Other facts.** Canonical promotions, accepted receipts, and erasures join the fact list when E2, E1, and M2 create them. Discarding a `Canonical` revision has no extra rule, since no revision can be `Canonical` before E2.
+* **Revocation scope.** A revocation is recorded in the log of the service's repository; links are per repository.
+* **No performance figures.** View folds are linear in the repository's operations. B2 has no hot-path acceptance and nothing was measured.
diff --git a/evidence/b2-operation-views/SHA256SUMS b/evidence/b2-operation-views/SHA256SUMS
new file mode 100644
index 0000000..544c513
--- /dev/null
+++ b/evidence/b2-operation-views/SHA256SUMS
@@ -0,0 +1,3 @@
+0cdd83c690cfb37d613171f6363b3fb7e3eee6eb097ef2737d4996a1b2150c4e  ./red-green/green.txt
+e76b637a49f021c4081cdb88b349580e370a74930f171e111fd099de58b062c1  ./red-green/red.txt
+b8041b97ff620138f82b13a7162ae5c9687631878e96e68cdb84183d5de73a32  ./red-green/run.sh
diff --git a/evidence/b2-operation-views/red-green/green.txt b/evidence/b2-operation-views/red-green/green.txt
new file mode 100644
index 0000000..17e7a82
--- /dev/null
+++ b/evidence/b2-operation-views/red-green/green.txt
@@ -0,0 +1,13 @@
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 60 filtered out; finished in 3.29s
+test b2_api_undo_and_discard_of_another_actor_need_a_dominating_chain ... ok
+test b2_api_final_discard_can_never_be_undone ... ok
+test b2_api_revocation_is_a_fact_and_is_enforced ... ok
+test b2_api_undo_requires_the_undo_capability ... ok
+test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.10s
diff --git a/evidence/b2-operation-views/red-green/red.txt b/evidence/b2-operation-views/red-green/red.txt
new file mode 100644
index 0000000..bb7c0a7
--- /dev/null
+++ b/evidence/b2-operation-views/red-green/red.txt
@@ -0,0 +1,152 @@
+=== undo-has-no-effect (crates/synapse-store/src/operation.rs): 'on[k] = false;' -> 'on[k] = on[k];'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... FAILED
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... FAILED
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... FAILED
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... FAILED
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... FAILED
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test result: FAILED. 2 passed; 5 failed; 0 ignored; 0 measured; 60 filtered out; finished in 0.21s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED undo-has-no-effect
+=== facts-undoable (crates/synapse-store/src/operation.rs): 'if op.is_fact() {' -> 'if false && op.is_fact() {'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... FAILED
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... FAILED
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 5 passed; 2 failed; 0 ignored; 0 measured; 60 filtered out; finished in 3.51s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED facts-undoable
+=== no-undo-dominance (crates/synapse-store/src/operation.rs): 'if !undoer.dominates(&op.actor) {' -> 'if false {'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... FAILED
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 3.99s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED no-undo-dominance
+=== filter-ignored (crates/synapse-store/src/operation.rs): 'if filter.is_some_and(|f| !f.dominates(&op.actor)) {' -> 'if false {'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... FAILED
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... FAILED
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... FAILED
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... FAILED
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 3 passed; 4 failed; 0 ignored; 0 measured; 60 filtered out; finished in 3.23s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED filter-ignored
+=== replay-discard-unchecked (crates/synapse-store/src/operation.rs): 'if !first_admitter(ops, *id, i).is_some_and(|c| op.actor.dominates(c)) =>' -> 'if false =>'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... FAILED
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 10.22s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED replay-discard-unchecked
+=== replay-revoke-unchecked (crates/synapse-store/src/operation.rs): 'OpKind::Revoke { revoked } if !op.actor.dominates(revoked) => {' -> 'OpKind::Revoke { .. } if false => {'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... FAILED
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 2.80s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED replay-revoke-unchecked
+=== conflicts-dropped (crates/synapse-store/src/operation.rs): 'view.conflicts.insert(*seq);' -> '{}'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... FAILED
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 3.34s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED conflicts-dropped
+=== final-discard-repeatable (crates/synapse-store/src/operation.rs): 'if fold(&ops).discarded.get(&id) == Some(&true) {' -> 'if false {'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... FAILED
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 3.42s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED final-discard-repeatable
+=== store-revoke-undominated (crates/synapse-store/src/operation.rs): 'if !chain.dominates(&revoked) {' -> 'if false {'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... FAILED
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 4.42s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED store-revoke-undominated
+=== digest-ignores-kind-12 (crates/synapse-store/src/revision.rs): 'let o = op.digest_bytes();' -> 'let o: Vec<u8> = Vec::new(); let _ = op;'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... FAILED
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... ok
+test result: FAILED. 6 passed; 1 failed; 0 ignored; 0 measured; 60 filtered out; finished in 3.52s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED digest-ignores-kind-12
+=== checkpoint-drops-kind-12 (crates/synapse-store/src/codec.rs): '7..=9 | 11 | 12)' -> '7..=9 | 11)'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... ok
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... ok
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... FAILED
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... ok
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... FAILED
+test result: FAILED. 5 passed; 2 failed; 0 ignored; 0 measured; 60 filtered out; finished in 0.51s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED checkpoint-drops-kind-12
+=== ledger-skips-kind-12 (crates/synapse-store/src/revision.rs): 'WalRecord::ViewOperationRecorded { .. } => {}' -> 'WalRecord::ViewOperationRecorded { .. } => return,'
+test operation_tests::b2_kind_12_codec_round_trips_and_refuses_unknown_tags ... ok
+test operation_tests::b2_property_undo_to_t_restores_the_view_of_t_across_replay_and_compaction ... FAILED
+test operation_tests::b2_undo_of_a_revocation_or_a_final_discard_is_refused ... FAILED
+test operation_tests::b2_per_actor_undo_records_conflicts_with_other_actors_markers ... FAILED
+test operation_tests::b2_undo_by_a_non_dominating_chain_is_refused ... FAILED
+test operation_tests::b2_forged_view_operations_change_nothing_on_replay ... FAILED
+test operation_tests::b2_per_actor_undo_leaves_other_actors_intact ... FAILED
+test result: FAILED. 1 passed; 6 failed; 0 ignored; 0 measured; 60 filtered out; finished in 0.19s
+error: test failed, to rerun pass `-p synapse-store --lib`
+RED ledger-skips-kind-12
+=== api-undo-capability (crates/synapse-api/src/lib.rs): '            "undo",
+            &self.repo_id,
+            Capability::Undo,' -> '            "undo",
+            &self.repo_id,
+            Capability::Propose,'
+test b2_api_undo_and_discard_of_another_actor_need_a_dominating_chain ... FAILED
+test b2_api_undo_requires_the_undo_capability ... FAILED
+test b2_api_final_discard_can_never_be_undone ... FAILED
+test b2_api_revocation_is_a_fact_and_is_enforced ... FAILED
+test result: FAILED. 0 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.07s
+error: test failed, to rerun pass `-p synapse-api --test b2_operation_views`
+RED api-undo-capability
+=== api-revoke-not-enforced (crates/synapse-api/src/lib.rs): '        self.auth.revoke_link(leaf, out.wal_seq)?;' -> ''
+test b2_api_undo_and_discard_of_another_actor_need_a_dominating_chain ... ok
+test b2_api_final_discard_can_never_be_undone ... ok
+test b2_api_revocation_is_a_fact_and_is_enforced ... FAILED
+test b2_api_undo_requires_the_undo_capability ... ok
+test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.85s
+error: test failed, to rerun pass `-p synapse-api --test b2_operation_views`
+RED api-revoke-not-enforced
diff --git a/evidence/b2-operation-views/red-green/run.sh b/evidence/b2-operation-views/red-green/run.sh
new file mode 100755
index 0000000..8062f72
--- /dev/null
+++ b/evidence/b2-operation-views/red-green/run.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# B2 red-before-green: one mutation per behaviour; each must turn its named test red.
+set -u
+cd "$HOME/workspace/syn-30"
+export CARGO_TARGET_DIR=$HOME/workspace/targets/syn-30
+OUT=${OUT:-/tmp/b2-red/red.txt}
+: > "$OUT"
+OP=crates/synapse-store/src/operation.rs
+CO=crates/synapse-store/src/codec.rs
+RV=crates/synapse-store/src/revision.rs
+API=crates/synapse-api/src/lib.rs
+mutate() { # file old new
+  A="$2" B="$3" perl -0pi -e 'BEGIN{$a=$ENV{A};$b=$ENV{B}} $n = s/\Q$a\E/$b/; die "no match\n" unless $n' "$1"
+}
+run() { # name file old new pkg testargs...
+  local name=$1 file=$2 old=$3 new=$4 pkg=$5; shift 5
+  cp "$file" /tmp/b2-red/backup
+  if ! mutate "$file" "$old" "$new"; then echo "MUTATION DID NOT APPLY: $name" | tee -a "$OUT"; cp /tmp/b2-red/backup "$file"; return; fi
+  echo "=== $name ($file): '$old' -> '$new'" >> "$OUT"
+  local log; log=$(cargo test -p "$pkg" "$@" 2>&1)
+  echo "$log" | grep -E '^test .* (ok|FAILED)$|test result|^error' >> "$OUT"
+  if echo "$log" | grep -q 'test result: FAILED\|^error'; then echo "RED $name" | tee -a "$OUT"; else echo "STILL GREEN $name" | tee -a "$OUT"; fi
+  cp /tmp/b2-red/backup "$file"
+}
+S="--lib b2_"
+run undo-has-no-effect $OP 'on[k] = false;' 'on[k] = on[k];' synapse-store $S
+run facts-undoable $OP 'if op.is_fact() {' 'if false && op.is_fact() {' synapse-store $S
+run no-undo-dominance $OP 'if !undoer.dominates(&op.actor) {' 'if false {' synapse-store $S
+run filter-ignored $OP 'if filter.is_some_and(|f| !f.dominates(&op.actor)) {' 'if false {' synapse-store $S
+run replay-discard-unchecked $OP 'if !first_admitter(ops, *id, i).is_some_and(|c| op.actor.dominates(c)) =>' 'if false =>' synapse-store $S
+run replay-revoke-unchecked $OP 'OpKind::Revoke { revoked } if !op.actor.dominates(revoked) => {' 'OpKind::Revoke { .. } if false => {' synapse-store $S
+run conflicts-dropped $OP 'view.conflicts.insert(*seq);' '{}' synapse-store $S
+run final-discard-repeatable $OP 'if fold(&ops).discarded.get(&id) == Some(&true) {' 'if false {' synapse-store $S
+run store-revoke-undominated $OP 'if !chain.dominates(&revoked) {' 'if false {' synapse-store $S
+run digest-ignores-kind-12 $RV 'let o = op.digest_bytes();' 'let o: Vec<u8> = Vec::new(); let _ = op;' synapse-store $S
+run checkpoint-drops-kind-12 $CO '7..=9 | 11 | 12)' '7..=9 | 11)' synapse-store $S
+run ledger-skips-kind-12 $RV 'WalRecord::ViewOperationRecorded { .. } => {}' 'WalRecord::ViewOperationRecorded { .. } => return,' synapse-store $S
+run api-undo-capability $API '            "undo",
+            &self.repo_id,
+            Capability::Undo,' '            "undo",
+            &self.repo_id,
+            Capability::Propose,' synapse-api --test b2_operation_views
+run api-revoke-not-enforced $API '        self.auth.revoke_link(leaf, out.wal_seq)?;' '' synapse-api --test b2_operation_views