{"record":{"id":"e08a0a69090d0fdc","repo":"Hmbown/CodeWhale","slug":"default-fragment-max-bytes-default-bytes-must-not-exceed-max","errorCode":null,"errorMessage":"DEFAULT_FRAGMENT_MAX_BYTES ({default_bytes}) must not exceed MAX_FRAGMENT_BYTES ({FRAGMENT_MAX_BYTES_CEILING})","messagePattern":"DEFAULT_FRAGMENT_MAX_BYTES \\((.+?)\\) must not exceed MAX_FRAGMENT_BYTES \\((.+?)\\)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":505,"sourceCode":"        )\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(\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","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L487-L523","documentation":"This guard enforces ordering between the caps: the default per-fragment byte limit must never be larger than the maximum allowed limit. In practice it is unreachable when MAX_FRAGMENT_BYTES stays at its pinned 40,000 ceiling (since the default literal must already equal 4096 at this point), but it exists as defense-in-depth should the ceilings be relaxed — the script keeps the default <= max invariant explicit.","triggerScenarios":"Running the check when DEFAULT_FRAGMENT_MAX_BYTES is a literal > FRAGMENT_MAX_BYTES_CEILING (e.g. after a reviewer raises FRAGMENT_MAX_BYTES_CEILING logic or the cap constants are decoupled). Note the equality check above must already pass, so this only fires if the ceilings themselves change.","commonSituations":"Relaxing the byte ceilings in a budget change and forgetting the default; configuring a default bigger than max after an upstream merge.","solutions":["Lower DEFAULT_FRAGMENT_MAX_BYTES so it is <= MAX_FRAGMENT_BYTES (4096 <= 40000 with current ceilings)","Or raise FRAGMENT_MAX_BYTES_CEILING in check_fragment_caps if the larger default is the reviewed intent","Keep both constants pinned: default 4096, max 40000"],"exampleFix":"// before (crates/core/src/fragments.rs)\npub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 64_000;\npub const MAX_FRAGMENT_BYTES: usize = 40_000;\n// after\npub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;\npub const MAX_FRAGMENT_BYTES: usize = MAX_FRAGMENT_TOKENS * 4;","handlingStrategy":"validation","validationCode":"import re\nsrc = open('crates/core/src/fragments.rs').read()\ndef val(name):\n    m = re.search(rf'pub const {name}:\\s*usize\\s*=\\s*([0-9_]+)', src)\n    return int(m.group(1).replace('_','')) if m else None\ndefb, maxb = val('DEFAULT_FRAGMENT_MAX_BYTES'), 40000\nif defb is not None and defb > maxb:\n    raise SystemExit('DEFAULT_FRAGMENT_MAX_BYTES must not exceed MAX_FRAGMENT_BYTES')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always keep default <= max when tuning fragment caps","Change default and ceiling constants together in one reviewed commit","Add a unit test in fragments.rs asserting DEFAULT_FRAGMENT_MAX_BYTES <= MAX_FRAGMENT_BYTES"],"tags":["static-check","rust","config","ci"],"backgroundTag":"conflicting-config-options","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"}