fix(tracing): serialize big integers as strings to prevent Traces dashboard precision loss#2960
Closed
xodn348 wants to merge 1 commit intoopenai:mainfrom
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,9007199254740993would display as9007199254740992.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:_sanitize_bigint(), converting anyintwhose absolute value exceeds_JS_MAX_SAFE_INTEGERto its decimal string representation.boolis checked beforeint(sinceboolis a subclass ofintin Python) soTrue/Falseare never converted.Malformed JSON in
self.inputis caught and passed through unchanged, preserving existing behavior.Testing
Example