{"record":{"id":"427e38f20a8260ef","repo":"Hmbown/CodeWhale","slug":"max-fragment-bytes-must-be-fragment-max-bytes-ceiling-got","errorCode":null,"errorMessage":"MAX_FRAGMENT_BYTES must be {FRAGMENT_MAX_BYTES_CEILING}, got {literal}","messagePattern":"MAX_FRAGMENT_BYTES must be (.+?), got (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":481,"sourceCode":"            raise RuntimeContractError(f\"fragment cap not an int: {pattern}\") from error\n\n    max_tokens = const_value(r\"pub const MAX_FRAGMENT_TOKENS:\\s*usize\\s*=\\s*([0-9_]+)\")\n    if max_tokens != FRAGMENT_MAX_TOKENS_CEILING:\n        raise RuntimeContractError(\n            f\"MAX_FRAGMENT_TOKENS must be {FRAGMENT_MAX_TOKENS_CEILING}, got {max_tokens}\"\n        )\n    # MAX_FRAGMENT_BYTES must be defined as MAX_FRAGMENT_TOKENS * 4 (canonical)\n    # or as a literal 40000. Either way the derived ceiling is 40_000.\n    has_multiplication = re.search(\n        r\"pub const MAX_FRAGMENT_BYTES:\\s*usize\\s*=\\s*MAX_FRAGMENT_TOKENS\\s*\\*\\s*4\", text\n    )\n    bytes_literal = re.search(\n        r\"pub const MAX_FRAGMENT_BYTES:\\s*usize\\s*=\\s*([0-9_]+)\", text\n    )\n    if bytes_literal:\n        literal = int(bytes_literal.group(1).replace(\"_\", \"\"))\n        if literal != FRAGMENT_MAX_BYTES_CEILING:\n            raise RuntimeContractError(\n                f\"MAX_FRAGMENT_BYTES must be {FRAGMENT_MAX_BYTES_CEILING}, got {literal}\"\n            )\n    elif not has_multiplication:\n        raise RuntimeContractError(\n            \"MAX_FRAGMENT_BYTES must be defined as MAX_FRAGMENT_TOKENS * 4 or as 40000\"\n        )\n    # DEFAULT is defined as 4 * 1024 (canonical) or 4096 literal\n    has_default_multiplication = re.search(\n        r\"pub const DEFAULT_FRAGMENT_MAX_BYTES:\\s*usize\\s*=\\s*4\\s*\\*\\s*1024\", text\n    )\n    default_literal = re.search(\n        r\"pub const DEFAULT_FRAGMENT_MAX_BYTES:\\s*usize\\s*=\\s*([0-9_]+)\", text\n    )\n    if has_default_multiplication:\n        # canonical 4*1024 == 4096, which equals ceiling\n        pass\n    elif default_literal:\n        default_bytes = int(default_literal.group(1).replace(\"_\", \"\"))","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L463-L499","documentation":"This static contract check parses crates/core/src/fragments.rs and verifies that the MAX_FRAGMENT_BYTES constant, when written as a numeric literal, equals the derived ceiling of 40,000 (MAX_FRAGMENT_TOKENS 10,000 * 4). The repository pins these hard caps so bounded fragments cannot silently grow the prompt/context budget. If someone edits the literal to a different number, the check raises RuntimeContractError and fails the gate.","triggerScenarios":"Running scripts/check-runtime-contract-budget.py when fragments.rs contains `pub const MAX_FRAGMENT_BYTES: usize = <literal>` whose integer value (underscores stripped) is not 40000 — e.g. after bumping the constant to 64_000 or 80_000.","commonSituations":"A developer raises the fragment byte cap to admit larger tool outputs or context blocks; a merge of an upstream branch with a different cap; someone re-derives the value from a different token ceiling.","solutions":["Set the literal in crates/core/src/fragments.rs back to 40000 (or `MAX_FRAGMENT_TOKENS * 4`)","If a larger cap is genuinely intended, first raise MAX_FRAGMENT_TOKENS/byte ceilings in check_fragment_caps (FRAGMENT_MAX_BYTES_CEILING) with review, then align the constant","Verify the value parsed by the regex: `grep -n 'MAX_FRAGMENT_BYTES' crates/core/src/fragments.rs`"],"exampleFix":"// before (crates/core/src/fragments.rs)\npub const MAX_FRAGMENT_BYTES: usize = 80_000;\n// after\npub const MAX_FRAGMENT_BYTES: usize = MAX_FRAGMENT_TOKENS * 4; // 40_000","handlingStrategy":"validation","validationCode":"import re\nsrc = open('crates/core/src/fragments.rs').read()\nm = re.search(r'pub const MAX_FRAGMENT_BYTES:\\s*usize\\s*=\\s*([0-9_]+)', src)\nif m and int(m.group(1).replace('_','')) != 40000:\n    raise SystemExit('MAX_FRAGMENT_BYTES must be 40000')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run scripts/check-runtime-contract-budget.py locally before committing fragment changes","Never edit the cap constants without a corresponding reviewed change to the script ceilings","Prefer the `MAX_FRAGMENT_TOKENS * 4` form so the value stays derived"],"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"}