Hmbown/CodeWhale · error · RuntimeContractError
fragment cap missing: {pattern}
Error message
fragment cap missing: {pattern} What it means
Inside check_fragment_caps(), the helper const_value() searches fragments.rs for the exact declaration pattern `pub const MAX_FRAGMENT_TOKENS: usize = <digits>` or `pub const MAX_FRAGMENTS_PER_CONTEXT: usize = <digits>` and raises this error when the regex finds nothing. The pattern (included verbatim in the message) encodes name, visibility, type, and literal form, so renames, type changes, moves, or expression-valued definitions all fail closed.
Source
Thrown at scripts/check-runtime-contract-budget.py:452
def check_fragment_caps() -> None:
"""Gate the bounded fragment hard caps (issue #5264).
Static check — no cargo needed. Fails closed if the fragment module is
missing, if any cap has been raised without review, or if the
project-instruction import is absent.
"""
try:
text = FRAGMENT_MODULE.read_text(encoding="utf-8")
except FileNotFoundError as error:
raise RuntimeContractError(
f"missing bounded fragment module: {FRAGMENT_MODULE} ({error})"
) from error
def const_value(pattern: str) -> int:
match = re.search(pattern, text)
if not match:
raise RuntimeContractError(f"fragment cap missing: {pattern}")
try:
return int(match.group(1).replace("_", ""))
except ValueError as error:
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
)View on GitHub (pinned to 8880682c63)
Solutions
- Restore a plain literal declaration in crates/core/src/fragments.rs: pub const MAX_FRAGMENT_TOKENS: usize = 10_000; and pub const MAX_FRAGMENTS_PER_CONTEXT: usize = 16;
- If the constant must live elsewhere, re-export it verbatim from fragments.rs so the pattern still matches there, or update the regexes in check_fragment_caps in the same reviewed change
- Avoid expression-valued definitions for these two constants; the checker only accepts digit literals (with underscores)
Example fix
// before (crates/core/src/fragments.rs) pub const MAX_FRAGMENT_TOKENS: usize = 10 * 1000; // after pub const MAX_FRAGMENT_TOKENS: usize = 10_000;
Defensive patterns
Strategy: validation
Validate before calling
import re
from pathlib import Path
CAP_PATTERNS = (
r"pub const MAX_FRAGMENT_TOKENS:\s*usize\s*=\s*([0-9_]+)",
r"pub const MAX_FRAGMENTS_PER_CONTEXT:\s*usize\s*=\s*([0-9_]+)",
)
def cap_declarations_present() -> bool:
text = Path("crates/core/src/fragments.rs").read_text(encoding="utf-8")
return all(re.search(p, text) for p in CAP_PATTERNS) Prevention
- Keep the two capped constants as plain digit literals with underscores in fragments.rs
- Avoid expression-valued or cfg-dependent definitions for capped constants
- If constants move, update the checker's regexes in the same reviewed change
When it happens
Trigger: Renaming the constant; changing the type away from usize; defining it as an expression (for example MAX_FRAGMENT_TOKENS: usize = 10 * 1000) which the ([0-9_]+) group cannot match; moving the const into another module while leaving fragments.rs present but cap-less.
Common situations: Refactors that centralize constants into a config module; well-meaning cleanups that switch literals to expressions; partial moves during a crate split.
Related errors
- provider!() invocations returned no providers
- ProvidersToml returned no provider tables
- could not parse match block after {signature!r}
- {context}: missing parse arm for {variant}
- ModelRegistry uses unknown provider variants: {sorted(missin
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/cc3597e04cafbc49.
Report an issue: GitHub.