[PR #559] fix(quickjs): resolve BigInt serialization crashes in REPL results an… #560

Open
opened 2026-06-05 17:23:44 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/559
Author: @noishey
Created: 5/30/2026
Status: 🔄 Open

Base: mainHead: fix/bigint-quickjs-serialization


📝 Commits (8)

  • 0f47e22 fix(quickjs): resolve BigInt serialization crashes in REPL results and logs
  • f8a25f3 chore(changeset): add patch changeset for @langchain/quickjs
  • 8f16977 chore: trigger security checks
  • 3408e1a fix(deepagents): resolve tsconfig duplicate definition index.d.ts overwrite error by adding paths mapping
  • cc38d32 Merge branch 'main' into fix/bigint-quickjs-serialization
  • fd36a37 fix(quickjs): fast-path BigInt in safeDump to avoid guest JSON fallback
  • a87b13b Update libs/deepagents/tsconfig.json
  • bd325ce Merge branch 'main' into fix/bigint-quickjs-serialization

📊 Changes

5 files changed (+192 additions, -17 deletions)

View changed files

.changeset/bigint-quickjs-serialization-fix.md (+5 -0)
📝 libs/providers/quickjs/src/session.test.ts (+27 -0)
📝 libs/providers/quickjs/src/session.ts (+92 -11)
📝 libs/providers/quickjs/src/utils.test.ts (+54 -5)
📝 libs/providers/quickjs/src/utils.ts (+14 -1)

📄 Description

…d logs

Description

Resolves Issue #558: BigInt values crash QuickJS interpreter result serialization.

This PR adds safe BigInt serialization and formatting within the @langchain/quickjs code interpreter. Prior to this fix, the interpreter would throw a TypeError: Do not know how to serialize a BigInt inside 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

  • Safe JSON Stringifier: Introduced stringifyJson in utils.ts to cleanly stringify nested objects containing bigint primitives by mapping them to strings instead of crashing.
  • Primitive BigInt Support: Updated formatReplResult to print primitive BigInt cell evaluations without surrounding quotes (matching standard number styling).
  • Resilient safeDump VM Bridge:
    • Implemented a custom safeDump(handle) on ReplSession in session.ts.
    • When standard context.dump() encounters serialization limits for objects containing BigInt and falls back to returning "[object Object]", safeDump automatically invokes a custom guest-side stringifier to prefix bigints with a sentinel ("__BIGINT__:").
    • The host cleanly parses and revives these sentinel string patterns back into native host-side bigint values.
    • Avoids relying on context.isEqual, preserving support for the asyncify WASM variant.
  • Direct Safe Stringification in Host-Paths: Replaced standard JSON.stringify inside host console listeners and tool result extractions with stringifyJson.

Verification & Tests

Automated Tests Added

  • Unit Tests (utils.test.ts):
    • Validated that primitive bigint cell results are formatted cleanly without quotes.
    • Validated that nested arrays/objects containing bigint types serialize to formatted JSON.
  • Integration Tests (session.test.ts):
    • Validated that evaluating 9007199254740993n + 7n yields a native host bigint (9007199254741000n).
    • Validated that evaluating objects/arrays containing bigints correctly returns the fully revived host object with native bigint properties.
    • Validated that console logging deep objects containing bigint properties behaves correctly.

Results

All 206 unit/integration tests and type-checks successfully passed.

pnpm --filter @langchain/quickjs typecheck  # Success (0 errors)
pnpm --filter @langchain/quickjs test       # Success (206/206 passed)
pnpm test                                   # Success (1500+ monorepo tests passed)


---

<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/559 **Author:** [@noishey](https://github.com/noishey) **Created:** 5/30/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/bigint-quickjs-serialization` --- ### 📝 Commits (8) - [`0f47e22`](https://github.com/langchain-ai/deepagentsjs/commit/0f47e222f0c8eea934d8d9d761d44fd2fbdf1554) fix(quickjs): resolve BigInt serialization crashes in REPL results and logs - [`f8a25f3`](https://github.com/langchain-ai/deepagentsjs/commit/f8a25f31b0c08250cf8f768da814c7b60df3f588) chore(changeset): add patch changeset for @langchain/quickjs - [`8f16977`](https://github.com/langchain-ai/deepagentsjs/commit/8f1697759c8edfb6f33b54b4c20b00f94810e68f) chore: trigger security checks - [`3408e1a`](https://github.com/langchain-ai/deepagentsjs/commit/3408e1aa54e631f23b31d2b0f0ebbd65b934a8dc) fix(deepagents): resolve tsconfig duplicate definition index.d.ts overwrite error by adding paths mapping - [`cc38d32`](https://github.com/langchain-ai/deepagentsjs/commit/cc38d32f2f461719c94f5bea6b5e293ba7eed643) Merge branch 'main' into fix/bigint-quickjs-serialization - [`fd36a37`](https://github.com/langchain-ai/deepagentsjs/commit/fd36a377b6c0da9549b736ca390ad61d62058aad) fix(quickjs): fast-path BigInt in safeDump to avoid guest JSON fallback - [`a87b13b`](https://github.com/langchain-ai/deepagentsjs/commit/a87b13b067356d346be6537fea33b9080c307e31) Update libs/deepagents/tsconfig.json - [`bd325ce`](https://github.com/langchain-ai/deepagentsjs/commit/bd325ce030bd76f254e4e6303663d9f2d6b43030) Merge branch 'main' into fix/bigint-quickjs-serialization ### 📊 Changes **5 files changed** (+192 additions, -17 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/bigint-quickjs-serialization-fix.md` (+5 -0) 📝 `libs/providers/quickjs/src/session.test.ts` (+27 -0) 📝 `libs/providers/quickjs/src/session.ts` (+92 -11) 📝 `libs/providers/quickjs/src/utils.test.ts` (+54 -5) 📝 `libs/providers/quickjs/src/utils.ts` (+14 -1) </details> ### 📄 Description …d logs # Description Resolves [Issue #558: BigInt values crash QuickJS interpreter result serialization](https://github.com/langchain-ai/deepagentsjs/issues/558). This PR adds safe BigInt serialization and formatting within the `@langchain/quickjs` code interpreter. Prior to this fix, the interpreter would throw a `TypeError: Do not know how to serialize a BigInt` inside 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 * **Safe JSON Stringifier**: Introduced `stringifyJson` in `utils.ts` to cleanly stringify nested objects containing `bigint` primitives by mapping them to strings instead of crashing. * **Primitive BigInt Support**: Updated `formatReplResult` to print primitive BigInt cell evaluations without surrounding quotes (matching standard number styling). * **Resilient `safeDump` VM Bridge**: - Implemented a custom `safeDump(handle)` on `ReplSession` in `session.ts`. - When standard `context.dump()` encounters serialization limits for objects containing BigInt and falls back to returning `"[object Object]"`, `safeDump` automatically invokes a custom guest-side stringifier to prefix bigints with a sentinel (`"__BIGINT__:"`). - The host cleanly parses and revives these sentinel string patterns back into native host-side `bigint` values. - Avoids relying on `context.isEqual`, preserving support for the asyncify WASM variant. * **Direct Safe Stringification in Host-Paths**: Replaced standard `JSON.stringify` inside host console listeners and tool result extractions with `stringifyJson`. --- ## Verification & Tests ### Automated Tests Added * **Unit Tests (`utils.test.ts`)**: - Validated that primitive `bigint` cell results are formatted cleanly without quotes. - Validated that nested arrays/objects containing `bigint` types serialize to formatted JSON. * **Integration Tests (`session.test.ts`)**: - Validated that evaluating `9007199254740993n + 7n` yields a native host `bigint` (`9007199254741000n`). - Validated that evaluating objects/arrays containing bigints correctly returns the fully revived host object with native `bigint` properties. - Validated that console logging deep objects containing `bigint` properties behaves correctly. ### Results All 206 unit/integration tests and type-checks successfully passed. ```bash pnpm --filter @langchain/quickjs typecheck # Success (0 errors) pnpm --filter @langchain/quickjs test # Success (206/206 passed) pnpm test # Success (1500+ monorepo tests passed) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:23:44 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#560