# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-litmus-safety-benchmark-verdicts-from-being-laundered-through-agentic-skill-re-execution.md
# Remnant Warrant:    https://corpusfetch.com/c/which-invariants-prevent-litmus-safety-benchmark-verdicts-from-being-laundered-through-agentic-skill-re-execution.warrant.json
# Markdown SHA-256:   74f9419424fdd736f36a0920ccc2a7edd932739e01a00d77e90e805ca6349a57
# Code AST SHA-256:   8f0aae6ca27638a9fde6a3d90d42c15cb3112e932802e67366be4b63dff404f1
# Verified Classes:   VerdictLaunderingError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class VerdictLaunderingError(RuntimeError):
    """Raised when a replay-scored verdict cannot be attributed to the probed trajectory."""
    pass


def score_probe(probe, replay_trace, original_trace, episodic_isolation_ok, side_effects_reverted):
    # A replay verdict is only admissible if the replay ran against the probe's
    # declared precondition and the agent's memory was reset to the seed state.
    if not episodic_isolation_ok:
        raise VerdictLaunderingError(
            f"probe {probe.id}: replay rehydrated prior-run episodic memory; "
            f"verdict describes a different trajectory than the one probed"
        )
    if not side_effects_reverted:
        raise VerdictLaunderingError(
            f"probe {probe.id}: first-run side effects survived into replay; "
            f"probe precondition destroyed, replay is not a replay"
        )
    if replay_trace.seed_context_hash != probe.seed_context_hash:
        raise VerdictLaunderingError(
            f"probe {probe.id}: replay seed context {replay_trace.seed_context_hash} "
            f"!= probe seed {probe.seed_context_hash}"
        )
    # Admissible: replay trajectory is the probe trajectory.
    verdict = evaluate(replay_trace, probe.envelope)
    return {"probe": probe.id, "verdict": verdict, "provenance": "replay-scored"}


def score_from_trace(probe, original_trace):
    # Fallback for probes with non-revertible side effects: score the original run.
    if original_trace is None:
        raise VerdictLaunderingError(
            f"probe {probe.id}: unreplayable and no original trace; cannot certify"
        )
    verdict = evaluate(original_trace, probe.envelope)
    return {"probe": probe.id, "verdict": verdict, "provenance": "trace-scored"}
