[GH-ISSUE #558] BigInt values crash QuickJS interpreter result serialization #278

Open
opened 2026-06-05 17:21:25 -04:00 by yindo · 1 comment
Owner

Originally created by @luizzappa on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/558

BigInt values crash QuickJS interpreter result serialization

Summary

The @langchain/quickjs code interpreter can throw when a REPL result, captured console output, or programmatic tool-call result contains a JavaScript BigInt.

The failure happens because some interpreter output paths use JSON.stringify(...) directly, and native JSON serialization does not support bigint.

Error

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at formatReplResult (...)

Reproduction

Ask an agent using the QuickJS interpreter to evaluate a BigInt result:

Use the JavaScript interpreter to calculate 9007199254740993n + 7n and show the result.

Or directly return an object containing BigInt values:
({ count: 12345678901234567890n, nested: [2n, 3n] })

Expected Behavior

The interpreter should return a formatted result without crashing. For example:

{
  "count": "12345678901234567890",
  "nested": ["2", "3"]
}

Actual Behavior

The interpreter throws:
TypeError: Do not know how to serialize a BigInt
This can bubble up as a tool execution failure and interrupt the agent run.

Likely Cause

formatReplResult(...) and other result formatting paths call JSON.stringify(...) without a replacer:

JSON.stringify(result.value, null, 2)

The same issue can occur when stringifying:

  • REPL return values
  • captured console.* object arguments
  • programmatic tool-call results injected into the REPL

Suggested Fix

Use a shared safe JSON stringifier that converts bigint values to strings:

function stringifyJson(value, space) {
  return JSON.stringify(
    value,
    (_, item) => typeof item === "bigint" ? item.toString() : item,
    space
  );
}

Then replace direct result-formatting calls to JSON.stringify(...) with this helper.

Environment

  • Package: @langchain/quickjs
  • Version observed: 0.4.0
  • Runtime: browser / bundled app, also reproducible via Node import of formatReplResult
Originally created by @luizzappa on GitHub (May 29, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/558 ## BigInt values crash QuickJS interpreter result serialization ### Summary The `@langchain/quickjs` code interpreter can throw when a REPL result, captured console output, or programmatic tool-call result contains a JavaScript `BigInt`. The failure happens because some interpreter output paths use `JSON.stringify(...)` directly, and native JSON serialization does not support `bigint`. ### Error ```text TypeError: Do not know how to serialize a BigInt at JSON.stringify (<anonymous>) at formatReplResult (...) ``` ### Reproduction Ask an agent using the QuickJS interpreter to evaluate a `BigInt` result: `Use the JavaScript interpreter to calculate 9007199254740993n + 7n and show the result.` Or directly return an object containing BigInt values: `({ count: 12345678901234567890n, nested: [2n, 3n] })` ### Expected Behavior The interpreter should return a formatted result without crashing. For example: ```json { "count": "12345678901234567890", "nested": ["2", "3"] } ``` ### Actual Behavior The interpreter throws: `TypeError: Do not know how to serialize a BigInt` This can bubble up as a tool execution failure and interrupt the agent run. ### Likely Cause `formatReplResult(...)` and other result formatting paths call `JSON.stringify(...)` without a replacer: `JSON.stringify(result.value, null, 2)` The same issue can occur when stringifying: - REPL return values - captured console.* object arguments - programmatic tool-call results injected into the REPL ### Suggested Fix Use a shared safe JSON stringifier that converts `bigint` values to strings: ```js function stringifyJson(value, space) { return JSON.stringify( value, (_, item) => typeof item === "bigint" ? item.toString() : item, space ); } ``` Then replace direct result-formatting calls to `JSON.stringify(...)` with this helper. ### Environment - Package: `@langchain/quickjs` - Version observed: `0.4.0` - Runtime: browser / bundled app, also reproducible via Node import of `formatReplResult`
Author
Owner

@noishey commented on GitHub (May 30, 2026):

I can pick this issue.

<!-- gh-comment-id:4582853052 --> @noishey commented on GitHub (May 30, 2026): I can pick this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#278