{"record":{"id":"7e3ef6c9b71a9cbf","repo":"Hmbown/CodeWhale","slug":"default-fragment-max-bytes-definition-not-found","errorCode":null,"errorMessage":"DEFAULT_FRAGMENT_MAX_BYTES definition not found","messagePattern":"DEFAULT_FRAGMENT_MAX_BYTES definition not found","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":502,"sourceCode":"    )\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\n    # project-instruction import is present as a typed fragment.\n    required_fragments = [\n        \"Workspace\",\n        \"Permissions\",","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L484-L520","documentation":"The fragment-cap gate requires DEFAULT_FRAGMENT_MAX_BYTES in crates/core/src/fragments.rs to be spelled one of two ways: the canonical multiplication '4 * 1024' or a plain decimal literal. This error means neither regex matched - the const was removed, renamed, or defined through another name (e.g. '4 * KIB') that the gate deliberately does not trust. The gate fails closed because the default cap is part of the bounded-fragment contract (issue #5264).","triggerScenarios":"check_fragment_caps() runs re.search for 'pub const DEFAULT_FRAGMENT_MAX_BYTES:\\s*usize\\s*=\\s*4\\s*\\*\\s*1024' and for '=\\s*([0-9_]+)'; both miss when the definition is '4 * KIB', '= DEFAULT_CAP', a cfg!() expression, or the const is deleted/renamed.","commonSituations":"Refactoring constants out of fragments.rs into a shared consts module; introducing named helpers (KIB) for readability; merging a branch that restructured the fragment caps.","solutions":["Restore the canonical form 'pub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;' in crates/core/src/fragments.rs","If a literal is preferred, use exactly 4096 (or 4_096) - the literal regex accepts underscores","Keep the const inside crates/core/src/fragments.rs - the gate reads only that file (FRAGMENT_MODULE, line 428)"],"exampleFix":"// before (crates/core/src/fragments.rs)\nconst KIB: usize = 1024;\npub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * KIB;\n\n// after\npub const DEFAULT_FRAGMENT_MAX_BYTES: usize = 4 * 1024;","handlingStrategy":"try-catch","validationCode":"import 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|[0-9_]+)\", text), \"DEFAULT_FRAGMENT_MAX_BYTES must be 4 * 1024 or a decimal literal\"","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] {error}\", file=sys.stderr)\n    raise SystemExit(2)","preventionTips":["Never define DEFAULT_FRAGMENT_MAX_BYTES via helper consts or expressions - use '4 * 1024' or '4096'","Keep all capped consts in crates/core/src/fragments.rs, the only file the gate reads","Add a pre-commit hook that greps fragments.rs for each required const name"],"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"}