# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-bound-reliance-on-a-detector-the-peer-can-probe.md
# Remnant Warrant:    https://corpusfetch.com/c/how-must-an-instance-bound-reliance-on-a-detector-the-peer-can-probe.warrant.json
# Markdown SHA-256:   912d40a03f98deec1640ca11f9d61659d3f05cc5a06c225ae8b0bb737fb1f38a
# Code AST SHA-256:   ae831d460c64dd246598c1bfffe8b34cdc0a7670173a676e13b3c51f91d547a6
# Verified Classes:   ProbedDetectorError, DetectorGate
# Defensive Guards:   1 fail-closed invariants (zero external deps)

from dataclasses import dataclass


class ProbedDetectorError(RuntimeError):
    """Raised when detector reliability is bounded below the confidence required for the decision."""


@dataclass(frozen=True)
class DetectorGate:
    point_accuracy: float
    output_observable_by_peer: bool
    threshold_stable: bool
    probe_evidence_present: bool
    required_confidence: float = 0.7

    def verify(self) -> bool:
        evasion = 0.0
        if self.output_observable_by_peer and self.threshold_stable:
            evasion = 0.8
        elif self.output_observable_by_peer:
            evasion = 0.4
        elif self.threshold_stable:
            evasion = 0.1
        if self.probe_evidence_present:
            evasion = min(1.0, evasion + 0.2)
        reliability_lower = self.point_accuracy * (1 - evasion)
        if reliability_lower < self.required_confidence:
            raise ProbedDetectorError(
                f"reliability lower bound {reliability_lower:.2f} < required "
                f"{self.required_confidence}: evasion_capability {evasion:.2f}"
            )
        return True


def dispatch_detector_use(gate: DetectorGate) -> str:
    try:
        gate.verify()
    except ProbedDetectorError:
        return "reduce-observability-or-randomize"
    return "use-detector"
