{"record":{"id":"60ca1e983be1dacb","repo":"Hmbown/CodeWhale","slug":"bounded-fragment-module-must-define-a-matches-text","errorCode":null,"errorMessage":"bounded fragment module must define a matches_text recognizer on the fragment trait","messagePattern":"bounded fragment module must define a matches_text recognizer on the fragment trait","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":572,"sourceCode":"            \"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}\"\n            )\n\n    # matches_text recognizer must exist on the fragment trait\n    if \"fn matches_text\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must define a matches_text recognizer on the fragment trait\"\n        )\n    if \"trait ContextFragment\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must define trait ContextFragment with matches_text\"\n        )\n\n    # No unbounded fragment — enforce that creation clamps to MAX_FRAGMENT_BYTES\n    if \"MAX_FRAGMENT_BYTES\" not in text or \"enforce_byte_cap\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must enforce byte caps via enforce_byte_cap and MAX_FRAGMENT_BYTES\"\n        )\n\n    # TUI must be unified with the core boundary (shared crates/core module)\n    tui_fragment = REPO_ROOT / \"crates\" / \"tui\" / \"src\" / \"model_context\" / \"fragment.rs\"\n    try:\n        tui_text = tui_fragment.read_text(encoding=\"utf-8\")\n    except FileNotFoundError as error:","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L554-L590","documentation":"The ContextFragment trait must declare a 'fn matches_text' recognizer (matching incoming text back to a fragment id). The gate substring-checks 'fn matches_text' in crates/core/src/fragments.rs; renaming the method, moving it off the trait, or deleting it fails this check.","triggerScenarios":"Renaming matches_text to recognizes/contains_text; moving the method to an impl block or free function; deleting the recognizer after its last caller moved.","commonSituations":"Trait refactors; consolidating recognition logic into a helper during cleanup.","solutions":["Keep 'fn matches_text(&self, haystack: &str) -> bool;' declared on 'pub trait ContextFragment' in crates/core/src/fragments.rs","If the method must be renamed, update the gate string at scripts/check-runtime-contract-budget.py:571 in the same reviewed commit - but prefer keeping the name (searchability contract)","Verify: 'grep -n \"fn matches_text\" crates/core/src/fragments.rs'"],"exampleFix":"// before (crates/core/src/fragments.rs)\npub trait ContextFragment {\n    fn recognizes(&self, haystack: &str) -> bool;\n}\n\n// after\npub trait ContextFragment {\n    fn matches_text(&self, haystack: &str) -> bool;\n}","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\ntext = Path(\"crates/core/src/fragments.rs\").read_text(encoding=\"utf-8\")\nassert \"fn matches_text\" in text, \"matches_text recognizer missing from trait\"","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":["Keep the method name matches_text on trait ContextFragment - it is a searchability contract","If renaming, update the gate string in the same reviewed commit","Grep 'fn matches_text' after any trait refactor"],"tags":["python","ci","static-analysis","rust","trait","api-surface"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}