{"record":{"id":"a4c746b66d9fc583","repo":"Hmbown/CodeWhale","slug":"codewhale-stream-json-did-not-end-with-exactly-one-done","errorCode":null,"errorMessage":"Codewhale stream-json did not end with exactly one done event","messagePattern":"Codewhale stream-json did not end with exactly one done event","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"integrations/verifiers-codewhale/codewhale_harness/harness.py","lineNumber":382,"sourceCode":"        ) != 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":364,"sourceCodeEnd":396,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/verifiers-codewhale/codewhale_harness/harness.py#L364-L396","documentation":"The harness requires the stream-json to terminate with exactly one `done` event as the final event. This error is raised when the done count is not exactly 1, the event list is empty, or the last event is not `done` — any of which means the stream did not complete cleanly.","triggerScenarios":"`_parse_stream_receipt` finishes the loop with `counts[\"done\"] != 1`, an empty `ordered_types`, or `ordered_types[-1] != \"done\"` (harness.py:382) — e.g. zero done events, two done events, or trailing events after done.","commonSituations":"Agent process killed or crashed before emitting done; a binary that emits done per turn (duplicate done events); extra non-standard events appended after done; a stream captured from a partial run.","solutions":["Re-run the agent and verify it exits normally after emitting exactly one done event","Upgrade or fix the Codewhale binary so done is emitted once at stream end","Remove any post-done events from the producing side or fixtures","Capture the raw stream to a file to see the actual event order when diagnosing"],"exampleFix":"// before (trailing event after done)\n{\"type\":\"metadata\",\"meta\":{...}}\n{\"type\":\"done\"}\n{\"type\":\"debug\",\"x\":1}\n// after\n{\"type\":\"metadata\",\"meta\":{...}}\n{\"type\":\"done\"}","handlingStrategy":"validation","validationCode":"types = [e.get(\"type\") for e in events]\nassert types.count(\"done\") == 1 and types[-1] == \"done\", f\"done count={types.count('done')}, last={types[-1] if types else None}\"","typeGuard":null,"tryCatchPattern":"try:\n    receipt = _parse_stream_receipt(events)\nexcept RuntimeError as e:\n    if \"exactly one done event\" in str(e):\n        log.error(\"stream did not terminate cleanly; inspect raw stream and binary\")\n    raise","preventionTips":["Emit done exactly once, at stream end","Never append events after done","Check for crashes that prevent done from being emitted","Capture raw streams to files for diagnosis"],"tags":["python","stream-parsing","protocol-violation","verifier-harness"],"backgroundTag":"unexpected-response-shape","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"}