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.
fix(read): preserve Int64 precision for unsafe Longs in tool outputs #1220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
fix(read): preserve Int64 precision for unsafe Longs in tool outputs #1220
Changes from all commits
1f618fb31b183dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not just do
EJSON.stringify(value, { relaxed: false })? Yes that gives you verbose EJSON always which we may or may not want, but then we don't need custom code at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using { relaxed: false }\ would force all BSON values (including safe \Long\s, \Int32\s, \Double\s, etc.) to serialize into their verbose strict EJSON representations (e.g. {\count: {\: \42}}\ or {\value: {\: \123}}).
This significantly reduces output readability for downstream LLMs and increases client payload sizes. By using this targeted preprocessing helper, we retain the highly readable relaxed representations for all safe numbers and other BSON types, while strictly preventing precision loss for numbers that exceed JS safe integer limits.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compass has this concept called "semi-relaxed" which does a variation of what you're doing here and that's probably what we should be using everywhere we output JSON. ie. do relaxed: true except for these edge cases. But it does have the problem that something that reads the output could work fine for years and then suddenly encounter an int greater than 2^^53 for the first time which suddenly changes the output format and then their code blows up.
And it still has the readability problem because those values are suddenly in EJSON. So if LLMs don't deal well with seeing { $numberLong: "value" } then it still applies in that case - it just goes from common to rare. Which as I explained above isn't necessarily better.
I think the team should probably deal with all all content and structuredContent in one go. Make a decision and apply it everywhere consistently. Also make sure that output always contains structuredContent while at it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some code-pointers for Compass' solution for reference: https://github.com/mongodb-js/compass/blob/42405c4f6f3fef390e0a511ad1913a6ce865b6d6/packages/hadron-document/src/utils.ts#L48-L82
https://github.com/mongodb-js/compass/blob/42405c4f6f3fef390e0a511ad1913a6ce865b6d6/packages/hadron-document/src/utils.ts#L104-L148
So there's a little more to it but not much.