{"record":{"id":"e82ca4903cf483af","repo":"Hmbown/CodeWhale","slug":"kind-metric-join-base-tools-must-equal-the-owned-tool-names","errorCode":null,"errorMessage":"{kind} metric `{'.'.join((*base, 'tools'))}` must equal the owned tool_names length ({len(names)})","messagePattern":"(.+?) metric `(.+?)` must equal the owned tool_names length \\((.+?)\\)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":234,"sourceCode":"            f\"{kind} tool execution_shell must be `bash`, got {shell!r}\"\n        )\n\n    for mode, _label in VISIBLE_MODES:\n        for surface, _surface_label in TOOL_SURFACES:\n            base = (\"tool_catalog\", \"modes\", mode, surface)\n            names = required_value(document, (*base, \"tool_names\"), kind)\n            dotted_names = \".\".join((*base, \"tool_names\"))\n            if (\n                not isinstance(names, list)\n                or any(not isinstance(name, str) or not name for name in names)\n                or names != sorted(set(names))\n            ):\n                raise RuntimeContractError(\n                    f\"{kind} field `{dotted_names}` must be sorted unique non-empty strings\"\n                )\n            count = metric_value(document, (*base, \"tools\"), kind)\n            if count != len(names):\n                raise RuntimeContractError(\n                    f\"{kind} metric `{'.'.join((*base, 'tools'))}` must equal the \"\n                    f\"owned tool_names length ({len(names)})\"\n                )\n            digest = required_value(document, (*base, \"identity_sha256\"), kind)\n            expected = tool_identity_digest(names)\n            if digest != expected:\n                raise RuntimeContractError(\n                    f\"{kind} field `{'.'.join((*base, 'identity_sha256'))}` must \"\n                    \"match the owned sorted tool_names\"\n                )\n\n    for stage, _label in REPRESENTATIVE_STAGES:\n        path = (\"representative_context\", \"stages\", stage, \"identity_sha256\")\n        digest = required_value(document, path, kind)\n        if not isinstance(digest, str) or re.fullmatch(r\"[0-9a-f]{64}\", digest) is None:\n            raise RuntimeContractError(\n                f\"{kind} field `{'.'.join(path)}` must be a lowercase SHA-256 digest\"\n            )","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L216-L252","documentation":"Each mode/surface section carries a tools count metric that must equal len(tool_names) in the same section. This cross-check catches drift between the human-readable list and the numeric metric used by budget comparisons.","triggerScenarios":"metric_value(document, (*base, \"tools\"), kind) returns a number different from the length of the sibling tool_names list — e.g. the count was updated but the list was not, or vice versa.","commonSituations":"Hand-edited receipts where a tool was added to the list but the count not incremented; two generators writing list and count at different times; merge conflict resolved on one side only.","solutions":["Set tools to exactly len(tool_names) for that section","Regenerate the receipt so both are written from the same source of truth","Fix the generator to derive the count from the list rather than tracking it separately"],"exampleFix":"// before\n\"tool_names\": [\"a\", \"b\"], \"tools\": 3\n// after\n\"tool_names\": [\"a\", \"b\"], \"tools\": 2","handlingStrategy":"validation","validationCode":"for mode, _ in VISIBLE_MODES:\n    for surface, _ in TOOL_SURFACES:\n        sec = doc[\"tool_catalog\"][\"modes\"][mode][surface]\n        assert sec[\"tools\"] == len(sec[\"tool_names\"]), f\"count drift in {mode}/{surface}\"","typeGuard":null,"tryCatchPattern":"try:\n    compare(receipt, budget)\nexcept RuntimeContractError as e:\n    if \"must equal the owned tool_names length\" in str(e):\n        print(\"count/list drift; regenerate the receipt\")\n    raise","preventionTips":["Derive the tools count from len(tool_names) in the generator — never track it separately","Never hand-edit one side of the count/list pair","Re-run the validator after any merge that touched tool lists"],"tags":["python","schema-validation","consistency-check"],"backgroundTag":"schema-validation-failed","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"}