fix(quickjs): resolve BigInt serialization crashes in REPL results an…#559
Open
Arjun Shenoy (noishey) wants to merge 10 commits into
Open
fix(quickjs): resolve BigInt serialization crashes in REPL results an…#559Arjun Shenoy (noishey) wants to merge 10 commits into
Arjun Shenoy (noishey) wants to merge 10 commits into
Conversation
🦋 Changeset detectedLatest commit: f90e3ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
deepagents-acp
deepagents
@langchain/sandbox-standard-tests
@langchain/daytona
@langchain/deno
@langchain/modal
@langchain/node-vfs
@langchain/quickjs
commit: |
Author
|
Please Review The PR. |
…rwrite error by adding paths mapping
Comment on lines
+736
to
+780
| private safeDump(handle: QuickJSHandle): unknown { | ||
| const context = this.context!; | ||
| const value = context.dump(handle); | ||
| if (value === "[object Object]") { | ||
| try { | ||
| const stringifyFn = context.evalCode(` | ||
| (val) => JSON.stringify(val, (k, v) => typeof v === "bigint" ? "__BIGINT__:" + v.toString() : v) | ||
| `); | ||
| if (stringifyFn.error) { | ||
| stringifyFn.error.dispose(); | ||
| return value; | ||
| } | ||
| const stringified = context.callFunction( | ||
| stringifyFn.value, | ||
| context.undefined, | ||
| handle, | ||
| ); | ||
| stringifyFn.value.dispose(); | ||
|
|
||
| if (stringified.error) { | ||
| stringified.error.dispose(); | ||
| return value; | ||
| } | ||
|
|
||
| const typeofStringified = context.typeof(stringified.value); | ||
| if (typeofStringified === "undefined") { | ||
| stringified.value.dispose(); | ||
| return value; | ||
| } | ||
|
|
||
| const jsonStr = context.getString(stringified.value); | ||
| stringified.value.dispose(); | ||
|
|
||
| return JSON.parse(jsonStr, (_k, v) => { | ||
| if (typeof v === "string" && v.startsWith("__BIGINT__:")) { | ||
| return BigInt(v.slice(11)); | ||
| } | ||
| return v; | ||
| }); | ||
| } catch { | ||
| return value; | ||
| } | ||
| } | ||
| return value; | ||
| } |
Member
There was a problem hiding this comment.
what is this for? Context values don't get serialized at .dump so we shouldn't need to indirect to bigint handling here?
Co-authored-by: Hunter Lovell <40191806+hntrl@users.noreply.github.com>
Signed-off-by: Arjun Shenoy <arjunshenoy23@gmail.com>
2355cfc to
f90e3ef
Compare
Author
|
Hunter Lovell (@hntrl) please check the merging of this PR #559 |
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.
…d logs
Description
Resolves Issue #558: BigInt values crash QuickJS interpreter result serialization.
This PR adds safe BigInt serialization and formatting within the
@langchain/quickjscode interpreter. Prior to this fix, the interpreter would throw aTypeError: Do not know how to serialize a BigIntinside standard host-side stringification paths (formatReplResult,setupConsole,extractToolText), and return"[object Object]"for nested objects containing bigints due to Emscripten bridge JSON limitations.Key Changes
stringifyJsoninutils.tsto cleanly stringify nested objects containingbigintprimitives by mapping them to strings instead of crashing.formatReplResultto print primitive BigInt cell evaluations without surrounding quotes (matching standard number styling).safeDumpVM Bridge:safeDump(handle)onReplSessioninsession.ts.context.dump()encounters serialization limits for objects containing BigInt and falls back to returning"[object Object]",safeDumpautomatically invokes a custom guest-side stringifier to prefix bigints with a sentinel ("__BIGINT__:").bigintvalues.context.isEqual, preserving support for the asyncify WASM variant.JSON.stringifyinside host console listeners and tool result extractions withstringifyJson.Verification & Tests
Automated Tests Added
utils.test.ts):bigintcell results are formatted cleanly without quotes.biginttypes serialize to formatted JSON.session.test.ts):9007199254740993n + 7nyields a native hostbigint(9007199254741000n).bigintproperties.bigintproperties behaves correctly.Results
All 206 unit/integration tests and type-checks successfully passed.