@remnic/core 10.0.116 → 10.0.118
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 +5 -5
- package/dist/access-cli.js +5 -5
- package/dist/access-extraction-force-flush.js +5 -5
- package/dist/access-http-briefing.js +5 -5
- package/dist/access-http-query.js +5 -5
- package/dist/access-http.js +5 -5
- package/dist/access-identity-continuity-surface.js +5 -5
- package/dist/access-lcm-surface.js +5 -5
- package/dist/access-mcp.d.ts.map +1 -1
- package/dist/access-mcp.js +5 -5
- package/dist/access-observe-write-surface.js +5 -5
- package/dist/access-operations-batch.js +5 -5
- package/dist/access-operations.js +5 -5
- package/dist/access-recall-concurrency.js +5 -5
- package/dist/access-recall-response.js +5 -5
- package/dist/access-recall-surface.js +5 -5
- package/dist/access-service.js +5 -5
- package/dist/buffer.js +2 -2
- package/dist/{chunk-U7LMXR2W.js → chunk-CAE7ALRH.js} +2 -2
- package/dist/{chunk-BTXK3JBP.js → chunk-IRFCIJTX.js} +6 -6
- package/dist/{chunk-BTXK3JBP.js.map → chunk-IRFCIJTX.js.map} +1 -1
- package/dist/{chunk-MYXJCR3E.js → chunk-TWPQVPD4.js} +2 -2
- package/dist/{chunk-WOXO4HE6.js → chunk-URXJ4CDO.js} +35 -8
- package/dist/chunk-URXJ4CDO.js.map +1 -0
- package/dist/{chunk-JSDKE6UY.js → chunk-VXMSMY65.js} +4 -4
- package/dist/{chunk-KBUFYKUN.js → chunk-ZPPKBURE.js} +2 -2
- package/dist/cli.js +5 -5
- package/dist/explicit-capture.js +5 -5
- package/dist/extraction.js +3 -3
- package/dist/index.js +5 -5
- package/dist/orchestration/backlog-scheduler.js +6 -6
- package/dist/orchestration/buffer-drain-runner.js +6 -6
- package/dist/orchestration/extraction-run.d.ts +3 -0
- package/dist/orchestration/extraction-run.d.ts.map +1 -1
- package/dist/orchestration/probe-deadline.d.ts +13 -0
- package/dist/orchestration/probe-deadline.d.ts.map +1 -0
- package/dist/orchestration/provider-breaker.d.ts +9 -0
- package/dist/orchestration/provider-breaker.d.ts.map +1 -1
- package/dist/orchestrator.js +5 -5
- package/dist/recall-navigation.js +5 -5
- package/dist/source-agent-qualifier.js +2 -2
- package/package.json +2 -2
- package/src/access-mcp.test.ts +38 -0
- package/src/access-mcp.ts +8 -2
- package/src/orchestration/extraction-run.test.ts +110 -0
- package/src/orchestration/extraction-run.ts +19 -7
- package/src/orchestration/probe-deadline.ts +38 -0
- package/src/orchestration/provider-breaker.ts +10 -0
- package/dist/chunk-WOXO4HE6.js.map +0 -1
- /package/dist/{chunk-U7LMXR2W.js.map → chunk-CAE7ALRH.js.map} +0 -0
- /package/dist/{chunk-MYXJCR3E.js.map → chunk-TWPQVPD4.js.map} +0 -0
- /package/dist/{chunk-JSDKE6UY.js.map → chunk-VXMSMY65.js.map} +0 -0
- /package/dist/{chunk-KBUFYKUN.js.map → chunk-ZPPKBURE.js.map} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExtractionResult } from "../types.js";
|
|
2
|
+
export interface ProbeDeadline {
|
|
3
|
+
/** The caller's signal, plus the probe timer's when this attempt owns the probe. */
|
|
4
|
+
readonly signal: AbortSignal | undefined;
|
|
5
|
+
/** True only when the probe timer fired (not when the caller aborted). */
|
|
6
|
+
timedOut(): boolean;
|
|
7
|
+
stop(): void;
|
|
8
|
+
}
|
|
9
|
+
/** Bounds the single half-open probe; any other attempt keeps the caller's signal and no timer. */
|
|
10
|
+
export declare function startProbeDeadline(probeOwned: boolean, callerSignal: AbortSignal | undefined, timeoutMs?: number): ProbeDeadline;
|
|
11
|
+
/** What a probe that got no answer in time reports: the ordinary retryable provider failure. */
|
|
12
|
+
export declare function probeTimedOutResult(): ExtractionResult;
|
|
13
|
+
//# sourceMappingURL=probe-deadline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe-deadline.d.ts","sourceRoot":"","sources":["../../src/orchestration/probe-deadline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,MAAM,WAAW,aAAa;IAC5B,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IACzC,0EAA0E;IAC1E,QAAQ,IAAI,OAAO,CAAC;IACpB,IAAI,IAAI,IAAI,CAAC;CACd;AAED,mGAAmG;AACnG,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,OAAO,EACnB,YAAY,EAAE,WAAW,GAAG,SAAS,EACrC,SAAS,GAAE,MAAmC,GAC7C,aAAa,CASf;AAED,gGAAgG;AAChG,wBAAgB,mBAAmB,IAAI,gBAAgB,CAStD"}
|
|
@@ -4,6 +4,15 @@ export interface ProviderBreakerConfig {
|
|
|
4
4
|
readonly cooldownMs: number;
|
|
5
5
|
readonly authCooldownMs: number;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* How long the single half-open probe may run before it counts as a provider
|
|
9
|
+
* failure and re-opens the breaker. Before this bound, a probe waiting in the
|
|
10
|
+
* local LLM queue and then timing out twice held every drain for up to 55 min.
|
|
11
|
+
* 15 min covers the slowest probe that did succeed in a 24 h production log
|
|
12
|
+
* (10 min) and caps a failed one at 15 min plus the cooldown.
|
|
13
|
+
* shortcut: a constant, not config; make it a config key if hosts need to tune it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const HALF_OPEN_PROBE_TIMEOUT_MS = 900000;
|
|
7
16
|
export interface ProbeOwnerToken {
|
|
8
17
|
readonly __probeOwner: true;
|
|
9
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-breaker.d.ts","sourceRoot":"","sources":["../../src/orchestration/provider-breaker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CA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AG,IAAI;IAM3C,OAAO,CAAC,GAAG,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,IAAI;IAqCpH,OAAO,CAAC,UAAU,CAAC,EAAE,eAAe,GAAG,IAAI;IAmB3C,QAAQ,IAAI,uBAAuB;IASnC,OAAO,CAAC,aAAa;CAStB"}
|
package/dist/orchestrator.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
mergeGraphExpandedResults,
|
|
7
7
|
qmdStartupCollectionChecksWithTimeout,
|
|
8
8
|
resolveEffectiveIdentityInjectionMode
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-IRFCIJTX.js";
|
|
10
10
|
import "./chunk-6P7U3HWG.js";
|
|
11
11
|
import "./chunk-PQM3B54K.js";
|
|
12
12
|
import "./chunk-B3DR2JBZ.js";
|
|
@@ -196,9 +196,9 @@ import "./chunk-IHCXMYSE.js";
|
|
|
196
196
|
import "./chunk-D6IGZYTN.js";
|
|
197
197
|
import "./chunk-W7K5BP3M.js";
|
|
198
198
|
import "./chunk-LZIOY7ZU.js";
|
|
199
|
-
import "./chunk-
|
|
199
|
+
import "./chunk-CAE7ALRH.js";
|
|
200
200
|
import "./chunk-EI6V5UXY.js";
|
|
201
|
-
import "./chunk-
|
|
201
|
+
import "./chunk-TWPQVPD4.js";
|
|
202
202
|
import "./chunk-UA2NDTIU.js";
|
|
203
203
|
import "./chunk-6XTUZKCZ.js";
|
|
204
204
|
import "./chunk-54V4BZWP.js";
|
|
@@ -296,10 +296,10 @@ import "./chunk-GKCXTSFF.js";
|
|
|
296
296
|
import "./chunk-2LSZVONP.js";
|
|
297
297
|
import "./chunk-DEUNUKTD.js";
|
|
298
298
|
import "./chunk-LXY5VVGM.js";
|
|
299
|
-
import "./chunk-
|
|
299
|
+
import "./chunk-ZPPKBURE.js";
|
|
300
300
|
import {
|
|
301
301
|
deriveTopicsFromExtraction
|
|
302
|
-
} from "./chunk-
|
|
302
|
+
} from "./chunk-URXJ4CDO.js";
|
|
303
303
|
import {
|
|
304
304
|
BulkImportBatchPartialFailureError,
|
|
305
305
|
COMPACTION_SIGNAL_MAX_AGE_MS,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runRecallNavigation
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IRFCIJTX.js";
|
|
4
4
|
import "./chunk-6P7U3HWG.js";
|
|
5
5
|
import "./chunk-PQM3B54K.js";
|
|
6
6
|
import "./chunk-B3DR2JBZ.js";
|
|
@@ -186,9 +186,9 @@ import "./chunk-IHCXMYSE.js";
|
|
|
186
186
|
import "./chunk-D6IGZYTN.js";
|
|
187
187
|
import "./chunk-W7K5BP3M.js";
|
|
188
188
|
import "./chunk-LZIOY7ZU.js";
|
|
189
|
-
import "./chunk-
|
|
189
|
+
import "./chunk-CAE7ALRH.js";
|
|
190
190
|
import "./chunk-EI6V5UXY.js";
|
|
191
|
-
import "./chunk-
|
|
191
|
+
import "./chunk-TWPQVPD4.js";
|
|
192
192
|
import "./chunk-UA2NDTIU.js";
|
|
193
193
|
import "./chunk-6XTUZKCZ.js";
|
|
194
194
|
import "./chunk-54V4BZWP.js";
|
|
@@ -286,8 +286,8 @@ import "./chunk-GKCXTSFF.js";
|
|
|
286
286
|
import "./chunk-2LSZVONP.js";
|
|
287
287
|
import "./chunk-DEUNUKTD.js";
|
|
288
288
|
import "./chunk-LXY5VVGM.js";
|
|
289
|
-
import "./chunk-
|
|
290
|
-
import "./chunk-
|
|
289
|
+
import "./chunk-ZPPKBURE.js";
|
|
290
|
+
import "./chunk-URXJ4CDO.js";
|
|
291
291
|
import "./chunk-THV6PZ7V.js";
|
|
292
292
|
import "./chunk-CSAKJVXW.js";
|
|
293
293
|
import "./chunk-K2XUWZBM.js";
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
headerConnector,
|
|
4
4
|
renderExtractionConversation,
|
|
5
5
|
resolveSourceConnector
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TWPQVPD4.js";
|
|
7
7
|
import "./chunk-UA2NDTIU.js";
|
|
8
8
|
import "./chunk-6XTUZKCZ.js";
|
|
9
9
|
import "./chunk-D3ZKHLN2.js";
|
|
@@ -14,7 +14,7 @@ import "./chunk-VEWZZM3H.js";
|
|
|
14
14
|
import "./chunk-BCMB7GJQ.js";
|
|
15
15
|
import "./chunk-3UXOZBHV.js";
|
|
16
16
|
import "./chunk-AL3TCNSJ.js";
|
|
17
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-URXJ4CDO.js";
|
|
18
18
|
import "./chunk-THV6PZ7V.js";
|
|
19
19
|
import "./chunk-CSAKJVXW.js";
|
|
20
20
|
import "./chunk-K2XUWZBM.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remnic/core",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.118",
|
|
4
4
|
"description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -3386,7 +3386,7 @@
|
|
|
3386
3386
|
"core"
|
|
3387
3387
|
],
|
|
3388
3388
|
"peerDependencies": {
|
|
3389
|
-
"@remnic/coding-graph": "^10.0.
|
|
3389
|
+
"@remnic/coding-graph": "^10.0.118"
|
|
3390
3390
|
},
|
|
3391
3391
|
"peerDependenciesMeta": {
|
|
3392
3392
|
"@remnic/coding-graph": {
|
package/src/access-mcp.test.ts
CHANGED
|
@@ -174,6 +174,44 @@ test("MCP reports a missing storage target as a non-retryable storage_target_req
|
|
|
174
174
|
assert.deepEqual(result.result?.structuredContent, { code: "storage_target_required", retryable: false }, JSON.stringify(response));
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
+
test("#3381: MCP returns the missing storage target explanation and does not log it as an internal error", async () => {
|
|
178
|
+
const failure = new Error("accepted capture requires an explicit storage target");
|
|
179
|
+
failure.name = "StorageTargetRequiredError";
|
|
180
|
+
// SAFETY: the mock overrides only observe; every other MCP dispatch path is unreachable in this test.
|
|
181
|
+
const service = Object.assign({} as EngramAccessService, {
|
|
182
|
+
observe: async () => {
|
|
183
|
+
throw failure;
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
const errorLines: string[] = [];
|
|
187
|
+
initLogger(
|
|
188
|
+
{
|
|
189
|
+
info() {},
|
|
190
|
+
warn() {},
|
|
191
|
+
error(msg: string) {
|
|
192
|
+
errorLines.push(msg);
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
false,
|
|
196
|
+
{ timestamps: false },
|
|
197
|
+
);
|
|
198
|
+
try {
|
|
199
|
+
const outcome = readCallToolOutcome(
|
|
200
|
+
await new EngramMcpServer(service).handleRequest(
|
|
201
|
+
makeToolRequest("engram.observe", {
|
|
202
|
+
sessionKey: "no-target-session",
|
|
203
|
+
messages: [{ role: "user", content: "cannot succeed on retry" }],
|
|
204
|
+
}),
|
|
205
|
+
),
|
|
206
|
+
);
|
|
207
|
+
assert.equal(outcome.isError, true);
|
|
208
|
+
assert.equal(outcome.text, failure.message, "a request fault must explain itself, not read as an internal error");
|
|
209
|
+
assert.deepEqual(errorLines, [], "a request fault is not a server error");
|
|
210
|
+
} finally {
|
|
211
|
+
resetLogger();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
177
215
|
// ──────────────────────────────────────────────────────────────────────────
|
|
178
216
|
// Finding 2 (#396 new): invalid MCP briefing format values must be rejected
|
|
179
217
|
// ──────────────────────────────────────────────────────────────────────────
|
package/src/access-mcp.ts
CHANGED
|
@@ -100,10 +100,16 @@ function throwMcpAbort(signal: AbortSignal | undefined, message: string): void {
|
|
|
100
100
|
/**
|
|
101
101
|
* Map tools/call failures to a client-safe message. Unexpected backend/fs
|
|
102
102
|
* errors become a stable generic string; detail stays in the server log.
|
|
103
|
-
* Intended EngramAccessInputError / EngramAccessForbiddenError stay readable
|
|
103
|
+
* Intended EngramAccessInputError / EngramAccessForbiddenError stay readable, and
|
|
104
|
+
* so does a missing storage target: it is a request fault, as on HTTP (400),
|
|
105
|
+
* not a server error (#3381).
|
|
104
106
|
*/
|
|
105
107
|
function mcpToolErrorMessage(err: Error): string {
|
|
106
|
-
if (
|
|
108
|
+
if (
|
|
109
|
+
err instanceof EngramAccessInputError ||
|
|
110
|
+
err instanceof EngramAccessForbiddenError ||
|
|
111
|
+
err.name === "StorageTargetRequiredError"
|
|
112
|
+
) {
|
|
107
113
|
return err.message;
|
|
108
114
|
}
|
|
109
115
|
log.error("engram MCP tools/call internal error", err);
|
|
@@ -1593,3 +1593,113 @@ test("#3227: a failed reflection-only persist stays retryable instead of an empt
|
|
|
1593
1593
|
await h.cleanup();
|
|
1594
1594
|
}
|
|
1595
1595
|
});
|
|
1596
|
+
|
|
1597
|
+
test("half-open probe: a probe that cannot answer in time re-opens the breaker instead of holding every attempt", async () => {
|
|
1598
|
+
const h = await makeHarness({
|
|
1599
|
+
extractionRetryScheduleMs: [3_600_000],
|
|
1600
|
+
extractionBreakerFailureThreshold: 1,
|
|
1601
|
+
extractionBreakerCooldownMs: 0, // the next call flips open to half_open and probes
|
|
1602
|
+
});
|
|
1603
|
+
try {
|
|
1604
|
+
let calls = 0;
|
|
1605
|
+
const abortedWhenStopped: boolean[] = [];
|
|
1606
|
+
const coord = new ExtractionRunCoordinator({
|
|
1607
|
+
...h.makeDeps(),
|
|
1608
|
+
halfOpenProbeTimeoutMs: 40,
|
|
1609
|
+
getExtraction: () => ({
|
|
1610
|
+
extract: async (_turns, _entities, signal) => {
|
|
1611
|
+
calls += 1;
|
|
1612
|
+
if (calls === 1) return failureResult("provider_retryable");
|
|
1613
|
+
// The probe: no answer until the caller gives up.
|
|
1614
|
+
const stopped = Promise.withResolvers<void>();
|
|
1615
|
+
signal?.addEventListener("abort", () => stopped.resolve(), { once: true });
|
|
1616
|
+
await stopped.promise;
|
|
1617
|
+
abortedWhenStopped.push(signal?.aborted === true);
|
|
1618
|
+
return successResult();
|
|
1619
|
+
},
|
|
1620
|
+
}),
|
|
1621
|
+
});
|
|
1622
|
+
await h.run(coord, "fp-1"); // one failure opens the breaker
|
|
1623
|
+
assert.equal(coord.getExtractionResilienceStatus().breaker.state, "open");
|
|
1624
|
+
|
|
1625
|
+
const guard = Promise.withResolvers<null>();
|
|
1626
|
+
const guardTimer = setTimeout(() => guard.resolve(null), 1_500);
|
|
1627
|
+
const outcome = await Promise.race([h.run(coord, "fp-2"), guard.promise]);
|
|
1628
|
+
clearTimeout(guardTimer);
|
|
1629
|
+
assert.ok(outcome !== null, "the probe is bounded, not held until the provider answers");
|
|
1630
|
+
assert.deepEqual(abortedWhenStopped, [true], "the in-flight request was cancelled");
|
|
1631
|
+
assert.equal(coord.getExtractionResilienceStatus().breaker.state, "open", "a timed-out probe re-opens the breaker");
|
|
1632
|
+
assert.equal(outcome.retainedBuffer, true, "the turns are kept for a retry");
|
|
1633
|
+
} finally {
|
|
1634
|
+
await h.cleanup();
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
|
|
1638
|
+
test("half-open probe timeout bounds only the probe: a normal attempt may run longer", async () => {
|
|
1639
|
+
const h = await makeHarness({ extractionRetryScheduleMs: [3_600_000] });
|
|
1640
|
+
try {
|
|
1641
|
+
const coord = new ExtractionRunCoordinator({
|
|
1642
|
+
...h.makeDeps(),
|
|
1643
|
+
halfOpenProbeTimeoutMs: 20,
|
|
1644
|
+
getExtraction: () => ({
|
|
1645
|
+
extract: async () => {
|
|
1646
|
+
const slow = Promise.withResolvers<void>();
|
|
1647
|
+
setTimeout(() => slow.resolve(), 150);
|
|
1648
|
+
await slow.promise;
|
|
1649
|
+
return successResult();
|
|
1650
|
+
},
|
|
1651
|
+
}),
|
|
1652
|
+
});
|
|
1653
|
+
const outcome = await h.run(coord, "fp-1"); // breaker closed: no probe, no bound
|
|
1654
|
+
assert.equal(outcome.status, "completed");
|
|
1655
|
+
} finally {
|
|
1656
|
+
await h.cleanup();
|
|
1657
|
+
}
|
|
1658
|
+
});
|
|
1659
|
+
|
|
1660
|
+
test("half-open probe timeout keeps the caller deadline enforced while the failure is recorded", async () => {
|
|
1661
|
+
const h = await makeHarness({
|
|
1662
|
+
extractionRetryScheduleMs: [3_600_000],
|
|
1663
|
+
extractionBreakerFailureThreshold: 1,
|
|
1664
|
+
extractionBreakerCooldownMs: 0,
|
|
1665
|
+
});
|
|
1666
|
+
try {
|
|
1667
|
+
let calls = 0;
|
|
1668
|
+
const coord = new ExtractionRunCoordinator({
|
|
1669
|
+
...h.makeDeps(),
|
|
1670
|
+
halfOpenProbeTimeoutMs: 20,
|
|
1671
|
+
getExtraction: () => ({
|
|
1672
|
+
extract: async (_turns, _entities, signal) => {
|
|
1673
|
+
calls += 1;
|
|
1674
|
+
if (calls === 1) return failureResult("provider_retryable");
|
|
1675
|
+
const stopped = Promise.withResolvers<void>();
|
|
1676
|
+
signal?.addEventListener("abort", () => stopped.resolve(), { once: true });
|
|
1677
|
+
await stopped.promise;
|
|
1678
|
+
return successResult();
|
|
1679
|
+
},
|
|
1680
|
+
}),
|
|
1681
|
+
});
|
|
1682
|
+
await h.run(coord, "fp-1"); // opens the breaker
|
|
1683
|
+
// Recording the probe failure must not outlive the caller deadline.
|
|
1684
|
+
const storage = await h.storageForNs("default");
|
|
1685
|
+
storage.updateMeta = () => new Promise<never>(() => {});
|
|
1686
|
+
const guard = Promise.withResolvers<"hung">();
|
|
1687
|
+
const guardTimer = setTimeout(() => guard.resolve("hung"), 2_000);
|
|
1688
|
+
const outcome = await Promise.race([
|
|
1689
|
+
coord
|
|
1690
|
+
.runExtraction(makeTurns("fp-2"), {
|
|
1691
|
+
skipCharThreshold: true,
|
|
1692
|
+
skipUserTurnThreshold: true,
|
|
1693
|
+
clearBufferAfterExtraction: false,
|
|
1694
|
+
bufferKey: "fp-2",
|
|
1695
|
+
deadlineMs: Date.now() + 300,
|
|
1696
|
+
})
|
|
1697
|
+
.then(() => "returned", () => "rejected"),
|
|
1698
|
+
guard.promise,
|
|
1699
|
+
]);
|
|
1700
|
+
clearTimeout(guardTimer);
|
|
1701
|
+
assert.notEqual(outcome, "hung", "the caller deadline cut the hung metadata write");
|
|
1702
|
+
} finally {
|
|
1703
|
+
await h.cleanup();
|
|
1704
|
+
}
|
|
1705
|
+
});
|
|
@@ -117,6 +117,9 @@ export interface ExtractionRunCoordinatorDeps {
|
|
|
117
117
|
* abort signal: queued tasks never start and in-flight runs abort the
|
|
118
118
|
* moment destroy() begins. Absent for standalone coordinators (tests). */
|
|
119
119
|
shutdownSignal?: AbortSignal;
|
|
120
|
+
/** Test seam: how long a half-open probe may run before it counts as a
|
|
121
|
+
* provider failure. Defaults to HALF_OPEN_PROBE_TIMEOUT_MS (provider-breaker.ts). */
|
|
122
|
+
halfOpenProbeTimeoutMs?: number;
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
// Recall/extraction abort helpers live in orchestrator-helpers.ts since
|
|
@@ -138,6 +141,7 @@ import {
|
|
|
138
141
|
import type { ExtractionResilienceStatus, ExtractionRetryStateEntry } from "./extraction-run-helpers.js";
|
|
139
142
|
import type { ExtractionPersistResult } from "./extraction-persist.js";
|
|
140
143
|
import { ProviderCircuitBreaker, type ProbeOwnerToken } from "./provider-breaker.js";
|
|
144
|
+
import { probeTimedOutResult, startProbeDeadline } from "./probe-deadline.js";
|
|
141
145
|
|
|
142
146
|
export {
|
|
143
147
|
capExtractionRetryStateEntries,
|
|
@@ -852,18 +856,26 @@ export class ExtractionRunCoordinator {
|
|
|
852
856
|
"during_list_entity_names",
|
|
853
857
|
);
|
|
854
858
|
let result: ExtractionResult;
|
|
859
|
+
// The half-open probe is bounded: one that gets no answer in time counts as
|
|
860
|
+
// a provider failure (re-opens the breaker) instead of holding every other
|
|
861
|
+
// attempt until the provider answers or times out.
|
|
862
|
+
const probe = startProbeDeadline(extractionProbeOwned, extractionAbortSignal, this.deps.halfOpenProbeTimeoutMs);
|
|
855
863
|
try {
|
|
856
864
|
result = await raceRecallAbort(
|
|
857
|
-
this.deps.getExtraction().extract(normalizedTurns, existingEntities,
|
|
858
|
-
|
|
865
|
+
this.deps.getExtraction().extract(normalizedTurns, existingEntities, probe.signal),
|
|
866
|
+
probe.signal,
|
|
859
867
|
"extraction aborted (during_extract)",
|
|
860
868
|
);
|
|
861
869
|
} catch (error) {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
throw error;
|
|
870
|
+
const pastDeadline = deadlineMs !== undefined && Date.now() >= deadlineMs;
|
|
871
|
+
// Keep the caller deadline timer running while a probe timeout is turned into a failure result.
|
|
872
|
+
if (pastDeadline || !probe.timedOut()) clearExtractionDeadlineTimer();
|
|
873
|
+
if (pastDeadline) throw new ExtractionDeadlineError("during_extract");
|
|
874
|
+
if (!probe.timedOut()) throw error;
|
|
875
|
+
log.warn("runExtraction: half-open probe got no answer in time; treating it as a provider failure");
|
|
876
|
+
result = probeTimedOutResult();
|
|
877
|
+
} finally {
|
|
878
|
+
probe.stop();
|
|
867
879
|
}
|
|
868
880
|
try {
|
|
869
881
|
throwIfDeadlineExceeded("before_persist");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ExtractionResult } from "../types.js";
|
|
2
|
+
import { HALF_OPEN_PROBE_TIMEOUT_MS } from "./provider-breaker.js";
|
|
3
|
+
|
|
4
|
+
export interface ProbeDeadline {
|
|
5
|
+
/** The caller's signal, plus the probe timer's when this attempt owns the probe. */
|
|
6
|
+
readonly signal: AbortSignal | undefined;
|
|
7
|
+
/** True only when the probe timer fired (not when the caller aborted). */
|
|
8
|
+
timedOut(): boolean;
|
|
9
|
+
stop(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Bounds the single half-open probe; any other attempt keeps the caller's signal and no timer. */
|
|
13
|
+
export function startProbeDeadline(
|
|
14
|
+
probeOwned: boolean,
|
|
15
|
+
callerSignal: AbortSignal | undefined,
|
|
16
|
+
timeoutMs: number = HALF_OPEN_PROBE_TIMEOUT_MS,
|
|
17
|
+
): ProbeDeadline {
|
|
18
|
+
if (!probeOwned) return { signal: callerSignal, timedOut: () => false, stop: () => undefined };
|
|
19
|
+
const timeout = new AbortController();
|
|
20
|
+
const timer = setTimeout(() => timeout.abort(), timeoutMs);
|
|
21
|
+
return {
|
|
22
|
+
signal: callerSignal ? AbortSignal.any([callerSignal, timeout.signal]) : timeout.signal,
|
|
23
|
+
timedOut: () => timeout.signal.aborted,
|
|
24
|
+
stop: () => clearTimeout(timer),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What a probe that got no answer in time reports: the ordinary retryable provider failure. */
|
|
29
|
+
export function probeTimedOutResult(): ExtractionResult {
|
|
30
|
+
return {
|
|
31
|
+
facts: [],
|
|
32
|
+
profileUpdates: [],
|
|
33
|
+
entities: [],
|
|
34
|
+
questions: [],
|
|
35
|
+
extractionFailure: "local_llm_unavailable",
|
|
36
|
+
extractionFailureClass: "provider_retryable",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -7,6 +7,16 @@ export interface ProviderBreakerConfig {
|
|
|
7
7
|
readonly authCooldownMs: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* How long the single half-open probe may run before it counts as a provider
|
|
12
|
+
* failure and re-opens the breaker. Before this bound, a probe waiting in the
|
|
13
|
+
* local LLM queue and then timing out twice held every drain for up to 55 min.
|
|
14
|
+
* 15 min covers the slowest probe that did succeed in a 24 h production log
|
|
15
|
+
* (10 min) and caps a failed one at 15 min plus the cooldown.
|
|
16
|
+
* shortcut: a constant, not config; make it a config key if hosts need to tune it.
|
|
17
|
+
*/
|
|
18
|
+
export const HALF_OPEN_PROBE_TIMEOUT_MS = 900_000;
|
|
19
|
+
|
|
10
20
|
export interface ProbeOwnerToken {
|
|
11
21
|
readonly __probeOwner: true;
|
|
12
22
|
}
|