{"record":{"id":"f25094734f9c37a3","repo":"Hmbown/CodeWhale","slug":"default-fragment-max-bytes-must-be-fragment-defau","errorCode":null,"errorMessage":"DEFAULT_FRAGMENT_MAX_BYTES must be {FRAGMENT_DEFAULT_MAX_BYTES_CEILING}, got {default_bytes}","messagePattern":"DEFAULT_FRAGMENT_MAX_BYTES must be (.+?), got (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":494,"sourceCode":"            )\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(\"_\", \"\"))\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(","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L476-L512","documentation":"check_fragment_caps() validates DEFAULT_FRAGMENT_MAX_BYTES (the default per-fragment cap applied by Fragment::new) in one of two shapes: the canonical `4 * 1024` multiplication, or a digit literal that must equal FRAGMENT_DEFAULT_MAX_BYTES_CEILING = 4096. This error fires for the literal form with any other value; the default must stay at 4 KiB so typical fragments stay well under the 40_000 hard cap.","triggerScenarios":"Editing pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4096; to another literal such as 8_192 to make bigger default fragments fit. The multiplication form `4 * 1024` short-circuits as canonical and is not numerically re-checked; the literal form is.","commonSituations":"Raising the default during local development of large-file ingestion features; codemods normalizing `4 * 1024` to a literal with a wrong value.","solutions":["Prefer the canonical form: pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;","Or restore the exact literal 4096","If a larger default is truly needed, raise it as an explicit reviewed change together with FRAGMENT_DEFAULT_MAX_BYTES_CEILING in the checker, keeping it under MAX_FRAGMENT_BYTES"],"exampleFix":"// before (crates/core/src/fragments.rs)\npub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 8_192;\n\n// after\npub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;","handlingStrategy":"validation","validationCode":"import re\nfrom pathlib import Path\n\nCANONICAL_DEFAULT = re.compile(\n    r\"pub const DEFAULT_FRAGMENT_MAX_BYTES:\\s*usize\\s*=\\s*4\\s*\\*\\s*1024\"\n)\nDEFAULT_LITERAL = re.compile(\n    r\"pub const DEFAULT_FRAGMENT_MAX_BYTES:\\s*usize\\s*=\\s*([0-9_]+)\"\n)\n\n\ndef default_cap_ok() -> bool:\n    text = Path(\"crates/core/src/fragments.rs\").read_text(encoding=\"utf-8\")\n    if CANONICAL_DEFAULT.search(text):\n        return True\n    m = DEFAULT_LITERAL.search(text)\n    return m is not None and int(m.group(1).replace(\"_\", \"\")) == 4096","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the 4 * 1024 form for the default fragment cap","Keep the default strictly below MAX_FRAGMENT_BYTES (4096 < 40_000)","Raise the default only as a reviewed change that updates FRAGMENT_DEFAULT_MAX_BYTES_CEILING too"],"tags":["rust","constants","budget","static-analysis"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}