Skip to content

Python bridge should disallow NaN/Infinity in JSON responses #95

@bbopen

Description

@bbopen

Summary

json.dumps in python_bridge.py allows NaN/Infinity by default, producing invalid JSON tokens (NaN, Infinity). Node’s JSON.parse rejects these and triggers protocol errors, killing the bridge.

Failure mode

  • Python function returns float('nan') or float('inf') (or includes these values in a list/dict).
  • json.dumps serializes them to NaN/Infinity.
  • Node side fails to parse and treats it as a protocol error.

Evidence

  • runtime/python_bridge.py encode_response() uses json.dumps(out) without allow_nan=False.

Proposed fix

  • Use json.dumps(..., allow_nan=False) and surface a clear error when NaN/Infinity is encountered.
  • Optionally sanitize to strings if a safe mode is configured.

Acceptance criteria

  • NaN/Infinity in responses produce a clear, explicit error payload instead of invalid JSON.
  • Node side does not receive malformed JSON for these values.
  • Add tests with functions returning NaN/Infinity.

Metadata

Metadata

Assignees

Labels

area:runtime-nodeArea: Node runtime bridgebugSomething isn't workingpriority:p1Priority P1 (high)

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions