Skip to content

arch: Unified numeric validation layer for NaN/Infinity handling #141

@bbopen

Description

@bbopen

Overview

Multiple issues relate to inconsistent handling of NaN, Infinity, and invalid numeric values across the codebase. This tracking issue proposes a unified validation layer.

Related Issues

Proposed Architecture

1. Configuration Validation (at construction)

function validatePositiveNumber(value: number, name: string): number {
  if (!Number.isFinite(value) || value <= 0) {
    throw new RangeError(`${name} must be a positive finite number, got: ${value}`);
  }
  return value;
}

2. Argument Validation (before serialization)

function validateSerializable(value: unknown): void {
  if (typeof value === 'number' && !Number.isFinite(value)) {
    throw new BridgeProtocolError(`Cannot serialize ${value} - NaN/Infinity not supported`);
  }
}

3. Response Validation (during deserialization)

  • Python bridge rejects NaN/Infinity in JSON responses
  • JS codec validates numeric values on decode

Acceptance Criteria

  • All bridge constructors validate numeric options (timeoutMs, maxLineLength, etc.)
  • BridgeCore.send() validates arguments before serialization
  • Python bridge returns explicit error for non-finite numbers
  • Codec rejects NaN/Infinity during decode
  • All 5 related issues can be closed

Scope

This fix touches:

  • src/runtime/node.ts - constructor validation
  • src/runtime/bridge-core.ts - argument validation
  • runtime/python_bridge.py - response validation
  • src/utils/codec.ts - decode validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions