{"record":{"id":"932b128806b723fe","repo":"Hmbown/CodeWhale","slug":"bounded-fragment-module-must-expose-load-project-i","errorCode":null,"errorMessage":"bounded fragment module must expose load_project_instruction_fragment (project-instruction import as typed fragment)","messagePattern":"bounded fragment module must expose load_project_instruction_fragment \\(project-instruction import as typed fragment\\)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":549,"sourceCode":"            if not re.search(rf\"\\b{name}\\b\", text):\n                raise RuntimeContractError(\n                    f\"FragmentId missing required variant {name}\"\n                )\n    # Marker stability — these strings are pinned by tests / prefix cache\n    required_markers = [\n        \"<!-- cw:ctx:workspace -->\",\n        \"<!-- cw:ctx:project_instructions -->\",\n        \"<!-- cw:ctx:constitution -->\",\n    ]\n    for marker in required_markers:\n        if marker not in text:\n            raise RuntimeContractError(\n                f\"bounded fragment module missing required marker {marker!r}\"\n            )\n\n    # Project-instruction import must be a typed fragment, not ad-hoc\n    if \"load_project_instruction_fragment\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must expose load_project_instruction_fragment (project-instruction import as typed fragment)\"\n        )\n    if \"PROJECT_INSTRUCTION_CANDIDATES\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must define PROJECT_INSTRUCTION_CANDIDATES\"\n        )\n    # Required candidate files from #3978\n    required_candidates = [\n        \".cursorrules\",\n        \".clinerules\",\n        \".windsurf/rules\",\n        \".gemini\",\n        \".github/copilot-instructions.md\",\n    ]\n    for candidate in required_candidates:\n        if candidate not in text:\n            raise RuntimeContractError(\n                f\"PROJECT_INSTRUCTION_CANDIDATES missing required entry {candidate!r}\"","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L531-L567","documentation":"The gate enforces that importing project-instruction files goes through the typed fragment API: the substring 'load_project_instruction_fragment' must appear in crates/core/src/fragments.rs. The public wrapper of that name delegates to load_project_instruction_fragment_from_candidates (which also satisfies the substring check), so this error means the typed import path was renamed, moved, or replaced by ad-hoc loading.","triggerScenarios":"Renaming or deleting load_project_instruction_fragment(_from_candidates); inlining candidate scanning into the context builder; moving the loader into another crate/module so the name no longer occurs in fragments.rs.","commonSituations":"Refactors relocating instruction loading into tui or a new crate; deleting the 'legacy' wrapper and keeping only a differently-named internal helper.","solutions":["Keep or re-expose 'pub fn load_project_instruction_fragment(...)' in crates/core/src/fragments.rs - it may simply delegate to *_from_candidates","If the loader moved, add a re-export or rename the new function back - the gate matches the exact substring","Verify: 'grep -n load_project_instruction_fragment crates/core/src/fragments.rs'"],"exampleFix":"// before (crates/core/src/fragments.rs)\nfn scan_instruction_files(workspace: &Path) -> Option<Fragment> { /* ad-hoc scan */ }\n\n// after\nfn scan_instruction_files(workspace: &Path) -> Option<Fragment> {\n    load_project_instruction_fragment_from_candidates(workspace, PROJECT_INSTRUCTION_CANDIDATES)\n}","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\ntext = Path(\"crates/core/src/fragments.rs\").read_text(encoding=\"utf-8\")\nassert \"load_project_instruction_fragment\" in text, \"typed project-instruction import missing\"","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":["Always load project instructions through load_project_instruction_fragment(_from_candidates), never ad-hoc fs scans","If moving the loader, leave a re-export with the exact name in fragments.rs","Grep for the function name in any refactor touching instruction loading"],"tags":["python","ci","static-analysis","rust","api-surface"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}