Dashboard › opencode-lore › Distillation
bd0a2481-2fbd-49f3-9fbd-9d269a374ef5["lore_tm_v1_v9DeGa60Qu5lgRexbEVgqV76tbJz5KUKY6Vd_JdLllA","lore_tm_v1_sxZ8nw5hfeTTa9UwBYwmTVcPp8o1oy8y_AkHEJ5zwhs","lore_tm_v1_nFa3CLbC5ZCih74F5uW0nMELd3wIxRQH-JuvH-mho7U"]
Date: Sep 17, 2026
packages/core/src/embedding-worker.ts:730-753 applies layerNorm(output, [fullDim]), optionally slices to [0, dimensions], then L2-normalizes with .normalize(2, -1); it extracts one copied Float32Array(dim) per input text from the batched tensor.processEmbed() in packages/core/src/embedding-worker.ts:756-828 increments inflight, awaits ensurePipeline(), posts { type: "started", id: req.id }, truncates via truncateTexts(req.texts, req.maxTokens ?? maxTokens), runs one inference attempt, and posts the resulting vectors.processEmbed() deliberately does not retry OOM in the same worker because WASM linear memory does not shrink and may remain exhausted or fragmented; an OOM causes process.exit(EMBED_OOM_EXIT_CODE) without first posting a per-request error, allowing the main thread to respawn a fresh worker and resubmit the pending request.stderrSilenced, emit console.debug("[lore] ONNX OOM at β€${effectiveMax} tokens (batch=${req.texts.length}, longestβ${longest} chars) β respawning worker at a lower cap"); the parent reconstructs OOM telemetry from the pending request.processEmbed() suppresses per-request errors when initFailed or wasmRespawnRequested; this preserves requests awaiting forced WASM respawn. The canonical predicate is shouldPostPerRequestError() in embedding-worker-types.ts, with a drift guard pinning the inline condition to it.isWasmFatalError(raw) posts { type: "error", id, error: "WASM fatal error (worker exiting): ${raw}" } and exits with code 1, allowing the main thread to latch the provider as broken; ordinary nonfatal request errors post { type: "error", id, error: raw } and leave the worker serving.processEmbed() always decrements inflight and calls maybeExit() in finally; maybeExit() governs deferred shutdown once shutdownRequested is true and no inference remains active.packages/core/src/db.ts configures PRAGMA busy_timeout at lines 3013, 4692, 4753, 4850, 4884, and 5251; no-wait or shutdown/checkpoint paths set it to 0 at lines 4692, 4746, 4846, and 4880. The line 4689 comment explains that setting busy_timeout=0 first prevents a reader mid-query from causing an approximately 5-second busy wait.packages/core/src/embedding/pool.ts:523-548 implements one-shot token-batch checkpoints: takeTokenBatchCheckpoint(key) prunes, removes the checkpoint, and returns cloned vectors; storeTokenBatchCheckpoint(key, nextIndex, vectors) stores only when the pool is open, nextIndex > 0, and vectors.length === nextIndex, records updatedAt: Date.now(), clones vectors, and prunes the bounded checkpoint set.recordSlotSuccess() in packages/core/src/embedding/pool.ts:550-575 marks a slot healthy. If its recoveryGeneration matches localEmbeddingState.initFailureGeneration, it logs recovery after the exact accumulated failed-init count, resets initFailures and initRetryAt, clears the provider latch only for failureCause === "transient-init-exhausted", and resets errorLogged; success from an already in-flight sibling instead calls preserveHealthyServiceAfterExhaustion() so it does not erase another slotβs retry debt or admit immediate respawns.runOperation() in packages/core/src/embedding/pool.ts:577-657 arms an "init" watchdog for embedInitWatchdogMs, re-arms an "execution" watchdog for embedExecutionWatchdogMs through the provider callback, clamps timeout scheduling with Math.max(1, timeoutMs), calls unref?.(), and races slot.provider.embed(...) against the watchdog promise.AbortSignal when invoking slot.provider.embed(operation.texts, operation.inputType, undefined, ...): the operation retains ownership of the worker slot until native inference settles, while aborting callers own only their individual waiters.runOperation() marks the slot healthy and the operation "completed", records completedAt, retains cloned vectors only when operation.retainResult === true and no waiters remain, clears owned texts, settles every waiter, and either prunes retained completions or removes the operation from the deduplication map.runOperation() removes the matching operation, clears texts and vectors, normalizes non-Error failures to new Error("embedding worker operation failed"), rejects all waiters, and retires the slot only for LocalProviderUnavailableError or EmbeddingWorkerWatchdogError; finally clears the watchdog, decrements slot.inflight, and redispatches.dispatch() in packages/core/src/embedding/pool.ts:659-708 is guarded against closure and reentrancy, drops queued operations with no waiters, and will not replace the final active slot or grow the pool while slots.length === 0 and retiredWorkers.size > 0, because a retiring worker still owns its native model and heap until exit is confirmed.pickSlot() raises EmbeddingWorkerRetryCooldownError, dispatch() schedules retry at error.retryAt and stops. Other slot-selection failures remove the queued operation and reject its waiters, using the thrown Error or a new LocalProviderUnavailableError; a busy selected slot also stops dispatch until later.embed() in packages/core/src/embedding/pool.ts:710-754 immediately rejects an already-aborted signal with EmbeddingRequestAbortedError and rejects a closing pool with LocalProviderUnavailableError("embedding pool is unavailable"). It clones the input texts, deduplicates by embeddingOperationKey(ownedTexts, inputType), and attaches callers to an existing operation when present."high" when isRecallEmbed(ownedTexts, inputType) is true and otherwise "normal"; byte size is the sum of Buffer.byteLength(text) for all texts. canEnqueueOperation(priority, byteSize) enforces queue capacity and rejects overflow with EmbeddingQueueCapacityError.hasHealthySlot() returns whether any slot has healthy === true.shutdown(timeoutMs = WORKER_SHUTDOWN_TIMEOUT_MS) in packages/core/src/embedding/pool.ts:760-803 is idempotent via shutdownPromise, marks the pool closing, clears retry dispatch, rejects all waiters with LocalProviderUnavailableError("embedding pool shut down"), empties operation payloads, queue state, operation mappings, and checkpoint vectors, then shuts down all active providers concurrently with Promise.allSettled.retiredWorkers.settle({ failureMessage: "embedding worker termination was not confirmed" }); active-provider and retired-worker termination failures are combined into AggregateError(failures, "embedding worker termination was not confirmed").