Skip to content

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

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#2959
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
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8fc567fefe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +185 to +187
try:
sanitized_input = json.dumps(_sanitize_bigint(json.loads(self.input)))
except (json.JSONDecodeError, TypeError):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Broaden sanitize error handling to avoid export thread crashes

FunctionSpanData.export() now assumes json.loads(self.input) only fails with JSONDecodeError/TypeError, but valid-yet-pathological inputs can also raise exceptions like RecursionError (very deep nesting) or ValueError (very large integer literals on Python 3.11+). In those cases this method raises instead of falling back to raw self.input, and because exporter paths call item.export() without guarding per-item failures in the batch worker, one such span can terminate trace exporting for subsequent spans.

Useful? React with 👍 / 👎.

@seratch
Copy link
Copy Markdown
Member

seratch commented Apr 20, 2026

This is a server-side issue, we won't manipulate the data on the client side.

@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 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