fix: handle WASM abort in embedding worker and suppress shutdown noise (#464)
## Problem
**Sentry Issues:**
- [LOREAI-GATEWAY-C](https://byk.sentry.io/issues/7478920553/) — 2
users, 92 events: `Worker embedding failed: Aborted(). Build with
-sASSERTIONS for more info.`
- [LOREAI-GATEWAY-Q](https://byk.sentry.io/issues/7489718633/) — 2
users, 29 events: `embedding worker shut down`
### Root Cause: LOREAI-GATEWAY-C (WASM Abort)
When ONNX runtime's WASM backend hits a fatal condition (e.g. assertion
failure, memory corruption), it calls `abort()` which throws
`"Aborted(). Build with -sASSERTIONS for more info."`. The existing
`isOomError()` function only matches numeric codes and explicit OOM
messages — it does **not** match `Aborted()`.
After an `Aborted()` error, the WASM runtime is in a corrupted state but
the worker stays alive. Every subsequent embedding request also fails
with the same error, generating unbounded Sentry events (92 from just 2
users).
### Root Cause: LOREAI-GATEWAY-Q (Shutdown Noise)
`shutdown()` rejects in-flight requests with `new Error("embedding
worker shut down")`. Fire-and-forget callers (`embedKnowledgeEntry`,
`embedDistillation`, `embedTemporalMessage`) catch these and call
`log.error()`, which forwards the Error to Sentry via
`captureException`. This is expected operational behavior, not a bug.
### Fix
1. **`embedding-worker.ts` — detect fatal WASM errors**: Added
`isWasmFatalError()` that matches `Aborted` and `RuntimeError` patterns.
When detected, the worker reports the error for the current request and
calls `process.exit(1)`. This triggers the main thread's `on("exit")`
handler which marks the provider as broken (`localProviderKnownBroken =
true`), stopping all future requests immediately.
2. **`embedding.ts` — `shutdown()` uses
`LocalProviderUnavailableError`**: Changed from plain `Error` to
`LocalProviderUnavailableError`, matching the error type used by all
other provider failure paths. This gives callers a consistent error type
for graceful degradation.
3. **`instrument.ts` — suppress embedding errors in Sentry
`beforeSend`**: Added `/embedding worker shut down/`, `/Worker embedding
failed/`, and `/LocalProviderUnavailableError/` to
`TRANSIENT_ERROR_PATTERNS`. These are operational errors (provider
unavailable, expected shutdown), not actionable bugs.
### Tests
- All 1810 tests pass, 0 failures
- Typecheck clean across all 4 packages B
Burak Yigit Kaya committed
b12bd016043568da15422ee39ed3b4e97063334e
Parent: 543a53d
Committed by GitHub <noreply@github.com>
on 5/23/2026, 10:47:45 PM