Hmbown/CodeWhale · error · RuntimeContractError

DEFAULT_FRAGMENT_MAX_BYTES definition not found

Error message

DEFAULT_FRAGMENT_MAX_BYTES definition not found

What it means

The fragment-cap gate requires DEFAULT_FRAGMENT_MAX_BYTES in crates/core/src/fragments.rs to be spelled one of two ways: the canonical multiplication '4 * 1024' or a plain decimal literal. This error means neither regex matched - the const was removed, renamed, or defined through another name (e.g. '4 * KIB') that the gate deliberately does not trust. The gate fails closed because the default cap is part of the bounded-fragment contract (issue #5264).

Source

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

    )
    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
    # project-instruction import is present as a typed fragment.
    required_fragments = [
        "Workspace",
        "Permissions",

View on GitHub (pinned to 8880682c63)

Solutions

  1. Restore the canonical form 'pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;' in crates/core/src/fragments.rs
  2. If a literal is preferred, use exactly 4096 (or 4_096) - the literal regex accepts underscores
  3. Keep the const inside crates/core/src/fragments.rs - the gate reads only that file (FRAGMENT_MODULE, line 428)

Example fix

// before (crates/core/src/fragments.rs)
const KIB: usize = 1024;
pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * KIB;

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

Strategy: try-catch

Validate before calling

import re
from pathlib import Path
text = Path("crates/core/src/fragments.rs").read_text(encoding="utf-8")
assert re.search(r"pub const DEFAULT_FRAGMENT_MAX_BYTES:\s*usize\s*=\s*(4\s*\*\s*1024|[0-9_]+)", text), "DEFAULT_FRAGMENT_MAX_BYTES must be 4 * 1024 or a decimal literal"

Type guard

def is_runtime_contract_error(exc: BaseException) -> bool:
    return isinstance(exc, ValueError) and type(exc).__name__ == "RuntimeContractError"

Try / catch

try:
    check_fragment_caps()
except RuntimeContractError as error:
    print(f"[gate] {error}", file=sys.stderr)
    raise SystemExit(2)

Prevention

When it happens

Trigger: check_fragment_caps() runs re.search for 'pub const DEFAULT_FRAGMENT_MAX_BYTES:\s*usize\s*=\s*4\s*\*\s*1024' and for '=\s*([0-9_]+)'; both miss when the definition is '4 * KIB', '= DEFAULT_CAP', a cfg!() expression, or the const is deleted/renamed.

Common situations: Refactoring constants out of fragments.rs into a shared consts module; introducing named helpers (KIB) for readability; merging a branch that restructured the fragment caps.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/7e3ef6c9b71a9cbf. Report an issue: GitHub.