{"record":{"id":"97c1f088f738a724","repo":"Hmbown/CodeWhale","slug":"max-fragments-per-context-must-be-fragment-max-count-ceiling","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":515,"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":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L497-L533","documentation":"MAX_FRAGMENTS_PER_CONTEXT is pinned to exactly 16 (FRAGMENT_MAX_COUNT_CEILING). The checker parses its literal from fragments.rs and fails if it differs. This cap bounds how many typed fragments can be injected into one context, protecting the prompt budget from unbounded growth.","triggerScenarios":"Running scripts/check-runtime-contract-budget.py when fragments.rs contains `pub const MAX_FRAGMENTS_PER_CONTEXT: usize = <literal>` with a value other than 16 — e.g. raised to 24 to add new fragment types.","commonSituations":"Adding a new fragment kind and bumping the cap instead of fitting the budget; merging a branch with a different cap; tuning the count for larger agent topologies.","solutions":["Set the literal in crates/core/src/fragments.rs back to 16","If more fragments are genuinely needed, raise FRAGMENT_MAX_COUNT_CEILING in scripts/check-runtime-contract-budget.py as a reviewed budget change and align the constant","Reduce the number of injected fragments (dedupe types in FragmentId::all()) instead of raising the cap"],"exampleFix":"// before\npub const MAX_FRAGMENTS_PER_CONTEXT: usize = 24;\n// after\npub const MAX_FRAGMENTS_PER_CONTEXT: usize = 16;","handlingStrategy":"validation","validationCode":"import re\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('_','')) != 16:\n    raise SystemExit('MAX_FRAGMENTS_PER_CONTEXT must be 16')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fit new fragment kinds within the existing 16-fragment budget instead of raising the cap","Run the budget check in pre-commit for any fragments.rs edit","Treat ceiling changes in the script as reviewed budget decisions, not drive-by edits"],"tags":["static-check","rust","config","ci"],"backgroundTag":"invalid-config-value","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"}