fix(tracing): serialize big integers as strings to prevent Traces dashboard precision loss#2959
Conversation
There was a problem hiding this comment.
💡 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".
| try: | ||
| sanitized_input = json.dumps(_sanitize_bigint(json.loads(self.input))) | ||
| except (json.JSONDecodeError, TypeError): |
There was a problem hiding this comment.
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 👍 / 👎.
|
This is a server-side issue, we won't manipulate the data on the client side. |
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