{"record":{"id":"97c1f088f738a724","repo":"Hmbown/CodeWhale","slug":"max-fragments-per-context-must-be-fragment-max-co","errorCode":null,"errorMessage":"MAX_FRAGMENTS_PER_CONTEXT must be {FRAGMENT_MAX_COUNT_CEILING}, got {max_count}","messagePattern":"MAX_FRAGMENTS_PER_CONTEXT must be (.+?), got (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":508,"sourceCode":"        pass\n    elif default_literal:\n        default_bytes = int(default_literal.group(1).replace(\"_\", \"\"))\n        if default_bytes != FRAGMENT_DEFAULT_MAX_BYTES_CEILING:\n            raise RuntimeContractError(\n                f\"DEFAULT_FRAGMENT_MAX_BYTES must be {FRAGMENT_DEFAULT_MAX_BYTES_CEILING}, got {default_bytes}\"\n            )\n        if default_bytes > FRAGMENT_MAX_BYTES_CEILING:\n            raise RuntimeContractError(\n                f\"DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed MAX_FRAGMENT_BYTES ({FRAGMENT_MAX_BYTES_CEILING})\"\n            )\n    else:\n        raise RuntimeContractError(\"DEFAULT_FRAGMENT_MAX_BYTES definition not found\")\n\n    max_count = const_value(\n        r\"pub const MAX_FRAGMENTS_PER_CONTEXT:\\s*usize\\s*=\\s*([0-9_]+)\"\n    )\n    if max_count != FRAGMENT_MAX_COUNT_CEILING:\n        raise RuntimeContractError(\n            f\"MAX_FRAGMENTS_PER_CONTEXT must be {FRAGMENT_MAX_COUNT_CEILING}, got {max_count}\"\n        )\n    if max_count > FRAGMENT_MAX_COUNT_CEILING:\n        raise RuntimeContractError(\n            f\"MAX_FRAGMENTS_PER_CONTEXT ({max_count}) must not exceed {FRAGMENT_MAX_COUNT_CEILING}\"\n        )\n\n    # Ensure every injection type is in FragmentId::all() and the\n    # project-instruction import is present as a typed fragment.\n    required_fragments = [\n        \"Workspace\",\n        \"Permissions\",\n        \"Route\",\n        \"AgentTopology\",\n        \"SkillsTools\",\n        \"TokenBudget\",\n        \"ProjectInstructions\",\n        \"Constitution\",","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L490-L526","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (crates/core/src/fragments.rs)\npub const MAX_FRAGMENTS_PER_CONTEXT: usize = 32;\n\n// after\npub const MAX_FRAGMENTS_PER_CONTEXT: usize = 16;","handlingStrategy":"try-catch","validationCode":"import re\nfrom pathlib import Path\ntext = Path(\"crates/core/src/fragments.rs\").read_text(encoding=\"utf-8\")\nm = re.search(r\"pub const MAX_FRAGMENTS_PER_CONTEXT:\\s*usize\\s*=\\s*([0-9_]+)\", text)\nassert m and int(m.group(1).replace(\"_\", \"\")) == 16, \"MAX_FRAGMENTS_PER_CONTEXT must stay 16\"","typeGuard":"def is_runtime_contract_error(exc: BaseException) -> bool:\n    return isinstance(exc, ValueError) and type(exc).__name__ == \"RuntimeContractError\"","tryCatchPattern":"try:\n    check_fragment_caps()\nexcept RuntimeContractError as error:\n    print(f\"[gate] {error}\", file=sys.stderr)\n    raise SystemExit(2)","preventionTips":["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"],"tags":["python","ci","static-analysis","rust","constants"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}