Skip to content

fix(tracing): serialize big integers as strings to prevent Traces dashboard precision loss#2960

Closed
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-2094-bigint-trace-serialization
Closed

fix(tracing): serialize big integers as strings to prevent Traces dashboard precision loss#2960
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-2094-bigint-trace-serialization

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented Apr 19, 2026

Summary

Fixes #2094

When a tool is called with integer arguments that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53 − 1 = 9007199254740991), the OpenAI Traces dashboard loses precision because it parses the JSON number as an IEEE-754 double. For example, 9007199254740993 would display as 9007199254740992.

Root Cause

FunctionSpanData.export() serializes tool call arguments as a JSON string (self.input). Python integers can be arbitrarily large, but when the resulting JSON is consumed by JavaScript, any integer > 2^53 − 1 is silently truncated.

Fix

In FunctionSpanData.export() (src/agents/tracing/span_data.py), before re-emitting the input JSON:

  1. Parse the stored JSON string back to a Python object.
  2. Walk the object recursively with _sanitize_bigint(), converting any int whose absolute value exceeds _JS_MAX_SAFE_INTEGER to its decimal string representation.
  3. Re-serialize to JSON.

bool is checked before int (since bool is a subclass of int in Python) so True/False are never converted.

Malformed JSON in self.input is caught and passed through unchanged, preserving existing behavior.

Testing

  • 31 existing tracing tests pass without modification.
  • No changes to the public API or any other span type.

Example

# Before fix — JS dashboard receives 9007199254740992 (wrong)
span_data = FunctionSpanData(name="tool", input='{"id": 9007199254740993}')
span_data.export()["input"]  # '{"id": 9007199254740993}'  ← JS truncates this

# After fix — JS dashboard receives the string "9007199254740993" (correct)
span_data.export()["input"]  # '{"id": "9007199254740993"}'

@github-actions github-actions bot added bug Something isn't working feature:tracing labels Apr 19, 2026
@seratch seratch added the duplicate This issue or pull request already exists label Apr 20, 2026
@seratch seratch closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working duplicate This issue or pull request already exists feature:tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traces dashboard shows big integer arguments incorrectly in tool calling traces

2 participants