Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(client-runtime): preserve negative zero in JSON tool output #48234

Opensaphid(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48234/headopened View on GitHub

Problem

Expanded tool results in the work log silently turn an explicitly signed negative zero (-0, -0.0e9) in raw JSON text into positive 0. Because decimalKey normalizes every zero mantissa to "0" without its sign, hasLossyJson treats negative zero as lossless and lets JSON.stringify drop the minus sign.

Deterministic repro on origin/main (9a08ffb84084c441dcf4a2f595682a44632ecc89):

  • Call turnItemOutputText (reached by apps/web/src/components/chat/V2ItemInspector.tsx, apps/mobile/src/features/threads/thread-work-log.tsx, and apps/mobile/src/features/threads/LinkedThreadSheet.tsx) on a dynamic_tool item whose output is { content: [{ type: "text", text: '{"reading":-0}' }] } (or '{"reading":-0.0e9}', '[1,-0,2]'), or return that text block from a local ACP/MCP tool and expand the result row.
  • Observed on origin/main: {\n "reading": 0\n} (and [\n 1,\n 0,\n 2\n]).
  • Expected: Keep the original JSON text ({"reading":-0}, {"reading":-0.0e9}, [1,-0,2]) so the minus sign is preserved, while still pretty-printing ordinary positive zero ({"reading":0,"note":"-0"}).

Change

Treat Object.is(value, -0) as lossy in hasLossyJson inside packages/client-runtime/src/work-log/itemDetail.ts so prettyJsonText preserves the original JSON text whenever a number parses to -0. Because Web/Electron (V2ItemInspector.tsx) and mobile (thread-work-log.tsx, LinkedThreadSheet.tsx) all format expanded tool results through turnItemOutputText in @t3tools/client-runtime, this single-line change covers every client surface.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Extended the parameterized cases in packages/client-runtime/src/work-log/itemDetail.test.ts with {"reading":-0}, {"reading":-0.0e9}, [1,-0,2], and the control case {"reading":0,"note":"-0"}.
  • Base (9a08ffb84084c441dcf4a2f595682a44632ecc89): vp test run packages/client-runtime/src/work-log/itemDetail.test.ts -t "tool text output formatting" failed on all 3 negative-zero cases (expected '{\n "reading": 0\n}' to be '{"reading":-0}', etc.); the positive-zero control passed.
  • Head (2bb05f80a66167b971e4a0ce71a11e4bd11d43c6): the same targeted run passed (22/22), and vp run check:changed exited 0 (format, lint, knip, typecheck across 7 affected packages, and 58/58 tests in itemDetail.test.ts).
  • Before/after transcript: https://gist.github.com/saphid/9843d0d488967a2c2c41b3c1339b2807
  • Not shown: Interactive Web/Electron and mobile UI screenshots were not captured because the change is confined to the shared turnItemOutputText formatter and verified at the unit layer.

Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • docs/internals/15_testing.md:48 — The draft gives a formatter repro and names the UI surfaces, but the transcript has no real-client capture or scenarios:prove run. For repeatable app proof, seed a completed text-only MCP result with content: [{ type: "text", text: '{"reading":-0}' }] and no structured content; expand its work-log row and assert the displayed result retains -0.
  • .github/pull_request_template.md:18 — The linked transcript corroborates the focused red/green run, but does not include the reported vp run check:changed exit-0 summary. Attach that summary with the exact HEAD SHA so the broader validation is independently auditable.
    1. tanstack-source added labelsbug

    2. Approvability

      Verdict: Approved at 2bb05f8

      Macroscope's review found this PR approvable — Preserves original JSON tool text when reformatting would erase negative zero. The change is confined to display formatting, with no storage or tool-execution changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The change updates hasLossyJson to detect parsed negative zero and adds tests for negative-zero numbers and the string "-0".

      Changes: JSON formatting

      Layer / File(s)Summary
      Negative-zero handling
      packages/client-runtime/src/work-log/itemDetail.ts, packages/client-runtime/src/work-log/itemDetail.test.ts
      hasLossyJson now treats parsed negative zero as lossy. Tests cover numeric negative zero in multiple forms and confirm that "-0" inside a string does not prevent pretty-printing.

      Estimated code review effort: 2 (Simple) | ~5 minutes

      Change: Bug fix

      Suggested reviewers: only21mil, yash-singh1

      Merge Risk: Minimal · up to 2bb05

      This change keeps a minus sign on zero in expanded tool output instead of dropping it. No merge-blocking risk was found.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title "fix(client-runtime): preserve negative zero in JSON tool output" matches the main change: hasLossyJson now treats Object.is(value, -0) as lossy so prettyJsonText keeps the original JSON tex…
      Description checkPassedThe description follows the template's Problem, Change, Scope, and Verification sections. It explains the bug with a deterministic repro, names the one-line fix in packages/client-runtime/src/work-log…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title "fix(client-runtime): preserve negative zero in JSON tool output" matches the main change: hasLossyJson now treats Object.is(value, -0) as lossy so prettyJsonText keeps the original JSON text containing -0. It is a conventional commit title in plain language and names the package and the behavior.

      Full details: Description check

      Explanation

      The description follows the template's Problem, Change, Scope, and Verification sections. It explains the bug with a deterministic repro, names the one-line fix in packages/client-runtime/src/work-log/itemDetail.ts, justifies the lack of a linked issue as a small obvious fix, and reports targeted test results plus a check:changed exit 0 at the head SHA. The template's note on UI evidence is addressed by stating that no screenshots were captured and why. Remaining gaps: the reviewer notes flag that the broader check:changed summary is not attached with the exact SHA, and that no real-client or end-to-end proof was captured for the MCP result path.

      Resolution

      Optional improvements: attach the vp run check:changed exit-0 output with the exact head SHA, and if feasible add a real-client check that expands a completed text-only MCP result containing -0 and confirms the displayed result keeps the minus sign.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 9a08ffb84084c441dcf4a2f595682a44632ecc89 and 2bb05f80a66167b971e4a0ce71a11e4bd11d43c6.

      Files selected for processing: 2

      • packages/client-runtime/src/work-log/itemDetail.test.ts
      • packages/client-runtime/src/work-log/itemDetail.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Sign in to join this conversation.