# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-starve-its-own-verifier-attention-budget-misallocation-when-a-single-token-allocation-policy-serves-heterogeneous-consumers.md
# Remnant Warrant:    https://corpusfetch.com/c/why-does-an-instance-starve-its-own-verifier-attention-budget-misallocation-when-a-single-token-allocation-policy-serves-heterogeneous-consumers.warrant.json
# Markdown SHA-256:   0bdae36be633cb5f1618bc44e75b25c8322303717755ea4f3450d9e68475f87f
# Code AST SHA-256:   2204866507a2bb7a0e07920dcfeec8bed1383bb6529503e60bcb3fb8ab9bc794
# Verified Classes:   ContextBudgetViolation
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class ContextBudgetViolation(RuntimeError):
    """Raised when a consumer's hard token floor cannot be met from residual budget."""
    pass


def allocate_verification_budget(
    claim_tokens: int,
    evidence_tokens: int,
    template_overhead: int,
    residual_budget: int,
    reclaimable_from_scratch: int,
) -> int:
    required = claim_tokens + evidence_tokens + template_overhead
    if required <= residual_budget:
        return required
    shortfall = required - residual_budget
    if reclaimable_from_scratch >= shortfall:
        # Reclaim from sublinear-utility consumer (planner scratch) to meet floor.
        return required
    raise ContextBudgetViolation(
        f"verifier floor {required} exceeds residual {residual_budget} "
        f"and reclaimable scratch {reclaimable_from_scratch}; "
        f"shortfall {shortfall} unresolvable -> must abstain UNVERIFIABLE"
    )


def verify(claim: str, evidence: str, budget: dict) -> str:
    try:
        allocate_verification_budget(
            claim_tokens=budget["claim"],
            evidence_tokens=budget["evidence"],
            template_overhead=budget["template"],
            residual_budget=budget["residual"],
            reclaimable_from_scratch=budget["scratch"],
        )
    except ContextBudgetViolation:
        # Abstention is a failed check, never a pass.
        return "UNVERIFIABLE_INSUFFICIENT_BUDGET"
    return "CHECKED"
