Hmbown/CodeWhale · error · RuntimeError

Codewhale stream-json contained an unknown event type

Error message

Codewhale stream-json contained an unknown event type

What it means

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.

Solutions

  1. Log the offending event's type value to identify the unknown kind
  2. Pin/upgrade the binary to match the harness's expected 0.9.1 schema (see STREAM_SCHEMA_VERSION)
  3. If the new event type is legitimate, add it to _EVENT_TYPES in the harness and decide its count semantics
  4. Check for forks or patched binaries in binary_path that introduce custom event types
  5. Report the new event type upstream so the harness and binary stay in lockstep

Example fix

# before
_EVENT_TYPES = {"content", "tool_use", ..., "error"}
# after (only if the emitter legitimately adds a type)
_EVENT_TYPES = {"content", "tool_use", ..., "error", "new_event_kind"}
Defensive patterns

Strategy: validation

Validate before calling

KNOWN = {"content","tool_use","tool_result","sandbox_denied","workflow_event",
         "session_capture","turn_usage","metadata","done","error"}
def types_known(stdout: str) -> bool:
    import json
    for line in stdout.splitlines():
        if line.strip() and isinstance((e := json.loads(line)), dict):
            if e.get("type") not in KNOWN:
                return False
    return True

Type guard

def is_known_event(event: dict) -> bool:
    return event.get("type") in {
        "content","tool_use","tool_result","sandbox_denied","workflow_event",
        "session_capture","turn_usage","metadata","done","error"}

Try / catch

try:
    result = await harness.launch(ctx, trace, runtime, endpoint, secret, mcp_urls)
except RuntimeError as e:
    if "unknown event type" in str(e):
        logger.error("protocol drift: binary emits an event type this harness doesn't know")
    raise

Prevention

When it happens

Trigger: _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.

Common situations: 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.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/33700f3b71058bc3. Report an issue: GitHub.

Appendix: source

Thrown at integrations/verifiers-codewhale/codewhale_harness/harness.py:368

        if not line.strip():
            continue
        try:
            event = json.loads(line)
        except json.JSONDecodeError as error:
            raise RuntimeError(
                f"Codewhale stream-json line {line_number} was not valid JSON"
            ) from error
        if not isinstance(event, dict):
            raise RuntimeError(
                f"Codewhale stream-json line {line_number} was not an object"
            )
        if event.get("schema") != STREAM_SCHEMA or event.get(
            "schema_version"
        ) != STREAM_SCHEMA_VERSION:
            raise RuntimeError("Codewhale stream-json schema did not match v0.9.1")
        event_type = event.get("type")
        if event_type not in _EVENT_TYPES:
            raise RuntimeError("Codewhale stream-json contained an unknown event type")
        counts[event_type] += 1
        ordered_types.append(event_type)
        if event_type == "metadata":
            if terminal is not None:
                raise RuntimeError("Codewhale emitted more than one terminal metadata receipt")
            meta = event.get("meta")
            if not isinstance(meta, dict) or meta.get("receipt_kind") != "terminal":
                raise RuntimeError("Codewhale metadata event was not a terminal receipt")
            terminal = _bounded_terminal(meta)

    if terminal is None:
        raise RuntimeError("Codewhale stream-json omitted terminal metadata")
    if counts["done"] != 1 or not ordered_types or ordered_types[-1] != "done":
        raise RuntimeError("Codewhale stream-json did not end with exactly one done event")
    if ordered_types[-2:-1] != ["metadata"]:
        raise RuntimeError("Codewhale terminal metadata did not immediately precede done")
    for field in ["binary_sha256", "prompt_sha256"]:
        if not isinstance(terminal.get(field), str) or not _SHA256.fullmatch(

View on GitHub (pinned to 433685b202)