# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-happens-when-an-instance-intercepts-its-own-memory-writes-through-an-ebpf-style-policy-hook-and-the-verdict-is-deferred.md
# Remnant Warrant:    https://corpusfetch.com/c/what-happens-when-an-instance-intercepts-its-own-memory-writes-through-an-ebpf-style-policy-hook-and-the-verdict-is-deferred.warrant.json
# Markdown SHA-256:   8be5e3ecc25baf3870d6c4b9b507a03fbab10614e5d7ff21a476f2b909958074
# Code AST SHA-256:   9ce76e25335ed43903b8f5a7a1f33b447aa118ea3c70007571f7e59115ac13dc
# Verified Classes:   PolicyEnforcementMisconfigured
# Defensive Guards:   5 fail-closed invariants (zero external deps)

class PolicyEnforcementMisconfigured(RuntimeError):
    """Raised when an eBPF-style interceptor cannot be trusted as an enforcement point."""
    pass


def assert_enforcement_sound(engine) -> None:
    """
    Refuse to treat `engine` as an enforcement point unless its verdict path is
    structurally disjoint from the resources it mediates.
    """
    if engine.verdict_transport_shares_memory_with_enforced_process:
        raise PolicyEnforcementMisconfigured(
            "verdict channel aliases enforced memory: deferred verdicts can "
            "re-enter the hook and livelock to the permissive branch"
        )

    if engine.hook_can_fire_on_verdict_daemon:
        raise PolicyEnforcementMisconfigured(
            "policy daemon is subject to its own hook; verdict delivery can "
            "block on the ring buffer it is meant to drain"
        )

    if engine.timeout_policy == "allow":
        raise PolicyEnforcementMisconfigured(
            "timeout branch is 'allow'; under load this silently fails open. "
            "Require 'deny' with a circuit breaker, or downgrade to audit-only."
        )

    if engine.reentrant_on_dispatch_path:
        raise PolicyEnforcementMisconfigured(
            "hook can fire reentrantly on the tool-call dispatch path; "
            "verdict callback will contend with the dispatcher's own lock"
        )

    if engine.verdict_daemon_cgroup_isolated is False:
        raise PolicyEnforcementMisconfigured(
            "verdict daemon not isolated to a cgroup with the LSM program "
            "detached; self-observation livelock is reachable"
        )


def classify_engine(engine) -> str:
    try:
        assert_enforcement_sound(engine)
    except PolicyEnforcementMisconfigured as exc:
        return f"AUDIT_ONLY: {exc}"
    return "ENFORCING"
