Skip to content

Conversation

@disconcision
Copy link
Member

@disconcision disconcision commented Jan 19, 2026

Closes #2066

BigInteger.js objects lose their prototype methods (like .lt()) when passed through postMessage's structured clone algorithm. This caused crashes when displaying large integers in evaluation results. Starting in v0.17.0, zarith_stubs_js switched to using native JavaScript BigInt instead of BigInteger.js. Native BigInt is a primitive type that fully survives structured clone. However, we cannot simply upgrade to zarith_stubs_js v0.17.0 due to versioning issues described in bigint-webworker-fix.md, so instead for now we'll vendor the runtime.js from zarith_stubs_js v0.17.0 and copy it into the opam switch at build time.

BigInteger.js objects lose their prototype methods (like .lt()) when
passed through postMessage's structured clone algorithm. This caused
crashes when displaying large integers in evaluation results.

Add BigIntShim module that serializes BigInts to tagged objects before
postMessage and reconstructs them using zarith's jsoo_z_of_js_string_base
after receiving.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.49%. Comparing base (32d1743) to head (199ff81).
⚠️ Report is 22 commits behind head on dev.

Files with missing lines Patch % Lines
src/web/util/WorkerServer.re 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2071      +/-   ##
==========================================
+ Coverage   50.47%   50.49%   +0.02%     
==========================================
  Files         229      229              
  Lines       25189    25188       -1     
==========================================
+ Hits        12713    12719       +6     
+ Misses      12476    12469       -7     
Files with missing lines Coverage Δ
src/web/util/WorkerServer.re 4.76% <0.00%> (+0.21%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

disconcision and others added 4 commits January 27, 2026 19:54
Replace the O(n) BigIntShim serialization workaround with a vendored
zarith_stubs_js runtime that uses native JavaScript BigInt instead of
BigInteger.js. Native BigInt survives structured clone (postMessage),
eliminating the need for manual serialization.

- Vendor zarith_stubs_js v0.17.0 runtime.js (uses native BigInt)
- Add setup-zarith Makefile target to install vendored runtime
- Remove BigIntShim.re and its usage in WorkerClient/WorkerServer
- Update CI workflow to run setup-zarith before build
- Add docs/bigint-webworker-fix.md explaining the approach

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Clarify that it's js_of_ocaml-compiler (not js_of_ocaml itself) that
has the ocaml < 5.2 constraint in versions before 5.7.0.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The 'different BigInt library' option was misleading since zarith is the
standard OCaml library and the issue was the JS backend, not zarith itself.
The Comlink option was an obscure reference that added confusion.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The constraint issue is specific to bonsai v0.17.0 on opam. The master
branch has been updated to require js_of_ocaml >= 6.0.0, so a future
release will resolve this.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@disconcision disconcision requested a review from cyrus- January 28, 2026 03:08
Copy link
Member

@cyrus- cyrus- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • licensing of the vendored library

@cyrus-
Copy link
Member

cyrus- commented Jan 28, 2026

update the PR description

@claude
Copy link

claude bot commented Jan 29, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

The vendored file from zarith_stubs_js v0.17.0 was missing its license.
Added the MIT license header from Jane Street as required for proper
attribution.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@disconcision
Copy link
Member Author

@cyrus- (MIT) license added, PR description changed

@cyrus- cyrus- merged commit 369f3dd into dev Feb 4, 2026
4 of 5 checks passed
@cyrus- cyrus- deleted the fix-2066 branch February 4, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception when entering large ints

2 participants