Hmbown/CodeWhale · error · RuntimeError
Codewhale terminal receipt contained an invalid count
Error message
Codewhale terminal receipt contained an invalid count
What it means
Integer terminal fields (token counters, duration_ms, retry_count, message_count, ...) must lie in [0, 2^63-1], the range safely representable downstream. Negative values or anything above 2^63-1 raise RuntimeError during parsing. Booleans are deliberately excluded from the integer branch (bool subclasses int in Python) and fall through to the non-scalar error instead.
Source
Thrown at integrations/verifiers-codewhale/codewhale_harness/harness.py:266
rf"(?<![0-9A-Za-z.+-]){re.escape(version)}(?![0-9A-Za-z.+-])",
output,
)
is not None
)
def _bounded_terminal(meta: dict[str, Any]) -> dict[str, Any]:
terminal: dict[str, Any] = {}
for key in _TERMINAL_FIELDS:
if key not in meta or meta[key] is None:
continue
value = meta[key]
if isinstance(value, str):
if len(value) > MAX_TERMINAL_STRING_CHARS:
raise RuntimeError("Codewhale terminal receipt exceeded its string bound")
elif isinstance(value, int) and not isinstance(value, bool):
if value < 0 or value > 2**63 - 1:
raise RuntimeError("Codewhale terminal receipt contained an invalid count")
else:
raise RuntimeError("Codewhale terminal receipt contained a non-scalar field")
terminal[key] = value
encoded = json.dumps(terminal, sort_keys=True, separators=(",", ":")).encode()
if len(encoded) > MAX_TERMINAL_RECEIPT_BYTES:
raise RuntimeError("Codewhale terminal receipt exceeded its total bound")
return terminal
def _install_script(version: str) -> str:
version_q = shlex.quote(version)
install_q = shlex.quote(INSTALL_DIR)
release_q = shlex.quote(RELEASE_ROOT)
return f"""
set -eu
version={version_q}
install_dir={install_q}
release_root={release_q}View on GitHub (pinned to 8880682c63)
Solutions
- Clamp counts to the valid range before emitting
- Use 0 or omit the field for unknown values; None fields are skipped entirely
- Fix u64 overflow in the emitter's usage accounting
Example fix
# before
meta = {'input_tokens': -1, 'output_tokens': 2**64 - 1}
# after
meta = {'input_tokens': 0, 'output_tokens': 2**63 - 1} Defensive patterns
Strategy: validation
Validate before calling
I64_MAX = 2**63 - 1
meta = {
k: (min(max(v, 0), I64_MAX) if isinstance(v, int) and not isinstance(v, bool) else v)
for k, v in meta.items()
} Prevention
- Use 0 or omit unknown counts; never -1 sentinels
- Watch for u64 saturation when porting counters
- Assert count ranges in facade unit tests
When it happens
Trigger: A facade emitting -1 sentinels for unknown counts; u64 saturation values such as 2^64-1 in token totals; overflow bugs in usage accounting.
Common situations: Stub facades using -1 for 'unknown'; counters ported from unsigned languages; aggregations that overflow during long runs.
Related errors
- Codewhale terminal receipt exceeded its string bound
- Codewhale terminal receipt contained a non-scalar field
- Codewhale terminal receipt did not use provider openai
- Codewhale terminal receipt model did not match rollout
- Codewhale terminal receipt did not confirm auto tools
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/2a8702b1c4e93964.
Report an issue: GitHub.