Hmbown/CodeWhale · error · RuntimeContractError

DEFAULT_FRAGMENT_MAX_BYTES definition not found

Error message

DEFAULT_FRAGMENT_MAX_BYTES definition not found

What it means

The checker requires an explicit `pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = ...` definition in crates/core/src/fragments.rs, matching either the `4 * 1024` form or a numeric literal. If neither regex matches — the constant is missing, renamed, reformatted, or commented out — the gate fails closed rather than assuming a default. This keeps the per-fragment default byte cap auditable.

Solutions

  1. Restore `pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;` in crates/core/src/fragments.rs
  2. Or restore the literal form `= 4096` with the exact name and type annotation on one line
  3. Check the constant was not moved/renamed — the regex only matches the exact identifier in the fragment module

Example fix

// before (constant removed during refactor)
// default now supplied by config layer
// after
pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;
Defensive patterns

Strategy: validation

Validate before calling

import re
src = open('crates/core/src/fragments.rs').read()
if not re.search(r'pub const DEFAULT_FRAGMENT_MAX_BYTES:\s*usize\s*=', src):
    raise SystemExit('DEFAULT_FRAGMENT_MAX_BYTES definition missing')

Prevention

When it happens

Trigger: Running scripts/check-runtime-contract-budget.py after removing or renaming DEFAULT_FRAGMENT_MAX_BYTES in fragments.rs, or after a reformat that splits the definition so the regexes `DEFAULT_FRAGMENT_MAX_BYTES:\s*usize\s*=\s*4\s*\*\s*1024` and `=\s*([0-9_]+)` no longer match.

Common situations: Deleting the constant while switching to a runtime-provided default; renaming it during a config refactor; moving the definition to another module.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

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

    )
    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 433685b202)