Dashboard › opencode-lore › Distillation
625e9f33-9cee-44e9-acf1-e094679f6447["lore_tm_v1_K8JiizvEMs66TcueiVIzsNvly0VKlV9ry_AP6WgYTao","lore_tm_v1_zgf91Sp6EgilPafHQq5qXTP2jBuCWYJ_N5EpkldDINQ","lore_tm_v1_drlQB2_XS7NMZAXaf31rOhOkllESvCfOczUe-5fcEVo","lore_tm_v1_Ww-cPyX7B2rJcm5NDbv3Lfroap4vBPhYNjqoTJmcUKI","lore_tm_v1_9i1V7bd1GGth7-9vr6d3UQAXbwoFMiXVYGCr3663-B0"]
Date: Sep 16, 2026
packages/core/src/embedding/local.ts: CommonJS uses __filename because it is always defined there; ESM uses import.meta.url, with the bundle shim keeping the source natural.packages/core/src/embedding/local.ts is for tests and is never set in production.exit(1) emitted by terminate() during a WASM fallback respawn in #1379/#1387-B1—to never clobber the fresh worker’s state.LocalProvider.trackRetiredWorkerTermination() in packages/core/src/embedding/local.ts delegates each ShutdownableWorker to this.retiredWorkers.retireOnce() and awaits worker.terminate(); settleRetiredWorkers(timeoutMs) reports timeout message retired embedding worker did not settle before shutdown deadline and failure message embedding worker termination was not confirmed.LocalProvider.embed() immediately throws EmbeddingRequestAbortedError for an already-aborted signal, awaits ensureWorker(), and throws LocalProviderUnavailableError("embedding worker closed during initialization") if closing or no worker remains.maybeReprobeCap() without respawning, truncates every input via safeLocalTruncate() before inference, prepends search_document: for documents or search_query: for queries, assigns id = this.nextRequestId++, and gives single query-type recall requests high priority while all others receive normal priority.EmbedRequest payloads include type: "embed", id, prefixed texts, inputType, priority, and maxTokens: this.effectiveMaxTokens(); the per-request cap accounts for current free memory and the worker’s pool share because sibling workers/live sessions may allocate after construction and native over-allocation can cause an uncatchable SIGKILL.settled guard. Cleanup removes the signal’s abort listener; abortion deletes the request from pendingRequests, updates the worker reference, and rejects with EmbeddingRequestAbortedError.LocalProvider.embed() stores each request’s resolve, reject, payload, and optional onExecutionStart in pendingRequests, registers the abort listener with { once: true }, rechecks abortion after registration, and posts payload satisfies WorkerInbound.worker.postMessage() races with worker termination, LocalProvider.embed() calls handleInitError("embedding worker terminated before request could be sent") so callers receive the expected graceful-degradation error type.LocalProvider.shutdown(timeoutMs = WORKER_SHUTDOWN_TIMEOUT_MS) is idempotent through shutdownPromise; it marks the provider closing/not ready, clears workerInitError, rejects every in-flight request with LocalProviderUnavailableError("embedding worker shut down"), and clears pendingRequests.worker.unref() before awaitWorkerShutdown(worker, timeoutMs), and concurrently waits for retired workers. One termination failure is rethrown directly; multiple failures produce AggregateError(..., "embedding worker termination was not confirmed").packages/core/src/embedding/pool.ts defines MAX_WAITERS_PER_EMBED_OPERATION = 64 and includes deterministic test controls such as _setPoolFreememForTest(bytes) and _setEmbeddingWorkerWatchdogsForTest(...).ceiling; deterministic test overrides bypass the memory gate, explicit config/environment ceilings are clamped, and production growth is memory-gated. liveFreemem() combines freemem(), constrainedMemoryLimit(), availableMemoryHeadroom(), and clampFreeToContainerLimit(); if a positive constraint exists but headroom is unavailable, it returns 0.LocalProvider receives the pool ceiling as its memory divisor so every worker sizes its token cap from free / ceiling; because the ceiling itself is selected by desiredEmbedPoolSize, provisioned workers collectively remain within one EMBED_MEM_FRACTION share of free memory.EmbeddingPool.takeTokenBatchCheckpoint(key) prunes checkpoints, removes the selected checkpoint for one-time consumption, and returns cloned vectors. storeTokenBatchCheckpoint(key, nextIndex, vectors) only stores when the pool is open, nextIndex > 0, and vectors.length === nextIndex; it clones vectors and timestamps the checkpoint.COMPLETED_EMBED_REUSE_MS, retains at most the newest MAX_COMPLETED_EMBED_RESULTS, and clears vector arrays on expired or excess entries to release memory.EmbeddingPool.recordSlotSuccess() marks a slot healthy. A matching recovery generation clears initFailures, initRetryAt, and errorLogged, logs the number of failed init attempts, and calls clearLocalProviderLatch() when failureCause === "transient-init-exhausted"; success from an already in-flight sibling preserves another slot’s retry debt rather than admitting immediate respawns.EmbeddingPool.runOperation() uses a watchdog with stages "init" and "execution"; timeout logging is embedding worker watchdog expired: stage=${stage} timeout_ms=${timeoutMs}, and expiration rejects with EmbeddingWorkerWatchdogError(stage). Timers use Math.max(1, timeoutMs) and unref?.().AbortSignal when invoking slot.provider.embed(...): the operation retains ownership of the worker slot until native inference settles, while callers own only their waiters. The watchdog switches from initialization to execution through the provider’s onExecutionStart callback.runOperation() records slot health, marks the operation completed, records completedAt, optionally retains cloned vectors only when retainResult === true and no waiters remain, clears input texts, settles all waiters, and either prunes retained completed operations or deletes the operation.Error (or new Error("embedding worker operation failed")), and the slot is retired for either LocalProviderUnavailableError or EmbeddingWorkerWatchdogError; the watchdog is cleared, slot.inflight is decremented, and dispatch resumes in finally.closing and dispatching; it drops queued operations with no waiters. If no active slots remain while retired workers still own native model/heap memory, dispatch pauses rather than replacing the last slot or exceeding the ceiling before retirement is confirmed.pickSlot() throws EmbeddingWorkerRetryCooldownError, dispatch schedules retry at error.retryAt and stops. Other slot-selection errors remove the queued operation, delete it from the operation map, settle all waiters with the owned error or LocalProviderUnavailableError, and continue.EmbeddingPool.embed() rejects pre-aborted calls with EmbeddingRequestAbortedError and closed-pool calls with LocalProviderUnavailableError("embedding pool is unavailable"). It copies inputs with texts.slice(), deduplicates operations by embeddingOperationKey(ownedTexts, inputType), and attaches callers to an existing operation when the key matches.high priority for recall embeds and normal otherwise, compute UTF-8 byte size with Buffer.byteLength(text), reject over-capacity work with EmbeddingQueueCapacityError, and store key, copied texts, byteSize, inputType, priority, state: "queued", and a waiter Set.EmbeddingPool.hasHealthySlot() returns whether any slot has healthy === true.EmbeddingPool.shutdown(timeoutMs = WORKER_SHUTDOWN_TIMEOUT_MS) is idempotent, marks the pool closing, clears the retry-dispatch timer, settles all operation waiters with LocalProviderUnavailableError("embedding pool shut down"), clears queued text/vector data, resets queue and queuedBytes, clears operations and checkpoint vectors, and shuts down all active providers concurrently.retiredWorkers.settle({ failureMessage: "embedding worker termination was not confirmed" }); any failures are combined into AggregateError(..., "embedding worker termination was not confirmed").