Hmbown/CodeWhale · error · RuntimeContractError
fragment cap not an int
Error message
fragment cap not an int: {pattern} What it means
const_value found a cap declaration but its captured value could not be parsed as an integer after stripping underscores (int() raised ValueError). The checker converts this into RuntimeContractError naming the pattern. Caps must be plain integer literals; expressions, hex, or suffixes are rejected so the derived ceiling math stays exact.
Solutions
- Change the Rust constant back to a decimal integer literal with optional underscores (e.g. 10_000).
- If it must be computed, compute the literal in Rust and keep the checker's regex fed by a plain literal alias.
- Verify the regex capture group (group(1)) covers only the digits in check_fragment_caps.
- Re-run the checker to confirm all caps parse.
Example fix
// before pub const MAX_FRAGMENT_BYTES: usize = MAX_FRAGMENT_TOKENS * 4; // after (checker reads literals) pub const MAX_FRAGMENT_TOKENS: usize = 10_000; pub const MAX_FRAGMENT_BYTES: usize = 40_000;
Defensive patterns
Strategy: validation
Validate before calling
import re
text = open("crates/core/src/bounded_fragments.rs").read()
m = re.search(r"pub const MAX_FRAGMENT_TOKENS:\\s*usize\\s*=\\s*([0-9_]+)", text)
assert m and m.group(1).replace("_", "").isdigit(), "cap must be a decimal int literal" Type guard
def is_int_literal(text: str) -> bool:
return text.replace("_", "").isdigit() Try / catch
try:
caps = {p: const_value(p) for p in CAP_PATTERNS}
except ValueError as e:
print(f"non-integer cap: {e}", file=sys.stderr)
sys.exit(1) Prevention
- Use plain decimal literals with underscores; no hex, no expressions.
- If a cap must be derived, also expose a literal the checker can parse.
- Verify capture groups only span digits after editing regexes.
When it happens
Trigger: The regex matched a declaration whose value is non-numeric — e.g. `MAX_FRAGMENT_TOKENS: usize = MAX_TOKENS / 2;`, a hex literal like 0x2710, or a value with a stray character captured by an overly broad pattern.
Common situations: A developer changed the constant to a computed expression; hex or scientific notation used; capture group grabbed surrounding text due to a regex edit.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- bounded fragment module must define a matches_text…
- bounded fragment module must define…
- bounded fragment module must define trait ContextFragment…
- bounded fragment module must enforce byte caps via…
- cannot parse exactly one Rust TRUSTED_KEYS table
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/dac6e477976094a7.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/check-runtime-contract-budget.py:463
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 433685b202)