{"record":{"id":"278c6ca765f215bb","repo":"Hmbown/CodeWhale","slug":"kind-field-join-base-identity-sha256-must-match-the-owned","errorCode":null,"errorMessage":"{kind} field `{'.'.join((*base, 'identity_sha256'))}` must match the owned sorted tool_names","messagePattern":"(.+?) field `(.+?)` must match the owned sorted tool_names","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":241,"sourceCode":"            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            )\n\n\ndef validate_receipt(receipt: dict[str, Any]) -> None:\n    validate_document(receipt, RECEIPT_KIND, \"receipt\")\n    skill_discovery = receipt.get(\"skill_discovery\")\n    identical = (\n        skill_discovery.get(\"prompts_byte_identical\")","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L223-L259","documentation":"Each mode/surface section stores identity_sha256, the SHA-256 of its sorted tool_names joined with NUL bytes (see tool_identity_digest). If the stored digest does not match the recomputed value, the section's tool list was altered after signing or the digest was computed differently.","triggerScenarios":"validate_identity_structure recomputes tool_identity_digest(names) and finds it differs from the stored tool_catalog.modes.<mode>.<surface>.identity_sha256.","commonSituations":"tool_names edited without recomputing the digest; digest computed over unsorted or differently joined names by a custom generator; receipt copied from a different catalog state.","solutions":["Recompute the digest with hashlib.sha256(\"\\0\".join(sorted(set(names))).encode()).hexdigest() and store it","Regenerate the receipt with the current script so list and digest are consistent","Ensure any external generator replicates the exact NUL-joined sorted-name hashing scheme"],"exampleFix":"# before (stale digest)\n\"identity_sha256\": \"aaa...\"\n# after\nimport hashlib\n\"identity_sha256\": hashlib.sha256(\"\\0\".join(names).encode()).hexdigest()","handlingStrategy":"validation","validationCode":"import hashlib\nnames = sorted(set(section[\"tool_names\"]))\nexpected = hashlib.sha256(\"\\0\".join(names).encode(\"utf-8\")).hexdigest()\nassert section[\"identity_sha256\"] == expected","typeGuard":null,"tryCatchPattern":"try:\n    validate_receipt(receipt)\nexcept RuntimeContractError as e:\n    if \"must match the owned sorted tool_names\" in str(e):\n        print(\"stale identity digest; regenerate the receipt\")\n    raise","preventionTips":["Compute the digest in the same function that writes tool_names","Never copy digests between catalog states","Mirror the exact NUL-join hashing scheme in any external generator"],"tags":["python","checksum","schema-validation"],"backgroundTag":"checksum-mismatch","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"}