Hmbown/CodeWhale · error · RuntimeError

Codewhale metadata event was not a terminal receipt

Error message

Codewhale metadata event was not a terminal receipt

What it means

When the harness sees a metadata event, its 'meta' payload must be a dict carrying receipt_kind == 'terminal'. This error means meta was absent, not an object, or labeled with a different receipt_kind — so the event cannot be used as the terminal receipt the harness needs.

Source

Thrown at integrations/verifiers-codewhale/codewhale_harness/harness.py:376

        if not isinstance(event, dict):
            raise RuntimeError(
                f"Codewhale stream-json line {line_number} was not an object"
            )
        if event.get("schema") != STREAM_SCHEMA or event.get(
            "schema_version"
        ) != STREAM_SCHEMA_VERSION:
            raise RuntimeError("Codewhale stream-json schema did not match v0.9.1")
        event_type = event.get("type")
        if event_type not in _EVENT_TYPES:
            raise RuntimeError("Codewhale stream-json contained an unknown event type")
        counts[event_type] += 1
        ordered_types.append(event_type)
        if event_type == "metadata":
            if terminal is not None:
                raise RuntimeError("Codewhale emitted more than one terminal metadata receipt")
            meta = event.get("meta")
            if not isinstance(meta, dict) or meta.get("receipt_kind") != "terminal":
                raise RuntimeError("Codewhale metadata event was not a terminal receipt")
            terminal = _bounded_terminal(meta)

    if terminal is None:
        raise RuntimeError("Codewhale stream-json omitted terminal metadata")
    if counts["done"] != 1 or not ordered_types or ordered_types[-1] != "done":
        raise RuntimeError("Codewhale stream-json did not end with exactly one done event")
    if ordered_types[-2:-1] != ["metadata"]:
        raise RuntimeError("Codewhale terminal metadata did not immediately precede done")
    for field in ["binary_sha256", "prompt_sha256"]:
        if not isinstance(terminal.get(field), str) or not _SHA256.fullmatch(
            terminal[field]
        ):
            raise RuntimeError(f"Codewhale terminal receipt omitted a valid {field}")
    return {
        "schema": STREAM_SCHEMA,
        "schema_version": STREAM_SCHEMA_VERSION,
        "events": dict(sorted(counts.items())),
        "terminal": terminal,

View on GitHub (pinned to 8880682c63)

Solutions

  1. Inspect the metadata event's payload in stdout: meta must be an object with "receipt_kind": "terminal".
  2. Fix the producer to wrap terminal data as event['meta'] = {'receipt_kind': 'terminal', ...bounded fields...}.
  3. If the event was meant as non-terminal metadata, ensure a proper terminal metadata event still follows later (immediately before done), or this same error surfaces.
  4. Align the facade with the 0.9.1 receipt contract or pin the harness-supported Codewhale version.

Example fix

# before
{"type": "metadata", "receipt_kind": "terminal", "model": "..."}

# after
{"type": "metadata", "meta": {"receipt_kind": "terminal", "model": "..."}}
Defensive patterns

Strategy: type-guard

Validate before calling

def metadata_has_terminal_meta(event: dict) -> bool:
    meta = event.get("meta")
    return isinstance(meta, dict) and meta.get("receipt_kind") == "terminal"

Type guard

def is_terminal_metadata_event(event: object) -> bool:
    return (
        isinstance(event, dict)
        and event.get("type") == "metadata"
        and isinstance(event.get("meta"), dict)
        and event["meta"].get("receipt_kind") == "terminal"
    )

Prevention

When it happens

Trigger: A metadata event shaped like {"type": "metadata"} with no meta key, meta set to a list/number, or meta.receipt_kind set to 'progress'/'session' while the harness expects exactly 'terminal'.

Common situations: Custom facades that treat metadata as a generic progress channel; schema drift where receipt_kind was renamed; fixtures copied from an older format that had no receipt_kind field at all.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/93378eda2d69c8a8. Report an issue: GitHub.