Hmbown/CodeWhale · error · RuntimeContractError

DEFAULT_FRAGMENT_MAX_BYTES must be

Error message

DEFAULT_FRAGMENT_MAX_BYTES must be {FRAGMENT_DEFAULT_MAX_BYTES_CEILING}, got {default_bytes}

What it means

When DEFAULT_FRAGMENT_MAX_BYTES is written as a numeric literal, the checker requires it to equal 4096 (FRAGMENT_DEFAULT_MAX_BYTES_CEILING, i.e. 4*1024). The default per-fragment byte limit is pinned so a fresh configuration never produces oversized fragments. A different literal fails the contract gate.

Solutions

  1. Set the literal in crates/core/src/fragments.rs back to 4096
  2. Or use the canonical spelling `pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;` which the checker accepts unconditionally
  3. If 4096 must change, update FRAGMENT_DEFAULT_MAX_BYTES_CEILING in scripts/check-runtime-contract-budget.py as part of a reviewed budget change

Example fix

// before
pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 8192;
// after
pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024; // 4096
Defensive patterns

Strategy: validation

Validate before calling

import re
src = open('crates/core/src/fragments.rs').read()
m = re.search(r'pub const DEFAULT_FRAGMENT_MAX_BYTES:\s*usize\s*=\s*([0-9_]+)', src)
if m and int(m.group(1).replace('_','')) != 4096:
    raise SystemExit('DEFAULT_FRAGMENT_MAX_BYTES must be 4096')

Prevention

When it happens

Trigger: Running scripts/check-runtime-contract-budget.py when fragments.rs contains `pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = <literal>` with a value other than 4096 (the `4 * 1024` multiplication form is accepted as canonical and bypasses this check).

Common situations: Tuning the default fragment size upward for bigger context imports; copying a value from another project; bumping the default during a refactor without updating the gate.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

            )
    elif not has_multiplication:
        raise RuntimeContractError(
            "MAX_FRAGMENT_BYTES must be defined as MAX_FRAGMENT_TOKENS * 4 or as 40000"
        )
    # 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(

View on GitHub (pinned to 433685b202)