@adhd/sox-embedding-provider 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/embedHostConfig.d.ts +120 -0
  2. package/dist/embedHostConfig.d.ts.map +1 -0
  3. package/dist/embedHostConfig.js +180 -0
  4. package/dist/embedHostConfig.js.map +1 -0
  5. package/dist/embedHostMain.d.ts +46 -0
  6. package/dist/embedHostMain.d.ts.map +1 -0
  7. package/dist/embedHostMain.js +192 -0
  8. package/dist/embedHostMain.js.map +1 -0
  9. package/dist/errors.d.ts +25 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +35 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/fastembed.d.ts.map +1 -1
  14. package/dist/fastembed.js +3 -0
  15. package/dist/fastembed.js.map +1 -1
  16. package/dist/fastembedLock.d.ts +47 -0
  17. package/dist/fastembedLock.d.ts.map +1 -1
  18. package/dist/fastembedLock.js +35 -0
  19. package/dist/fastembedLock.js.map +1 -1
  20. package/dist/fastembedProcessHost.d.ts.map +1 -1
  21. package/dist/fastembedProcessHost.js +33 -12
  22. package/dist/fastembedProcessHost.js.map +1 -1
  23. package/dist/funnelClient.d.ts +97 -0
  24. package/dist/funnelClient.d.ts.map +1 -0
  25. package/dist/funnelClient.js +311 -0
  26. package/dist/funnelClient.js.map +1 -0
  27. package/dist/index.d.ts +27 -12
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +43 -39
  30. package/dist/index.js.map +1 -1
  31. package/dist/onnxStderrFilter.d.ts +79 -0
  32. package/dist/onnxStderrFilter.d.ts.map +1 -0
  33. package/dist/onnxStderrFilter.js +101 -0
  34. package/dist/onnxStderrFilter.js.map +1 -0
  35. package/dist/package.json +8 -2
  36. package/dist/sharedFastembedProcess.d.ts +70 -32
  37. package/dist/sharedFastembedProcess.d.ts.map +1 -1
  38. package/dist/sharedFastembedProcess.js +174 -52
  39. package/dist/sharedFastembedProcess.js.map +1 -1
  40. package/package.json +9 -3
@@ -0,0 +1,311 @@
1
+ /**
2
+ * funnelClient.ts — the host-aware `SharedFastembedClient` (SPEC-EMBEDDING-FUNNEL.md §D).
3
+ *
4
+ * A drop-in `SharedFastembedClient` that transparently dials — and, when absent,
5
+ * peer-spawns — the ONE machine-wide embedding host for `(model, ep, cacheDir)`.
6
+ * It is the consumer half of the funnel: N processes each hold a
7
+ * `FunneledFastembedClient`, but `ensureBackend()`'s O_EXCL spawn-lock collapses
8
+ * their concurrent spawn attempts to a single detached host, and the host
9
+ * reaps itself once the last client leaves (see `embedHostMain.ts`).
10
+ *
11
+ * ── Honest failure, never a silent private re-fork ─────────────────────────────
12
+ *
13
+ * Under the default `host: 'shared'`, a failure to bring the host up throws a
14
+ * typed `TransientEmbeddingError` naming the socket — it does NOT fall back to
15
+ * forking a private host. A silent fallback would defeat the entire funnel
16
+ * (each of 535 short-lived CLIs/day would quietly become its own ONNX host) and
17
+ * is exactly the behaviour this design removes. `host: 'private'` is the
18
+ * explicit, typed CI/diagnostics selection (ADR-0013 closed union).
19
+ *
20
+ * ── Circuit breaker ────────────────────────────────────────────────────────────
21
+ *
22
+ * After `ENSURE_FAILURE_THRESHOLD` consecutive failed ensures, the client fails
23
+ * fast with a typed error for `ENSURE_CIRCUIT_COOLDOWN_MS` rather than paying
24
+ * the full `ensureBackend` ready-timeout on every call. The breaker is
25
+ * per-process (a short-lived CLI cannot share it) — it bounds a retrying
26
+ * consumer, not the fleet; that is stated here rather than implied.
27
+ *
28
+ * Leaf module — `@adhd/sox-service-proxy` + node builtins.
29
+ */
30
+ import { dialBackend, ensureBackend, probeSocketLive } from '@adhd/sox-service-proxy';
31
+ import { TransientEmbeddingError, PermanentEmbeddingError } from './errors.js';
32
+ import { embedHostSingletonKey, embedHostSocketPath, resolveEmbedHostConfig, resolveEmbedHostMainPath, resolveEmbedHostStderrLogPath, } from './embedHostConfig.js';
33
+ /** Consecutive failed ensures before the breaker opens. */
34
+ export const ENSURE_FAILURE_THRESHOLD = 3;
35
+ /** How long the breaker stays open (fail-fast window) once tripped. */
36
+ export const ENSURE_CIRCUIT_COOLDOWN_MS = 10_000;
37
+ /** Bound on bringing the host up (`ensureBackend`'s readyTimeoutMs). */
38
+ export const HOST_READY_TIMEOUT_MS = 10_000;
39
+ /** Per-probe connect timeout. */
40
+ const PROBE_TIMEOUT_MS = 250;
41
+ /** Bound on a control call (reset/health) — never hang the caller. */
42
+ const CONTROL_TIMEOUT_MS = 5_000;
43
+ /**
44
+ * The last-constructed funnel client. `resetSharedFastembedHost()` targets it.
45
+ * Production constructs exactly one (via `getSharedFastembedProcess()`); tests
46
+ * that construct extras simply re-point it, which is why the reset helper is
47
+ * explicitly documented as operating on the current accessor client.
48
+ */
49
+ let _activeClient = null;
50
+ /** TEST-ONLY: clear the active-client reference. */
51
+ export function __resetActiveFunnelClientForTests() {
52
+ _activeClient = null;
53
+ }
54
+ /** Extract a host/model/error message safely. */
55
+ function msg(err) {
56
+ return err instanceof Error ? err.message : String(err);
57
+ }
58
+ export class FunneledFastembedClient {
59
+ conn = null;
60
+ socketPath = null;
61
+ initContext = null;
62
+ ensurePromise = null;
63
+ _started = false;
64
+ _pending = 0;
65
+ nextId = 1;
66
+ consecutiveEnsureFailures = 0;
67
+ circuitOpenUntil = 0;
68
+ constructor() {
69
+ _activeClient = this;
70
+ }
71
+ /** True once the host has been resolved and the dial connection established. */
72
+ get started() {
73
+ return this._started;
74
+ }
75
+ /** In-flight request count on THIS consumer (not the host's). */
76
+ get pendingCount() {
77
+ return this._pending;
78
+ }
79
+ /** The resolved host socket path, or `null` before the first successful ensure. */
80
+ get hostSocketPath() {
81
+ return this.socketPath;
82
+ }
83
+ async request(payload, timeoutMs, signal) {
84
+ const type = typeof payload['type'] === 'string' ? payload['type'] : '';
85
+ if (type === 'init') {
86
+ // The host's identity is keyed on (model, ep, cacheDir), all carried by
87
+ // the init payload. Record it so `ensureHost()` can compute the key; a
88
+ // non-init first request is a programming error, reported honestly below.
89
+ if (!this.initContext) {
90
+ this.initContext = {
91
+ model: String(payload['model'] ?? ''),
92
+ cacheDir: String(payload['cacheDir'] ?? ''),
93
+ };
94
+ }
95
+ }
96
+ await this.ensureHost();
97
+ const conn = this.conn;
98
+ if (!conn) {
99
+ // ensureHost() guarantees a connection or throws; this is unreachable but
100
+ // keeps the type honest rather than asserting.
101
+ throw new TransientEmbeddingError(`embedding funnel: no connection to host at ${this.socketPath ?? '(unresolved)'}`);
102
+ }
103
+ const id = `embed-funnel-${this.nextId++}`;
104
+ const request = { jsonrpc: '2.0', id, method: `embedding.${type}`, params: payload };
105
+ this._pending++;
106
+ try {
107
+ const resp = await this.awaitResponse(conn.send(request), id, timeoutMs, signal);
108
+ const error = resp.error;
109
+ if (error)
110
+ throw this.mapError(error);
111
+ return resp.result;
112
+ }
113
+ finally {
114
+ this._pending--;
115
+ }
116
+ }
117
+ /**
118
+ * NO-OP by design: under `host: 'shared'` the host is shared with every other
119
+ * consumer on the machine — a consumer must never kill it. Its lifetime is
120
+ * governed solely by its own debounced, ref-counted teardown
121
+ * (`embedHostMain.ts`). Kept to satisfy `SharedFastembedClient`.
122
+ */
123
+ async terminate() {
124
+ // Intentionally empty — see the method doc.
125
+ }
126
+ // ── internals ───────────────────────────────────────────────────────────────
127
+ mapError(error) {
128
+ const where = this.socketPath ?? '(unresolved socket)';
129
+ if (error.code === -32001) {
130
+ return new TransientEmbeddingError(`embedding host unavailable at ${where}: ${error.message}`, 1_000);
131
+ }
132
+ if (error.code === -32601) {
133
+ return new PermanentEmbeddingError(`embedding host does not implement the method: ${error.message}`);
134
+ }
135
+ // Application error from the private ONNX host (e.g. "Model not
136
+ // initialized") — preserve the pre-funnel `new Error(message)` shape so
137
+ // `FastembedProvider.initModel()`'s catch/retry logic is unchanged.
138
+ return new Error(error.message);
139
+ }
140
+ awaitResponse(pending, id, timeoutMs, signal) {
141
+ return new Promise((resolve, reject) => {
142
+ let settled = false;
143
+ let timer = null;
144
+ const onAbort = () => {
145
+ if (settled)
146
+ return;
147
+ settle();
148
+ reject(signal?.reason instanceof Error
149
+ ? signal.reason
150
+ : new TransientEmbeddingError(`embedding funnel request ${id} aborted`));
151
+ };
152
+ const settle = () => {
153
+ settled = true;
154
+ if (timer)
155
+ clearTimeout(timer);
156
+ if (signal)
157
+ signal.removeEventListener('abort', onAbort);
158
+ };
159
+ if (timeoutMs !== undefined && timeoutMs > 0) {
160
+ timer = setTimeout(() => {
161
+ if (settled)
162
+ return;
163
+ settle();
164
+ reject(new TransientEmbeddingError(`embedding funnel request timed out after ${timeoutMs}ms`, timeoutMs));
165
+ }, timeoutMs);
166
+ }
167
+ if (signal) {
168
+ if (signal.aborted) {
169
+ onAbort();
170
+ return;
171
+ }
172
+ signal.addEventListener('abort', onAbort, { once: true });
173
+ }
174
+ pending.then((resp) => {
175
+ if (settled)
176
+ return;
177
+ settle();
178
+ resolve(resp);
179
+ }, (err) => {
180
+ if (settled)
181
+ return;
182
+ settle();
183
+ reject(new TransientEmbeddingError(`embedding funnel transport error: ${msg(err)}`, 1_000));
184
+ });
185
+ });
186
+ }
187
+ /** Idempotent: resolves once a host is live and dialed, or throws typed. */
188
+ ensureHost() {
189
+ if (this._started && this.conn?.isConnected())
190
+ return Promise.resolve();
191
+ if (this.ensurePromise)
192
+ return this.ensurePromise;
193
+ this.ensurePromise = this.doEnsure().finally(() => {
194
+ this.ensurePromise = null;
195
+ });
196
+ return this.ensurePromise;
197
+ }
198
+ async doEnsure() {
199
+ if (Date.now() < this.circuitOpenUntil) {
200
+ throw new TransientEmbeddingError(`embedding funnel circuit open for ${this.circuitOpenUntil - Date.now()}ms more after ` +
201
+ `${this.consecutiveEnsureFailures} consecutive ensure failures`, this.circuitOpenUntil - Date.now());
202
+ }
203
+ const cfg = resolveEmbedHostConfig();
204
+ const ctx = this.initContext;
205
+ if (!ctx) {
206
+ throw new TransientEmbeddingError('embedding funnel requires an {type:"init"} request before any other request ' +
207
+ '(the host is keyed on model + cacheDir, which only init carries)');
208
+ }
209
+ const ep = process.env['SOX_EMBED_EXECUTION_PROVIDER'] ?? 'auto';
210
+ const key = embedHostSingletonKey(ctx.model, ep, ctx.cacheDir);
211
+ const socketPath = embedHostSocketPath(cfg, key);
212
+ if (this.socketPath !== socketPath) {
213
+ // The identity changed (a different model/ep/cacheDir). Drop the old dial
214
+ // and re-point. The old host is NOT killed — it self-reaps.
215
+ this.conn?.close();
216
+ this.conn = null;
217
+ this._started = false;
218
+ this.socketPath = socketPath;
219
+ }
220
+ const live = await probeSocketLive(socketPath, PROBE_TIMEOUT_MS);
221
+ if (!live) {
222
+ const result = await ensureBackend({
223
+ socketPath,
224
+ singletonKey: key,
225
+ command: process.execPath,
226
+ args: [resolveEmbedHostMainPath()],
227
+ env: { ...process.env, SOX_EMBED_HOST_SOCKET: socketPath, SOX_EMBED_HOST_KEY: key },
228
+ stderrLogPath: resolveEmbedHostStderrLogPath(cfg),
229
+ readyTimeoutMs: HOST_READY_TIMEOUT_MS,
230
+ });
231
+ if (result.disposition === 'failed') {
232
+ this.noteEnsureFailure();
233
+ throw new TransientEmbeddingError(`embedding funnel could not bring up a host at ${socketPath}: ${result.detail}`, 1_000);
234
+ }
235
+ }
236
+ this.consecutiveEnsureFailures = 0;
237
+ if (!this.conn) {
238
+ this.conn = dialBackend({
239
+ socketPath,
240
+ onDisconnect: () => {
241
+ // The host may have self-reaped (idle) or crashed. The next request's
242
+ // `send()` re-dials and, on failure, re-ensures. Mark unstarted so
243
+ // `ensureHost()` runs the full probe/spawn path again.
244
+ this._started = false;
245
+ },
246
+ });
247
+ }
248
+ this._started = true;
249
+ }
250
+ noteEnsureFailure() {
251
+ this.consecutiveEnsureFailures++;
252
+ if (this.consecutiveEnsureFailures >= ENSURE_FAILURE_THRESHOLD) {
253
+ this.circuitOpenUntil = Date.now() + ENSURE_CIRCUIT_COOLDOWN_MS;
254
+ }
255
+ }
256
+ /**
257
+ * Ask the live host to tear down and re-fork its PRIVATE pool, then drop this
258
+ * consumer's connection so the next request re-dials the (still-live) host.
259
+ * No-op when no host has been resolved. Public so the module-level
260
+ * `resetSharedFastembedHost()` can target the accessor client.
261
+ */
262
+ async resetHost() {
263
+ if (!this.socketPath)
264
+ return;
265
+ try {
266
+ await this.control('embedding.reset');
267
+ }
268
+ catch {
269
+ // Best-effort: an unreachable host has either reaped (fine) or is wedged;
270
+ // dropping the connection lets the next request re-ensure.
271
+ }
272
+ finally {
273
+ this.dropConnection();
274
+ }
275
+ }
276
+ /**
277
+ * Send a control method (`embedding.reset` / `embedding.health`) to the live
278
+ * host, bounded. Returns the result, or `null` when no host is resolved.
279
+ */
280
+ async control(method) {
281
+ if (!this.conn || !this.socketPath)
282
+ return null;
283
+ const id = `embed-funnel-ctl-${this.nextId++}`;
284
+ const resp = await this.awaitResponse(this.conn.send({ jsonrpc: '2.0', id, method }), id, CONTROL_TIMEOUT_MS, undefined);
285
+ const error = resp.error;
286
+ if (error)
287
+ throw this.mapError(error);
288
+ return (resp.result ?? {});
289
+ }
290
+ /**
291
+ * Drop this consumer's dial connection. The host stays alive.
292
+ */
293
+ dropConnection() {
294
+ this.conn?.close();
295
+ this.conn = null;
296
+ this._started = false;
297
+ }
298
+ }
299
+ /**
300
+ * Ask the peer-shared host to tear down and re-fork its PRIVATE pool, then drop
301
+ * this consumer's connection so the next request re-dials the (still-live) host.
302
+ *
303
+ * This is memory-core's heal entry point: under `host: 'shared'`,
304
+ * `terminate()` is a no-op (a consumer must never kill a shared host), so a
305
+ * wedged private child is recovered by asking the host to reset its own pool.
306
+ * A no-op when no host has been resolved yet — nothing to reset.
307
+ */
308
+ export async function resetSharedFastembedHost() {
309
+ await _activeClient?.resetHost();
310
+ }
311
+ //# sourceMappingURL=funnelClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"funnelClient.js","sourceRoot":"","sources":["../src/funnelClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,E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AAM,KAAK,GAAI,IAA6B,CAAC,KAAK,CAAC;QACnD,IAAI,KAAK;YAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACtC,OAAO,CAAE,IAA6B,CAAC,MAAM,IAAI,EAAE,CAAM,CAAC;IAC5D,CAAC;IAED;;OAEG;IACK,cAAc;QACpB,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB;IAC5C,MAAM,aAAa,EAAE,SAAS,EAAE,CAAC;AACnC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -14,6 +14,13 @@ export interface EmbeddingHealth {
14
14
  dimensions: number | null;
15
15
  last_error: string | null;
16
16
  execution_provider?: string;
17
+ /**
18
+ * The resolved host-selection posture (SPEC-EMBEDDING-FUNNEL.md): `'shared'`
19
+ * funnels through the peer-spawned host, `'private'` is the pre-funnel
20
+ * per-process fork. Reported so an operator can see the active mode from one
21
+ * call (ADR-0013 D2) — never inferred, never a placeholder.
22
+ */
23
+ host?: 'shared' | 'private';
17
24
  }
18
25
  export interface EmbeddingProvider {
19
26
  readonly metadata: EmbeddingProviderMetadata;
@@ -30,17 +37,15 @@ export interface EmbeddingProviderConfig {
30
37
  type: string;
31
38
  model: string;
32
39
  options?: Record<string, unknown>;
40
+ /**
41
+ * Host-selection posture (SPEC-EMBEDDING-FUNNEL.md; ADR-0013). Defaults to
42
+ * `'shared'` — funnel through the one peer-spawned, self-reaping host.
43
+ * `'private'` is the explicit pre-funnel per-process fork (CI/diagnostics);
44
+ * it is a closed union, never an env toggle, and is reported in `health()`.
45
+ */
46
+ host?: 'shared' | 'private';
33
47
  }
34
- export declare class TransientEmbeddingError extends Error {
35
- readonly retryAfterMs: number | undefined;
36
- constructor(message: string, retryAfterMs?: number);
37
- }
38
- export declare class PermanentEmbeddingError extends Error {
39
- constructor(message: string);
40
- }
41
- export declare class ResolutionError extends Error {
42
- constructor(message: string);
43
- }
48
+ export { TransientEmbeddingError, PermanentEmbeddingError, ResolutionError } from './errors.js';
44
49
  /**
45
50
  * Static registration for a fastembed ONNX model.
46
51
  * Each model has a known HF repo, dimension, context window, and description.
@@ -145,8 +150,18 @@ export { getSharedFastembedProcess, SharedFastembedProcessClient, resetSharedFas
145
150
  * `resolveFastembedPoolSize` (kept for backward compatibility) used to
146
151
  * compute as one value — see their doc comments for why the split exists.
147
152
  */
148
- export type { SharedFastembedClient } from './sharedFastembedProcess.js';
149
- export { FastembedProcessPool, AdaptiveFastembedProcessPool, type AdaptiveFastembedPoolOptions, FastembedBusyError, resolveFastembedPoolSize, resolveFastembedPoolPin, resolveFastembedPoolCeiling, resolveFastembedAdmissionLimit, } from './sharedFastembedProcess.js';
153
+ export type { SharedFastembedClient, PrivateFastembedProcess } from './sharedFastembedProcess.js';
154
+ export { getPrivateFastembedProcess, FastembedProcessPool, AdaptiveFastembedProcessPool, type AdaptiveFastembedPoolOptions, FastembedBusyError, resolveFastembedPoolSize, resolveFastembedPoolPin, resolveFastembedPoolCeiling, resolveFastembedAdmissionLimit, } from './sharedFastembedProcess.js';
155
+ /**
156
+ * The host-aware client and its heal entry point. `FunneledFastembedClient` is
157
+ * what `getSharedFastembedProcess()` returns by default (`host: 'shared'`):
158
+ * N processes share ONE peer-spawned, self-reaping ONNX host, and a consumer's
159
+ * `terminate()` is a no-op (it must never kill a shared host).
160
+ * `resetSharedFastembedHost()` is the heal path — it asks the live host to
161
+ * re-fork its private pool (memory-core's `reinitEmbedProvider` routes here).
162
+ */
163
+ export { FunneledFastembedClient, resetSharedFastembedHost } from './funnelClient.js';
164
+ export { resolveEmbedHostConfig, configureEmbedHostHost, resolveEmbedHostSocketDir, embedHostSingletonKey, embedHostSocketPath, resolveEmbedHostMainPath, resolveEmbedHostIdleGraceMs, EMBED_HOST_PROTOCOL_VERSION, type EmbedHostConfig, type EmbedHostMode, } from './embedHostConfig.js';
150
165
  export declare function createEmbeddingProvider(config: EmbeddingProviderConfig): Promise<EmbeddingProvider>;
151
166
  /**
152
167
  * Single source of truth for the fastembed warmup/init timeout budget.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAE7C,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;IACtD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,CAAC;IAC7C,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACnE,UAAU,CACR,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,SAAS,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9C,aAAa,CAAC,YAAY,CAAC,CAAC;IAC/B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAA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WG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAG7D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzE"}
package/dist/index.js CHANGED
@@ -3,27 +3,15 @@
3
3
  import { existsSync } from 'node:fs';
4
4
  import { homedir } from 'node:os';
5
5
  import { join } from 'node:path';
6
+ // Local binding so this module's own throws/type-guards use the SAME classes the
7
+ // barrel re-exports (one home — see `errors.ts`).
8
+ import { ResolutionError } from './errors.js';
9
+ import { configureEmbedHostHost } from './embedHostConfig.js';
6
10
  // ── Error taxonomy — three tiers, no silent degradation ──────────────────────
7
- export class TransientEmbeddingError extends Error {
8
- retryAfterMs;
9
- constructor(message, retryAfterMs) {
10
- super(message);
11
- this.name = 'TransientEmbeddingError';
12
- this.retryAfterMs = retryAfterMs;
13
- }
14
- }
15
- export class PermanentEmbeddingError extends Error {
16
- constructor(message) {
17
- super(message);
18
- this.name = 'PermanentEmbeddingError';
19
- }
20
- }
21
- export class ResolutionError extends Error {
22
- constructor(message) {
23
- super(message);
24
- this.name = 'ResolutionError';
25
- }
26
- }
11
+ // Defined in `errors.ts` so `funnelClient.ts` can throw them without importing
12
+ // this barrel (which re-exports the funnel client) — re-exported here so the
13
+ // public surface and `instanceof` identity are unchanged.
14
+ export { TransientEmbeddingError, PermanentEmbeddingError, ResolutionError } from './errors.js';
27
15
  // ── Re-exports ────────────────────────────────────────────────────────────────
28
16
  /**
29
17
  * @deprecated SOX-BUG-002: dead API, not used by `createEmbeddingProvider` or
@@ -52,12 +40,34 @@ export { getSharedOnnxWorker, SharedOnnxWorkerClient, resetSharedOnnxWorker } fr
52
40
  * root-cause writeup and rationale.
53
41
  */
54
42
  export { getSharedFastembedProcess, SharedFastembedProcessClient, resetSharedFastembedProcess, } from './sharedFastembedProcess.js';
55
- export { FastembedProcessPool, AdaptiveFastembedProcessPool, FastembedBusyError, resolveFastembedPoolSize, resolveFastembedPoolPin, resolveFastembedPoolCeiling, resolveFastembedAdmissionLimit, } from './sharedFastembedProcess.js';
43
+ export { getPrivateFastembedProcess, FastembedProcessPool, AdaptiveFastembedProcessPool, FastembedBusyError, resolveFastembedPoolSize, resolveFastembedPoolPin, resolveFastembedPoolCeiling, resolveFastembedAdmissionLimit, } from './sharedFastembedProcess.js';
44
+ // ── The embedding funnel (SPEC-EMBEDDING-FUNNEL.md) ────────────────────────────
45
+ /**
46
+ * The host-aware client and its heal entry point. `FunneledFastembedClient` is
47
+ * what `getSharedFastembedProcess()` returns by default (`host: 'shared'`):
48
+ * N processes share ONE peer-spawned, self-reaping ONNX host, and a consumer's
49
+ * `terminate()` is a no-op (it must never kill a shared host).
50
+ * `resetSharedFastembedHost()` is the heal path — it asks the live host to
51
+ * re-fork its private pool (memory-core's `reinitEmbedProvider` routes here).
52
+ */
53
+ export { FunneledFastembedClient, resetSharedFastembedHost } from './funnelClient.js';
54
+ export { resolveEmbedHostConfig, configureEmbedHostHost, resolveEmbedHostSocketDir, embedHostSingletonKey, embedHostSocketPath, resolveEmbedHostMainPath, resolveEmbedHostIdleGraceMs, EMBED_HOST_PROTOCOL_VERSION, } from './embedHostConfig.js';
56
55
  // ── Factory ───────────────────────────────────────────────────────────────────
57
56
  export async function createEmbeddingProvider(config) {
58
57
  if (!config.type || typeof config.type !== 'string') {
59
58
  throw new ResolutionError(`Invalid provider type: ${String(config.type)}`);
60
59
  }
60
+ // SPEC-EMBEDDING-FUNNEL.md / ADR-0013: apply the typed host-selection posture
61
+ // BEFORE the accessor singleton is first constructed. Process-wide (the host
62
+ // is shared by every provider in the process); reported in `health()`.
63
+ if (config.host !== undefined) {
64
+ try {
65
+ configureEmbedHostHost(config.host);
66
+ }
67
+ catch (err) {
68
+ throw new ResolutionError(`Invalid embedding host mode: ${err instanceof Error ? err.message : String(err)}`);
69
+ }
70
+ }
61
71
  switch (config.type) {
62
72
  case 'fastembed':
63
73
  return createFastembedProvider(config);
@@ -79,9 +89,19 @@ async function createFastembedProvider(config) {
79
89
  process.env['SOX_EMBED_CACHE_DIR'] ??
80
90
  joinDefaultCacheDir();
81
91
  try {
92
+ // SPEC-EMBEDDING-FUNNEL.md §E: NO eager warmup. Construction is deliberately
93
+ // INERT — it resolves the model's static metadata but does NOT load the ONNX
94
+ // model, and therefore does NOT spawn the shared embedding host. A host that
95
+ // constructs a provider but never embeds (e.g. `backlog query` on a read-only
96
+ // view) spawns zero hosts. The model loads — and the host spawns — on the
97
+ // first real `embedSingle`/`embedBatch`, via `FastembedProvider.ensureReady()`.
98
+ //
99
+ // Contract note (was: "throws ResolutionError at factory time if the model
100
+ // cannot load"): CONFIG errors (unknown model/type) still fail here at
101
+ // factory time. A MODEL-LOAD failure now surfaces on first use — still a
102
+ // loud, typed throw, never a silent downgrade — which is the cost of not
103
+ // paying a model load (and a host spawn) for a verb that never embeds.
82
104
  const provider = new FastembedProvider(modelId, cfg.dim, cacheDir);
83
- const cacheHit = isModelCached(cacheDir, cfg.hfRepoId);
84
- await withTimeout(provider.embedSingle('warmup'), warmupOuterBudgetMs(cacheHit), 'fastembed warmup');
85
105
  return provider;
86
106
  }
87
107
  catch (err) {
@@ -178,22 +198,6 @@ export function warmupOuterBudgetMs(cacheHit) {
178
198
  export function isModelCached(cacheDir, hfRepoId) {
179
199
  return existsSync(join(cacheDir, hfRepoId, 'model_optimized.onnx'));
180
200
  }
181
- function withTimeout(p, ms, label) {
182
- return new Promise((resolve, reject) => {
183
- const to = setTimeout(() => {
184
- reject(new Error(`${label} timed out after ${ms}ms`));
185
- }, ms);
186
- if (typeof to.unref === 'function')
187
- to.unref();
188
- p.then((v) => {
189
- clearTimeout(to);
190
- resolve(v);
191
- }, (e) => {
192
- clearTimeout(to);
193
- reject(e instanceof Error ? e : new Error(String(e)));
194
- });
195
- });
196
- }
197
201
  function joinDefaultCacheDir() {
198
202
  const xdg = process.env['XDG_CACHE_HOME'];
199
203
  return join(xdg ?? join(homedir(), '.cache'), 'sox', 'models');
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,iFAAiF;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA0CjC,gFAAgF;AAEhF,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACvC,YAAY,CAAqB;IAC1C,YAAY,OAAe,EAAE,YAAqB;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAmED,iFAAiF;AAEjF;;;;;GAKG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;GAOG;AACH,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE3G;;;;;;;;;GASG;AACH,OAAO,EACL,yBAAyB,EACzB,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,6BAA6B,CAAC;AAkBrC,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAE5B,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,2BAA2B,EA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fastembed child's inherited stderr,
4
+ * while forwarding every other byte through verbatim, unbuffered, and in
5
+ * order.
6
+ *
7
+ * ── Why this exists ─────────────────────────────────────────────────────────
8
+ *
9
+ * `sharedFastembedProcess.ts` forks `fastembedProcessHost.ts` with
10
+ * `resolveExecutionProviders()` returning `['coreml', 'cpu']` on darwin
11
+ * (`fastembedProcessHost.ts`). bge-base's `word_embeddings` tensor is shaped
12
+ * `{30522,768}`, and CoreML's execution provider cannot host any input
13
+ * dimension over 16384 — so onnxruntime's native CoreML EP logs, at EVERY
14
+ * model load:
15
+ *
16
+ * [W:onnxruntime:, helper.cc:83 IsInputSupported] CoreML does not support
17
+ * input dim > 16384. Input:embeddings.word_embeddings.weight,
18
+ * shape: {30522,768}
19
+ *
20
+ * This is emitted by the native onnxruntime addon straight to the process's
21
+ * real stderr fd (not through any JS logger this package controls), and
22
+ * `sharedFastembedProcess.ts` forks the child with
23
+ * `stdio: ['ignore', 'inherit', 'inherit', 'ipc']` — so it lands on every
24
+ * `adhd-backlog` (or any other consumer) invocation's terminal, on every
25
+ * single command, even though the node in question simply falls back to CPU
26
+ * silently and nothing is actually wrong.
27
+ *
28
+ * ── Why this is a stderr *filter*, not a log-severity option ────────────────
29
+ *
30
+ * onnxruntime-node's `InferenceSession.SessionOptions` DOES expose a
31
+ * `logSeverityLevel` (0=Verbose…4=Fatal) that would suppress Warning-level
32
+ * messages at the source — a cleaner fix, if it were reachable. It is not:
33
+ * `fastembed@2.1.0`'s `FlagEmbedding.init()` (`fastembed.js`'s
34
+ * `ort.InferenceSession.create(modelPath, { executionProviders,
35
+ * graphOptimizationLevel: "all" })`) hardcodes its own `SessionOptions`
36
+ * literal with no passthrough for caller options, and `fastembed`'s public
37
+ * `InitOptions` type has no `sessionOptions`/`logSeverityLevel` field either
38
+ * (verified against the installed `fastembed@2.1.0` and
39
+ * `onnxruntime-node@1.21.0` packages — not assumed). Filtering the child's
40
+ * stderr byte stream is therefore the only lever this package can pull.
41
+ *
42
+ * ── Why this must NOT become "throw away all child stderr" ──────────────────
43
+ *
44
+ * `fastembedProcessHost.ts`'s BL-331 lock check intentionally
45
+ * `console.error`s a loud, greppable line when a competing fastembed host is
46
+ * detected (so an otherwise-unattributable embed-latency regression has a
47
+ * visible correlate), and
48
+ * `resolveExecutionProviders()` intentionally `console.error`s when
49
+ * `SOX_EMBED_EXECUTION_PROVIDER` forces a non-default provider. A blanket
50
+ * "pipe stderr, discard everything" fix would silently destroy both of those
51
+ * — reintroducing exactly the silent-failure class BL-331 exists to prevent.
52
+ * So this filter matches ONLY the known-benign CoreML dim-limit warning text
53
+ * and passes every other line — including genuine errors and both lines
54
+ * above — straight through unmodified.
55
+ */
56
+ /**
57
+ * True if `line` is the known-benign ONNX Runtime CoreML dim-limit warning
58
+ * (see module doc comment). This is a plain substring match — deliberately
59
+ * narrow (not a broad `onnxruntime`/`[W:` pattern) so this filter can never
60
+ * swallow an unrelated onnxruntime warning or error that happens to share the
61
+ * `[W:onnxruntime:...]` prefix format.
62
+ */
63
+ export declare function isBenignOnnxCoreMlWarning(line: string): boolean;
64
+ /**
65
+ * Attach a line-buffering filter to a child process's stderr `Readable`,
66
+ * dropping only lines matching {@link isBenignOnnxCoreMlWarning} and writing
67
+ * every other line through to `dest` (defaults to `process.stderr`)
68
+ * unbuffered, verbatim (original line content, `\n`-terminated), and in the
69
+ * order it was received.
70
+ *
71
+ * Chunk boundaries never line up with `\n` boundaries in a real pipe, so
72
+ * this buffers a trailing partial line across `data` events instead of
73
+ * filtering mid-line: `source` is split on `\n` as chunks arrive, each
74
+ * complete line is tested and (if not benign) written immediately, and any
75
+ * remaining partial line is flushed on `end` (also filtered, so a benign
76
+ * warning that happens to be the final unterminated write is still caught).
77
+ */
78
+ export declare function attachOnnxStderrFilter(source: NodeJS.ReadableStream, dest?: NodeJS.WritableStream): void;
79
+ //# sourceMappingURL=onnxStderrFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onnxStderrFilter.d.ts","sourceRoot":"","sources":["../src/onnxStderrFilter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAIH;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,CAAC,cAAc,EAC7B,IAAI,GAAE,MAAM,CAAC,cAA+B,GAC3C,IAAI,CAmBN"}