Hmbown/CodeWhale · error · RuntimeError

Codewhale emitted more than one terminal metadata receipt

Error message

Codewhale emitted more than one terminal metadata receipt

What it means

The Codewhale verifier harness parses the agent's stream-json output in `_parse_stream_receipt` and requires exactly one terminal metadata receipt. This RuntimeError is raised when a second `metadata` event with `receipt_kind == "terminal"` appears after one was already captured, i.e. the stream contains duplicate terminal receipts, which would make the attested terminal ambiguous.

Solutions

  1. Inspect the stream-json output and find both metadata events; determine why the binary emitted two terminal receipts
  2. Upgrade or rebuild the Codewhale binary to the version the harness expects (one terminal receipt per stream)
  3. If retries/restarts occur, restart the stream parse per attempt instead of feeding events from multiple runs into one `_parse_stream_receipt` call
  4. Fix any test fixture or mock stream so it contains exactly one terminal metadata event before the single done event

Example fix

// before (fixture emits two receipts)
{"type":"metadata","meta":{"receipt_kind":"terminal",...}}
{"type":"metadata","meta":{"receipt_kind":"terminal",...}}
{"type":"done"}
// after (exactly one terminal receipt, immediately before done)
{"type":"metadata","meta":{"receipt_kind":"terminal",...}}
{"type":"done"}
Defensive patterns

Strategy: validation

Validate before calling

meta_events = [e for e in stream if e.get("type") == "metadata" and isinstance(e.get("meta"), dict) and e["meta"].get("receipt_kind") == "terminal"]
assert len(meta_events) == 1, f"expected 1 terminal receipt, got {len(meta_events)}"

Type guard

def is_terminal_metadata(event) -> bool:
    meta = event.get("meta") if isinstance(event, dict) else None
    return isinstance(meta, dict) and meta.get("receipt_kind") == "terminal"

Try / catch

try:
    receipt = _parse_stream_receipt(events)
except RuntimeError as e:
    if "more than one terminal" in str(e):
        log.error("duplicate terminal receipt; check binary version/stream concatenation")
    raise

Prevention

When it happens

Trigger: `launch()` runs a Codewhale binary whose stream-json emits two or more metadata events that both carry `receipt_kind: "terminal"`; the loop at harness.py:373 sees `terminal is not None` on the second occurrence and raises.

Common situations: Running a stale or patched Codewhale binary that emits a terminal receipt per turn instead of per session; wrapping the agent so its output is concatenated (e.g. retry/restart inside the stream) so two receipts appear in one stream; a hand-crafted or mocked stream for tests containing duplicated metadata lines.

Related errors


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

Appendix: source

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

            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(
            terminal[field]
        ):
            raise RuntimeError(f"Codewhale terminal receipt omitted a valid {field}")
    return {
        "schema": STREAM_SCHEMA,

View on GitHub (pinned to 433685b202)