{"record":{"id":"33700f3b71058bc3","repo":"Hmbown/CodeWhale","slug":"codewhale-stream-json-contained-an-unknown-event-type","errorCode":null,"errorMessage":"Codewhale stream-json contained an unknown event type","messagePattern":"Codewhale stream-json contained an unknown event type","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"integrations/verifiers-codewhale/codewhale_harness/harness.py","lineNumber":368,"sourceCode":"        if not line.strip():\n            continue\n        try:\n            event = json.loads(line)\n        except json.JSONDecodeError as error:\n            raise RuntimeError(\n                f\"Codewhale stream-json line {line_number} was not valid JSON\"\n            ) from error\n        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(","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/verifiers-codewhale/codewhale_harness/harness.py#L350-L386","documentation":"Only known event types (content, tool_use, tool_result, sandbox_denied, workflow_event, session_capture, turn_usage, metadata, done, error) are accepted in the stream. This RuntimeError means an event object had a 'type' outside _EVENT_TYPES. The harness throws it because unrecognized events indicate a protocol change it cannot account for, so counting and receipt validation would be silently wrong.","triggerScenarios":"_parse_stream_receipt read an event whose 'type' was absent from _EVENT_TYPES — e.g. a new event kind introduced by a newer binary, a typo, or a renamed type from a fork.","commonSituations":"Running a Codewhale build newer than the harness's pinned 0.9.1 that emits new event types; a fork with custom event kinds; envelope corruption changing the type string.","solutions":["Log the offending event's type value to identify the unknown kind","Pin/upgrade the binary to match the harness's expected 0.9.1 schema (see STREAM_SCHEMA_VERSION)","If the new event type is legitimate, add it to _EVENT_TYPES in the harness and decide its count semantics","Check for forks or patched binaries in binary_path that introduce custom event types","Report the new event type upstream so the harness and binary stay in lockstep"],"exampleFix":"# before\n_EVENT_TYPES = {\"content\", \"tool_use\", ..., \"error\"}\n# after (only if the emitter legitimately adds a type)\n_EVENT_TYPES = {\"content\", \"tool_use\", ..., \"error\", \"new_event_kind\"}","handlingStrategy":"validation","validationCode":"KNOWN = {\"content\",\"tool_use\",\"tool_result\",\"sandbox_denied\",\"workflow_event\",\n         \"session_capture\",\"turn_usage\",\"metadata\",\"done\",\"error\"}\ndef types_known(stdout: str) -> bool:\n    import json\n    for line in stdout.splitlines():\n        if line.strip() and isinstance((e := json.loads(line)), dict):\n            if e.get(\"type\") not in KNOWN:\n                return False\n    return True","typeGuard":"def is_known_event(event: dict) -> bool:\n    return event.get(\"type\") in {\n        \"content\",\"tool_use\",\"tool_result\",\"sandbox_denied\",\"workflow_event\",\n        \"session_capture\",\"turn_usage\",\"metadata\",\"done\",\"error\"}","tryCatchPattern":"try:\n    result = await harness.launch(ctx, trace, runtime, endpoint, secret, mcp_urls)\nexcept RuntimeError as e:\n    if \"unknown event type\" in str(e):\n        logger.error(\"protocol drift: binary emits an event type this harness doesn't know\")\n    raise","preventionTips":["Match the binary version to the harness's expected schema before upgrading either side","Maintain a fixture stream per release and validate it against _EVENT_TYPES","When adding event types upstream, update the harness's _EVENT_TYPES in the same change","Avoid forks that introduce custom event kinds without harness support"],"tags":["schema","versioning","protocol"],"backgroundTag":"invalid-enum-value","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"}