Dashboard › opencode-lore › Distillation
5278e359-cd28-4e90-b0ae-3f5d1c74f898["lore_tm_v1_xvgRiQlNAijPfbLD8ITYVAvm1yutvk4of-oWDhMnA3M","lore_tm_v1_fqckEclXYQKIL92fZG7C503b5UM7A0jJ39JTeklkynk","lore_tm_v1_340qG4oQXds4qFdhXeen9Jcj2ptueaASOv1ekdZ096M","lore_tm_v1_IKvl5g4UEuSN6hbJ7p08fp97szzd26u3z3aFl8qBqDY"]
Date: September 16, 2026
packages/core/src/embedding/local.ts: CommonJS uses __filename, which is always defined; ESM uses import.meta.url.script/bundle.ts always defines the relevant import.meta compatibility value; a shim keeps the source natural.testWorkerFactory is a test seam that is never set in production and allows deterministic fake workers.exit(1) emitted after terminating a native worker during WASM fallback—must never clobber the fresh worker.0.7 down to MIN_EMBED_TOKENS, then latches FTS-only mode, ensuring recovery can never loop unbounded or create an event storm.packages/core/src/embedding/local.ts: failures such as a model read racing a concurrent writer during a multi-instance restart or momentary memory pressure retry with a fresh worker after a cooldown rather than disabling local embeddings for the process lifetime.localEmbeddingState.initFailures and localEmbeddingState.initFailureGeneration; reaching LOCAL_INIT_MAX_ATTEMPTS calls latchLocalProvider("transient-init-exhausted"), resets localEmbeddingState.initRetryAt to 0, and logs the terminal error only once through localEmbeddingState.errorLogged.computeInitRetryDelayMs(localEmbeddingState.initFailures, localInitCooldownMs), sets localEmbeddingState.initRetryAt = Date.now() + retryDelayMs, and warns that recall remains FTS-only until retry.this.pendingRequests with LocalProviderUnavailableError(errorMsg), clears the map, calls this.updateWorkerRef(), and invokes this.onUnavailable?.().respawnForWasm() in packages/core/src/embedding/local.ts: it detaches the dead worker, clears this.initPromise, and explicitly resets this.workerReady = false before ensureWorker() so the WASM worker cannot be skipped and pending requests cannot be lost.trackRetiredWorkerTermination(dead) retains ownership of the old worker generation so final shutdown joins it and fails closed if Node cannot confirm exit.spawned worker and returns early after this.worker advances to a new generation, preventing the terminated native worker’s asynchronous exit(1) from latching the provider broken or clobbering the fresh WASM worker (#1387-B1).LocalProviderUnavailableError("embedding worker respawn failed after WASM fallback") and clears this.pendingRequests, because the local embed path has no timeout to settle them otherwise.p.payload.maxTokens = this.effectiveMaxTokens(); a postMessage() failure is converted to an error message and passed to this.handleInitError(errorMsg).trackRetiredWorkerTermination() uses this.retiredWorkers.retireOnce(worker, async () => await worker.terminate()); settleRetiredWorkers(timeoutMs) uses timeout message "retired embedding worker did not settle before shutdown deadline" and failure message "embedding worker termination was not confirmed".LocalProvider.embed() behavior in packages/core/src/embedding/local.ts: an already-aborted signal throws EmbeddingRequestAbortedError; after ensureWorker(), a closing provider or absent worker throws LocalProviderUnavailableError("embedding worker closed during initialization").packages/core/test/embedding-wasm-fallback.test.ts: tests verify 1. init-needs-wasm respawns with forceWasm: true, terminates the native worker, and resubmits the in-flight request; 2. forceWasm remains sticky through a later OOM respawn; 3. a second init-needs-wasm after WASM is already active becomes a genuine initialization failure with no respawn loop; 4. the provider remains available under the real protocol sequence of init-needs-wasm, a trailing per-request error, and termination exit.exit(1) with queueMicrotask().