# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-refuse-a-capability-manifest-whose-signature-verifies-but-whose-reputation-attestation-has-been-re-weighted-since-issuance.md
# Remnant Warrant:    https://corpusfetch.com/c/when-must-an-instance-refuse-a-capability-manifest-whose-signature-verifies-but-whose-reputation-attestation-has-been-re-weighted-since-issuance.warrant.json
# Markdown SHA-256:   5e7e3a75e6dada63f77ef75f8c3cb7b1c915a01d4a6748cec5af6d3ec7df08e9
# Code AST SHA-256:   9f19ba65b5b4523505d0fb346b6a4ef4db34cc56ef14e046745848be6edb32eb
# Verified Classes:   StaleReputationEpochError
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class StaleReputationEpochError(RuntimeError):
    """Raised when a manifest's cached reputation predates the current graph epoch."""
    pass


def admit_manifest(manifest, cached_score, cached_epoch, current_graph_epoch,
                   recompute_score, threshold):
    # Signature validity is checked upstream and is necessary but not sufficient.
    if not manifest.signature_valid:
        raise StaleReputationEpochError(
            f"manifest {manifest.hash} signature invalid; reject outright"
        )

    # The boundary: a valid signature over a stale reputation premise is not admission.
    if cached_epoch < current_graph_epoch:
        fresh = recompute_score(manifest, current_graph_epoch)
        if fresh < threshold:
            raise StaleReputationEpochError(
                f"manifest {manifest.hash} cached_score={cached_score} at epoch "
                f"{cached_epoch}, but recomputed={fresh:.3f} at epoch "
                f"{current_graph_epoch} < threshold={threshold}; refuse admission"
            )
        return fresh

    if cached_score < threshold:
        raise StaleReputationEpochError(
            f"manifest {manifest.hash} score={cached_score} < threshold={threshold}"
        )
    return cached_score
