{"record":{"id":"c76d05a172f356ca","repo":"Hmbown/CodeWhale","slug":"missing-bounded-fragment-module-fragment-module","errorCode":null,"errorMessage":"missing bounded fragment module: {FRAGMENT_MODULE} ({error})","messagePattern":"missing bounded fragment module: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":445,"sourceCode":"\nFRAGMENT_MODULE = REPO_ROOT / \"crates\" / \"core\" / \"src\" / \"fragments.rs\"\nFRAGMENT_MAX_TOKENS_CEILING = 10_000\nFRAGMENT_MAX_BYTES_CEILING = FRAGMENT_MAX_TOKENS_CEILING * 4\nFRAGMENT_DEFAULT_MAX_BYTES_CEILING = 4 * 1024\nFRAGMENT_MAX_COUNT_CEILING = 16\n\n\ndef check_fragment_caps() -> None:\n    \"\"\"Gate the bounded fragment hard caps (issue #5264).\n\n    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)","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L427-L463","documentation":"check_fragment_caps(), the static pre-gate that runs before any measurement, reads crates/core/src/fragments.rs and fails closed with FileNotFoundError context when the module is absent. The message embeds the full expected path and the OS error. It protects the bounded-fragment hard caps (issue #5264) from being silently skipped by moving the module.","triggerScenarios":"Running the checker from a partial or sparse checkout that lacks crates/core; a refactor renaming or relocating fragments.rs without updating FRAGMENT_MODULE; invoking the script from outside the repository root with a copied-but-incomplete tree.","commonSituations":"CI sparse-checkout configs that only include scripts/ and crates/tui/; archiving only some crates for a docker layer; branch experiments that split fragments into a submodule.","solutions":["Restore crates/core/src/fragments.rs at the exact path (or update FRAGMENT_MODULE in the checker as part of the move, keeping the caps)","Run the checker from a full checkout of this repository; REPO_ROOT is derived from the script location","If the module was intentionally relocated, port the cap regexes to the new file in the same commit so the gate keeps failing closed on missing caps"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from pathlib import Path\n\n\ndef fragment_module_present() -> bool:\n    return Path(\"crates/core/src/fragments.rs\").is_file()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the checker from a full checkout; it resolves REPO_ROOT from its own location","If you sparse-checkout in CI, include crates/core/src/fragments.rs and crates/tui/src/model_context/fragment.rs","When relocating the module, update FRAGMENT_MODULE in the same commit so the gate keeps failing closed"],"tags":["python","filesystem","static-analysis","ci"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}