{"record":{"id":"2bf4c6ee5b09d069","repo":"Hmbown/CodeWhale","slug":"max-fragments-per-context-max-count-must-not-e","errorCode":null,"errorMessage":"MAX_FRAGMENTS_PER_CONTEXT ({max_count}) must not exceed {FRAGMENT_MAX_COUNT_CEILING}","messagePattern":"MAX_FRAGMENTS_PER_CONTEXT \\((.+?)\\) must not exceed (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":512,"sourceCode":"            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\",\n    ]\n    for name in required_fragments:\n        if f\"Self::{name}\" not in text and f\"{name} =>\" not in text and f'\"{name.lower()}\"' not in text.lower():\n            # Fallback: search for enum variant declaration","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L494-L530","documentation":"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.","triggerScenarios":"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.","commonSituations":"Local edits to the checker that relax the equality into a '>' only; merging an experimental branch that restructured the cap checks.","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"],"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, \"count exceeds ceiling\"","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":["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"],"tags":["python","ci","static-analysis","rust","dead-code"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}