Hmbown/CodeWhale · error · RuntimeContractError
MAX_FRAGMENT_BYTES must be
Error message
MAX_FRAGMENT_BYTES must be {FRAGMENT_MAX_BYTES_CEILING}, got {literal} What it means
This static contract check parses crates/core/src/fragments.rs and verifies that the MAX_FRAGMENT_BYTES constant, when written as a numeric literal, equals the derived ceiling of 40,000 (MAX_FRAGMENT_TOKENS 10,000 * 4). The repository pins these hard caps so bounded fragments cannot silently grow the prompt/context budget. If someone edits the literal to a different number, the check raises RuntimeContractError and fails the gate.
Solutions
- Set the literal in crates/core/src/fragments.rs back to 40000 (or `MAX_FRAGMENT_TOKENS * 4`)
- If a larger cap is genuinely intended, first raise MAX_FRAGMENT_TOKENS/byte ceilings in check_fragment_caps (FRAGMENT_MAX_BYTES_CEILING) with review, then align the constant
- Verify the value parsed by the regex: `grep -n 'MAX_FRAGMENT_BYTES' crates/core/src/fragments.rs`
Example fix
// before (crates/core/src/fragments.rs) pub const MAX_FRAGMENT_BYTES: usize = 80_000; // after pub const MAX_FRAGMENT_BYTES: usize = MAX_FRAGMENT_TOKENS * 4; // 40_000
Defensive patterns
Strategy: validation
Validate before calling
import re
src = open('crates/core/src/fragments.rs').read()
m = re.search(r'pub const MAX_FRAGMENT_BYTES:\s*usize\s*=\s*([0-9_]+)', src)
if m and int(m.group(1).replace('_','')) != 40000:
raise SystemExit('MAX_FRAGMENT_BYTES must be 40000') Prevention
- Run scripts/check-runtime-contract-budget.py locally before committing fragment changes
- Never edit the cap constants without a corresponding reviewed change to the script ceilings
- Prefer the `MAX_FRAGMENT_TOKENS * 4` form so the value stays derived
When it happens
Trigger: Running scripts/check-runtime-contract-budget.py when fragments.rs contains `pub const MAX_FRAGMENT_BYTES: usize = <literal>` whose integer value (underscores stripped) is not 40000 — e.g. after bumping the constant to 64_000 or 80_000.
Common situations: A developer raises the fragment byte cap to admit larger tool outputs or context blocks; a merge of an upstream branch with a different cap; someone re-derives the value from a different token ceiling.
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
- DEFAULT_FRAGMENT_MAX_BYTES
- DEFAULT_FRAGMENT_MAX_BYTES must be
- MAX_FRAGMENT_BYTES must be defined as MAX_FRAGMENT_TOKENS *…
- MAX_FRAGMENTS_PER_CONTEXT
- MAX_FRAGMENTS_PER_CONTEXT must be
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/427e38f20a8260ef.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/check-runtime-contract-budget.py:481
raise RuntimeContractError(f"fragment cap not an int: {pattern}") from error
max_tokens = const_value(r"pub const MAX_FRAGMENT_TOKENS:\s*usize\s*=\s*([0-9_]+)")
if max_tokens != FRAGMENT_MAX_TOKENS_CEILING:
raise RuntimeContractError(
f"MAX_FRAGMENT_TOKENS must be {FRAGMENT_MAX_TOKENS_CEILING}, got {max_tokens}"
)
# MAX_FRAGMENT_BYTES must be defined as MAX_FRAGMENT_TOKENS * 4 (canonical)
# or as a literal 40000. Either way the derived ceiling is 40_000.
has_multiplication = re.search(
r"pub const MAX_FRAGMENT_BYTES:\s*usize\s*=\s*MAX_FRAGMENT_TOKENS\s*\*\s*4", text
)
bytes_literal = re.search(
r"pub const MAX_FRAGMENT_BYTES:\s*usize\s*=\s*([0-9_]+)", text
)
if bytes_literal:
literal = int(bytes_literal.group(1).replace("_", ""))
if literal != FRAGMENT_MAX_BYTES_CEILING:
raise RuntimeContractError(
f"MAX_FRAGMENT_BYTES must be {FRAGMENT_MAX_BYTES_CEILING}, got {literal}"
)
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("_", ""))View on GitHub (pinned to 433685b202)