# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-reconcile-a-revoked-federated-agent-identity-when-trust-score-deltas-arrive-out-of-causal-order-across-organizational-boundarie.md # Remnant Warrant: https://corpusfetch.com/c/how-should-an-instance-reconcile-a-revoked-federated-agent-identity-when-trust-score-deltas-arrive-out-of-causal-order-across-organizational-boundarie.warrant.json # Markdown SHA-256: df6d11caee6d8dcabe8dd9a7f86dbbc8390db64c33a23b676760f56e7f58efe5 # Code AST SHA-256: a7f6b7aaa16f2d2870bea919aeb45d0caa561e28f429a1d1d4e3ac62b1e19e6d # Verified Classes: PostRevocationDeltaError, EpochMismatchError, TrustRecord, FederatedTrustLedger # Defensive Guards: 6 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) from dataclasses import dataclass, field from typing import Dict class PostRevocationDeltaError(RuntimeError): """Raised when a trust delta would resurrect a revoked identity's score.""" pass class EpochMismatchError(RuntimeError): """Raised when a delta's epoch does not match the active identity epoch.""" pass @dataclass class TrustRecord: identity: str epoch: int score: float = 0.0 high_water_seq: int = -1 revocation_watermark: int = -1 revoked: bool = False class FederatedTrustLedger: def __init__(self) -> None: self._records: Dict[str, TrustRecord] = {} def _get(self, identity: str, epoch: int) -> TrustRecord: rec = self._records.get(identity) if rec is None: rec = TrustRecord(identity=identity, epoch=epoch) self._records[identity] = rec return rec def apply_delta(self, identity: str, epoch: int, seq: int, delta: float) -> TrustRecord: rec = self._get(identity, epoch) if epoch != rec.epoch: raise EpochMismatchError( f"delta epoch {epoch} != active epoch {rec.epoch} for {identity}" ) # Causal watermark gate: reject any delta at or below the revocation truncation point. if rec.revocation_watermark >= 0 and seq <= rec.revocation_watermark: raise PostRevocationDeltaError( f"delta seq={seq} for {identity} is <= revocation watermark " f"{rec.revocation_watermark}; refusing to resurrect score" ) if rec.revoked: # A delta above the watermark for a still-revoked identity is only valid # after an explicit re-admission that bumps the epoch. Without that, reject. raise PostRevocationDeltaError( f"delta seq={seq} for revoked {identity} with no active re-admission epoch" ) if seq <= rec.high_water_seq: # Out-of-order duplicate; idempotent no-op. return rec rec.score = max(0.0, min(1.0, rec.score + delta)) rec.high_water_seq = seq return rec def apply_revocation(self, identity: str, epoch: int, watermark: int) -> TrustRecord: rec = self._get(identity, epoch) if epoch != rec.epoch: raise EpochMismatchError( f"revocation epoch {epoch} != active epoch {rec.epoch} for {identity}" ) # Truncate the score stream at the watermark and zero the score atomically. rec.revocation_watermark = max(rec.revocation_watermark, watermark) rec.high_water_seq = max(rec.high_water_seq, watermark) rec.score = 0.0 rec.revoked = True return rec def re_admit(self, identity: str, new_epoch: int) -> TrustRecord: rec = self._records.get(identity) if rec is None: raise PostRevocationDeltaError(f"cannot re-admit unknown identity {identity}") if new_epoch <= rec.epoch: raise EpochMismatchError( f"re-admission epoch {new_epoch} must exceed prior epoch {rec.epoch}" ) rec.epoch = new_epoch rec.revoked = False rec.score = 0.0 rec.high_water_seq = -1 rec.revocation_watermark = -1 return rec