@remnic/core 10.0.157 → 10.0.159
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.
- package/dist/access-admin-ops-surface.js +10 -10
- package/dist/access-cli.js +10 -10
- package/dist/access-extraction-force-flush-preempt.js +10 -10
- package/dist/access-extraction-force-flush.js +10 -10
- package/dist/access-http-briefing.js +10 -10
- package/dist/access-http-query.js +10 -10
- package/dist/access-http.js +10 -10
- package/dist/access-identity-continuity-surface.js +10 -10
- package/dist/access-lcm-surface.js +10 -10
- package/dist/access-mcp.js +10 -10
- package/dist/access-observe-write-surface.js +10 -10
- package/dist/access-operations-batch.js +10 -10
- package/dist/access-operations.js +10 -10
- package/dist/access-recall-concurrency.js +10 -10
- package/dist/access-recall-response.js +10 -10
- package/dist/access-recall-surface.js +10 -10
- package/dist/access-service.js +10 -10
- package/dist/calibration.js +3 -3
- package/dist/{chunk-RGXNPAMA.js → chunk-3RHD5TF5.js} +38 -30
- package/dist/{chunk-RGXNPAMA.js.map → chunk-3RHD5TF5.js.map} +1 -1
- package/dist/{chunk-SKCMEZBU.js → chunk-52EM4UQU.js} +2 -2
- package/dist/{chunk-QAQL2OQH.js → chunk-5V3IBSVB.js} +2 -2
- package/dist/{chunk-K4TMUEYI.js → chunk-BT5TAOXG.js} +1 -1
- package/dist/{chunk-4IJBNRMZ.js → chunk-DRXFLPSE.js} +12 -2
- package/dist/chunk-DRXFLPSE.js.map +1 -0
- package/dist/{chunk-AGMMHT4P.js → chunk-GT2HWRST.js} +21 -3
- package/dist/chunk-GT2HWRST.js.map +1 -0
- package/dist/{chunk-BDKLKX43.js → chunk-KYZMCH4I.js} +79 -6
- package/dist/{chunk-BDKLKX43.js.map → chunk-KYZMCH4I.js.map} +1 -1
- package/dist/{chunk-RXG3WF7C.js → chunk-TXVTNDQT.js} +2 -2
- package/dist/{chunk-2TUWMP7B.js → chunk-UADAXWUJ.js} +3 -3
- package/dist/{chunk-Z6AP6O32.js → chunk-XC5BRK7J.js} +2 -2
- package/dist/{chunk-XWRSQWQO.js → chunk-YOR5QBEU.js} +60 -59
- package/dist/chunk-YOR5QBEU.js.map +1 -0
- package/dist/cli.js +10 -10
- package/dist/compounding/engine.js +1 -1
- package/dist/explicit-capture.js +10 -10
- package/dist/extraction.js +4 -4
- package/dist/index.js +10 -10
- package/dist/local-llm-helpers.d.ts +22 -8
- package/dist/local-llm-helpers.d.ts.map +1 -1
- package/dist/local-llm-helpers.js +11 -1
- package/dist/local-llm-rate-limit.d.ts +1 -5
- package/dist/local-llm-rate-limit.d.ts.map +1 -1
- package/dist/local-llm-rate-limit.js +3 -1
- package/dist/local-llm.d.ts +2 -4
- package/dist/local-llm.d.ts.map +1 -1
- package/dist/local-llm.js +3 -3
- package/dist/orchestration/backlog-scheduler.js +11 -11
- package/dist/orchestration/buffer-drain-runner.js +11 -11
- package/dist/orchestration/maintenance.js +5 -5
- package/dist/orchestration/recall-internal.d.ts.map +1 -1
- package/dist/orchestrator.js +10 -10
- package/dist/recall-enrichment-promise.d.ts +7 -2
- package/dist/recall-enrichment-promise.d.ts.map +1 -1
- package/dist/recall-enrichment-promise.js +1 -1
- package/dist/recall-navigation.js +10 -10
- package/dist/summarizer.js +4 -4
- package/dist/support-passport/index.js +4 -4
- package/package.json +12 -2
- package/src/local-llm-helpers.ts +116 -14
- package/src/local-llm-rate-limit.test.ts +79 -1
- package/src/local-llm-rate-limit.ts +37 -1
- package/src/local-llm.ts +75 -74
- package/src/orchestration/recall-internal.ts +36 -24
- package/src/recall-enrichment-promise.ts +20 -2
- package/src/recall-qos.test.ts +24 -0
- package/src/recall-timings-request-contract.test.ts +10 -8
- package/dist/chunk-4IJBNRMZ.js.map +0 -1
- package/dist/chunk-AGMMHT4P.js.map +0 -1
- package/dist/chunk-XWRSQWQO.js.map +0 -1
- /package/dist/{chunk-SKCMEZBU.js.map → chunk-52EM4UQU.js.map} +0 -0
- /package/dist/{chunk-QAQL2OQH.js.map → chunk-5V3IBSVB.js.map} +0 -0
- /package/dist/{chunk-K4TMUEYI.js.map → chunk-BT5TAOXG.js.map} +0 -0
- /package/dist/{chunk-RXG3WF7C.js.map → chunk-TXVTNDQT.js.map} +0 -0
- /package/dist/{chunk-2TUWMP7B.js.map → chunk-UADAXWUJ.js.map} +0 -0
- /package/dist/{chunk-Z6AP6O32.js.map → chunk-XC5BRK7J.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runRecallNavigation
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3RHD5TF5.js";
|
|
4
4
|
import "./chunk-TH6OYP6I.js";
|
|
5
5
|
import "./chunk-PQM3B54K.js";
|
|
6
6
|
import "./chunk-2MWKUVHT.js";
|
|
@@ -16,7 +16,7 @@ import "./chunk-K3KSTSGM.js";
|
|
|
16
16
|
import "./chunk-BV2TIZ4F.js";
|
|
17
17
|
import "./chunk-Z734BLO3.js";
|
|
18
18
|
import "./chunk-HDDRVXX4.js";
|
|
19
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-5V3IBSVB.js";
|
|
20
20
|
import "./chunk-OZKVVUJB.js";
|
|
21
21
|
import "./chunk-2DL3OFLD.js";
|
|
22
22
|
import "./chunk-G4IAEX6D.js";
|
|
@@ -30,7 +30,7 @@ import "./chunk-FGDKJJZS.js";
|
|
|
30
30
|
import "./chunk-AJVLDJU6.js";
|
|
31
31
|
import "./chunk-TBUEE7XF.js";
|
|
32
32
|
import "./chunk-5PHOU5QI.js";
|
|
33
|
-
import "./chunk-
|
|
33
|
+
import "./chunk-UADAXWUJ.js";
|
|
34
34
|
import "./chunk-I74SUMNI.js";
|
|
35
35
|
import "./chunk-ILNPU5W5.js";
|
|
36
36
|
import "./chunk-VZAKYDMJ.js";
|
|
@@ -60,7 +60,7 @@ import "./chunk-4AKPTHOO.js";
|
|
|
60
60
|
import "./chunk-TECVW3JP.js";
|
|
61
61
|
import "./chunk-C5JF6EZ7.js";
|
|
62
62
|
import "./chunk-2524MOWK.js";
|
|
63
|
-
import "./chunk-
|
|
63
|
+
import "./chunk-BT5TAOXG.js";
|
|
64
64
|
import "./chunk-JVBAPAWZ.js";
|
|
65
65
|
import "./chunk-HSSERO3E.js";
|
|
66
66
|
import "./chunk-NOUJNHWG.js";
|
|
@@ -97,7 +97,7 @@ import "./chunk-OBPOIZNR.js";
|
|
|
97
97
|
import "./chunk-ECZU5BJH.js";
|
|
98
98
|
import "./chunk-77NTFICT.js";
|
|
99
99
|
import "./chunk-LJLGH2DE.js";
|
|
100
|
-
import "./chunk-
|
|
100
|
+
import "./chunk-TXVTNDQT.js";
|
|
101
101
|
import "./chunk-HNOSWPKG.js";
|
|
102
102
|
import "./chunk-ODZKV2F7.js";
|
|
103
103
|
import "./chunk-WWDO7ZWM.js";
|
|
@@ -138,7 +138,7 @@ import "./chunk-VYDGHJIN.js";
|
|
|
138
138
|
import "./chunk-6NPLVV6M.js";
|
|
139
139
|
import "./chunk-7O5EW7KX.js";
|
|
140
140
|
import "./chunk-H7XKCNR6.js";
|
|
141
|
-
import "./chunk-
|
|
141
|
+
import "./chunk-DRXFLPSE.js";
|
|
142
142
|
import "./chunk-H6OTEBPK.js";
|
|
143
143
|
import "./chunk-SOBJ6NEY.js";
|
|
144
144
|
import "./chunk-O7CHKXSF.js";
|
|
@@ -193,7 +193,7 @@ import "./chunk-64NJRYU2.js";
|
|
|
193
193
|
import "./chunk-U2PSE7MB.js";
|
|
194
194
|
import "./chunk-BPPUH5JM.js";
|
|
195
195
|
import "./chunk-LEO4MQ3S.js";
|
|
196
|
-
import "./chunk-
|
|
196
|
+
import "./chunk-52EM4UQU.js";
|
|
197
197
|
import "./chunk-EI6V5UXY.js";
|
|
198
198
|
import "./chunk-773QSFFN.js";
|
|
199
199
|
import "./chunk-YAVIBVCU.js";
|
|
@@ -301,11 +301,11 @@ import "./chunk-QASTQVGK.js";
|
|
|
301
301
|
import "./chunk-CSAKJVXW.js";
|
|
302
302
|
import "./chunk-K2XUWZBM.js";
|
|
303
303
|
import "./chunk-OD4FM2U7.js";
|
|
304
|
-
import "./chunk-
|
|
304
|
+
import "./chunk-YOR5QBEU.js";
|
|
305
305
|
import "./chunk-MJFL75J6.js";
|
|
306
|
-
import "./chunk-
|
|
306
|
+
import "./chunk-GT2HWRST.js";
|
|
307
307
|
import "./chunk-U4LUIE6Y.js";
|
|
308
|
-
import "./chunk-
|
|
308
|
+
import "./chunk-KYZMCH4I.js";
|
|
309
309
|
import "./chunk-5YQXWVCP.js";
|
|
310
310
|
import "./chunk-YN2DQ2D6.js";
|
|
311
311
|
import "./chunk-FKBGK3NC.js";
|
package/dist/summarizer.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HourlySummarizer,
|
|
3
3
|
summarizeHourlyStatus
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TXVTNDQT.js";
|
|
5
5
|
import "./chunk-HNOSWPKG.js";
|
|
6
6
|
import "./chunk-5Y43VGYB.js";
|
|
7
7
|
import "./chunk-QNUNAXBE.js";
|
|
8
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-YOR5QBEU.js";
|
|
9
9
|
import "./chunk-MJFL75J6.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-GT2HWRST.js";
|
|
11
11
|
import "./chunk-U4LUIE6Y.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-KYZMCH4I.js";
|
|
13
13
|
import "./chunk-5YQXWVCP.js";
|
|
14
14
|
import "./chunk-KF7PQ7G2.js";
|
|
15
15
|
import "./chunk-TOTT6S2V.js";
|
|
@@ -31,12 +31,12 @@ import {
|
|
|
31
31
|
parseSupportPassportModelJob,
|
|
32
32
|
resolveSupportPassportModelRoutePlan,
|
|
33
33
|
syncDirectoryForDurability
|
|
34
|
-
} from "../chunk-
|
|
35
|
-
import "../chunk-
|
|
34
|
+
} from "../chunk-5V3IBSVB.js";
|
|
35
|
+
import "../chunk-YOR5QBEU.js";
|
|
36
36
|
import "../chunk-MJFL75J6.js";
|
|
37
|
-
import "../chunk-
|
|
37
|
+
import "../chunk-GT2HWRST.js";
|
|
38
38
|
import "../chunk-U4LUIE6Y.js";
|
|
39
|
-
import "../chunk-
|
|
39
|
+
import "../chunk-KYZMCH4I.js";
|
|
40
40
|
import "../chunk-5YQXWVCP.js";
|
|
41
41
|
import "../chunk-TOTT6S2V.js";
|
|
42
42
|
import {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remnic/core",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.159",
|
|
4
4
|
"description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -3339,6 +3339,16 @@
|
|
|
3339
3339
|
"types": "./dist/write-quarantine.d.ts",
|
|
3340
3340
|
"remnic-source": "./src/write-quarantine.ts",
|
|
3341
3341
|
"import": "./dist/write-quarantine.js"
|
|
3342
|
+
},
|
|
3343
|
+
"./local-llm-helpers": {
|
|
3344
|
+
"types": "./dist/local-llm-helpers.d.ts",
|
|
3345
|
+
"remnic-source": "./src/local-llm-helpers.ts",
|
|
3346
|
+
"import": "./dist/local-llm-helpers.js"
|
|
3347
|
+
},
|
|
3348
|
+
"./local-llm-helpers.js": {
|
|
3349
|
+
"types": "./dist/local-llm-helpers.d.ts",
|
|
3350
|
+
"remnic-source": "./src/local-llm-helpers.ts",
|
|
3351
|
+
"import": "./dist/local-llm-helpers.js"
|
|
3342
3352
|
}
|
|
3343
3353
|
},
|
|
3344
3354
|
"files": [
|
|
@@ -3396,7 +3406,7 @@
|
|
|
3396
3406
|
"core"
|
|
3397
3407
|
],
|
|
3398
3408
|
"peerDependencies": {
|
|
3399
|
-
"@remnic/coding-graph": "^10.0.
|
|
3409
|
+
"@remnic/coding-graph": "^10.0.159"
|
|
3400
3410
|
},
|
|
3401
3411
|
"peerDependenciesMeta": {
|
|
3402
3412
|
"@remnic/coding-graph": {
|
package/src/local-llm-helpers.ts
CHANGED
|
@@ -274,21 +274,123 @@ export class SingleFlightProbe {
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
/**
|
|
278
|
-
*
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
277
|
+
/** True when `value` is safe for `fetch` request headers. Node's `Headers`
|
|
278
|
+
* accepts a ByteString: controls and DEL are out, and so is anything above
|
|
279
|
+
* U+00FF — `é` is sendable, `Ā` is not (Kilo review on #3474). */
|
|
280
|
+
export function isHttpHeaderFieldValue(value: string): boolean {
|
|
281
|
+
if (!value) return false;
|
|
282
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
283
|
+
const code = value.charCodeAt(i);
|
|
284
|
+
if (code < 0x20 || code === 0x7f || code > 0xff) return false;
|
|
285
|
+
}
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function trimTrailingSlashes(url: string): string {
|
|
290
|
+
let end = url.length;
|
|
291
|
+
while (end > 0 && url.charCodeAt(end - 1) === 47) end -= 1;
|
|
292
|
+
return end === url.length ? url : url.slice(0, end);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Circuit-breaker and rate-limit scope when recall/extraction share one proxy URL. */
|
|
296
|
+
export function formatLocalLlmPoolKey(chatUrl: string, operation: string): string {
|
|
297
|
+
let normalized = chatUrl.replace("localhost", "127.0.0.1");
|
|
298
|
+
normalized = trimTrailingSlashes(normalized);
|
|
299
|
+
if (normalized.endsWith("/v1")) {
|
|
300
|
+
normalized = normalized.slice(0, -3);
|
|
301
|
+
}
|
|
302
|
+
const completions = normalized.endsWith("/chat/completions")
|
|
303
|
+
? normalized
|
|
304
|
+
: `${normalized}/v1/chat/completions`;
|
|
305
|
+
return `${completions}|op=${operation}`;
|
|
306
|
+
}
|
|
284
307
|
|
|
285
|
-
/**
|
|
308
|
+
/** HTTP headers the jarvis-ml recall proxy reads for pool routing. */
|
|
286
309
|
export function buildLocalLlmRoutingHeaders(
|
|
287
310
|
operation: string,
|
|
288
|
-
priority:
|
|
289
|
-
):
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
311
|
+
priority: "recall-critical" | "background" | undefined,
|
|
312
|
+
): Record<string, string> {
|
|
313
|
+
const routingEntries: Array<readonly [string, string]> = [
|
|
314
|
+
["Content-Type", "application/json"],
|
|
315
|
+
];
|
|
316
|
+
if (operation !== "unspecified" && isHttpHeaderFieldValue(operation)) {
|
|
317
|
+
routingEntries.push(["X-Remnic-Operation", operation]);
|
|
318
|
+
}
|
|
319
|
+
if (priority) {
|
|
320
|
+
routingEntries.push(["X-Remnic-Priority", priority]);
|
|
321
|
+
}
|
|
322
|
+
return Object.fromEntries(routingEntries) satisfies Record<string, string>;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const LOCAL_LLM_GLOBAL_BACKEND_STATE = "__openclawEngramLocalLlmBackendState";
|
|
326
|
+
|
|
327
|
+
export type LocalLlmBackendPoolState = {
|
|
328
|
+
untilMs: number;
|
|
329
|
+
reason: string;
|
|
330
|
+
/** Once the trip lapses this is set instead of deleting the entry: every
|
|
331
|
+
* client must observe the transition once, so a tombstone stays visible for
|
|
332
|
+
* BACKEND_POOL_TOMBSTONE_MS. */
|
|
333
|
+
expiredAtMs?: number;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/** How long a lapsed circuit stays readable so each client can invalidate its
|
|
337
|
+
* cached health verdict once (the health cache is 60s; this leaves margin). */
|
|
338
|
+
const BACKEND_POOL_TOMBSTONE_MS = 15 * 60_000;
|
|
339
|
+
|
|
340
|
+
function localLlmBackendPoolMap(): Map<string, LocalLlmBackendPoolState> {
|
|
341
|
+
// SAFETY: globalThis carries one optional Map slot keyed for backend pool state.
|
|
342
|
+
const globalAny = globalThis as typeof globalThis & {
|
|
343
|
+
[LOCAL_LLM_GLOBAL_BACKEND_STATE]?: Map<string, LocalLlmBackendPoolState>;
|
|
344
|
+
};
|
|
345
|
+
const existing = globalAny[LOCAL_LLM_GLOBAL_BACKEND_STATE];
|
|
346
|
+
if (existing) return existing;
|
|
347
|
+
const created = new Map<string, LocalLlmBackendPoolState>();
|
|
348
|
+
globalAny[LOCAL_LLM_GLOBAL_BACKEND_STATE] = created;
|
|
349
|
+
return created;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function getLocalLlmTrippedBackendPoolState(
|
|
353
|
+
now: number,
|
|
354
|
+
chatUrl: string,
|
|
355
|
+
operation: string,
|
|
356
|
+
): LocalLlmBackendPoolState | null {
|
|
357
|
+
const key = formatLocalLlmPoolKey(chatUrl, operation);
|
|
358
|
+
const map = localLlmBackendPoolMap();
|
|
359
|
+
const state = map.get(key) ?? null;
|
|
360
|
+
if (!state) return null;
|
|
361
|
+
if (state.untilMs <= now) {
|
|
362
|
+
state.expiredAtMs ??= state.untilMs;
|
|
363
|
+
if (state.expiredAtMs + BACKEND_POOL_TOMBSTONE_MS <= now) map.delete(key);
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
return state;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** The instant this pool's circuit lapsed, or null while it is active or
|
|
370
|
+
* absent. The tombstone stays in the map so every client holding a cached
|
|
371
|
+
* health verdict can observe the transition once — deleting on first read left
|
|
372
|
+
* later clients stale (wAN review on #3474). */
|
|
373
|
+
export function localLlmBackendPoolExpiredAtMs(now: number, chatUrl: string, operation: string): number | null {
|
|
374
|
+
const key = formatLocalLlmPoolKey(chatUrl, operation);
|
|
375
|
+
const state = localLlmBackendPoolMap().get(key) ?? null;
|
|
376
|
+
if (state && state.untilMs <= now) {
|
|
377
|
+
state.expiredAtMs ??= state.untilMs;
|
|
378
|
+
return state.expiredAtMs;
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function markLocalLlmBackendPoolUnavailable(
|
|
384
|
+
reason: string,
|
|
385
|
+
durationMs: number,
|
|
386
|
+
chatUrl: string,
|
|
387
|
+
operation: string,
|
|
388
|
+
): void {
|
|
389
|
+
const normalizedReason = normalizeBackendTripReason(reason);
|
|
390
|
+
const key = formatLocalLlmPoolKey(chatUrl, operation);
|
|
391
|
+
if (durationMs > 0) {
|
|
392
|
+
localLlmBackendPoolMap().set(key, { untilMs: Date.now() + durationMs, reason: normalizedReason });
|
|
393
|
+
} else {
|
|
394
|
+
localLlmBackendPoolMap().delete(key);
|
|
395
|
+
}
|
|
294
396
|
}
|
|
@@ -2,6 +2,11 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
|
|
4
4
|
import { parseConfig } from "./config.js";
|
|
5
|
+
import {
|
|
6
|
+
formatLocalLlmPoolKey,
|
|
7
|
+
getLocalLlmTrippedBackendPoolState,
|
|
8
|
+
markLocalLlmBackendPoolUnavailable,
|
|
9
|
+
} from "./local-llm-helpers.js";
|
|
5
10
|
import type { LocalLlmChatCompletionOptions } from "./local-llm-helpers.js";
|
|
6
11
|
import {
|
|
7
12
|
LocalLlmConcurrencyLimiter,
|
|
@@ -11,6 +16,7 @@ import {
|
|
|
11
16
|
endpointBackoffRemainingMs,
|
|
12
17
|
extendEndpointBackoff,
|
|
13
18
|
isRateLimitedResponse,
|
|
19
|
+
isTerminalLocalLlmProxyPoolError,
|
|
14
20
|
parseRetryAfterMs,
|
|
15
21
|
parseTryAgainHintMs,
|
|
16
22
|
resetLocalLlmRateLimitStateForTests,
|
|
@@ -113,6 +119,58 @@ test("classifies 429/503/408 and LiteLLM cooldown bodies as rate limits, not 400
|
|
|
113
119
|
assert.equal(isRateLimitedResponse(500, "internal error"), false);
|
|
114
120
|
assert.equal(isRateLimitedResponse(400, "Context Window exceeded ... fallbacks cooldown_list"), false);
|
|
115
121
|
assert.equal(isRateLimitedResponse(502, ""), false);
|
|
122
|
+
assert.equal(
|
|
123
|
+
isRateLimitedResponse(
|
|
124
|
+
503,
|
|
125
|
+
JSON.stringify({ code: "remnic_recall_pool_unavailable", error: "recall pool missing" }),
|
|
126
|
+
),
|
|
127
|
+
false,
|
|
128
|
+
);
|
|
129
|
+
assert.equal(
|
|
130
|
+
isRateLimitedResponse(
|
|
131
|
+
503,
|
|
132
|
+
JSON.stringify({ code: "remnic_extraction_pool_unavailable", error: "trained pool missing" }),
|
|
133
|
+
),
|
|
134
|
+
false,
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("the terminal predicate matches the proxy's error-only pool-missing payload", () => {
|
|
139
|
+
// remnic-llm-proxy.py answers {"error": "..."} — no code field. The terminal
|
|
140
|
+
// check must catch the same bodies isRateLimitedResponse rejects, or the
|
|
141
|
+
// generic 5xx retry still fires (wAN review on #3474).
|
|
142
|
+
const proxyBody = JSON.stringify({
|
|
143
|
+
error: "recall pool missing or disabled; recall ops must not use the extraction pool",
|
|
144
|
+
});
|
|
145
|
+
assert.equal(isTerminalLocalLlmProxyPoolError(503, proxyBody), true);
|
|
146
|
+
assert.equal(isTerminalLocalLlmProxyPoolError(503, "embed pool missing or disabled (test)"), true);
|
|
147
|
+
assert.equal(isTerminalLocalLlmProxyPoolError(500, proxyBody), false);
|
|
148
|
+
assert.equal(isTerminalLocalLlmProxyPoolError(503, "upstream timeout"), false);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("the terminal predicate parses a structured pool code at any JSON spacing", () => {
|
|
152
|
+
// kilo on #3474: the needles matched only '"code":"x"' and '"code": "x"'; any
|
|
153
|
+
// other valid JSON spacing ('"code" : "x"', key reorder, pretty print with a
|
|
154
|
+
// deeper indent) fell through to the generic 5xx retry. Parse the body.
|
|
155
|
+
assert.equal(
|
|
156
|
+
isTerminalLocalLlmProxyPoolError(503, '{"code" : "remnic_recall_pool_unavailable"}'),
|
|
157
|
+
true,
|
|
158
|
+
);
|
|
159
|
+
assert.equal(
|
|
160
|
+
isTerminalLocalLlmProxyPoolError(
|
|
161
|
+
503,
|
|
162
|
+
JSON.stringify({ extra: 1, code: "remnic_extraction_pool_unavailable", detail: "x" }, null, 4),
|
|
163
|
+
),
|
|
164
|
+
true,
|
|
165
|
+
);
|
|
166
|
+
assert.equal(
|
|
167
|
+
isTerminalLocalLlmProxyPoolError(503, '{"code":"remnic_unrelated_error"}'),
|
|
168
|
+
false,
|
|
169
|
+
);
|
|
170
|
+
assert.equal(
|
|
171
|
+
isTerminalLocalLlmProxyPoolError(503, '{"code":"remnic_recall_pool_unavailable"}'),
|
|
172
|
+
true,
|
|
173
|
+
);
|
|
116
174
|
});
|
|
117
175
|
|
|
118
176
|
test("a pool-missing 503 is a config failure, not endpoint saturation (#3475)", () => {
|
|
@@ -290,7 +348,9 @@ test("a server hint beyond the max skips the retry and gates every client on tha
|
|
|
290
348
|
const b = new LocalLlmClient(createConfig({ localLlmUrl: url }));
|
|
291
349
|
assert.equal(await a.chatCompletion([{ role: "user", content: "x" }]), null);
|
|
292
350
|
assert.equal(calls, 1, "60s hint > 20ms max: no immediate retry");
|
|
293
|
-
assert.ok(
|
|
351
|
+
assert.ok(
|
|
352
|
+
endpointBackoffRemainingMs(formatLocalLlmPoolKey(`${url}/v1/chat/completions`, "unspecified")) > 50_000,
|
|
353
|
+
);
|
|
294
354
|
const options: LocalLlmChatCompletionOptions = { failureDiag: {} };
|
|
295
355
|
assert.equal(await b.chatCompletion([{ role: "user", content: "y" }], options), null);
|
|
296
356
|
assert.equal(calls, 1, "second client must not hit the proxy during the shared backoff");
|
|
@@ -497,3 +557,21 @@ test("one-permit and unlimited limits still admit background work", async () =>
|
|
|
497
557
|
assert.equal(limiter.inFlight, 0);
|
|
498
558
|
}
|
|
499
559
|
});
|
|
560
|
+
|
|
561
|
+
test("rate-limit backoff on one proxy operation does not block another", () => {
|
|
562
|
+
resetLocalLlmRateLimitStateForTests();
|
|
563
|
+
const chatUrl = "http://127.0.0.1:4399/v1/chat/completions";
|
|
564
|
+
const extractionKey = formatLocalLlmPoolKey(chatUrl, "extraction");
|
|
565
|
+
const recallKey = formatLocalLlmPoolKey(chatUrl, "rerank");
|
|
566
|
+
extendEndpointBackoff(extractionKey, 60_000);
|
|
567
|
+
assert.ok(endpointBackoffRemainingMs(extractionKey) > 0);
|
|
568
|
+
assert.equal(endpointBackoffRemainingMs(recallKey), 0);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
test("backend circuit on one proxy operation does not trip another", () => {
|
|
572
|
+
const chatUrl = "http://127.0.0.1:4399/v1/chat/completions";
|
|
573
|
+
const now = Date.now();
|
|
574
|
+
markLocalLlmBackendPoolUnavailable("model load failure", 60_000, chatUrl, "extraction");
|
|
575
|
+
assert.ok(getLocalLlmTrippedBackendPoolState(now, chatUrl, "extraction"));
|
|
576
|
+
assert.equal(getLocalLlmTrippedBackendPoolState(now, chatUrl, "rerank"), null);
|
|
577
|
+
});
|
|
@@ -83,8 +83,44 @@ const POOL_MISSING_PATTERN = /pool missing or disabled/i;
|
|
|
83
83
|
* 408/429/503, or a 5xx whose body carries LiteLLM's cooldown wording.
|
|
84
84
|
* 400s are never rate limits (context-window errors mention fallbacks).
|
|
85
85
|
*/
|
|
86
|
+
/** Proxy 503 with a pool-config error code is terminal; do not enter rate-limit retries. */
|
|
87
|
+
const TERMINAL_PROXY_POOL_CODES: ReadonlySet<string> = new Set([
|
|
88
|
+
"remnic_recall_pool_unavailable",
|
|
89
|
+
"remnic_extraction_pool_unavailable",
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
/** Today's proxy answers {"error": "..."} with no code field, so the code path
|
|
93
|
+
* parses the body instead of substring-matching JSON — spacing and key order
|
|
94
|
+
* must not decide whether a terminal refusal retries (kilo on #3474). */
|
|
95
|
+
function bodyHasTerminalPoolCode(bodyText: string): boolean {
|
|
96
|
+
try {
|
|
97
|
+
// SAFETY: the proxy body is an opaque JSON object and `code` is optional, so a
|
|
98
|
+
// wrong-shape or wrong-type payload reads as undefined and fails the Set lookup.
|
|
99
|
+
const { code } = JSON.parse(bodyText) as { code?: string };
|
|
100
|
+
return code !== undefined && TERMINAL_PROXY_POOL_CODES.has(code);
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The proxy answers pool-config refusals as {"error": "... pool missing or
|
|
107
|
+
* disabled ..."} with no code field; the text shape is part of the terminal
|
|
108
|
+
* contract, or the generic 5xx retry still fires (wAN review on #3474). */
|
|
109
|
+
const TERMINAL_PROXY_POOL_TEXT = "pool missing or disabled";
|
|
110
|
+
|
|
111
|
+
export function isTerminalLocalLlmProxyPoolError(status: number, bodyText: string): boolean {
|
|
112
|
+
if (status !== 503) return false;
|
|
113
|
+
return (
|
|
114
|
+
bodyText.toLowerCase().includes(TERMINAL_PROXY_POOL_TEXT) ||
|
|
115
|
+
bodyHasTerminalPoolCode(bodyText)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
86
119
|
export function isRateLimitedResponse(status: number, bodyText: string): boolean {
|
|
87
|
-
if (
|
|
120
|
+
if (isTerminalLocalLlmProxyPoolError(status, bodyText)) return false;
|
|
121
|
+
// Pool-side refusals carry "pool missing or disabled" as text: a config
|
|
122
|
+
// failure, not endpoint saturation. Substring check, no regex.
|
|
123
|
+
if (bodyText.toLowerCase().includes("pool missing or disabled")) return false;
|
|
88
124
|
if (RATE_LIMIT_STATUSES.has(status)) return true;
|
|
89
125
|
return status >= 500 && RATE_LIMIT_BODY_PATTERN.test(bodyText);
|
|
90
126
|
}
|