Skip to content

bug: reject non-finite numbers in JSON and NDJSON contracts #342

Description

@codeforester

Problem

The public JSON serializers use Python's permissive NaN/Infinity defaults. They can report successful output containing tokens rejected by strict JSON consumers such as JavaScript JSON.parse, undermining the advertised cross-language machine boundary.

Verified evidence

Reviewed on 2026-09-12 at 7faf347a5b90969e169c88f3ac18e7202d142dd0; the local checkout matches GitHub main.

stream = io.StringIO()
base_cli.NdjsonWriter(stream).write({"value": float("nan")})
print(stream.getvalue())
# {"schema_version":1,"schema":"base-cli.record","record":{"value":NaN}}

render_records(..., requested_format="json") and dumps_envelope(success_envelope(run_id=None, details={"value":float("inf")})) have the same permissive serialization path. Python json.loads accepts these extensions, so round-trip tests using only Python miss the violation.

Sources:

Acceptance criteria

  • Choose and document strict handling for NaN and positive/negative infinity (prefer rejecting with a clear error rather than silently changing data).
  • Serialize a full record before writing it so an invalid record does not leave a partial NDJSON line.
  • Test all public JSON/envelope/NDJSON emitters with nested non-finite values.
  • Use a strict parser, including the Node contract path, to reject nonstandard output.

Project fields

  • Status: Backlog
  • Priority: P2
  • Area: CLI
  • Initiative: v1.0 Readiness
  • Size: S
  • Assignee: @codeforester
  • Milestone: v1.0.0
  • Target date: unscheduled

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

Projects

  • Status
    Backlog

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions