Hmbown/CodeWhale · error · RuntimeContractError

is missing required field

Error message

{kind} is missing required field `{dotted}`

What it means

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.

Solutions

  1. Open the receipt/budget JSON and add the missing field at the reported dotted path
  2. Regenerate the receipt with the current version of check-runtime-contract-budget.py instead of hand-editing
  3. Check for version skew: the script may expect a newer document schema than the tool that produced it

Example fix

// before: receipt missing the field
{"tool_catalog": {"surface_profile": "..."}}
// after
{"tool_catalog": {"surface_profile": "...", "execution_shell": "bash", "modes": {}}}
Defensive patterns

Strategy: validation

Validate before calling

def has_path(doc, parts):
    cur = doc
    for p in parts:
        if not isinstance(cur, dict) or p not in cur:
            return False
        cur = cur[p]
    return True

if not has_path(receipt, ("tool_catalog", "surface_profile")):
    raise ValueError("receipt missing tool_catalog.surface_profile")

Type guard

def is_section(v) -> bool:
    return isinstance(v, dict)

Try / catch

from scripts.check_runtime_contract_budget import RuntimeContractError
try:
    validate_receipt(receipt)
except RuntimeContractError as e:
    print(f"invalid receipt, regenerate it: {e}")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/89a63801ee6cb39b. Report an issue: GitHub.

Appendix: source

Thrown at scripts/check-runtime-contract-budget.py:196

            f"{source} document_kind must be `{expected_kind}`, got {actual_kind!r}"
        )
    version = document.get("schema_version")
    if (
        isinstance(version, bool)
        or not isinstance(version, int)
        or version != SCHEMA_VERSION
    ):
        raise RuntimeContractError(
            f"{source} schema_version must be {SCHEMA_VERSION}, got {version!r}"
        )


def required_value(document: dict[str, Any], path: MetricPath, kind: str) -> Any:
    value: Any = document
    dotted = ".".join(path)
    for part in path:
        if not isinstance(value, dict) or part not in value:
            raise RuntimeContractError(f"{kind} is missing required field `{dotted}`")
        value = value[part]
    return value


def tool_identity_digest(names: list[str]) -> str:
    return hashlib.sha256("\0".join(names).encode("utf-8")).hexdigest()


def validate_identity_structure(document: dict[str, Any], kind: str) -> None:
    profile = required_value(document, ("tool_catalog", "surface_profile"), kind)
    if profile != TOOL_SURFACE_PROFILE:
        raise RuntimeContractError(
            f"{kind} tool surface_profile must be `{TOOL_SURFACE_PROFILE}`, "
            f"got {profile!r}"
        )

    shell = required_value(document, ("tool_catalog", "execution_shell"), kind)
    if shell != "bash":

View on GitHub (pinned to 433685b202)