{"record":{"id":"d988d5b824e8d25e","repo":"Hmbown/CodeWhale","slug":"kind-field-dotted-names-must-be-sorted-unique-non-empty","errorCode":null,"errorMessage":"{kind} field `{dotted_names}` must be sorted unique non-empty strings","messagePattern":"(.+?) field `(.+?)` must be sorted unique non-empty strings","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":229,"sourceCode":"        )\n\n    shell = required_value(document, (\"tool_catalog\", \"execution_shell\"), kind)\n    if shell != \"bash\":\n        raise RuntimeContractError(\n            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\")","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L211-L247","documentation":"For each visible mode/tool-surface pair, the owned tool_names list must be a list of non-empty strings, sorted, and free of duplicates. validate_identity_structure enforces this so the identity digest (error 805) is deterministic. Anything unsorted, duplicated, empty, or non-string fails.","triggerScenarios":"A tool_catalog.modes.<mode>.<surface>.tool_names array in a receipt/budget that is unsorted, contains duplicates, contains empty strings, or contains non-string entries.","commonSituations":"Generator appends tools in discovery order rather than sorted; duplicate registration of a tool; a tool with an empty name after a rename; hand-edited list.","solutions":["Sort the list and deduplicate: names = sorted(set(names)) in the generator before writing","Remove empty or non-string entries from tool_names","Regenerate the receipt with the current generator instead of editing by hand"],"exampleFix":"// before\n\"tool_names\": [\"read\", \"edit\", \"read\"]\n// after\n\"tool_names\": [\"edit\", \"read\"]","handlingStrategy":"validation","validationCode":"names = doc[\"tool_catalog\"][\"modes\"][mode][surface][\"tool_names\"]\nok = (isinstance(names, list)\n      and all(isinstance(n, str) and n for n in names)\n      and names == sorted(set(names)))\nassert ok, \"tool_names must be sorted unique non-empty strings\"","typeGuard":"def valid_tool_names(v) -> bool:\n    return (isinstance(v, list)\n            and all(isinstance(n, str) and n for n in v)\n            and v == sorted(set(v)))","tryCatchPattern":"try:\n    validate_receipt(receipt)\nexcept RuntimeContractError as e:\n    if \"sorted unique non-empty strings\" in str(e):\n        print(\"regenerate: generator emitted unsorted or duplicated tool_names\")\n    raise","preventionTips":["In generators, always write sorted(set(names))","Reject empty tool names at registration time","Add a pre-write assertion in the generator mirroring this rule"],"tags":["python","schema-validation","sorting"],"backgroundTag":"invalid-argument-format","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"}