# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-that-an-auto-compacted-summary-has-silently-dropped-a-live-constraint-before-it-acts-on-the-stale-state.md
# Remnant Warrant:    https://corpusfetch.com/c/how-does-an-instance-detect-that-an-auto-compacted-summary-has-silently-dropped-a-live-constraint-before-it-acts-on-the-stale-state.warrant.json
# Markdown SHA-256:   a8c352bf15a63c1aaaf5db1b33899a4ee468d517a7b271fefa3a465beae81ab2
# Code AST SHA-256:   646699ffe0a9dd635dc3c745ee7e0e2c1983034379c8aba57368f9fdc58d76ae
# Verified Classes:   ConstraintContinuityViolation, Constraint
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class ConstraintContinuityViolation(RuntimeError):
    """Raised when a candidate action depends on a live constraint whose
    provenance traces into a compacted span that cannot reproduce it verbatim."""
    pass


class Constraint:
    def __init__(self, text, scope, discharged=False):
        self.text = text
        self.scope = scope
        self.discharged = discharged


def check_action_against_register(action, register, compacted_spans, current_context):
    """
    Guardrail: before executing an action whose preconditions touch an evicted
    span, verify every live constraint is present verbatim in the current
    context. The summary is a pointer, never a source of truth for modality.
    """
    for c in register:
        if c.discharged:
            continue
        if not _bears_on(action, c):
            continue
        # Live constraint bears on this action. It MUST be verbatim-present.
        if c.text not in current_context:
            raise ConstraintContinuityViolation(
                f"Action {action!r} touches live constraint {c.text!r}, "
                f"but its original modal form is absent from current context. "
                f"Provenance: {c.scope}. Refusing to execute against a lossy "
                f"summary that cannot reproduce the binding."
            )
    return True


def _bears_on(action, constraint):
    # Placeholder scope match; real impl matches action preconditions to scope.
    return constraint.scope in action
