Skip to content

fix(server): floatRepr spells non-finite floats as Python's repr does - #604

Merged
ashhart merged 1 commit into
ashhart:mainfrom
chaog992:floatrepr-nonfinite
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
chaog992:floatrepr-nonfinite

Conversation

@chaog992

Copy link
Copy Markdown
Contributor

What this changes

floatRepr in zig/src/server/json_write.zig renders a float in scientific form and parses the exponent after the e. NaN and ±inf render as nan and inf, which have no e, so the slice at json_write.zig:116 starts past the end and panics; the server module is built ReleaseSafe, so that ends the process. The callers that render a value as Python's str() does (tool_specs.pyStr, decisions.zig:135, serve.zig:192, tool_params.zig:223) pass non-finite values on without a check.

floatRepr now returns nan, inf or -inf for them, which is Python's repr and the spelling pyrepr.zig already writes. JSON output is unchanged, because floatJson spells NaN and Infinity before it calls floatRepr. Every finite float renders as before.

Receipt

  • Environment: base 2f8284e8, fix c7f583d0, Zig 0.17.0, Linux x86_64 under WSL2. No GPU or model is needed.
  • Tests: zig build test passes 37/37 steps and 358/358 tests. bash zig/tests/server/zig_test.sh passes 108 and 84 tests, as on the base; the change adds three rows (NaN, inf, -inf) to the existing float repr table test.
  • Failing receipt: that test on the unfixed floatRepr:
    json_write.test.float repr...thread … panic: start index 4 is larger than end index 3
    zig/src/server/json_write.zig:116:42: … in floatRepr (root.zig)
    
  • Lean check: python3 tools/zig/lean_check.py reports 1057 files and 542 problems on the base, and the same list with this change.
  • Format and cross-compilation: zig fmt --check zig/src/server/json_write.zig passes. The Zig format job already fails on main itself, on files this change does not touch. The server tests compile for aarch64-macos with -mcpu apple_m1 --test-no-exec; this is a compile check, not a macOS test run.
  • Not run: the macOS host tests (including test-golden) and a served model on Metal or CUDA. The change touches no inference path.

@ashhart ashhart mentioned this pull request Oct 10, 2026
@ashhart
ashhart merged commit ee1d4b9 into ashhart:main Oct 10, 2026
1 of 2 checks passed
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @chaog992. This is merged into main (ee1d4b9), your commit as it was, and it ships in 1.0.6. A NaN reaching any of the str() paths took the whole server down, so this was well worth finding, and the failing receipt on the float repr table made it quick to confirm. The host gates pass with it on a Mac (golden 309 of 319 equal, no unexpected differences), and JSON output is unchanged because floatJson spells non-finite values before it calls floatRepr, as you said.

philip-pentatonic pushed a commit to machinegenieorg/TensorFold that referenced this pull request Oct 10, 2026
@chaog992
chaog992 deleted the floatrepr-nonfinite branch October 12, 2026 14:34
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants