@remnic/core 10.0.153 → 10.0.154
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 +40 -40
- package/dist/access-cli.js +40 -40
- package/dist/access-extraction-force-flush-preempt.js +40 -40
- package/dist/access-extraction-force-flush.js +40 -40
- package/dist/access-http-briefing.js +40 -40
- package/dist/access-http-query.js +40 -40
- package/dist/access-http.js +40 -40
- package/dist/access-identity-continuity-surface.js +40 -40
- package/dist/access-lcm-surface.js +40 -40
- package/dist/access-mcp.js +40 -40
- package/dist/access-observe-write-surface.js +40 -40
- package/dist/access-operations-batch.js +40 -40
- package/dist/access-operations.js +40 -40
- package/dist/access-recall-concurrency.js +40 -40
- package/dist/access-recall-response.js +40 -40
- package/dist/access-recall-surface.js +40 -40
- package/dist/access-service.js +40 -40
- package/dist/active-recall.js +4 -4
- package/dist/briefing.js +5 -5
- package/dist/buffer.js +4 -4
- package/dist/causal-consolidation.js +6 -6
- package/dist/{chunk-HOENUZJ7.js → chunk-2EFXVRYX.js} +2 -2
- package/dist/{chunk-LYSE5FNF.js → chunk-3LO6OFRM.js} +2 -2
- package/dist/{chunk-NQ2WFFPQ.js → chunk-447ERYQ5.js} +2 -2
- package/dist/{chunk-5LL2X5SO.js → chunk-4KHGOVRI.js} +2 -2
- package/dist/{chunk-6M3VJJON.js → chunk-56BVK6DU.js} +2 -2
- package/dist/{chunk-Z5QZHDG2.js → chunk-5ZZZDDSF.js} +2 -2
- package/dist/{chunk-SENCYTQ2.js → chunk-73MEZ6LB.js} +2 -2
- package/dist/{chunk-DPF7TX3D.js → chunk-CYPS6NPQ.js} +2 -2
- package/dist/{chunk-4Y4LPKFV.js → chunk-DDUWI2XM.js} +47 -13
- package/dist/chunk-DDUWI2XM.js.map +1 -0
- package/dist/{chunk-HAEMXLHX.js → chunk-DUAGLBFC.js} +2 -2
- package/dist/{chunk-SBG5RR6X.js → chunk-E2CJNFAZ.js} +7 -7
- package/dist/{chunk-KZBUOWKB.js → chunk-FXZEKC32.js} +2 -2
- package/dist/{chunk-272GJCTZ.js → chunk-G2NTB4TM.js} +2 -2
- package/dist/{chunk-JOQZRIL4.js → chunk-G4SAFDNR.js} +2 -2
- package/dist/{chunk-M7BJEWPQ.js → chunk-GYJI34G6.js} +2 -2
- package/dist/{chunk-AMPTUYKS.js → chunk-H36HLLSU.js} +2 -2
- package/dist/{chunk-XSG2S43P.js → chunk-IACG6B5R.js} +3 -3
- package/dist/{chunk-C4AAKTP5.js → chunk-IQBBNFSP.js} +5 -5
- package/dist/{chunk-6ENFCUYH.js → chunk-JE2ZI4SS.js} +3 -3
- package/dist/{chunk-5N767BMB.js → chunk-KNOWIDYI.js} +2 -2
- package/dist/{chunk-5Y3UVK6S.js → chunk-MV3D5IDW.js} +2 -2
- package/dist/{chunk-EK3GC76D.js → chunk-NNZR5JZJ.js} +2 -2
- package/dist/{chunk-MONIOXEG.js → chunk-ONMYWZLY.js} +2 -2
- package/dist/{chunk-HASIFVWH.js → chunk-OOLREGPZ.js} +2 -2
- package/dist/{chunk-VZCX3DOD.js → chunk-P7TJUCNC.js} +2 -2
- package/dist/{chunk-WE6MSFYM.js → chunk-PXCQKVIF.js} +2 -2
- package/dist/{chunk-UUY7OEO7.js → chunk-QMDYZIXK.js} +2 -2
- package/dist/{chunk-RAOM5WU2.js → chunk-RAGRW65B.js} +3 -3
- package/dist/{chunk-ALNINIUB.js → chunk-SDDHY437.js} +2 -2
- package/dist/{chunk-T266H3RJ.js → chunk-SFRAXHQO.js} +2 -2
- package/dist/{chunk-MXMFRU45.js → chunk-SPQXVDUP.js} +7 -7
- package/dist/{chunk-O2677F2E.js → chunk-TZ7KXZ47.js} +2 -2
- package/dist/{chunk-EUIWWY2F.js → chunk-VHSCKVWB.js} +3 -3
- package/dist/{chunk-T2IKH7XD.js → chunk-VPTPLNTS.js} +2 -2
- package/dist/{chunk-G2TK5YYU.js → chunk-W5T7QBYZ.js} +2 -2
- package/dist/{chunk-ZFGXIEQU.js → chunk-W7KDTZWR.js} +2 -2
- package/dist/{chunk-E2JONYZR.js → chunk-X6VXQALC.js} +35 -35
- package/dist/{chunk-XTJUE2ON.js → chunk-XUYUYYK2.js} +2 -2
- package/dist/{chunk-BHZ72ZQ3.js → chunk-ZCJP4UA6.js} +2 -2
- package/dist/{chunk-LMFINE37.js → chunk-ZH36OFFA.js} +2 -2
- package/dist/{chunk-J2NQZJRG.js → chunk-ZRTFGKPG.js} +2 -2
- package/dist/cli.js +40 -40
- package/dist/coding/export-okf-codegraph.js +4 -4
- package/dist/compounding/engine.js +6 -6
- package/dist/config.js +4 -4
- package/dist/connectors/codex-materialize-runner.js +5 -5
- package/dist/connectors/index.js +5 -5
- package/dist/convergence-refresh.js +7 -7
- package/dist/corpus-watermark.js +7 -7
- package/dist/entity-retrieval.js +5 -5
- package/dist/explicit-capture.js +40 -40
- package/dist/extraction.js +9 -9
- package/dist/harmonic-retrieval.js +5 -5
- package/dist/index.js +40 -40
- package/dist/location/index.js +6 -6
- package/dist/maintenance/memory-governance.js +5 -5
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +5 -5
- package/dist/maintenance/rebuild-memory-projection-runner.js +7 -7
- package/dist/maintenance/rebuild-memory-projection.js +6 -6
- package/dist/memory-browse.js +4 -4
- package/dist/namespaces/migrate.js +6 -6
- package/dist/namespaces/search.js +3 -3
- package/dist/namespaces/storage.js +5 -5
- package/dist/operator-doctor-corpus.js +8 -8
- package/dist/operator-toolkit.js +11 -11
- package/dist/orchestration/backlog-scheduler.js +41 -41
- package/dist/orchestration/buffer-drain-runner.js +41 -41
- package/dist/orchestration/maintenance.js +13 -13
- package/dist/orchestrator.js +40 -40
- package/dist/qmd.d.ts +9 -3
- package/dist/qmd.d.ts.map +1 -1
- package/dist/qmd.js +1 -1
- package/dist/recall-navigation.js +40 -40
- package/dist/recall-state-view-admission.js +4 -4
- package/dist/recall-why-service.js +4 -4
- package/dist/resume-bundles.js +4 -4
- package/dist/search/factory.js +2 -2
- package/dist/search/index.js +2 -2
- package/dist/semantic-consolidation.js +6 -6
- package/dist/semantic-rule-promotion.js +5 -5
- package/dist/semantic-rule-verifier.js +5 -5
- package/dist/source-agent-qualifier.js +8 -8
- package/dist/standup/build.js +5 -5
- package/dist/storage.js +4 -4
- package/dist/transfer/export-okf.js +5 -5
- package/dist/verified-recall.js +5 -5
- package/dist/who-knows-cli.js +6 -6
- package/dist/who-knows.js +5 -5
- package/package.json +2 -2
- package/src/qmd-daemon-congestion.test.ts +260 -0
- package/src/qmd.ts +59 -23
- package/dist/chunk-4Y4LPKFV.js.map +0 -1
- /package/dist/{chunk-HOENUZJ7.js.map → chunk-2EFXVRYX.js.map} +0 -0
- /package/dist/{chunk-LYSE5FNF.js.map → chunk-3LO6OFRM.js.map} +0 -0
- /package/dist/{chunk-NQ2WFFPQ.js.map → chunk-447ERYQ5.js.map} +0 -0
- /package/dist/{chunk-5LL2X5SO.js.map → chunk-4KHGOVRI.js.map} +0 -0
- /package/dist/{chunk-6M3VJJON.js.map → chunk-56BVK6DU.js.map} +0 -0
- /package/dist/{chunk-Z5QZHDG2.js.map → chunk-5ZZZDDSF.js.map} +0 -0
- /package/dist/{chunk-SENCYTQ2.js.map → chunk-73MEZ6LB.js.map} +0 -0
- /package/dist/{chunk-DPF7TX3D.js.map → chunk-CYPS6NPQ.js.map} +0 -0
- /package/dist/{chunk-HAEMXLHX.js.map → chunk-DUAGLBFC.js.map} +0 -0
- /package/dist/{chunk-SBG5RR6X.js.map → chunk-E2CJNFAZ.js.map} +0 -0
- /package/dist/{chunk-KZBUOWKB.js.map → chunk-FXZEKC32.js.map} +0 -0
- /package/dist/{chunk-272GJCTZ.js.map → chunk-G2NTB4TM.js.map} +0 -0
- /package/dist/{chunk-JOQZRIL4.js.map → chunk-G4SAFDNR.js.map} +0 -0
- /package/dist/{chunk-M7BJEWPQ.js.map → chunk-GYJI34G6.js.map} +0 -0
- /package/dist/{chunk-AMPTUYKS.js.map → chunk-H36HLLSU.js.map} +0 -0
- /package/dist/{chunk-XSG2S43P.js.map → chunk-IACG6B5R.js.map} +0 -0
- /package/dist/{chunk-C4AAKTP5.js.map → chunk-IQBBNFSP.js.map} +0 -0
- /package/dist/{chunk-6ENFCUYH.js.map → chunk-JE2ZI4SS.js.map} +0 -0
- /package/dist/{chunk-5N767BMB.js.map → chunk-KNOWIDYI.js.map} +0 -0
- /package/dist/{chunk-5Y3UVK6S.js.map → chunk-MV3D5IDW.js.map} +0 -0
- /package/dist/{chunk-EK3GC76D.js.map → chunk-NNZR5JZJ.js.map} +0 -0
- /package/dist/{chunk-MONIOXEG.js.map → chunk-ONMYWZLY.js.map} +0 -0
- /package/dist/{chunk-HASIFVWH.js.map → chunk-OOLREGPZ.js.map} +0 -0
- /package/dist/{chunk-VZCX3DOD.js.map → chunk-P7TJUCNC.js.map} +0 -0
- /package/dist/{chunk-WE6MSFYM.js.map → chunk-PXCQKVIF.js.map} +0 -0
- /package/dist/{chunk-UUY7OEO7.js.map → chunk-QMDYZIXK.js.map} +0 -0
- /package/dist/{chunk-RAOM5WU2.js.map → chunk-RAGRW65B.js.map} +0 -0
- /package/dist/{chunk-ALNINIUB.js.map → chunk-SDDHY437.js.map} +0 -0
- /package/dist/{chunk-T266H3RJ.js.map → chunk-SFRAXHQO.js.map} +0 -0
- /package/dist/{chunk-MXMFRU45.js.map → chunk-SPQXVDUP.js.map} +0 -0
- /package/dist/{chunk-O2677F2E.js.map → chunk-TZ7KXZ47.js.map} +0 -0
- /package/dist/{chunk-EUIWWY2F.js.map → chunk-VHSCKVWB.js.map} +0 -0
- /package/dist/{chunk-T2IKH7XD.js.map → chunk-VPTPLNTS.js.map} +0 -0
- /package/dist/{chunk-G2TK5YYU.js.map → chunk-W5T7QBYZ.js.map} +0 -0
- /package/dist/{chunk-ZFGXIEQU.js.map → chunk-W7KDTZWR.js.map} +0 -0
- /package/dist/{chunk-E2JONYZR.js.map → chunk-X6VXQALC.js.map} +0 -0
- /package/dist/{chunk-XTJUE2ON.js.map → chunk-XUYUYYK2.js.map} +0 -0
- /package/dist/{chunk-BHZ72ZQ3.js.map → chunk-ZCJP4UA6.js.map} +0 -0
- /package/dist/{chunk-LMFINE37.js.map → chunk-ZH36OFFA.js.map} +0 -0
- /package/dist/{chunk-J2NQZJRG.js.map → chunk-ZRTFGKPG.js.map} +0 -0
package/dist/who-knows.js
CHANGED
|
@@ -9,15 +9,15 @@ import {
|
|
|
9
9
|
loadWhoKnowsEntities,
|
|
10
10
|
tokenizeTopic,
|
|
11
11
|
validateWhoKnowsInput
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-56BVK6DU.js";
|
|
13
|
+
import "./chunk-447ERYQ5.js";
|
|
14
14
|
import "./chunk-QGVCFVX6.js";
|
|
15
15
|
import "./chunk-UHVXE24Y.js";
|
|
16
16
|
import "./chunk-AW56K4SI.js";
|
|
17
17
|
import "./chunk-G6OFEGUR.js";
|
|
18
18
|
import "./chunk-SDGD6MYV.js";
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-G2NTB4TM.js";
|
|
20
|
+
import "./chunk-73MEZ6LB.js";
|
|
21
21
|
import "./chunk-YCK26VSL.js";
|
|
22
22
|
import "./chunk-EXYT52NR.js";
|
|
23
23
|
import "./chunk-MX5VGD6C.js";
|
|
@@ -55,7 +55,7 @@ import "./chunk-UUSL22HE.js";
|
|
|
55
55
|
import "./chunk-5WITETWU.js";
|
|
56
56
|
import "./chunk-6CIAGZ6X.js";
|
|
57
57
|
import "./chunk-Y33KJ556.js";
|
|
58
|
-
import "./chunk-
|
|
58
|
+
import "./chunk-DDUWI2XM.js";
|
|
59
59
|
import "./chunk-B7HYXVME.js";
|
|
60
60
|
import "./chunk-EZ47HOJ6.js";
|
|
61
61
|
import "./chunk-AF2XMJKD.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remnic/core",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.154",
|
|
4
4
|
"description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -3396,7 +3396,7 @@
|
|
|
3396
3396
|
"core"
|
|
3397
3397
|
],
|
|
3398
3398
|
"peerDependencies": {
|
|
3399
|
-
"@remnic/coding-graph": "^10.0.
|
|
3399
|
+
"@remnic/coding-graph": "^10.0.154"
|
|
3400
3400
|
},
|
|
3401
3401
|
"peerDependenciesMeta": {
|
|
3402
3402
|
"@remnic/coding-graph": {
|
|
@@ -197,6 +197,266 @@ test("a congestion mark from one client gates siblings sharing the daemon sessio
|
|
|
197
197
|
assert.deepEqual(legTypes(calls[1]!), ["lex"]);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
+
test("an already slow in-flight hybrid query degrades a sibling on the same daemon (#3499)", async (t) => {
|
|
201
|
+
let now = 1000;
|
|
202
|
+
t.mock.method(performance, "now", () => now);
|
|
203
|
+
const calls: CapturedCall[] = [];
|
|
204
|
+
const started = Promise.withResolvers<void>();
|
|
205
|
+
const release = Promise.withResolvers<void>();
|
|
206
|
+
const sessionCallTool: CallToolFn = async (name, args) => {
|
|
207
|
+
calls.push({ name, args });
|
|
208
|
+
if (calls.length === 1) {
|
|
209
|
+
started.resolve();
|
|
210
|
+
await release.promise;
|
|
211
|
+
}
|
|
212
|
+
return mcpOk([{ path: "result.md" }]);
|
|
213
|
+
};
|
|
214
|
+
const first = makeClient(sessionCallTool);
|
|
215
|
+
const sibling = makeClient(sessionCallTool);
|
|
216
|
+
sibling.internals.daemonSession = first.internals.daemonSession;
|
|
217
|
+
|
|
218
|
+
const pending = first.client.search("first recall", "memories", 3);
|
|
219
|
+
try {
|
|
220
|
+
await started.promise;
|
|
221
|
+
assert.deepEqual(legTypes(calls[0]!), ["lex", "vec", "hyde"]);
|
|
222
|
+
now += first.internals.daemonSlowQueryMs;
|
|
223
|
+
const results = await sibling.client.search("second recall", "memories", 3);
|
|
224
|
+
assert.equal(results.length, 1);
|
|
225
|
+
assert.deepEqual(calls[1]!.args.collections, ["memories"]);
|
|
226
|
+
assert.deepEqual(legTypes(calls[1]!), ["lex"]);
|
|
227
|
+
assert.equal(calls[1]!.args.rerank, false);
|
|
228
|
+
} finally {
|
|
229
|
+
release.resolve();
|
|
230
|
+
await pending;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test("a repeat of a slow query takes a lexical plan without waiting for the original", async (t) => {
|
|
235
|
+
let now = 1_000;
|
|
236
|
+
t.mock.method(performance, "now", () => now);
|
|
237
|
+
const calls: CapturedCall[] = [];
|
|
238
|
+
const started = Promise.withResolvers<void>();
|
|
239
|
+
const release = Promise.withResolvers<void>();
|
|
240
|
+
const { client, internals } = makeClient(async (name, args) => {
|
|
241
|
+
calls.push({ name, args });
|
|
242
|
+
if (calls.length === 1) {
|
|
243
|
+
started.resolve();
|
|
244
|
+
await release.promise;
|
|
245
|
+
return mcpOk([{ path: "hybrid.md" }]);
|
|
246
|
+
}
|
|
247
|
+
return mcpOk([{ path: "lexical.md" }]);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const original = client.search("repeat during a slow query", "memories", 3);
|
|
251
|
+
await started.promise;
|
|
252
|
+
now += internals.daemonSlowQueryMs;
|
|
253
|
+
const repeat = client.search("repeat during a slow query", "memories", 3);
|
|
254
|
+
try {
|
|
255
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
256
|
+
assert.equal(calls.length, 2, "the repeat must not join the slow hybrid call");
|
|
257
|
+
assert.deepEqual(legTypes(calls[1]!), ["lex"]);
|
|
258
|
+
assert.equal((await repeat)[0]?.path, "lexical.md");
|
|
259
|
+
} finally {
|
|
260
|
+
release.resolve();
|
|
261
|
+
await Promise.all([original, repeat]);
|
|
262
|
+
}
|
|
263
|
+
now += internals.daemonCongestionWindowMs + 1;
|
|
264
|
+
assert.equal((await client.search("repeat during a slow query", "memories", 3))[0]?.path, "hybrid.md");
|
|
265
|
+
assert.equal(calls.length, 2);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
for (const [leg, rerank, gatesSibling] of [
|
|
269
|
+
["lex", false, false],
|
|
270
|
+
["lex", undefined, true],
|
|
271
|
+
["vec", false, true],
|
|
272
|
+
] as const) {
|
|
273
|
+
test(`slow in-flight ${leg} (rerank=${rerank ?? "default"}) gates hybrid: ${gatesSibling}`, async (t) => {
|
|
274
|
+
let now = 1000;
|
|
275
|
+
t.mock.method(performance, "now", () => now);
|
|
276
|
+
const calls: CapturedCall[] = [];
|
|
277
|
+
const started = Promise.withResolvers<void>();
|
|
278
|
+
const release = Promise.withResolvers<void>();
|
|
279
|
+
const { client, internals } = makeClient(async (name, args) => {
|
|
280
|
+
calls.push({ name, args });
|
|
281
|
+
if (calls.length === 1) {
|
|
282
|
+
started.resolve();
|
|
283
|
+
await release.promise;
|
|
284
|
+
}
|
|
285
|
+
return mcpOk([{ path: "result.md" }]);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const query = `slow ${leg} recall (rerank=${rerank ?? "default"})`;
|
|
289
|
+
const options: Parameters<typeof client.search>[3] = {
|
|
290
|
+
structuredSearches: [{ type: leg, query }],
|
|
291
|
+
};
|
|
292
|
+
if (rerank === false) {
|
|
293
|
+
options.rerank = false;
|
|
294
|
+
}
|
|
295
|
+
const pending = client.search(query, "memories", 3, options);
|
|
296
|
+
try {
|
|
297
|
+
await started.promise;
|
|
298
|
+
assert.deepEqual(legTypes(calls[0]!), [leg]);
|
|
299
|
+
assert.equal(calls[0]!.args.rerank, rerank);
|
|
300
|
+
now += internals.daemonSlowQueryMs;
|
|
301
|
+
const results = await client.search(`hybrid sibling of ${query}`, "memories", 3);
|
|
302
|
+
assert.equal(results[0]?.path, "result.md");
|
|
303
|
+
assert.deepEqual(legTypes(calls[1]!), gatesSibling ? ["lex"] : ["lex", "vec", "hyde"]);
|
|
304
|
+
} finally {
|
|
305
|
+
release.resolve();
|
|
306
|
+
await pending;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
test("a fresh in-flight call does not gate siblings yet (#3499)", async (t) => {
|
|
312
|
+
let now = 1000;
|
|
313
|
+
t.mock.method(performance, "now", () => now);
|
|
314
|
+
const calls: CapturedCall[] = [];
|
|
315
|
+
const started = Promise.withResolvers<void>();
|
|
316
|
+
const release = Promise.withResolvers<void>();
|
|
317
|
+
const sessionCallTool: CallToolFn = async (name, args) => {
|
|
318
|
+
calls.push({ name, args });
|
|
319
|
+
if (calls.length === 1) {
|
|
320
|
+
started.resolve();
|
|
321
|
+
await release.promise;
|
|
322
|
+
}
|
|
323
|
+
return mcpOk([{ path: "r.md" }]);
|
|
324
|
+
};
|
|
325
|
+
const first = makeClient(sessionCallTool);
|
|
326
|
+
const sibling = makeClient(sessionCallTool);
|
|
327
|
+
sibling.internals.daemonSession = first.internals.daemonSession;
|
|
328
|
+
|
|
329
|
+
const pending = first.client.search("first young recall", "memories", 3);
|
|
330
|
+
try {
|
|
331
|
+
await started.promise;
|
|
332
|
+
now += first.internals.daemonSlowQueryMs - 1;
|
|
333
|
+
const results = await sibling.client.search("second young recall", "memories", 3);
|
|
334
|
+
assert.deepEqual(legTypes(calls[1]!), ["lex", "vec", "hyde"]);
|
|
335
|
+
assert.equal(results.length, 1);
|
|
336
|
+
} finally {
|
|
337
|
+
release.resolve();
|
|
338
|
+
await pending;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("a slow success clears the marker; hybrid returns only after the window also clears (#3499)", async (t) => {
|
|
343
|
+
let now = 1000;
|
|
344
|
+
t.mock.method(performance, "now", () => now);
|
|
345
|
+
const calls: CapturedCall[] = [];
|
|
346
|
+
const started = Promise.withResolvers<void>();
|
|
347
|
+
const release = Promise.withResolvers<void>();
|
|
348
|
+
const sessionCallTool: CallToolFn = async (name, args) => {
|
|
349
|
+
calls.push({ name, args });
|
|
350
|
+
if (calls.length === 1) {
|
|
351
|
+
started.resolve();
|
|
352
|
+
await release.promise;
|
|
353
|
+
}
|
|
354
|
+
return mcpOk([{ path: "r.md" }]);
|
|
355
|
+
};
|
|
356
|
+
const first = makeClient(sessionCallTool);
|
|
357
|
+
const sibling = makeClient(sessionCallTool);
|
|
358
|
+
sibling.internals.daemonSession = first.internals.daemonSession;
|
|
359
|
+
|
|
360
|
+
const pending = first.client.search("first success recall", "memories", 3);
|
|
361
|
+
await started.promise;
|
|
362
|
+
now += first.internals.daemonSlowQueryMs + 1;
|
|
363
|
+
release.resolve();
|
|
364
|
+
await pending; // a slow success still opens the congestion window (#3476)
|
|
365
|
+
assert.equal(
|
|
366
|
+
daemonCongestionForTest.inflightCalls(first.internals.daemonSession),
|
|
367
|
+
0,
|
|
368
|
+
"the marker is removed on success",
|
|
369
|
+
);
|
|
370
|
+
assert.ok(
|
|
371
|
+
daemonCongestionForTest.get(first.internals.daemonSession) > now,
|
|
372
|
+
"the slow success opened the congestion window",
|
|
373
|
+
);
|
|
374
|
+
now += first.internals.daemonCongestionWindowMs + 1;
|
|
375
|
+
const results = await sibling.client.search("second success recall", "memories", 3);
|
|
376
|
+
assert.deepEqual(legTypes(calls[1]!), ["lex", "vec", "hyde"]);
|
|
377
|
+
assert.equal(results.length, 1);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("a failed slow call clears the marker and opens no window (#3499)", async (t) => {
|
|
381
|
+
let now = 1000;
|
|
382
|
+
t.mock.method(performance, "now", () => now);
|
|
383
|
+
const calls: CapturedCall[] = [];
|
|
384
|
+
const started = Promise.withResolvers<void>();
|
|
385
|
+
const release = Promise.withResolvers<void>();
|
|
386
|
+
const sessionCallTool: CallToolFn = async (name, args) => {
|
|
387
|
+
calls.push({ name, args });
|
|
388
|
+
if (calls.length === 1) {
|
|
389
|
+
started.resolve();
|
|
390
|
+
await release.promise;
|
|
391
|
+
throw new Error("fetch failed");
|
|
392
|
+
}
|
|
393
|
+
return mcpOk([{ path: "r.md" }]);
|
|
394
|
+
};
|
|
395
|
+
const first = makeClient(sessionCallTool);
|
|
396
|
+
const sibling = makeClient(sessionCallTool);
|
|
397
|
+
sibling.internals.daemonSession = first.internals.daemonSession;
|
|
398
|
+
|
|
399
|
+
const pending = first.client.search("first failure recall", "memories", 3);
|
|
400
|
+
await started.promise;
|
|
401
|
+
now += first.internals.daemonSlowQueryMs + 1;
|
|
402
|
+
release.resolve();
|
|
403
|
+
const results = await pending; // transient failure degrades to [] without a window
|
|
404
|
+
assert.deepEqual(results, []);
|
|
405
|
+
assert.equal(
|
|
406
|
+
daemonCongestionForTest.inflightCalls(first.internals.daemonSession),
|
|
407
|
+
0,
|
|
408
|
+
"the marker is removed on failure",
|
|
409
|
+
);
|
|
410
|
+
assert.equal(
|
|
411
|
+
daemonCongestionForTest.get(first.internals.daemonSession),
|
|
412
|
+
0,
|
|
413
|
+
"a transient failure opens no congestion window",
|
|
414
|
+
);
|
|
415
|
+
await sibling.client.search("second failure recall", "memories", 3);
|
|
416
|
+
assert.deepEqual(legTypes(calls[1]!), ["lex", "vec", "hyde"]);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test("a cancelled slow call clears the marker; the existing slow-cancel window still applies (#3499)", async (t) => {
|
|
420
|
+
let now = 1000;
|
|
421
|
+
t.mock.method(performance, "now", () => now);
|
|
422
|
+
const calls: CapturedCall[] = [];
|
|
423
|
+
const started = Promise.withResolvers<void>();
|
|
424
|
+
const sessionCallTool: CallToolFn = async (name, args, _timeout, signal) => {
|
|
425
|
+
calls.push({ name, args });
|
|
426
|
+
if (calls.length === 1) {
|
|
427
|
+
started.resolve();
|
|
428
|
+
return new Promise<McpToolResult>((_resolve, reject) => {
|
|
429
|
+
signal?.addEventListener("abort", () => reject(new DOMException("aborted", "AbortError")));
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
return mcpOk([{ path: "r.md" }]);
|
|
433
|
+
};
|
|
434
|
+
const first = makeClient(sessionCallTool);
|
|
435
|
+
const sibling = makeClient(sessionCallTool);
|
|
436
|
+
sibling.internals.daemonSession = first.internals.daemonSession;
|
|
437
|
+
const ac = new AbortController();
|
|
438
|
+
|
|
439
|
+
const pending = first.client.search("first cancel recall", "memories", 3, undefined, { signal: ac.signal });
|
|
440
|
+
await started.promise;
|
|
441
|
+
now += first.internals.daemonSlowQueryMs + 1;
|
|
442
|
+
ac.abort();
|
|
443
|
+
await assert.rejects(pending, /aborted/);
|
|
444
|
+
assert.equal(
|
|
445
|
+
daemonCongestionForTest.inflightCalls(first.internals.daemonSession),
|
|
446
|
+
0,
|
|
447
|
+
"the marker is removed on cancellation",
|
|
448
|
+
);
|
|
449
|
+
assert.ok(
|
|
450
|
+
daemonCongestionForTest.get(first.internals.daemonSession) > now,
|
|
451
|
+
"a cancellation after the slow mark keeps the existing window",
|
|
452
|
+
);
|
|
453
|
+
await sibling.client.search("second cancel recall", "memories", 3);
|
|
454
|
+
assert.deepEqual(legTypes(calls[1]!), ["lex"]);
|
|
455
|
+
now += first.internals.daemonCongestionWindowMs + 1;
|
|
456
|
+
await sibling.client.search("third cancel recall", "memories", 3);
|
|
457
|
+
assert.deepEqual(legTypes(calls[2]!), ["lex", "vec", "hyde"]);
|
|
458
|
+
});
|
|
459
|
+
|
|
200
460
|
test("a daemon call cancelled after the slow mark still opens the window", async () => {
|
|
201
461
|
const calls: CapturedCall[] = [];
|
|
202
462
|
const { client, internals } = makeClient((name, args, _timeout, signal) => {
|
package/src/qmd.ts
CHANGED
|
@@ -848,12 +848,23 @@ export { releaseSharedDaemonSession as releaseSharedDaemonSessionForTest };
|
|
|
848
848
|
// from any sibling gates them all (#3476).
|
|
849
849
|
const DAEMON_CONGESTED_UNTIL = new WeakMap<QmdDaemonSession, number>();
|
|
850
850
|
|
|
851
|
+
// In-flight slow-call markers (#3499): a hybrid/vector daemon call that is
|
|
852
|
+
// already past the slow-query threshold gates siblings on the same session
|
|
853
|
+
// even before its result opens the congestion window above. Handles carry the
|
|
854
|
+
// mocked-clock-friendly start time; the gate is a pure clock comparison.
|
|
855
|
+
type DaemonInflightHandle = { since: number };
|
|
856
|
+
/** What `watchDaemonCall` hands back: the settle that clears the handle. */
|
|
857
|
+
type DaemonInflightWatch = { settle: () => void };
|
|
858
|
+
const DAEMON_INFLIGHT_CALLS = new WeakMap<QmdDaemonSession, DaemonInflightHandle[]>();
|
|
859
|
+
|
|
851
860
|
// Test-only seam: congestion tests drive a stub session object directly.
|
|
852
861
|
export const daemonCongestionForTest = {
|
|
853
862
|
get: (session: QmdDaemonSession): number => DAEMON_CONGESTED_UNTIL.get(session) ?? 0,
|
|
854
863
|
set: (session: QmdDaemonSession, untilMs: number): void => {
|
|
855
864
|
DAEMON_CONGESTED_UNTIL.set(session, untilMs);
|
|
856
865
|
},
|
|
866
|
+
inflightCalls: (session: QmdDaemonSession): number =>
|
|
867
|
+
(DAEMON_INFLIGHT_CALLS.get(session) ?? []).length,
|
|
857
868
|
};
|
|
858
869
|
|
|
859
870
|
// The `query`/`search` MCP tools take this shape; the daemon serializes it verbatim.
|
|
@@ -936,14 +947,16 @@ export class QmdClient implements SearchBackend {
|
|
|
936
947
|
private readonly daemonRecheckIntervalMs: number;
|
|
937
948
|
/** Consecutive transient daemon failures before invalidating the session. */
|
|
938
949
|
private daemonTransientFailures = 0;
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
950
|
+
private shouldDegradeDaemonSearch(): boolean {
|
|
951
|
+
const session = this.daemonSession;
|
|
952
|
+
if (!session) return false;
|
|
953
|
+
const now = performance.now();
|
|
954
|
+
if (now < (DAEMON_CONGESTED_UNTIL.get(session) ?? 0)) return true;
|
|
955
|
+
return (DAEMON_INFLIGHT_CALLS.get(session) ?? []).some(
|
|
956
|
+
(call) => now - call.since >= this.daemonSlowQueryMs,
|
|
957
|
+
);
|
|
942
958
|
}
|
|
943
959
|
|
|
944
|
-
private isDaemonCongested(): boolean {
|
|
945
|
-
return performance.now() < this.daemonCongestedUntilMs();
|
|
946
|
-
}
|
|
947
960
|
private daemonSlowQueryMs = QMD_DAEMON_SLOW_QUERY_MS;
|
|
948
961
|
private daemonCongestionWindowMs = QMD_DAEMON_CONGESTION_WINDOW_MS;
|
|
949
962
|
private static readonly DAEMON_MAX_TRANSIENT_FAILURES = 3;
|
|
@@ -1523,6 +1536,27 @@ export class QmdClient implements SearchBackend {
|
|
|
1523
1536
|
);
|
|
1524
1537
|
}
|
|
1525
1538
|
|
|
1539
|
+
/**
|
|
1540
|
+
* Watch one daemon call (#3499): register the call's start time on the
|
|
1541
|
+
* session so siblings see an in-flight slow call once it passes the
|
|
1542
|
+
* threshold. `settle` removes the handle on success, failure, and
|
|
1543
|
+
* cancellation; call it in a `finally`.
|
|
1544
|
+
*/
|
|
1545
|
+
private watchDaemonCall(session: QmdDaemonSession): DaemonInflightWatch {
|
|
1546
|
+
const handle: DaemonInflightHandle & DaemonInflightWatch = {
|
|
1547
|
+
since: performance.now(),
|
|
1548
|
+
settle: () => {
|
|
1549
|
+
const live = DAEMON_INFLIGHT_CALLS.get(session);
|
|
1550
|
+
const index = live ? live.indexOf(handle) : -1;
|
|
1551
|
+
if (live && index >= 0) live.splice(index, 1);
|
|
1552
|
+
},
|
|
1553
|
+
};
|
|
1554
|
+
const calls = DAEMON_INFLIGHT_CALLS.get(session) ?? [];
|
|
1555
|
+
calls.push(handle);
|
|
1556
|
+
DAEMON_INFLIGHT_CALLS.set(session, calls);
|
|
1557
|
+
return handle;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1526
1560
|
/**
|
|
1527
1561
|
* Handle a non-timeout, non-cancellation daemon error.
|
|
1528
1562
|
* Tolerates up to DAEMON_MAX_TRANSIENT_FAILURES consecutive failures
|
|
@@ -1716,14 +1750,13 @@ export class QmdClient implements SearchBackend {
|
|
|
1716
1750
|
const optionsFingerprint = searchOptions ? JSON.stringify(searchOptions) : "";
|
|
1717
1751
|
// Key must capture daemon/subprocess strategies to avoid cross-instance collisions (#1335).
|
|
1718
1752
|
const strategyFingerprint = `${this.qmdSearchStrategy}:${this.qmdSubprocessStrategy}`;
|
|
1719
|
-
//
|
|
1720
|
-
// for the TTL (#3476). The write key uses the plan that actually ran —
|
|
1721
|
-
// the window can open between this sample and execution (#3479 review).
|
|
1753
|
+
// Cache and join only calls with the same plan (#3476, #3499).
|
|
1722
1754
|
const makeCacheKey = (planFingerprint: string) =>
|
|
1723
1755
|
createHash("sha256")
|
|
1724
1756
|
.update(`${strategyFingerprint}:${planFingerprint}:${col}:${n}:${optionsFingerprint}:${trimmed}`)
|
|
1725
1757
|
.digest("hex");
|
|
1726
|
-
const
|
|
1758
|
+
const degrade = this.daemonAvailable && this.shouldDegradeDaemonSearch();
|
|
1759
|
+
const cacheKey = makeCacheKey(degrade ? "deg" : "std");
|
|
1727
1760
|
const cached = getCachedQmdSearch(cacheKey);
|
|
1728
1761
|
if (cached) {
|
|
1729
1762
|
// No degradation on cache hit by design (#1536): only trustworthy results are cached.
|
|
@@ -1736,7 +1769,7 @@ export class QmdClient implements SearchBackend {
|
|
|
1736
1769
|
let outcome: { results: QmdSearchResult[]; degraded: boolean } | null;
|
|
1737
1770
|
try {
|
|
1738
1771
|
outcome = await this.daemonSearchJoiner.join(cacheKey, execution?.signal, (sharedSignal) =>
|
|
1739
|
-
this.searchViaDaemon(trimmed, col, n, searchOptions, sharedSignal)
|
|
1772
|
+
this.searchViaDaemon(trimmed, col, n, searchOptions, sharedSignal, degrade)
|
|
1740
1773
|
);
|
|
1741
1774
|
} catch (err) {
|
|
1742
1775
|
if (isCallerCancellation(err, execution?.signal)) {
|
|
@@ -1989,25 +2022,23 @@ export class QmdClient implements SearchBackend {
|
|
|
1989
2022
|
collection: string | undefined,
|
|
1990
2023
|
maxResults: number,
|
|
1991
2024
|
options?: SearchQueryOptions,
|
|
1992
|
-
signal?: AbortSignal
|
|
2025
|
+
signal?: AbortSignal,
|
|
2026
|
+
degrade = this.shouldDegradeDaemonSearch(),
|
|
1993
2027
|
): Promise<{ results: QmdSearchResult[]; degraded: boolean } | null> {
|
|
1994
2028
|
if (!this.daemonSession || !this.daemonAvailable) return null;
|
|
1995
2029
|
|
|
1996
|
-
//
|
|
1997
|
-
|
|
1998
|
-
// waits on it serially. While the congestion window is open, serve
|
|
1999
|
-
// lex-only FTS — no embed legs — so recall stays responsive instead of
|
|
2000
|
-
// stacking multi-second hybrid calls. The collection scope is preserved:
|
|
2001
|
-
// a global search stays global while degraded.
|
|
2002
|
-
if (this.isDaemonCongested()) {
|
|
2030
|
+
// Keep the collection scope when falling back to lexical search.
|
|
2031
|
+
if (degrade) {
|
|
2003
2032
|
const degraded = await this.bm25SearchViaDaemon(query, collection, maxResults, signal, options);
|
|
2004
2033
|
return degraded === null ? null : { results: degraded, degraded: true };
|
|
2005
2034
|
}
|
|
2006
2035
|
|
|
2007
2036
|
const startedAtMs = performance.now();
|
|
2008
2037
|
const v2 = this.isQmdV2();
|
|
2038
|
+
let watch: DaemonInflightWatch | undefined;
|
|
2009
2039
|
try {
|
|
2010
2040
|
let args: Record<string, unknown>;
|
|
2041
|
+
let usesModels = true; // The v1 tool chooses its own search legs.
|
|
2011
2042
|
if (v2) {
|
|
2012
2043
|
// QMD v2: query tool expects { searches: [...], collections?: [...] }
|
|
2013
2044
|
// The MCP tool is structured-only in 2.x; use lex+vec+hyde by default
|
|
@@ -2020,6 +2051,7 @@ export class QmdClient implements SearchBackend {
|
|
|
2020
2051
|
args.collections = [collection];
|
|
2021
2052
|
}
|
|
2022
2053
|
this.addResolvedSearchOptionsToMcpArgs(args, options);
|
|
2054
|
+
usesModels = args.rerank !== false || searches.some(({ type }) => type !== "lex");
|
|
2023
2055
|
} else {
|
|
2024
2056
|
// QMD v1: query tool accepts { query, collection?, limit }
|
|
2025
2057
|
args = { query, limit: maxResults };
|
|
@@ -2029,6 +2061,7 @@ export class QmdClient implements SearchBackend {
|
|
|
2029
2061
|
this.addResolvedSearchOptionsToMcpArgs(args, options);
|
|
2030
2062
|
}
|
|
2031
2063
|
|
|
2064
|
+
if (usesModels) watch = this.watchDaemonCall(this.daemonSession);
|
|
2032
2065
|
const result = await this.daemonSession.callTool("query", args, this.daemonTimeoutMs, signal);
|
|
2033
2066
|
const durationMs = performance.now() - startedAtMs;
|
|
2034
2067
|
|
|
@@ -2068,6 +2101,8 @@ export class QmdClient implements SearchBackend {
|
|
|
2068
2101
|
// Transient error: tolerate a few before invalidating.
|
|
2069
2102
|
this.handleDaemonTransientError("search", err, durationMs);
|
|
2070
2103
|
return null;
|
|
2104
|
+
} finally {
|
|
2105
|
+
watch?.settle();
|
|
2071
2106
|
}
|
|
2072
2107
|
}
|
|
2073
2108
|
|
|
@@ -2135,15 +2170,14 @@ export class QmdClient implements SearchBackend {
|
|
|
2135
2170
|
): Promise<QmdSearchResult[] | null> {
|
|
2136
2171
|
if (!this.daemonSession || !this.daemonAvailable) return null;
|
|
2137
2172
|
|
|
2138
|
-
//
|
|
2139
|
-
|
|
2140
|
-
// so hybridSearch/vectorSearch callers keep working without embedding.
|
|
2141
|
-
if (this.isDaemonCongested()) {
|
|
2173
|
+
// Use lexical search here too so vector callers skip embedding.
|
|
2174
|
+
if (this.shouldDegradeDaemonSearch()) {
|
|
2142
2175
|
return this.bm25SearchViaDaemon(query, collection, maxResults, signal);
|
|
2143
2176
|
}
|
|
2144
2177
|
|
|
2145
2178
|
const startedAtMs = performance.now();
|
|
2146
2179
|
const v2 = this.isQmdV2();
|
|
2180
|
+
const watch = this.watchDaemonCall(this.daemonSession);
|
|
2147
2181
|
try {
|
|
2148
2182
|
let result: unknown;
|
|
2149
2183
|
if (v2) {
|
|
@@ -2191,6 +2225,8 @@ export class QmdClient implements SearchBackend {
|
|
|
2191
2225
|
}
|
|
2192
2226
|
this.handleDaemonTransientError("vsearch", err, durationMs);
|
|
2193
2227
|
return null;
|
|
2228
|
+
} finally {
|
|
2229
|
+
watch.settle();
|
|
2194
2230
|
}
|
|
2195
2231
|
}
|
|
2196
2232
|
|