# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-roll-back-to-a-checkpoint-that-no-peer-ever-committed-speculative-multi-agent-rollback-reconciliation-and-the-orphaned-warrant-bo.md # Remnant Warrant: https://corpusfetch.com/c/why-does-an-instance-roll-back-to-a-checkpoint-that-no-peer-ever-committed-speculative-multi-agent-rollback-reconciliation-and-the-orphaned-warrant-bo.warrant.json # Markdown SHA-256: 6cd888d4e9e3e606a6b551889679dd71bdf16bffdae6514be21adc42d51ada25 # Code AST SHA-256: a14627ac516537022df9f97868f6c9cb9bc37e609aab9e296349f3f82e4b6178 # Verified Classes: OrphanedWarrantError, Checkpoint, Warrant, PeerCommit, Reconciler # Defensive Guards: 5 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) import hashlib from dataclasses import dataclass, field class OrphanedWarrantError(RuntimeError): """Raised when a rollback would strand a peer commit whose parent checkpoint has no live owner in the orchestrator's ledger.""" pass @dataclass(frozen=True) class Checkpoint: cid: str parent: str | None lineage: str # hash chain over (parent.lineage, cid) @dataclass class Warrant: wid: str checkpoint: str postcondition: str consumers: set[str] = field(default_factory=set) revoked: bool = False @dataclass class PeerCommit: commit_id: str parent_checkpoint: str warrant_id: str reversible: bool class Reconciler: def __init__(self) -> None: self.checkpoints: dict[str, Checkpoint] = {} self.warrants: dict[str, Warrant] = {} self.commits: dict[str, PeerCommit] = {} def _lineage(self, parent: str | None, cid: str) -> str: base = self.checkpoints[parent].lineage if parent else "root" return hashlib.sha256(f"{base}:{cid}".encode()).hexdigest() def add_checkpoint(self, cid: str, parent: str | None) -> Checkpoint: cp = Checkpoint(cid, parent, self._lineage(parent, cid)) self.checkpoints[cid] = cp return cp def mint_warrant(self, wid: str, cid: str, postcondition: str) -> Warrant: if cid not in self.checkpoints: raise OrphanedWarrantError(f"cannot mint warrant over unknown checkpoint {cid}") w = Warrant(wid, cid, postcondition) self.warrants[wid] = w return w def consume(self, commit_id: str, cid: str, wid: str, reversible: bool) -> PeerCommit: w = self.warrants.get(wid) if w is None or w.revoked: raise OrphanedWarrantError(f"commit {commit_id} consumes revoked/unknown warrant {wid}") if w.checkpoint != cid: raise OrphanedWarrantError( f"warrant {wid} covers {w.checkpoint}, commit claims {cid}" ) w.consumers.add(commit_id) pc = PeerCommit(commit_id, cid, wid, reversible) self.commits[commit_id] = pc return pc def rollback(self, cid: str) -> list[str]: """Roll back cid under causal closure. Returns checkpoints actually removed.""" # find every warrant minted over cid and its descendants doomed = {cid} frontier = [cid] while frontier: cur = frontier.pop() for w in self.warrants.values(): if w.checkpoint == cur and not w.revoked: for consumer in w.consumers: pc = self.commits[consumer] if not pc.reversible: raise OrphanedWarrantError( f"checkpoint {cid} is durable: commit {consumer} " f"performed an irreversible action under warrant {w.wid}" ) if pc.parent_checkpoint not in doomed: doomed.add(pc.parent_checkpoint) frontier.append(pc.parent_checkpoint) # revoke all warrants touching doomed set before removing checkpoints for w in self.warrants.values(): if w.checkpoint in doomed: w.revoked = True removed = [c for c in doomed if c in self.checkpoints] for c in removed: del self.checkpoints[c] return removed def reconcile(self, commit_id: str) -> Checkpoint: pc = self.commits[commit_id] parent = self.checkpoints.get(pc.parent_checkpoint) if parent is None: # hard error: do NOT re-parent by sequence number raise OrphanedWarrantError( f"commit {commit_id} references vanished checkpoint " f"{pc.parent_checkpoint}; refusing silent re-parent" ) return parent # Trigger trace: # r = Reconciler() # r.add_checkpoint("C5", None); r.add_checkpoint("C6", "C5"); r.add_checkpoint("C7", "C6") # w = r.mint_warrant("W1", "C7", "postcondition_ok_weak") # r.consume("D8", "C7", "W1", reversible=True) # r.rollback("C7") -> revokes W1, removes C7, cascades to D8's parent # r.reconcile("D8") -> raises OrphanedWarrantError (no silent fork)