{"record":{"id":"93378eda2d69c8a8","repo":"Hmbown/CodeWhale","slug":"codewhale-metadata-event-was-not-a-terminal-receipt","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/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/verifiers-codewhale/codewhale_harness/harness.py#L358-L394","documentation":"When `_parse_stream_receipt` encounters a `metadata` event, it requires `event[\"meta\"]` to be a dict with `meta[\"receipt_kind\"] == \"terminal\"`. This error means a metadata event was present but its shape or kind was wrong — missing `meta`, non-dict `meta`, or a different receipt kind — so no valid terminal receipt could be captured.","triggerScenarios":"A metadata event in the stream-json lacks the `meta` key, has `meta` set to a non-dict (string/list/null), or carries `receipt_kind` with any value other than `\"terminal\"` while `_parse_stream_receipt` (called from `launch()`) processes it at harness.py:376.","commonSituations":"Binary version mismatch where the agent emits a different receipt schema (e.g. `kind` instead of `receipt_kind`, or a progress/intermediate receipt); a truncated or hand-edited stream line; a mock stream written against an older schema.","solutions":["Print the offending metadata event and compare its keys against the expected schema (`meta` dict with `receipt_kind == \"terminal\"`)","Rebuild/pin the Codewhale binary to the schema version matching STREAM_SCHEMA_VERSION in the harness","If intermediate receipts are legitimate, ensure they use a non-terminal `receipt_kind` and that exactly one terminal receipt exists","Fix mock/test fixtures to emit `meta` as an object with `receipt_kind: \"terminal\"`"],"exampleFix":"// before\n{\"type\":\"metadata\",\"meta\":{\"kind\":\"terminal\"}}\n// after\n{\"type\":\"metadata\",\"meta\":{\"receipt_kind\":\"terminal\"}}","handlingStrategy":"type-guard","validationCode":"for e in events:\n    if e.get(\"type\") == \"metadata\":\n        meta = e.get(\"meta\")\n        assert isinstance(meta, dict) and meta.get(\"receipt_kind\") == \"terminal\", f\"bad metadata: {e!r}\"","typeGuard":"def has_terminal_meta(event: dict) -> bool:\n    meta = event.get(\"meta\")\n    return isinstance(meta, dict) and isinstance(meta.get(\"receipt_kind\"), str) and meta[\"receipt_kind\"] == \"terminal\"","tryCatchPattern":"try:\n    receipt = _parse_stream_receipt(events)\nexcept RuntimeError as e:\n    if \"not a terminal receipt\" in str(e):\n        log.error(\"metadata schema mismatch; compare binary version to harness STREAM_SCHEMA_VERSION\")\n    raise","preventionTips":["Match receipt_kind field names to the current harness schema exactly","Emit intermediate receipts under a non-terminal receipt_kind","Test mock streams against the real parser before using them","Pin binary + harness versions together"],"tags":["python","stream-parsing","schema-validation","verifier-harness"],"backgroundTag":"schema-validation-failed","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"}