{"record":{"id":"2bf4c6ee5b09d069","repo":"Hmbown/CodeWhale","slug":"max-fragments-per-context-max-count-must-not-exceed-fragment","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":519,"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":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L501-L537","documentation":"A belt-and-braces companion to the equality check: even if the equality gate above were relaxed, the count must never exceed 16. Since the checker currently requires exact equality with FRAGMENT_MAX_COUNT_CEILING, this branch is defense-in-depth for future ceiling changes, keeping the monotonic 'never exceed' contract explicit in the script.","triggerScenarios":"Running the check when the parsed MAX_FRAGMENTS_PER_CONTEXT value is strictly greater than FRAGMENT_MAX_COUNT_CEILING — only reachable if the equality gate is loosened or the ceiling constant is lowered below the current literal.","commonSituations":"Lowering FRAGMENT_MAX_COUNT_CEILING in a budget-tightening change while fragments.rs still carries the old higher literal.","solutions":["Lower MAX_FRAGMENTS_PER_CONTEXT in crates/core/src/fragments.rs to match the new ceiling","Or keep both at the current pinned value 16","Update both the script ceiling and the constant together in one reviewed change"],"exampleFix":"// script: FRAGMENT_MAX_COUNT_CEILING = 12, fragments.rs still 16\n// before (crates/core/src/fragments.rs)\npub const MAX_FRAGMENTS_PER_CONTEXT: usize = 16;\n// after\npub const MAX_FRAGMENTS_PER_CONTEXT: usize = 12;","handlingStrategy":"validation","validationCode":"import re\nCEILING = 16\nsrc = open('crates/core/src/fragments.rs').read()\nm = re.search(r'pub const MAX_FRAGMENTS_PER_CONTEXT:\\s*usize\\s*=\\s*([0-9_]+)', src)\nif m and int(m.group(1).replace('_','')) > CEILING:\n    raise SystemExit('MAX_FRAGMENTS_PER_CONTEXT exceeds ceiling')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Update the script ceiling and the constant in the same commit","Never raise the fragment count silently; it is a prompt-budget contract","Review the ceiling value whenever fragment types are added"],"tags":["static-check","rust","config","ci"],"backgroundTag":"value-out-of-range","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}