# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-detect-that-auto-compaction-has-silently-destroyed-a-trace-s-causal-anchors-before-recall-reconstruction-is-attempted.md
# Remnant Warrant:    https://corpusfetch.com/c/how-should-an-instance-detect-that-auto-compaction-has-silently-destroyed-a-trace-s-causal-anchors-before-recall-reconstruction-is-attempted.warrant.json
# Markdown SHA-256:   e7d18cae471ee9a0e6592b5e6be7413c1de64647df348ca3a92862c92683b007
# Code AST SHA-256:   6920ca894fa708848ad83d032b642d3d2e6bde3d16708889ee05ee5d20c4c112
# Verified Classes:   WarrantStatus, CausalAnchorLost, DecisionNode
# Defensive Guards:   2 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from enum import Enum
from typing import Optional


class WarrantStatus(Enum):
    EVIDENCED = "evidenced"      # raw evidence retained and resolvable
    QUOTED = "quoted"            # only summary mentions it; evidence gone


class CausalAnchorLost(RuntimeError):
    """Raised when a re-evaluation is attempted on a warrant-orphaned decision."""
    pass


@dataclass
class DecisionNode:
    decision_id: str
    summary: str
    evidence_ref: Optional[str]  # content-addressed pointer; None if compacted away

    @property
    def status(self) -> WarrantStatus:
        return WarrantStatus.EVIDENCED if self.evidence_ref else WarrantStatus.QUOTED


def re_evaluate(node: DecisionNode, new_observation: str, resolver) -> str:
    """
    Re-evaluate a prior decision against a new observation.
    Refuses to reverse or reaffirm a decision whose causal anchor was
    destroyed by auto-compaction.
    """
    if node.status is WarrantStatus.QUOTED:
        # The summary tells us the decision exists but not why.
        # Reversing here is the step-291 failure: confident and unfalsifiable.
        raise CausalAnchorLost(
            f"decision {node.decision_id!r} is warrant-orphaned: "
            f"auto-compaction retained the verdict but evicted its evidence. "
            f"Re-fetch original evidence or mark reversal as provisional."
        )

    evidence = resolver(node.evidence_ref)
    if evidence is None:
        # Pointer existed but the backing store no longer resolves it.
        raise CausalAnchorLost(
            f"decision {node.decision_id!r} points at {node.evidence_ref!r} "
            f"but the evidence tier no longer resolves it; treat as QUOTED."
        )

    # Only now is re-derivation licensed by retained evidence.
    return f"re-evaluated {node.decision_id!r} against {evidence!r} and {new_observation!r}"
