Hmbown/CodeWhale · error · RuntimeContractError
MAX_FRAGMENTS_PER_CONTEXT ({max_count}) must not exceed {FRA
Error message
MAX_FRAGMENTS_PER_CONTEXT ({max_count}) must not exceed {FRAGMENT_MAX_COUNT_CEILING} What it means
Belt-and-braces upper-bound message for MAX_FRAGMENTS_PER_CONTEXT. It cannot fire today because the preceding equality check (line 507) already rejects every value != 16, including all values > 16. It exists so that if the equality check is ever relaxed into a range, an explicit exceed-message remains; actually seeing it means the checker itself was locally edited.
Source
Thrown at scripts/check-runtime-contract-budget.py:512
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 the
# project-instruction import is present as a typed fragment.
required_fragments = [
"Workspace",
"Permissions",
"Route",
"AgentTopology",
"SkillsTools",
"TokenBudget",
"ProjectInstructions",
"Constitution",
]
for name in required_fragments:
if f"Self::{name}" not in text and f"{name} =>" not in text and f'"{name.lower()}"' not in text.lower():
# Fallback: search for enum variant declarationView on GitHub (pinned to 8880682c63)
Solutions
- Treat it as error [222]: restore MAX_FRAGMENTS_PER_CONTEXT to 16 in crates/core/src/fragments.rs
- If refactoring the checker, keep invariants consistent (equality implies bound) or deliberately delete the dead branch
- Re-run from a clean checkout ('git stash && python3 scripts/check-runtime-contract-budget.py --receipt scripts/runtime-contract-budget.json') to rule out local checker edits
Example fix
// before (crates/core/src/fragments.rs) pub const MAX_FRAGMENTS_PER_CONTEXT: usize = 32; // after pub const MAX_FRAGMENTS_PER_CONTEXT: usize = 16;
Defensive patterns
Strategy: try-catch
Validate before calling
import re
from pathlib import Path
text = Path("crates/core/src/fragments.rs").read_text(encoding="utf-8")
m = re.search(r"pub const MAX_FRAGMENTS_PER_CONTEXT:\s*usize\s*=\s*([0-9_]+)", text)
assert m and int(m.group(1).replace("_", "")) <= 16, "count exceeds ceiling" 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] {error}", file=sys.stderr)
raise SystemExit(2) Prevention
- Seeing this (currently unreachable) message means the checker was locally edited - diff scripts/check-runtime-contract-budget.py against HEAD
- Keep checker refactors preserving the invariant 'equality check implies bound check'
- Run the gate from a clean checkout before reporting a failure
When it happens
Trigger: Requires max_count > 16 while the equality check 'max_count == 16' simultaneously passed - impossible with the current script; reachable only if line 507 is changed to a lower-bound or removed.
Common situations: Local edits to the checker that relax the equality into a '>' only; merging an experimental branch that restructured the cap checks.
Related errors
- DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed
- DEFAULT_FRAGMENT_MAX_BYTES definition not found
- MAX_FRAGMENTS_PER_CONTEXT must be {FRAGMENT_MAX_COUNT_CEILIN
- 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/2bf4c6ee5b09d069.
Report an issue: GitHub.