{"record":{"id":"c76d05a172f356ca","repo":"Hmbown/CodeWhale","slug":"missing-bounded-fragment-module-fragment-module-error","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":452,"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":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L434-L470","documentation":"check_fragment_caps reads the bounded-fragment Rust module (FRAGMENT_MODULE, the file defining MAX_FRAGMENT_TOKENS/MAX_FRAGMENT_BYTES) to verify caps match the checker's ceilings. If the module file does not exist (FileNotFoundError from read_text), it raises RuntimeContractError naming the missing path. The KV-cache fragment budget cannot be audited without its source of truth.","triggerScenarios":"Running the checker when the Rust source file at FRAGMENT_MODULE has been moved, renamed, deleted, or the repo is a partial/sparse checkout missing crates/core's fragment module.","commonSituations":"A refactor renamed the fragments module without updating FRAGMENT_MODULE in the checker; working from an archive or sparse checkout that excluded the crate; checking out an old tag before the module existed.","solutions":["Restore or locate the fragment module (e.g. `git checkout -- <path>` or find the renamed file) so FRAGMENT_MODULE resolves.","If the module legitimately moved, update the FRAGMENT_MODULE constant in check-runtime-contract-budget.py.","Verify you are in a full checkout of the repository, not a sparse/partial one.","Check you are on a branch that contains the fragments module (git log on the path)."],"exampleFix":"# before\nFRAGMENT_MODULE = REPO_ROOT / \"crates\" / \"core\" / \"src\" / \"old_fragments.rs\"\n# after\nFRAGMENT_MODULE = REPO_ROOT / \"crates\" / \"core\" / \"src\" / \"bounded_fragments.rs\"","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nmod = Path(\"crates/core/src/bounded_fragments.rs\")\nif not mod.exists():\n    raise SystemExit(f\"fragment module missing: {mod}; restore or update FRAGMENT_MODULE\")","typeGuard":"def fragment_module_available(path) -> bool:\n    from pathlib import Path\n    return Path(path).is_file()","tryCatchPattern":"try:\n    check_fragment_caps()\nexcept FileNotFoundError as e:\n    print(f\"fragment module missing ({e}); is this a full checkout?\", file=sys.stderr)\n    sys.exit(1)","preventionTips":["Use full checkouts in CI; avoid sparse checkout of crates/.","Update FRAGMENT_MODULE in the same commit that moves the Rust module.","Grep for the constants after any crate restructure to keep the path valid."],"tags":["file-not-found","contract-check","rust","config"],"backgroundTag":"file-not-found","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"}