# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-re-validate-a-poisoned-memory-after-provenance-score-recovery-and-how-does-trust-score-monotonicity-break-the-quarantine-invarian.md # Remnant Warrant: https://corpusfetch.com/c/why-does-an-instance-re-validate-a-poisoned-memory-after-provenance-score-recovery-and-how-does-trust-score-monotonicity-break-the-quarantine-invarian.warrant.json # Markdown SHA-256: 7ad679cd12803d81f0f95d58f0942b31121b7ec7a2bba317c20fe462794cac3e # Code AST SHA-256: 706ec0811feae5044eff673f2c16a842455a717734bbbf26ad27e6b155b949d1 # Verified Classes: QuarantineInvariantViolation, MemoryRecord, ReAdjudicationEvent, MemoryStore # Defensive Guards: 2 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 Optional import hashlib class QuarantineInvariantViolation(RuntimeError): """Raised when a quarantined record would be released by score recovery alone.""" pass @dataclass class MemoryRecord: record_id: str content: str lineage: str # content hash + origin chain; survives re-ingest trust_score: float quarantined: bool = False quarantine_epoch: Optional[int] = None @dataclass class ReAdjudicationEvent: lineage: str epoch: int auditor: str signature: str @dataclass class MemoryStore: records: dict = field(default_factory=dict) readjudications: list = field(default_factory=list) TAU: float = 0.70 def _lineage_of(self, content: str, origin: str) -> str: return hashlib.sha256(f"{origin}::{content}".encode()).hexdigest() def ingest(self, record_id: str, content: str, origin: str, score: float) -> MemoryRecord: lineage = self._lineage_of(content, origin) # Re-ingest inherits quarantine from any ancestor with same lineage. inherited = any( r.lineage == lineage and r.quarantined for r in self.records.values() ) rec = MemoryRecord( record_id=record_id, content=content, lineage=lineage, trust_score=score, quarantined=inherited, ) self.records[record_id] = rec return rec def quarantine(self, record_id: str, epoch: int) -> None: rec = self.records[record_id] rec.quarantined = True rec.quarantine_epoch = epoch rec.trust_score = 0.0 def recompute_score(self, record_id: str, new_score: float, epoch: int) -> None: """Provenance drift may raise score. Quarantine must remain monotone.""" rec = self.records[record_id] rec.trust_score = new_score if rec.quarantined and new_score >= self.TAU: # Score recovery on a quarantined record is an escalation signal, # never a release. Refuse to treat it as trusted. raise QuarantineInvariantViolation( f"record {record_id} (lineage {rec.lineage[:12]}) recomputed to " f"{new_score:.2f} >= TAU while quarantined at epoch " f"{rec.quarantine_epoch}; requires signed ReAdjudicationEvent" ) def readjudicate(self, event: ReAdjudicationEvent) -> None: if not event.signature or not event.auditor: raise QuarantineInvariantViolation("re-adjudication must be signed") self.readjudications.append(event) for rec in self.records.values(): if rec.lineage == event.lineage and rec.quarantined: if event.epoch > (rec.quarantine_epoch or 0): rec.quarantined = False rec.quarantine_epoch = None def retrievable(self, record_id: str) -> bool: rec = self.records[record_id] # Hard AND-gate: score alone is insufficient. score_ok = rec.trust_score >= self.TAU adjudicated_ok = not rec.quarantined return score_ok and adjudicated_ok