{"record":{"id":"89a63801ee6cb39b","repo":"Hmbown/CodeWhale","slug":"kind-is-missing-required-field-dotted","errorCode":null,"errorMessage":"{kind} is missing required field `{dotted}`","messagePattern":"(.+?) is missing required field `(.+?)`","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":196,"sourceCode":"            f\"{source} document_kind must be `{expected_kind}`, got {actual_kind!r}\"\n        )\n    version = document.get(\"schema_version\")\n    if (\n        isinstance(version, bool)\n        or not isinstance(version, int)\n        or version != SCHEMA_VERSION\n    ):\n        raise RuntimeContractError(\n            f\"{source} schema_version must be {SCHEMA_VERSION}, got {version!r}\"\n        )\n\n\ndef required_value(document: dict[str, Any], path: MetricPath, kind: str) -> Any:\n    value: Any = document\n    dotted = \".\".join(path)\n    for part in path:\n        if not isinstance(value, dict) or part not in value:\n            raise RuntimeContractError(f\"{kind} is missing required field `{dotted}`\")\n        value = value[part]\n    return value\n\n\ndef tool_identity_digest(names: list[str]) -> str:\n    return hashlib.sha256(\"\\0\".join(names).encode(\"utf-8\")).hexdigest()\n\n\ndef validate_identity_structure(document: dict[str, Any], kind: str) -> None:\n    profile = required_value(document, (\"tool_catalog\", \"surface_profile\"), kind)\n    if profile != TOOL_SURFACE_PROFILE:\n        raise RuntimeContractError(\n            f\"{kind} tool surface_profile must be `{TOOL_SURFACE_PROFILE}`, \"\n            f\"got {profile!r}\"\n        )\n\n    shell = required_value(document, (\"tool_catalog\", \"execution_shell\"), kind)\n    if shell != \"bash\":","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L178-L214","documentation":"This script validates runtime contract receipts/budgets (JSON documents pinning the tool catalog identity). required_value walks a dotted path (e.g. tool_catalog.surface_profile) and throws RuntimeContractError when an intermediate key is not a dict or the final key is absent. It exists so malformed measurement documents fail loudly instead of producing bogus budget comparisons.","triggerScenarios":"Calling required_value (directly or via validate_identity_structure / metric_value / compare / budget_from_receipt) with a document lacking any key in the checked path — e.g. a receipt JSON missing tool_catalog, tool_catalog.modes, or the per-mode surface section.","commonSituations":"Hand-edited or partially generated receipts from an older script version; a truncated/partial JSON file; running compare against a receipt produced before a new required field (e.g. representative_context.stages) was added.","solutions":["Open the receipt/budget JSON and add the missing field at the reported dotted path","Regenerate the receipt with the current version of check-runtime-contract-budget.py instead of hand-editing","Check for version skew: the script may expect a newer document schema than the tool that produced it"],"exampleFix":"// before: receipt missing the field\n{\"tool_catalog\": {\"surface_profile\": \"...\"}}\n// after\n{\"tool_catalog\": {\"surface_profile\": \"...\", \"execution_shell\": \"bash\", \"modes\": {}}}","handlingStrategy":"validation","validationCode":"def has_path(doc, parts):\n    cur = doc\n    for p in parts:\n        if not isinstance(cur, dict) or p not in cur:\n            return False\n        cur = cur[p]\n    return True\n\nif not has_path(receipt, (\"tool_catalog\", \"surface_profile\")):\n    raise ValueError(\"receipt missing tool_catalog.surface_profile\")","typeGuard":"def is_section(v) -> bool:\n    return isinstance(v, dict)","tryCatchPattern":"from scripts.check_runtime_contract_budget import RuntimeContractError\ntry:\n    validate_receipt(receipt)\nexcept RuntimeContractError as e:\n    print(f\"invalid receipt, regenerate it: {e}\")","preventionTips":["Always generate receipts with the current script, never hand-edit them","Validate documents with has_path checks before passing to compare/budget_from_receipt","Keep receipts under version control so schema drift is visible in diffs"],"tags":["python","schema-validation","contract-check"],"backgroundTag":"missing-required-config-field","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"}