Skip to content

runtime-node: restore bytes semantics across JS↔Python bridge #193

@bbopen

Description

@bbopen

Summary

When calling into Python, binary payloads using Tywrap's bytes marker are not consistently decoded on the Python side, and Python responses are not fully revived into Uint8Array on the TypeScript side. This causes incorrect behavior in boundaries that depend on byte semantics (for example, length calculations and byte payload shape).

Reproduction

  • Call bridge.call<number>('builtins', 'len', [new Uint8Array([72, 101, 108, 108, 111])] and observe incorrect length behavior before fix.
  • Ensure responses from Python that include bytes envelopes like { "__type__": "bytes" ... } are parsed into typed arrays.

Expected Behavior

  • JavaScript Uint8Array/byte-like inputs are decoded to Python bytes for runtime invocation args/kwargs/method calls.
  • Python byte envelopes are revived to Uint8Array by SafeCodec.decodeResponse and decodeResponseAsync.
  • Bridge behavior is stable across handle_call, handle_instantiate, and handle_call_method boundaries.
  • Tests cover regressions around byte round-trip and length semantics.

Acceptance Criteria

  • Add protocol decode path for __tywrap_bytes__ / __type__: 'bytes' envelopes in Python runtime bridge.
  • Add Python bytes envelope reviver for SafeCodec.decodeResponse and decodeResponseAsync.
  • Add regression tests for byte round-trip and bytes length semantics.
  • Run relevant test suites and keep CI green.
  • Keep changes constrained to bridge/codec boundary only with explicit error behavior on malformed envelopes.

Notes

  • Keep a small compatibility-safe scope: no protocol version bump unless transport contract is changed beyond envelope compatibility.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions