fix(ruvector-gnn): RuvectorLayer constructor panics instead of returning Result
Summary
MultiHeadAttention::new() and RuvectorLayer::new() in ruvector-gnn use assert!() / panic!() for input validation instead of returning Result. When called from NAPI-RS or WASM bindings, this causes a fatal abort() that crashes the entire host process — no try/catch can intercept it.
Reproduction
const { RuvectorLayer } = require('@ruvector/gnn');
// This kills the process — no exception, just abort()
const layer = new RuvectorLayer(384, 128, 3, 0.1);
// hidden_dim=128 is NOT divisible by heads=3 → panic
thread '<unnamed>' panicked at crates/ruvector-gnn/src/layer.rs:97:9:
Embedding dimension must be divisible by number of heads
fatal runtime error: failed to initiate panic, error 5, aborting
Aborted (core dumped)
Root Cause
Two issues:
- Rust-side (
crates/ruvector-gnn/src/layer.rs):MultiHeadAttention::new()usesassert!()instead ofResult— panics across FFI boundary = process abort - JS-side (downstream
agentdbGNNService): passesconfig.layers(=3) as theheadsparameter instead ofconfig.heads, so128 % 3 ≠ 0triggers the panic
Fix
MultiHeadAttention::new()→ returnsResult<Self, GnnError>RuvectorLayer::new()→ returnsResult<Self, GnnError>- All WASM/NAPI wrappers propagate errors as catchable JS exceptions
- Also fixed pre-existing
mmap.rstest compilation errors (grad_offset returnsOption<usize>)
Affected Versions
@ruvector/[email protected](all platforms)ruvector-gnn(Rust crate)
Impact
| Surface | Before | After |
|---|---|---|
| Native Rust | panic!() → process abort |
Err(GnnError::LayerConfig(...)) |
| NAPI-RS (Node.js) | abort() → uncatchable crash |
Catchable napi::Error |
| WASM | WASM trap | Catchable JsError |
Additional finding in ruvector 0.2.12 (Windows win32-x64):
The fix described in this issue may not have shipped correctly in 0.2.12. On Windows, the constructor is completely non-functional — not panicking, just missing:
const { gnnWrapper } = require('ruvector');
// gnnWrapper.RuvectorLayer exists as a property...
console.log(typeof gnnWrapper.RuvectorLayer); // "function"
// ...but instantiation fails with non-panic error:
new gnnWrapper.RuvectorLayer(384, 128);
// Error: NativeRuvectorLayer is not a constructor
// Same for TensorCompress:
new gnnWrapper.TensorCompress();
// Error: NativeTensorCompress is not a constructor
// And differentiableSearch:
gnnWrapper.differentiableSearch(vectors, query, 2);
// Error: nativeDifferentiableSearch is not a function
However, isGnnAvailable() returns true and isNative() returns true, which is misleading since the native constructors don't work.
Environment: ruvector 0.2.12, Node.js 22.17.1, Windows MINGW64 win32-x64
This may be a Windows-specific binary packaging issue — the JS wrappers exist but the native .node bindings they delegate to may not have been included for win32-x64.