{"record":{"id":"9ec42ed8467e531f","repo":"Hmbown/CodeWhale","slug":"codewhale-terminal-receipt-contained-a-non-scalar-field","errorCode":null,"errorMessage":"Codewhale terminal receipt contained a non-scalar field","messagePattern":"Codewhale terminal receipt contained a non-scalar field","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"integrations/verifiers-codewhale/codewhale_harness/harness.py","lineNumber":268,"sourceCode":"        )\n        is not None\n    )\n\n\ndef _bounded_terminal(meta: dict[str, Any]) -> dict[str, Any]:\n    terminal: dict[str, Any] = {}\n    for key in _TERMINAL_FIELDS:\n        if key not in meta or meta[key] is None:\n            continue\n        value = meta[key]\n        if isinstance(value, str):\n            if len(value) > MAX_TERMINAL_STRING_CHARS:\n                raise RuntimeError(\"Codewhale terminal receipt exceeded its string bound\")\n        elif isinstance(value, int) and not isinstance(value, bool):\n            if value < 0 or value > 2**63 - 1:\n                raise RuntimeError(\"Codewhale terminal receipt contained an invalid count\")\n        else:\n            raise RuntimeError(\"Codewhale terminal receipt contained a non-scalar field\")\n        terminal[key] = value\n    encoded = json.dumps(terminal, sort_keys=True, separators=(\",\", \":\")).encode()\n    if len(encoded) > MAX_TERMINAL_RECEIPT_BYTES:\n        raise RuntimeError(\"Codewhale terminal receipt exceeded its total bound\")\n    return terminal\n\n\ndef _install_script(version: str) -> str:\n    version_q = shlex.quote(version)\n    install_q = shlex.quote(INSTALL_DIR)\n    release_q = shlex.quote(RELEASE_ROOT)\n    return f\"\"\"\nset -eu\nversion={version_q}\ninstall_dir={install_q}\nrelease_root={release_q}\nif [ \"$(uname -s)\" != Linux ]; then\n    echo \"automatic Codewhale installation supports Linux runtimes; set binary_path\" >&2","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/verifiers-codewhale/codewhale_harness/harness.py#L250-L286","documentation":"Every field the harness copies from the terminal receipt must be a scalar: string or non-bool int. This RuntimeError fires when a _TERMINAL_FIELDS value in the metadata event's meta is another type — bool, float, list, dict, or null is skipped, anything else is rejected. The harness throws it to guarantee trace metadata stays small, JSON-canonical, and free of nested blobs.","triggerScenarios":"_bounded_terminal, invoked from _parse_stream_receipt on the 'metadata' event, hit a meta field (e.g. model, input_tokens, status) whose value was a bool, float, array, or object instead of str/int.","commonSituations":"Running a modified Codewhale that emits booleans for status-like fields or nested objects for usage; a schema drift where a field became a float token count; tampered or proxied stream output.","solutions":["Log the offending metadata event's meta to see which field and type broke the contract","Ensure the binary is the genuine pinned 0.9.1 Codewhale release","Report/fix the emitter so fields match the documented scalar schema (strings and ints only)","If the schema legitimately changed, update _TERMINAL_FIELDS handling and STREAM_SCHEMA_VERSION together"],"exampleFix":"// before (emitting binary)\n\"input_tokens\": 12.5\n// after\n\"input_tokens\": 12","handlingStrategy":"type-guard","validationCode":"SCALARS = (str, int)\nnon_scalar = [k for k, v in meta.items()\n              if v is not None and (isinstance(v, bool) or not isinstance(v, SCALARS))]\nassert not non_scalar, f\"non-scalar fields: {non_scalar}\"","typeGuard":"def is_scalar(value: object) -> bool:\n    if isinstance(value, bool):\n        return False\n    return isinstance(value, (str, int))","tryCatchPattern":"try:\n    receipt = await harness.launch(ctx, trace, runtime, endpoint, secret, mcp_urls)\nexcept RuntimeError as e:\n    if \"non-scalar field\" in str(e):\n        logger.error(\"receipt contained nested/typed field; schema drift\")\n    raise","preventionTips":["Keep receipt fields strictly string or int at the emitter","Bump STREAM_SCHEMA_VERSION whenever a field's type changes","Lint emitter code against the documented _TERMINAL_FIELDS schema","Test the metadata event fixture against the harness before shipping binary changes"],"tags":["validation","type-mismatch","schema"],"backgroundTag":"type-mismatch","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"}