Hmbown/CodeWhale · error · RuntimeContractError
MAX_FRAGMENTS_PER_CONTEXT must be {FRAGMENT_MAX_COUNT_CEILIN
Error message
MAX_FRAGMENTS_PER_CONTEXT must be {FRAGMENT_MAX_COUNT_CEILING}, got {max_count} What it means
The gate pins MAX_FRAGMENTS_PER_CONTEXT in crates/core/src/fragments.rs to exactly FRAGMENT_MAX_COUNT_CEILING (16); any other parsed literal raises this error. The cap bounds how many context fragments a session may accumulate (hard cap from issue #5264). The separate '>' check immediately after (line 511) is shadowed by this equality check, so any deviation - up or down - is reported here.
Source
Thrown at scripts/check-runtime-contract-budget.py:508
pass
elif default_literal:
default_bytes = int(default_literal.group(1).replace("_", ""))
if default_bytes != FRAGMENT_DEFAULT_MAX_BYTES_CEILING:
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",View on GitHub (pinned to 8880682c63)
Solutions
- Restore 'pub const MAX_FRAGMENTS_PER_CONTEXT: usize = 16;' in crates/core/src/fragments.rs
- If more fragments are genuinely required, raise FRAGMENT_MAX_COUNT_CEILING in scripts/check-runtime-contract-budget.py:432 in the same reviewed commit and update tests/docs that pin 16
- Verify with the checker: 'python3 scripts/check-runtime-contract-budget.py --receipt scripts/runtime-contract-budget.json' - check_fragment_caps() runs before any receipt/budget loading
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, "MAX_FRAGMENTS_PER_CONTEXT must stay 16" 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
- Treat the four FRAGMENT_* ceilings as review-required constants - change them only in dedicated, reviewed commits
- Run 'python3 scripts/check-runtime-contract-budget.py --receipt scripts/runtime-contract-budget.json' locally after touching fragments.rs
- Add a Rust unit test asserting MAX_FRAGMENTS_PER_CONTEXT == 16 so failures surface in cargo test too
When it happens
Trigger: const_value() extracts the integer from 'pub const MAX_FRAGMENTS_PER_CONTEXT: usize = <N>' and N != 16 - e.g. someone bumps it to 24 to fit more injection types, or lowers it to 8.
Common situations: Adding a new injection type and 'temporarily' raising the count; cherry-picking a change without its budget-renegotiation commit; rebasing across a release where the ceiling moved.
Related errors
- DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed
- DEFAULT_FRAGMENT_MAX_BYTES definition not found
- MAX_FRAGMENTS_PER_CONTEXT ({max_count}) must not exceed {FRA
- 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/97c1f088f738a724.
Report an issue: GitHub.