{"record":{"id":"93378eda2d69c8a8","repo":"Hmbown/CodeWhale","slug":"codewhale-metadata-event-was-not-a-terminal-receip","errorCode":null,"errorMessage":"Codewhale metadata event was not a terminal receipt","messagePattern":"Codewhale metadata event was not a terminal receipt","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"integrations/verifiers-codewhale/codewhale_harness/harness.py","lineNumber":376,"sourceCode":"        if not isinstance(event, dict):\n            raise RuntimeError(\n                f\"Codewhale stream-json line {line_number} was not an object\"\n            )\n        if event.get(\"schema\") != STREAM_SCHEMA or event.get(\n            \"schema_version\"\n        ) != STREAM_SCHEMA_VERSION:\n            raise RuntimeError(\"Codewhale stream-json schema did not match v0.9.1\")\n        event_type = event.get(\"type\")\n        if event_type not in _EVENT_TYPES:\n            raise RuntimeError(\"Codewhale stream-json contained an unknown event type\")\n        counts[event_type] += 1\n        ordered_types.append(event_type)\n        if event_type == \"metadata\":\n            if terminal is not None:\n                raise RuntimeError(\"Codewhale emitted more than one terminal metadata receipt\")\n            meta = event.get(\"meta\")\n            if not isinstance(meta, dict) or meta.get(\"receipt_kind\") != \"terminal\":\n                raise RuntimeError(\"Codewhale metadata event was not a terminal receipt\")\n            terminal = _bounded_terminal(meta)\n\n    if terminal is None:\n        raise RuntimeError(\"Codewhale stream-json omitted terminal metadata\")\n    if counts[\"done\"] != 1 or not ordered_types or ordered_types[-1] != \"done\":\n        raise RuntimeError(\"Codewhale stream-json did not end with exactly one done event\")\n    if ordered_types[-2:-1] != [\"metadata\"]:\n        raise RuntimeError(\"Codewhale terminal metadata did not immediately precede done\")\n    for field in [\"binary_sha256\", \"prompt_sha256\"]:\n        if not isinstance(terminal.get(field), str) or not _SHA256.fullmatch(\n            terminal[field]\n        ):\n            raise RuntimeError(f\"Codewhale terminal receipt omitted a valid {field}\")\n    return {\n        \"schema\": STREAM_SCHEMA,\n        \"schema_version\": STREAM_SCHEMA_VERSION,\n        \"events\": dict(sorted(counts.items())),\n        \"terminal\": terminal,","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/integrations/verifiers-codewhale/codewhale_harness/harness.py#L358-L394","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["Inspect the metadata event's payload in stdout: meta must be an object with \"receipt_kind\": \"terminal\".","Fix the producer to wrap terminal data as event['meta'] = {'receipt_kind': 'terminal', ...bounded fields...}.","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.","Align the facade with the 0.9.1 receipt contract or pin the harness-supported Codewhale version."],"exampleFix":"# before\n{\"type\": \"metadata\", \"receipt_kind\": \"terminal\", \"model\": \"...\"}\n\n# after\n{\"type\": \"metadata\", \"meta\": {\"receipt_kind\": \"terminal\", \"model\": \"...\"}}","handlingStrategy":"type-guard","validationCode":"def metadata_has_terminal_meta(event: dict) -> bool:\n    meta = event.get(\"meta\")\n    return isinstance(meta, dict) and meta.get(\"receipt_kind\") == \"terminal\"","typeGuard":"def is_terminal_metadata_event(event: object) -> bool:\n    return (\n        isinstance(event, dict)\n        and event.get(\"type\") == \"metadata\"\n        and isinstance(event.get(\"meta\"), dict)\n        and event[\"meta\"].get(\"receipt_kind\") == \"terminal\"\n    )","tryCatchPattern":null,"preventionTips":["Nest terminal data under event['meta'] with receipt_kind='terminal' — never at the event top level.","Document the receipt shape next to the facade's emission code so drift is caught in review.","Contract-test the metadata event shape in the facade's unit tests."],"tags":["metadata","validation","stream-json","codewhale-harness"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}