Hmbown/CodeWhale · error · RuntimeContractError
fragment cap not an int: {pattern}
Error message
fragment cap not an int: {pattern} What it means
const_value() matched a cap declaration but int() could not parse the captured group after stripping underscores. Because the capture is ([0-9_]+), this branch is nearly unreachable - it requires a degenerate group with no digits at all (for example a value of just underscores). It exists as a defensive guard so a pathological literal fails with a clear message instead of an unhandled ValueError.
Source
Thrown at scripts/check-runtime-contract-budget.py:456
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
)
if bytes_literal:
literal = int(bytes_literal.group(1).replace("_", ""))
if literal != FRAGMENT_MAX_BYTES_CEILING:
raise RuntimeContractError(View on GitHub (pinned to 8880682c63)
Solutions
- Fix the literal named by the pattern in the message to a proper digit literal with optional underscore separators (10_000, 16)
- Check git diff on crates/core/src/fragments.rs for mangled lines from an automated edit or merge
- Re-run python3 scripts/check-runtime-contract-budget.py --receipt <receipt.json> to confirm only the static gate was affected
Defensive patterns
Strategy: try-catch
Try / catch
import re
from pathlib import Path
text = Path("crates/core/src/fragments.rs").read_text(encoding="utf-8")
for name in ("MAX_FRAGMENT_TOKENS", "MAX_FRAGMENTS_PER_CONTEXT"):
m = re.search(rf"pub const {name}:\s*usize\s*=\s*([0-9_]+)", text)
if m is None:
continue # error 214 territory
try:
value = int(m.group(1).replace("_", ""))
except ValueError:
print(f"degenerate literal for {name}: {m.group(1)!r}")
raise Prevention
- Run the checker after any codemod that rewrites literals in fragments.rs
- Resolve merge conflicts fully inside const declarations before running gates
- Seeing this error usually means file corruption - diff the module before anything else
When it happens
Trigger: A literal consisting only of underscores (pub const MAX_FRAGMENT_TOKENS: usize = ___;) or editor corruption that leaves underscores where digits should be. Real-world occurrences are rare enough that seeing this usually means the file was machine-mangled or a merge marker half-resolved.
Common situations: Half-resolved merge conflicts inside the const declarations; sed/regex-based codemods that replaced digit groups with placeholder underscores.
Related errors
- could not parse match block after {signature!r}
- {context}: missing {needle!r}
- {context}: missing parse arm for {variant}
- provider!() invocations returned no providers
- ProvidersToml returned no provider tables
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/dac6e477976094a7.
Report an issue: GitHub.