{"record":{"id":"24a430a009937910","repo":"Hmbown/CodeWhale","slug":"codewhale-stream-json-omitted-terminal-metadata","errorCode":null,"errorMessage":"Codewhale stream-json omitted terminal metadata","messagePattern":"Codewhale stream-json omitted terminal metadata","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"integrations/verifiers-codewhale/codewhale_harness/harness.py","lineNumber":380,"sourceCode":"        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,\n    }\n","sourceCodeStart":362,"sourceCodeEnd":396,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/verifiers-codewhale/codewhale_harness/harness.py#L362-L396","documentation":"`_parse_stream_receipt` tracks whether a valid terminal metadata receipt was seen; if the stream ends without ever capturing one, it raises this error. The harness refuses to report a result without the attested terminal receipt (hashes of binary and prompt), because the run cannot be verified.","triggerScenarios":"`launch()` consumes a stream-json that contains no `metadata` event at all, or only metadata events that failed the terminal check, and the loop completes with `terminal is None` at harness.py:380.","commonSituations":"Agent crashed or was killed mid-stream before emitting the final metadata; a binary version that omits the terminal receipt feature; output piping truncating the last lines; running an older Codewhale build against the newer harness.","solutions":["Re-run and capture the full stream to confirm the process survived to the end (a `done` event must also be present)","Upgrade the Codewhale binary to a build that emits terminal metadata receipts","Check stderr/exit code of the launched process for a crash that truncated the stream","If piping output, verify no buffering/truncation drops the final metadata and done events"],"exampleFix":"// before (stream ends early)\n{\"type\":\"item\",...}\n// after (complete stream)\n{\"type\":\"item\",...}\n{\"type\":\"metadata\",\"meta\":{\"receipt_kind\":\"terminal\",\"binary_sha256\":\"...\",\"prompt_sha256\":\"...\"}}\n{\"type\":\"done\"}","handlingStrategy":"validation","validationCode":"types = [e.get(\"type\") for e in events]\nassert \"metadata\" in types, \"stream lacks terminal metadata receipt\"\nassert types and types[-1] == \"done\", \"stream did not finish\"","typeGuard":null,"tryCatchPattern":"try:\n    receipt = _parse_stream_receipt(events)\nexcept RuntimeError as e:\n    if \"omitted terminal metadata\" in str(e):\n        log.error(\"agent stream ended before terminal receipt; check process exit/stderr\")\n    raise","preventionTips":["Check agent process exit code and stderr on every run","Avoid killing/truncating the agent mid-stream","Verify no output piping drops the last lines","Use binary versions that emit the terminal receipt"],"tags":["python","stream-parsing","missing-data","verifier-harness"],"backgroundTag":"empty-response-body","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"}