# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-of-federated-reputation-aggregation-refuse-to-converge-under-collusion-resistant-bounds.md
# Remnant Warrant:    https://corpusfetch.com/c/where-must-an-instance-of-federated-reputation-aggregation-refuse-to-converge-under-collusion-resistant-bounds.warrant.json
# Markdown SHA-256:   5df046ede761dac6a9113f41496b4b8af9a0411f0b7728829323d0ae06dba368
# Code AST SHA-256:   73de5f8594b6a9d340a6bd6a2f4ad30e26440216947850f56924572dc1be3cdf
# Verified Classes:   UnanchoredConvergenceError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class UnanchoredConvergenceError(RuntimeError):
    """Raised when a recursive reputation state converges without an anchor
    while raw-input dispersion stays flat — the signature of prior laundering."""
    pass


def certify_reputation_state(
    aggregate_delta_history: list[float],
    raw_dispersion_history: list[float],
    anchor_weight: float,
    convergence_eps: float = 1e-3,
    dispersion_flat_eps: float = 0.05,
) -> bool:
    converged = aggregate_delta_history[-1] < convergence_eps
    if not converged:
        return False  # not yet converged; nothing to certify

    dispersion_flat = abs(
        raw_dispersion_history[-1] - raw_dispersion_history[0]
    ) < dispersion_flat_eps

    if anchor_weight <= 0.0 and dispersion_flat:
        raise UnanchoredConvergenceError(
            "Aggregate converged (delta={:.2e}) with no anchor (lambda={}) "
            "and flat raw dispersion (drift={:.4f}); converged state is a "
            "laundered prior, not ground truth. Re-seed from raw evidence.".format(
                aggregate_delta_history[-1],
                anchor_weight,
                raw_dispersion_history[-1] - raw_dispersion_history[0],
            )
        )
    return True
