Skip to content

bug: ESM wasm/ path missing .wasm binary + benchmarkEquality() unreachable trap in v0.3.2 #2

@JLMA-Agentic-Ai

Description

@JLMA-Agentic-Ai

Environment

  • Package: lean-agentic@0.3.2
  • Node.js: v24.15.0
  • OS: Ubuntu 22.04 (Linux x86_64)

Bug 1: ESM entry point references wasm/ directory which is missing the .wasm binary

Root Cause

dist/index.mjs line 9 imports from ../wasm/leanr_wasm.js, but the wasm/ directory only contains JS glue — no .wasm binary:

wasm/
leanr_wasm.js ← JS glue only, no binary
leanr_wasm.d.ts

wasm-node/
leanr_wasm.js
leanr_wasm_bg.wasm ← binary lives here
leanr_wasm_bg.wasm.d.ts
package.json

dist/index.js (CJS) correctly uses ../wasm-node/leanr_wasm.js and works. The ESM counterpart uses the wrong path, causing any ESM import to fail to load the WASM module.

Suggested fix

--- a/dist/index.mjs
+++ b/dist/index.mjs
-import * as wasm from '../wasm/leanr_wasm.js';
+import { createRequire } from 'module';
+const _req = createRequire(import.meta.url);
+const wasm = _req('../wasm-node/leanr_wasm.js');

Or update the build pipeline so the ESM output resolves to wasm-node/ consistently with the CJS build.


Bug 2: benchmarkEquality() always throws RuntimeError: unreachable

Reproduction (CJS, isolated fresh instance)

const { LeanDemo } = require('lean-agentic/wasm-node/leanr_wasm.js');
const d = new LeanDemo();
d.benchmarkEquality();
// → RuntimeError: unreachable

Tested on a fresh instance with no prior method calls. Every invocation traps immediately.

Stack trace

RuntimeError: unreachable
at wasm://wasm/leandemo_benchmarkEquality
at LeanDemo.benchmarkEquality (wasm-node/leanr_wasm.js:204)

Analysis

The Rust benchmark_equality function appears to contain an unreachable!() stub or is behind a feature flag not compiled into the published .wasm. The JS wrapper calls wasm.leandemo_benchmarkEquality(this.__wbg_ptr) — the symbol resolves but traps immediately.

Workaround

demonstrateHashConsing() on a fresh isolated instance works:
const d = new LeanDemo();
d.demonstrateHashConsing();
// → "Hash-consing test: var1=TermId(0), var2=TermId(0), same=true"


Summary

┌──────────────────────────────────────┬────────────────────────────┬──────────────────────────────┐
│ Bug │ Severity │ Workaround │
├──────────────────────────────────────┼────────────────────────────┼──────────────────────────────┤
│ ESM wasm/ path missing .wasm binary │ High — ESM imports broken │ Use CJS (require) │
├──────────────────────────────────────┼────────────────────────────┼──────────────────────────────┤
│ benchmarkEquality() unreachable trap │ Medium — function unusable │ Use demonstrateHashConsing() │
└──────────────────────────────────────┴────────────────────────────┴──────────────────────────────┘

Happy to test a fix if a patch or pre-release is available.


Both bugs were confirmed by direct reproduction against the installed v0.3.2 package. The ESM/CJS path split and the unreachable trap are both real and reproducible on Node 24.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions