Hmbown/CodeWhale · error · RuntimeContractError

DEFAULT_FRAGMENT_MAX_BYTES

Error message

DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed MAX_FRAGMENT_BYTES ({FRAGMENT_MAX_BYTES_CEILING})

What it means

This guard enforces ordering between the caps: the default per-fragment byte limit must never be larger than the maximum allowed limit. In practice it is unreachable when MAX_FRAGMENT_BYTES stays at its pinned 40,000 ceiling (since the default literal must already equal 4096 at this point), but it exists as defense-in-depth should the ceilings be relaxed — the script keeps the default <= max invariant explicit.

Solutions

  1. Lower DEFAULT_FRAGMENT_MAX_BYTES so it is <= MAX_FRAGMENT_BYTES (4096 <= 40000 with current ceilings)
  2. Or raise FRAGMENT_MAX_BYTES_CEILING in check_fragment_caps if the larger default is the reviewed intent
  3. Keep both constants pinned: default 4096, max 40000

Example fix

// before (crates/core/src/fragments.rs)
pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 64_000;
pub const MAX_FRAGMENT_BYTES: usize = 40_000;
// after
pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;
pub const MAX_FRAGMENT_BYTES: usize = MAX_FRAGMENT_TOKENS * 4;
Defensive patterns

Strategy: validation

Validate before calling

import re
src = open('crates/core/src/fragments.rs').read()
def val(name):
    m = re.search(rf'pub const {name}:\s*usize\s*=\s*([0-9_]+)', src)
    return int(m.group(1).replace('_','')) if m else None
defb, maxb = val('DEFAULT_FRAGMENT_MAX_BYTES'), 40000
if defb is not None and defb > maxb:
    raise SystemExit('DEFAULT_FRAGMENT_MAX_BYTES must not exceed MAX_FRAGMENT_BYTES')

Prevention

When it happens

Trigger: Running the check when DEFAULT_FRAGMENT_MAX_BYTES is a literal > FRAGMENT_MAX_BYTES_CEILING (e.g. after a reviewer raises FRAGMENT_MAX_BYTES_CEILING logic or the cap constants are decoupled). Note the equality check above must already pass, so this only fires if the ceilings themselves change.

Common situations: Relaxing the byte ceilings in a budget change and forgetting the default; configuring a default bigger than max after an upstream merge.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/e08a0a69090d0fdc. Report an issue: GitHub.

Appendix: source

Thrown at scripts/check-runtime-contract-budget.py:505

        )
    # DEFAULT is defined as 4 * 1024 (canonical) or 4096 literal
    has_default_multiplication = re.search(
        r"pub const DEFAULT_FRAGMENT_MAX_BYTES:\s*usize\s*=\s*4\s*\*\s*1024", text
    )
    default_literal = re.search(
        r"pub const DEFAULT_FRAGMENT_MAX_BYTES:\s*usize\s*=\s*([0-9_]+)", text
    )
    if has_default_multiplication:
        # canonical 4*1024 == 4096, which equals ceiling
        pass
    elif default_literal:
        default_bytes = int(default_literal.group(1).replace("_", ""))
        if default_bytes != FRAGMENT_DEFAULT_MAX_BYTES_CEILING:
            raise RuntimeContractError(
                f"DEFAULT_FRAGMENT_MAX_BYTES must be {FRAGMENT_DEFAULT_MAX_BYTES_CEILING}, got {default_bytes}"
            )
        if default_bytes > FRAGMENT_MAX_BYTES_CEILING:
            raise RuntimeContractError(
                f"DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed MAX_FRAGMENT_BYTES ({FRAGMENT_MAX_BYTES_CEILING})"
            )
    else:
        raise RuntimeContractError("DEFAULT_FRAGMENT_MAX_BYTES definition not found")

    max_count = const_value(
        r"pub const MAX_FRAGMENTS_PER_CONTEXT:\s*usize\s*=\s*([0-9_]+)"
    )
    if max_count != FRAGMENT_MAX_COUNT_CEILING:
        raise RuntimeContractError(
            f"MAX_FRAGMENTS_PER_CONTEXT must be {FRAGMENT_MAX_COUNT_CEILING}, got {max_count}"
        )
    if max_count > FRAGMENT_MAX_COUNT_CEILING:
        raise RuntimeContractError(
            f"MAX_FRAGMENTS_PER_CONTEXT ({max_count}) must not exceed {FRAGMENT_MAX_COUNT_CEILING}"
        )

    # Ensure every injection type is in FragmentId::all() and the

View on GitHub (pinned to 433685b202)