{"record":{"id":"dac6e477976094a7","repo":"Hmbown/CodeWhale","slug":"fragment-cap-not-an-int-pattern","errorCode":null,"errorMessage":"fragment cap not an int: {pattern}","messagePattern":"fragment cap not an int: (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":456,"sourceCode":"    Static check — no cargo needed. Fails closed if the fragment module is\n    missing, if any cap has been raised without review, or if the\n    project-instruction import is absent.\n    \"\"\"\n    try:\n        text = FRAGMENT_MODULE.read_text(encoding=\"utf-8\")\n    except FileNotFoundError as error:\n        raise RuntimeContractError(\n            f\"missing bounded fragment module: {FRAGMENT_MODULE} ({error})\"\n        ) from error\n\n    def const_value(pattern: str) -> int:\n        match = re.search(pattern, text)\n        if not match:\n            raise RuntimeContractError(f\"fragment cap missing: {pattern}\")\n        try:\n            return int(match.group(1).replace(\"_\", \"\"))\n        except ValueError as error:\n            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(","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L438-L474","documentation":"const_value() matched a cap declaration but int() could not parse the captured group after stripping underscores. Because the capture is ([0-9_]+), this branch is nearly unreachable - it requires a degenerate group with no digits at all (for example a value of just underscores). It exists as a defensive guard so a pathological literal fails with a clear message instead of an unhandled ValueError.","triggerScenarios":"A literal consisting only of underscores (pub const MAX_FRAGMENT_TOKENS: usize = ___;) or editor corruption that leaves underscores where digits should be. Real-world occurrences are rare enough that seeing this usually means the file was machine-mangled or a merge marker half-resolved.","commonSituations":"Half-resolved merge conflicts inside the const declarations; sed/regex-based codemods that replaced digit groups with placeholder underscores.","solutions":["Fix the literal named by the pattern in the message to a proper digit literal with optional underscore separators (10_000, 16)","Check git diff on crates/core/src/fragments.rs for mangled lines from an automated edit or merge","Re-run python3 scripts/check-runtime-contract-budget.py --receipt <receipt.json> to confirm only the static gate was affected"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"import re\nfrom pathlib import Path\n\ntext = Path(\"crates/core/src/fragments.rs\").read_text(encoding=\"utf-8\")\nfor name in (\"MAX_FRAGMENT_TOKENS\", \"MAX_FRAGMENTS_PER_CONTEXT\"):\n    m = re.search(rf\"pub const {name}:\\s*usize\\s*=\\s*([0-9_]+)\", text)\n    if m is None:\n        continue  # error 214 territory\n    try:\n        value = int(m.group(1).replace(\"_\", \"\"))\n    except ValueError:\n        print(f\"degenerate literal for {name}: {m.group(1)!r}\")\n        raise","preventionTips":["Run the checker after any codemod that rewrites literals in fragments.rs","Resolve merge conflicts fully inside const declarations before running gates","Seeing this error usually means file corruption - diff the module before anything else"],"tags":["python","parsing","defensive","static-analysis"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}