Hmbown/CodeWhale · error · RuntimeContractError
DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed
Error message
DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed MAX_FRAGMENT_BYTES ({FRAGMENT_MAX_BYTES_CEILING}) What it means
Defense-in-depth branch of the fragment-cap gate in scripts/check-runtime-contract-budget.py: fires when a literal-spelled DEFAULT_FRAGMENT_MAX_BYTES in crates/core/src/fragments.rs equals FRAGMENT_DEFAULT_MAX_BYTES_CEILING and exceeds FRAGMENT_MAX_BYTES_CEILING (40_000). Because the preceding equality check (line 493) pins the default to 4096, this branch is unreachable with today's script constants; it only goes live if a maintainer raises FRAGMENT_DEFAULT_MAX_BYTES_CEILING above FRAGMENT_MAX_BYTES_CEILING. Like every RuntimeContractError it aborts the checker with exit code 2.
Source
Thrown at scripts/check-runtime-contract-budget.py:498
)
# 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 theView on GitHub (pinned to 8880682c63)
Solutions
- Keep the canonical spelling 'pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;' in crates/core/src/fragments.rs - the multiplication form bypasses the literal checks entirely
- If renegotiating ceilings in scripts/check-runtime-contract-budget.py, keep FRAGMENT_DEFAULT_MAX_BYTES_CEILING <= FRAGMENT_MAX_BYTES_CEILING
- Run 'python3 scripts/check-runtime-contract-budget.py --receipt scripts/runtime-contract-budget.json' locally before pushing so the gate fails in your worktree, not CI
Example fix
# before (scripts/check-runtime-contract-budget.py) FRAGMENT_MAX_TOKENS_CEILING = 10_000 FRAGMENT_MAX_BYTES_CEILING = FRAGMENT_MAX_TOKENS_CEILING * 4 FRAGMENT_DEFAULT_MAX_BYTES_CEILING = 48 * 1024 # raised past MAX (40_000) # after FRAGMENT_MAX_TOKENS_CEILING = 10_000 FRAGMENT_MAX_BYTES_CEILING = FRAGMENT_MAX_TOKENS_CEILING * 4 FRAGMENT_DEFAULT_MAX_BYTES_CEILING = 4 * 1024 # keep DEFAULT <= MAX
Defensive patterns
Strategy: try-catch
Validate before calling
# Preflight: canonical multiplication form bypasses both literal checks
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", text), "use canonical 4 * 1024 spelling" 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] fragment caps violated: {error}", file=sys.stderr)
raise SystemExit(2) Prevention
- Keep the canonical '4 * 1024' spelling for DEFAULT_FRAGMENT_MAX_BYTES so the literal branch never runs
- When editing FRAGMENT_*_CEILING constants in the checker, keep DEFAULT <= MAX in the same commit
- Run the checker in CI on every PR touching crates/core/src/fragments.rs or the script itself
When it happens
Trigger: check_fragment_caps() parses 'pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = <literal>' and reaches line 497 only when default_bytes == 4096 AND default_bytes > 40000 - impossible unless the script's own ceiling constants are edited inconsistently (e.g. FRAGMENT_DEFAULT_MAX_BYTES_CEILING raised to 48*1024 while FRAGMENT_MAX_TOKENS_CEILING stays 10_000).
Common situations: Renegotiating fragment budgets by editing the FRAGMENT_*_CEILING constants in the checker without preserving DEFAULT <= MAX; copying an older checker with different ceilings over a newer fragments.rs.
Related errors
- DEFAULT_FRAGMENT_MAX_BYTES definition not found
- MAX_FRAGMENTS_PER_CONTEXT must be {FRAGMENT_MAX_COUNT_CEILIN
- MAX_FRAGMENTS_PER_CONTEXT ({max_count}) must not exceed {FRA
- FragmentId missing required variant {name}
- bounded fragment module missing required marker {marker!r}
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/e08a0a69090d0fdc.
Report an issue: GitHub.