{"record":{"id":"e08a0a69090d0fdc","repo":"Hmbown/CodeWhale","slug":"default-fragment-max-bytes-default-bytes-must","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":498,"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":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L480-L516","documentation":"Defense-in-depth branch of the fragment-cap gate in scripts/check-runtime-contract-budget.py: fires when a literal-spelled DEFAULT_FRAGMENT_MAX_BYTES in crates/core/src/fragments.rs equals FRAGMENT_DEFAULT_MAX_BYTES_CEILING and exceeds FRAGMENT_MAX_BYTES_CEILING (40_000). Because the preceding equality check (line 493) pins the default to 4096, this branch is unreachable with today's script constants; it only goes live if a maintainer raises FRAGMENT_DEFAULT_MAX_BYTES_CEILING above FRAGMENT_MAX_BYTES_CEILING. Like every RuntimeContractError it aborts the checker with exit code 2.","triggerScenarios":"check_fragment_caps() parses 'pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = <literal>' and reaches line 497 only when default_bytes == 4096 AND default_bytes > 40000 - impossible unless the script's own ceiling constants are edited inconsistently (e.g. FRAGMENT_DEFAULT_MAX_BYTES_CEILING raised to 48*1024 while FRAGMENT_MAX_TOKENS_CEILING stays 10_000).","commonSituations":"Renegotiating fragment budgets by editing the FRAGMENT_*_CEILING constants in the checker without preserving DEFAULT <= MAX; copying an older checker with different ceilings over a newer fragments.rs.","solutions":["Keep the canonical spelling 'pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;' in crates/core/src/fragments.rs - the multiplication form bypasses the literal checks entirely","If renegotiating ceilings in scripts/check-runtime-contract-budget.py, keep FRAGMENT_DEFAULT_MAX_BYTES_CEILING <= FRAGMENT_MAX_BYTES_CEILING","Run 'python3 scripts/check-runtime-contract-budget.py --receipt scripts/runtime-contract-budget.json' locally before pushing so the gate fails in your worktree, not CI"],"exampleFix":"# before (scripts/check-runtime-contract-budget.py)\nFRAGMENT_MAX_TOKENS_CEILING = 10_000\nFRAGMENT_MAX_BYTES_CEILING = FRAGMENT_MAX_TOKENS_CEILING * 4\nFRAGMENT_DEFAULT_MAX_BYTES_CEILING = 48 * 1024  # raised past MAX (40_000)\n\n# after\nFRAGMENT_MAX_TOKENS_CEILING = 10_000\nFRAGMENT_MAX_BYTES_CEILING = FRAGMENT_MAX_TOKENS_CEILING * 4\nFRAGMENT_DEFAULT_MAX_BYTES_CEILING = 4 * 1024  # keep DEFAULT <= MAX","handlingStrategy":"try-catch","validationCode":"# Preflight: canonical multiplication form bypasses both literal checks\nimport re\nfrom pathlib import Path\ntext = Path(\"crates/core/src/fragments.rs\").read_text(encoding=\"utf-8\")\nassert re.search(r\"pub const DEFAULT_FRAGMENT_MAX_BYTES:\\s*usize\\s*=\\s*4\\s*\\*\\s*1024\", text), \"use canonical 4 * 1024 spelling\"","typeGuard":"def is_runtime_contract_error(exc: BaseException) -> bool:\n    return isinstance(exc, ValueError) and type(exc).__name__ == \"RuntimeContractError\"","tryCatchPattern":"try:\n    check_fragment_caps()\nexcept RuntimeContractError as error:\n    print(f\"[gate] fragment caps violated: {error}\", file=sys.stderr)\n    raise SystemExit(2)","preventionTips":["Keep the canonical '4 * 1024' spelling for DEFAULT_FRAGMENT_MAX_BYTES so the literal branch never runs","When editing FRAGMENT_*_CEILING constants in the checker, keep DEFAULT <= MAX in the same commit","Run the checker in CI on every PR touching crates/core/src/fragments.rs or the script itself"],"tags":["python","ci","static-analysis","rust","constants"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}