Skip to content

fix(codec): reject unsafe Python integers before JSON encoding #331

Closed

Description

@bbopen

Python integers silently round when JSON decodes them as JavaScript numbers.

Reproduced on 6b84614 through NodeBridge: fixtures.values_torture.integer_first_rounded() returns 9007199254740992. Python returns 9007199254740993.

Serialization passes native integers through. Five menagerie rows record unsafe results.

Scope for 0.11: reject integers outside the JavaScript safe range before JSON output. Preserve safe numbers, finite float behavior, and Arrow int64 semantics. Keep Python int mapped to TypeScript number.

Acceptance criteria:

  • Both safe integer boundaries round-trip exactly.
  • Positive and negative values at and beyond 2**53 reject, including signed int64 bounds and factorial examples.
  • Root values, nested containers, supported NumPy scalar conversions, and Pydantic output cannot bypass validation.
  • Errors include the result path and explicit conversion guidance.
  • Booleans and valid finite floats remain supported.
  • Arrow int64 rows remain exact.
  • Affected menagerie rows become LOUD_FAIL with discriminating expectations.
  • Generated-wrapper tests exercise the rejection through the real bridge.
  • Migration documentation explains this behavior change.

Tagged bigint transport is separate work in #337. Do not return bigint under an unchanged Promise.

Architectural approach:

Apply the integer policy from #343 consistently across producer, generated types, and validation. Use #344 to verify boundaries. Preserve this issue's rejection policy unless a separately reviewed design changes it. Coordinate through #345.

Activity

  1. added this to the Next milestone on Sep 11, 2026
  2. self-assigned this
    on Sep 11, 2026
  3. added
    bugSomething isn't working
    area:codecArea: codecs and serialization
    on Sep 11, 2026
  4. bbopen commented on Sep 20, 2026

    @bbopen
    OwnerAuthor

    Unsafe Python integers now raise a conversion error before JSON can round them. Safe boundaries, both signs of unsafe bounds, factorial results, and nested paths have producer, generated-validator, menagerie, and isolated-consumer coverage. Migration guidance explains the safe-number range and explicit alternatives.

    Evidence: runtime/tywrap_bridge_core.py, src/contracts/value-contract.ts, src/core/callable-compiler.ts, test/python/test_bridge_core.py, test/isolated_consumer.conformance.ts, and docs/guide/migrating-to-0-11.md.

    Verified release evidence:

    The architecture decision records the accepted scope and prototype limits.

    Closing with the implemented and verified 0.11 release outcome.

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

Metadata

Metadata

Assignees

Labels

area:codecArea: codecs and serializationarea:runtime-nodeArea: Node runtime bridgebreakingBreaking changebugSomething isn't workingpriority:p1Priority P1 (high)

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions