@remnic/core 10.0.174 → 10.0.176
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 +72 -71
- package/dist/access-audit.js +2 -2
- package/dist/access-cli.js +72 -71
- package/dist/access-cli.js.map +1 -1
- package/dist/access-extraction-force-flush-preempt.js +72 -71
- package/dist/access-extraction-force-flush.js +72 -71
- package/dist/access-http-briefing.js +72 -71
- package/dist/access-http-query.js +72 -71
- package/dist/access-http.js +72 -71
- package/dist/access-identity-continuity-surface.js +72 -71
- package/dist/access-lcm-surface.js +72 -71
- package/dist/access-mcp.js +72 -71
- package/dist/access-observe-write-surface.js +72 -71
- package/dist/access-operations-batch.js +72 -71
- package/dist/access-operations.js +72 -71
- package/dist/access-recall-concurrency.js +72 -71
- package/dist/access-recall-response.js +72 -71
- package/dist/access-recall-surface.js +72 -71
- package/dist/access-service.js +72 -71
- package/dist/active-recall.js +16 -14
- package/dist/active-recall.js.map +1 -1
- package/dist/adapters/index.js +4 -4
- package/dist/adapters/registry.js +2 -2
- package/dist/briefing.js +14 -13
- package/dist/buffer-add-turns-bounded.js +2 -2
- package/dist/buffer-session-cap.d.ts +1 -1
- package/dist/buffer-session-cap.d.ts.map +1 -1
- package/dist/buffer-session-cap.js +1 -1
- package/dist/buffer.js +11 -10
- package/dist/causal-consolidation.js +15 -14
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/{chunk-IO4AAVYZ.js → chunk-2EKXMZ6E.js} +2 -2
- package/dist/{chunk-TOQK5A4Y.js → chunk-2LXROA34.js} +6 -6
- package/dist/{chunk-IUM3VSHI.js → chunk-2WREX7KD.js} +10 -1
- package/dist/chunk-2WREX7KD.js.map +1 -0
- package/dist/{chunk-IHB3JO4B.js → chunk-3FS6IVSU.js} +2 -2
- package/dist/{chunk-UBQ2ZOWA.js → chunk-3SP7EZWA.js} +2 -2
- package/dist/{chunk-4PBHMJRC.js → chunk-4GI2IGUK.js} +2 -2
- package/dist/{chunk-OWD365QW.js → chunk-4TIGRBKH.js} +5 -5
- package/dist/{chunk-HHVK2JRE.js → chunk-4TPU36X4.js} +2 -2
- package/dist/{chunk-DMPZABKG.js → chunk-4TZOOUMK.js} +2 -2
- package/dist/{chunk-Y2LZW3EQ.js → chunk-5CLKLKID.js} +3 -3
- package/dist/{chunk-5MTKGNZ5.js → chunk-5RBHL5TF.js} +121 -41
- package/dist/chunk-5RBHL5TF.js.map +1 -0
- package/dist/{chunk-HR3DKJCU.js → chunk-6SROXED4.js} +2 -2
- package/dist/{chunk-L3DDKXQJ.js → chunk-76LDFLAG.js} +2 -2
- package/dist/{chunk-5RONA5FF.js → chunk-7DFJ4JX2.js} +4 -4
- package/dist/{chunk-OK3X3TBR.js → chunk-7L73PLRG.js} +2 -2
- package/dist/{chunk-PUQQPLVV.js → chunk-AJQI2XCB.js} +2 -2
- package/dist/chunk-AJQI2XCB.js.map +1 -0
- package/dist/{chunk-RSUNBJ4I.js → chunk-AOHQ4OJR.js} +8 -8
- package/dist/{chunk-WKNMKV52.js → chunk-AQ6V47Q7.js} +2 -2
- package/dist/{chunk-H4KIMZJD.js → chunk-B4ZA2PZC.js} +3 -3
- package/dist/{chunk-DLR3SBOM.js → chunk-B7GZL7PR.js} +2 -2
- package/dist/{chunk-XYNUEXLC.js → chunk-BAMF6J4W.js} +4 -4
- package/dist/{chunk-WI2WTIMY.js → chunk-CFFYGKDJ.js} +5 -5
- package/dist/{chunk-NTR72OL5.js → chunk-CXIBBZ6N.js} +2 -2
- package/dist/{chunk-3DJ6R4CC.js → chunk-DLPS5YP3.js} +2 -2
- package/dist/{chunk-EXGY5TPU.js → chunk-EQSOXIIH.js} +7 -7
- package/dist/{chunk-6OMSYPOL.js → chunk-F2XXZR6A.js} +3 -3
- package/dist/{chunk-CY2C5LM4.js → chunk-FDLPNFKE.js} +2 -2
- package/dist/{chunk-KAGLV5KH.js → chunk-FTQF3G3B.js} +2 -2
- package/dist/{chunk-2GQVYLQK.js → chunk-FTV2C3CA.js} +2 -2
- package/dist/{chunk-B7HYXVME.js → chunk-FZF7JX76.js} +1 -1
- package/dist/chunk-FZF7JX76.js.map +1 -0
- package/dist/{chunk-ZKXNSPGQ.js → chunk-G77MHQFZ.js} +2 -2
- package/dist/{chunk-66DUCUOC.js → chunk-GGQ3CJVH.js} +2 -2
- package/dist/{chunk-BN5SK2RZ.js → chunk-HHKUWNHQ.js} +2 -2
- package/dist/{chunk-KMOH6W5B.js → chunk-HOTAHSO3.js} +3 -3
- package/dist/{chunk-OY3IULYL.js → chunk-IFXQGDMG.js} +2 -2
- package/dist/{chunk-OWBI5477.js → chunk-JUROR7PB.js} +2 -2
- package/dist/{chunk-4ACKO4U2.js → chunk-JXYFXVPB.js} +2 -2
- package/dist/{chunk-ASWECJXS.js → chunk-KYPFQO43.js} +3 -3
- package/dist/{chunk-4WOEEMGK.js → chunk-KZBE4KBZ.js} +2 -2
- package/dist/{chunk-V6MN37WG.js → chunk-MFJM35R7.js} +2 -2
- package/dist/{chunk-LKXW6W42.js → chunk-OTE5E44O.js} +2 -2
- package/dist/{chunk-KPLKABGR.js → chunk-P3SMXKFR.js} +2 -2
- package/dist/{chunk-27BH67PT.js → chunk-PCLTJUOY.js} +2 -2
- package/dist/{chunk-JDH2BA2P.js → chunk-RXAWE76Y.js} +2 -2
- package/dist/{chunk-IXI6S2VJ.js → chunk-S45VECVD.js} +29 -2
- package/dist/chunk-S45VECVD.js.map +1 -0
- package/dist/{chunk-WTFHZQXM.js → chunk-T3NEDSLZ.js} +3 -3
- package/dist/{chunk-HB2PRTXX.js → chunk-V425GW5W.js} +2 -2
- package/dist/{chunk-XKFL2WQO.js → chunk-V5FCMJW4.js} +2 -2
- package/dist/{chunk-SNI526DD.js → chunk-VR6NF6VX.js} +2 -2
- package/dist/{chunk-V6UFCV6T.js → chunk-VRDG7XFJ.js} +80 -80
- package/dist/{chunk-5ACIRCBO.js → chunk-WTXUUZYI.js} +6 -4
- package/dist/chunk-WTXUUZYI.js.map +1 -0
- package/dist/chunk-XBJOO7G5.js +87 -0
- package/dist/chunk-XBJOO7G5.js.map +1 -0
- package/dist/{chunk-RASE4TEF.js → chunk-Y26CFLHD.js} +5 -2
- package/dist/chunk-Y26CFLHD.js.map +1 -0
- package/dist/{chunk-AM6H7BIY.js → chunk-YMNPQMHA.js} +2 -2
- package/dist/{chunk-QVXRE66C.js → chunk-ZBDTOWGX.js} +7 -7
- package/dist/{chunk-YCK26VSL.js → chunk-ZMEEOLQG.js} +2 -2
- package/dist/{chunk-R2AJAAHJ.js → chunk-ZNHLUYIT.js} +90 -16
- package/dist/chunk-ZNHLUYIT.js.map +1 -0
- package/dist/{chunk-DAOMWGO2.js → chunk-ZX5N5D6M.js} +4 -4
- package/dist/cli.js +72 -71
- package/dist/coding/export-okf-codegraph.js +13 -12
- package/dist/coding/export-okf-codegraph.js.map +1 -1
- package/dist/compounding/engine.js +15 -14
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -14
- package/dist/connectors/codex-materialize-runner.js +14 -13
- package/dist/connectors/index.js +14 -13
- package/dist/convergence-refresh.js +16 -15
- package/dist/corpus-watermark.js +16 -15
- package/dist/entity-retrieval.js +14 -13
- package/dist/explicit-capture.js +72 -71
- package/dist/extraction.js +18 -17
- package/dist/{first-start-migration-CCZ5SM3V.js → first-start-migration-TCPK2I7J.js} +4 -4
- package/dist/harmonic-retrieval.js +14 -13
- package/dist/index.js +104 -103
- package/dist/lcm/index.js +3 -3
- package/dist/location/index.js +15 -14
- package/dist/maintenance/memory-governance.js +14 -13
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +14 -13
- package/dist/maintenance/rebuild-memory-projection-runner.js +16 -15
- package/dist/maintenance/rebuild-memory-projection.js +15 -14
- package/dist/memory-browse.js +9 -8
- package/dist/namespaces/migrate.js +15 -14
- package/dist/namespaces/search.d.ts +5 -1
- package/dist/namespaces/search.d.ts.map +1 -1
- package/dist/namespaces/search.js +12 -11
- package/dist/namespaces/storage.js +14 -13
- package/dist/operator-doctor-corpus.js +17 -16
- package/dist/operator-toolkit.js +23 -21
- package/dist/orchestration/backlog-scheduler.js +75 -74
- package/dist/orchestration/backlog-scheduler.js.map +1 -1
- package/dist/orchestration/buffer-drain-runner.js +73 -72
- package/dist/orchestration/maintenance.js +22 -21
- package/dist/orchestrator.js +72 -71
- package/dist/peers/index.js +1 -1
- package/dist/peers/interaction-log-append.d.ts.map +1 -1
- package/dist/qmd-daemon-session.d.ts +8 -0
- package/dist/qmd-daemon-session.d.ts.map +1 -1
- package/dist/qmd-daemon-session.js +1 -1
- package/dist/qmd-health-metadata.d.ts +39 -0
- package/dist/qmd-health-metadata.d.ts.map +1 -0
- package/dist/qmd-health-metadata.js +12 -0
- package/dist/qmd-health-metadata.js.map +1 -0
- package/dist/qmd-status.d.ts.map +1 -1
- package/dist/qmd-status.js +1 -1
- package/dist/qmd.d.ts +5 -1
- package/dist/qmd.d.ts.map +1 -1
- package/dist/qmd.js +8 -7
- package/dist/recall-composition-decision.js +2 -2
- package/dist/recall-navigation.js +72 -71
- package/dist/recall-state-view-admission.js +9 -8
- package/dist/recall-why-service.js +9 -8
- package/dist/resume-bundles.js +19 -17
- package/dist/search/factory.js +11 -10
- package/dist/search/index.js +11 -10
- package/dist/search/lancedb-backend.js +2 -2
- package/dist/search/meilisearch-backend.js +2 -2
- package/dist/search/orama-backend.js +2 -2
- package/dist/search/port.d.ts +21 -0
- package/dist/search/port.d.ts.map +1 -1
- package/dist/search/port.js +1 -1
- package/dist/search/remote-backend.js +2 -2
- package/dist/semantic-consolidation.js +15 -14
- package/dist/semantic-rule-promotion.js +14 -13
- package/dist/semantic-rule-verifier.js +14 -13
- package/dist/source-agent-qualifier.js +17 -16
- package/dist/standup/build.js +14 -13
- package/dist/storage.js +13 -12
- package/dist/transcript.js +2 -2
- package/dist/transfer/export-okf.js +14 -13
- package/dist/verified-recall.js +14 -13
- package/dist/who-knows-cli.js +15 -14
- package/dist/who-knows.js +14 -13
- package/package.json +2 -2
- package/src/buffer-session-cap-default.test.ts +86 -0
- package/src/buffer-session-cap.ts +7 -1
- package/src/config.ts +2 -1
- package/src/namespaces/search.test.ts +320 -4
- package/src/namespaces/search.ts +147 -51
- package/src/peers/interaction-log-append.ts +11 -3
- package/src/peers/peers.test.ts +27 -0
- package/src/qmd-client.test.ts +34 -3
- package/src/qmd-daemon-session.ts +34 -1
- package/src/qmd-health-metadata.test.ts +493 -0
- package/src/qmd-health-metadata.ts +95 -0
- package/src/qmd-status.ts +10 -1
- package/src/qmd.ts +83 -3
- package/src/search/port.ts +23 -0
- package/dist/chunk-5ACIRCBO.js.map +0 -1
- package/dist/chunk-5MTKGNZ5.js.map +0 -1
- package/dist/chunk-B7HYXVME.js.map +0 -1
- package/dist/chunk-IUM3VSHI.js.map +0 -1
- package/dist/chunk-IXI6S2VJ.js.map +0 -1
- package/dist/chunk-PUQQPLVV.js.map +0 -1
- package/dist/chunk-R2AJAAHJ.js.map +0 -1
- package/dist/chunk-RASE4TEF.js.map +0 -1
- /package/dist/{chunk-IO4AAVYZ.js.map → chunk-2EKXMZ6E.js.map} +0 -0
- /package/dist/{chunk-TOQK5A4Y.js.map → chunk-2LXROA34.js.map} +0 -0
- /package/dist/{chunk-IHB3JO4B.js.map → chunk-3FS6IVSU.js.map} +0 -0
- /package/dist/{chunk-UBQ2ZOWA.js.map → chunk-3SP7EZWA.js.map} +0 -0
- /package/dist/{chunk-4PBHMJRC.js.map → chunk-4GI2IGUK.js.map} +0 -0
- /package/dist/{chunk-OWD365QW.js.map → chunk-4TIGRBKH.js.map} +0 -0
- /package/dist/{chunk-HHVK2JRE.js.map → chunk-4TPU36X4.js.map} +0 -0
- /package/dist/{chunk-DMPZABKG.js.map → chunk-4TZOOUMK.js.map} +0 -0
- /package/dist/{chunk-Y2LZW3EQ.js.map → chunk-5CLKLKID.js.map} +0 -0
- /package/dist/{chunk-HR3DKJCU.js.map → chunk-6SROXED4.js.map} +0 -0
- /package/dist/{chunk-L3DDKXQJ.js.map → chunk-76LDFLAG.js.map} +0 -0
- /package/dist/{chunk-5RONA5FF.js.map → chunk-7DFJ4JX2.js.map} +0 -0
- /package/dist/{chunk-OK3X3TBR.js.map → chunk-7L73PLRG.js.map} +0 -0
- /package/dist/{chunk-RSUNBJ4I.js.map → chunk-AOHQ4OJR.js.map} +0 -0
- /package/dist/{chunk-WKNMKV52.js.map → chunk-AQ6V47Q7.js.map} +0 -0
- /package/dist/{chunk-H4KIMZJD.js.map → chunk-B4ZA2PZC.js.map} +0 -0
- /package/dist/{chunk-DLR3SBOM.js.map → chunk-B7GZL7PR.js.map} +0 -0
- /package/dist/{chunk-XYNUEXLC.js.map → chunk-BAMF6J4W.js.map} +0 -0
- /package/dist/{chunk-WI2WTIMY.js.map → chunk-CFFYGKDJ.js.map} +0 -0
- /package/dist/{chunk-NTR72OL5.js.map → chunk-CXIBBZ6N.js.map} +0 -0
- /package/dist/{chunk-3DJ6R4CC.js.map → chunk-DLPS5YP3.js.map} +0 -0
- /package/dist/{chunk-EXGY5TPU.js.map → chunk-EQSOXIIH.js.map} +0 -0
- /package/dist/{chunk-6OMSYPOL.js.map → chunk-F2XXZR6A.js.map} +0 -0
- /package/dist/{chunk-CY2C5LM4.js.map → chunk-FDLPNFKE.js.map} +0 -0
- /package/dist/{chunk-KAGLV5KH.js.map → chunk-FTQF3G3B.js.map} +0 -0
- /package/dist/{chunk-2GQVYLQK.js.map → chunk-FTV2C3CA.js.map} +0 -0
- /package/dist/{chunk-ZKXNSPGQ.js.map → chunk-G77MHQFZ.js.map} +0 -0
- /package/dist/{chunk-66DUCUOC.js.map → chunk-GGQ3CJVH.js.map} +0 -0
- /package/dist/{chunk-BN5SK2RZ.js.map → chunk-HHKUWNHQ.js.map} +0 -0
- /package/dist/{chunk-KMOH6W5B.js.map → chunk-HOTAHSO3.js.map} +0 -0
- /package/dist/{chunk-OY3IULYL.js.map → chunk-IFXQGDMG.js.map} +0 -0
- /package/dist/{chunk-OWBI5477.js.map → chunk-JUROR7PB.js.map} +0 -0
- /package/dist/{chunk-4ACKO4U2.js.map → chunk-JXYFXVPB.js.map} +0 -0
- /package/dist/{chunk-ASWECJXS.js.map → chunk-KYPFQO43.js.map} +0 -0
- /package/dist/{chunk-4WOEEMGK.js.map → chunk-KZBE4KBZ.js.map} +0 -0
- /package/dist/{chunk-V6MN37WG.js.map → chunk-MFJM35R7.js.map} +0 -0
- /package/dist/{chunk-LKXW6W42.js.map → chunk-OTE5E44O.js.map} +0 -0
- /package/dist/{chunk-KPLKABGR.js.map → chunk-P3SMXKFR.js.map} +0 -0
- /package/dist/{chunk-27BH67PT.js.map → chunk-PCLTJUOY.js.map} +0 -0
- /package/dist/{chunk-JDH2BA2P.js.map → chunk-RXAWE76Y.js.map} +0 -0
- /package/dist/{chunk-WTFHZQXM.js.map → chunk-T3NEDSLZ.js.map} +0 -0
- /package/dist/{chunk-HB2PRTXX.js.map → chunk-V425GW5W.js.map} +0 -0
- /package/dist/{chunk-XKFL2WQO.js.map → chunk-V5FCMJW4.js.map} +0 -0
- /package/dist/{chunk-SNI526DD.js.map → chunk-VR6NF6VX.js.map} +0 -0
- /package/dist/{chunk-V6UFCV6T.js.map → chunk-VRDG7XFJ.js.map} +0 -0
- /package/dist/{chunk-AM6H7BIY.js.map → chunk-YMNPQMHA.js.map} +0 -0
- /package/dist/{chunk-QVXRE66C.js.map → chunk-ZBDTOWGX.js.map} +0 -0
- /package/dist/{chunk-YCK26VSL.js.map → chunk-ZMEEOLQG.js.map} +0 -0
- /package/dist/{chunk-DAOMWGO2.js.map → chunk-ZX5N5D6M.js.map} +0 -0
- /package/dist/{first-start-migration-CCZ5SM3V.js.map → first-start-migration-TCPK2I7J.js.map} +0 -0
package/src/namespaces/search.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveNamespaceCapabilities } from "../capabilities.js";
|
|
1
|
+
import { resolveNamespaceCapabilities, resolveQmdCapabilities } from "../capabilities.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import type { PluginConfig, QmdSearchResult } from "../types.js";
|
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
SearchBackend,
|
|
7
7
|
SearchExecutionOptions,
|
|
8
8
|
SearchQueryOptions,
|
|
9
|
+
SearchBackendStatus,
|
|
10
|
+
OperationalSearchHealth,
|
|
9
11
|
} from "../search/port.js";
|
|
10
12
|
import { reportSearchDegradation } from "../search/port.js";
|
|
11
13
|
import { createSearchBackend } from "../search/factory.js";
|
|
@@ -90,13 +92,15 @@ export function embeddingBacklogExceeds(pending: number | null, threshold: numbe
|
|
|
90
92
|
* reports it, and `healthForNamespace` refuses to cache it.
|
|
91
93
|
*/
|
|
92
94
|
export function isSearchHealthDegraded(
|
|
93
|
-
health: Pick<NamespaceSearchHealth, "available" | "collectionState" | "pendingEmbeddings"
|
|
95
|
+
health: Pick<NamespaceSearchHealth, "available" | "collectionState" | "pendingEmbeddings"> &
|
|
96
|
+
Partial<Pick<NamespaceSearchHealth, "supported">>,
|
|
94
97
|
backlogThreshold: number,
|
|
95
98
|
): boolean {
|
|
96
99
|
const active = health.available && health.collectionState !== "missing";
|
|
97
100
|
return (
|
|
98
101
|
!active ||
|
|
99
102
|
health.collectionState === "unknown" ||
|
|
103
|
+
health.supported === false ||
|
|
100
104
|
embeddingBacklogExceeds(health.pendingEmbeddings, backlogThreshold)
|
|
101
105
|
);
|
|
102
106
|
}
|
|
@@ -113,6 +117,8 @@ type BackendRecordOptions = {
|
|
|
113
117
|
|
|
114
118
|
export class NamespaceSearchRouter {
|
|
115
119
|
private readonly cache = new Map<string, Promise<NamespaceBackendRecord>>();
|
|
120
|
+
// Scoped to the backend record's lifetime; a native result supersedes older CLI probes.
|
|
121
|
+
private readonly nativeHealthRevision = new WeakMap<Promise<NamespaceBackendRecord>, number>();
|
|
116
122
|
private readonly healthResultCache = new Map<
|
|
117
123
|
string,
|
|
118
124
|
{ expiresAt: number; value: NamespaceSearchHealth }
|
|
@@ -156,7 +162,7 @@ export class NamespaceSearchRouter {
|
|
|
156
162
|
if (maxResults === 0) return [];
|
|
157
163
|
|
|
158
164
|
const method = options.mode ?? "search";
|
|
159
|
-
const namespaces = Array.from(new Set(options.namespaces.map(
|
|
165
|
+
const namespaces = Array.from(new Set(options.namespaces.map(normalizeNamespaceIdentity).filter(Boolean)));
|
|
160
166
|
if (namespaces.length === 0) return [];
|
|
161
167
|
|
|
162
168
|
const resultsByNamespace = await Promise.all(
|
|
@@ -286,7 +292,7 @@ export class NamespaceSearchRouter {
|
|
|
286
292
|
execution?: SearchExecutionOptions,
|
|
287
293
|
options?: { strict?: boolean; force?: boolean },
|
|
288
294
|
): Promise<NamespaceUpdateResult> {
|
|
289
|
-
const unique = Array.from(new Set(namespaces.map(
|
|
295
|
+
const unique = Array.from(new Set(namespaces.map(normalizeNamespaceIdentity).filter(Boolean)));
|
|
290
296
|
const eligible = (await Promise.all(
|
|
291
297
|
unique.map(async (namespace) => {
|
|
292
298
|
const record = await this.backendRecordFor(namespace);
|
|
@@ -315,7 +321,7 @@ export class NamespaceSearchRouter {
|
|
|
315
321
|
}
|
|
316
322
|
|
|
317
323
|
async embedNamespaces(namespaces: string[], options?: { strict?: boolean }): Promise<void> {
|
|
318
|
-
const unique = Array.from(new Set(namespaces.map(
|
|
324
|
+
const unique = Array.from(new Set(namespaces.map(normalizeNamespaceIdentity).filter(Boolean)));
|
|
319
325
|
await Promise.all(
|
|
320
326
|
unique.map(async (namespace) => {
|
|
321
327
|
const record = await this.backendRecordFor(namespace);
|
|
@@ -337,12 +343,22 @@ export class NamespaceSearchRouter {
|
|
|
337
343
|
namespace: string,
|
|
338
344
|
execution?: SearchExecutionOptions,
|
|
339
345
|
): Promise<NamespaceSearchHealth> {
|
|
340
|
-
const key =
|
|
346
|
+
const key = this.namespaceKey(namespace);
|
|
347
|
+
let pending = this.cache.get(key);
|
|
348
|
+
let operational = await this.operationalHealthForNamespace(key, execution);
|
|
349
|
+
if (!operational && this.cache.get(key) !== pending) {
|
|
350
|
+
pending = this.cache.get(key);
|
|
351
|
+
operational = await this.operationalHealthForNamespace(key, execution);
|
|
352
|
+
}
|
|
353
|
+
if (operational) return operational();
|
|
341
354
|
const cached = this.healthResultCache.get(key);
|
|
342
|
-
if (
|
|
355
|
+
if (operational === undefined && this.cache.get(key) === pending &&
|
|
356
|
+
cached && cached.expiresAt > Date.now() &&
|
|
357
|
+
!execution?.signal?.aborted && resolveQmdCapabilities(this.config).qmd !== false) {
|
|
343
358
|
return { ...cached.value };
|
|
344
359
|
}
|
|
345
360
|
|
|
361
|
+
const nativeRevision = pending && this.nativeHealthRevision.get(pending);
|
|
346
362
|
const record = await this.createBackendRecordFor(
|
|
347
363
|
key,
|
|
348
364
|
execution,
|
|
@@ -352,18 +368,12 @@ export class NamespaceSearchRouter {
|
|
|
352
368
|
failOpenMissingGuardedCollection: false,
|
|
353
369
|
},
|
|
354
370
|
);
|
|
371
|
+
let health: NamespaceSearchHealth;
|
|
355
372
|
try {
|
|
356
373
|
const liveRecord = await this.liveCachedRecordForHealth(key, record, execution);
|
|
357
374
|
const diagnosticBackend = liveRecord?.backend ?? record.backend;
|
|
358
|
-
const versionStatus =
|
|
359
|
-
"getVersionStatus" in diagnosticBackend &&
|
|
360
|
-
typeof diagnosticBackend.getVersionStatus === "function"
|
|
361
|
-
? diagnosticBackend.getVersionStatus()
|
|
362
|
-
: null;
|
|
363
|
-
const daemonMode = daemonModeForBackend(diagnosticBackend);
|
|
364
375
|
const backendStatus =
|
|
365
|
-
|
|
366
|
-
typeof diagnosticBackend.status === "function"
|
|
376
|
+
diagnosticBackend.status
|
|
367
377
|
? await Promise.race([
|
|
368
378
|
diagnosticBackend.status().catch(() => null),
|
|
369
379
|
new Promise<null>((resolve) => setTimeout(() => resolve(null), 5_000).unref?.()),
|
|
@@ -374,42 +384,124 @@ export class NamespaceSearchRouter {
|
|
|
374
384
|
? "missing"
|
|
375
385
|
: record.collectionState;
|
|
376
386
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
installedVersion: versionStatus?.installedVersion ?? null,
|
|
384
|
-
supportedVersion: versionStatus?.supportedVersion ?? null,
|
|
385
|
-
supported: versionStatus?.supported ?? null,
|
|
386
|
-
upgradeAvailable: versionStatus?.upgradeAvailable ?? null,
|
|
387
|
-
doctorAvailable: versionStatus?.capabilities?.doctor ?? null,
|
|
388
|
-
daemonMode,
|
|
389
|
-
pendingEmbeddings: backendStatus?.pendingEmbeddings ?? null,
|
|
390
|
-
oldestPendingAgeMs: backendStatus?.oldestPendingAgeMs ?? null,
|
|
391
|
-
embeddingBacklogThreshold: this.config.qmdEmbeddingBacklogThreshold,
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
// Cache only a healthy answer that carries backlog data when the backend
|
|
395
|
-
// reports status. A degraded or incomplete answer must re-probe so a
|
|
396
|
-
// readiness poll sees recovery on the next call, not one TTL late.
|
|
397
|
-
const statusMissing = backendStatus === null && "status" in diagnosticBackend;
|
|
398
|
-
if (
|
|
399
|
-
execution?.signal?.aborted !== true &&
|
|
400
|
-
!statusMissing &&
|
|
401
|
-
!isSearchHealthDegraded(health, health.embeddingBacklogThreshold)
|
|
402
|
-
) {
|
|
403
|
-
this.healthResultCache.set(key, {
|
|
404
|
-
expiresAt: Date.now() + HEALTH_RESULT_CACHE_TTL_MS,
|
|
405
|
-
value: { ...health },
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
return { ...health };
|
|
387
|
+
health = this.describeHealth(
|
|
388
|
+
record, diagnosticBackend,
|
|
389
|
+
execution?.signal?.aborted ? "unknown" : collectionState,
|
|
390
|
+
execution?.signal?.aborted ? null : backendStatus,
|
|
391
|
+
liveRecord?.available ?? record.available,
|
|
392
|
+
);
|
|
409
393
|
} finally {
|
|
410
394
|
const dispose = (record.backend as { dispose?: () => void | Promise<void> }).dispose;
|
|
411
395
|
await dispose?.call(record.backend);
|
|
412
396
|
}
|
|
397
|
+
|
|
398
|
+
if (execution?.signal?.aborted || this.cache.get(key) !== pending ||
|
|
399
|
+
(pending && this.nativeHealthRevision.get(pending) !== nativeRevision)) {
|
|
400
|
+
return { ...health, collectionState: "unknown", pendingEmbeddings: null, oldestPendingAgeMs: null };
|
|
401
|
+
}
|
|
402
|
+
// Cache only a healthy, unsuperseded diagnostic.
|
|
403
|
+
if (
|
|
404
|
+
operational === undefined &&
|
|
405
|
+
!isSearchHealthDegraded(health, health.embeddingBacklogThreshold)
|
|
406
|
+
) {
|
|
407
|
+
this.healthResultCache.set(key, {
|
|
408
|
+
expiresAt: Date.now() + HEALTH_RESULT_CACHE_TTL_MS,
|
|
409
|
+
value: { ...health },
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
return health;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private describeHealth(
|
|
416
|
+
record: NamespaceBackendRecord,
|
|
417
|
+
diagnosticBackend: SearchBackend,
|
|
418
|
+
collectionState: CollectionState,
|
|
419
|
+
backendStatus: SearchBackendStatus | null,
|
|
420
|
+
available = record.available,
|
|
421
|
+
): NamespaceSearchHealth {
|
|
422
|
+
const versionStatus = diagnosticBackend.getVersionStatus?.();
|
|
423
|
+
const statusFailed = diagnosticBackend.status &&
|
|
424
|
+
(backendStatus === null || "error" in backendStatus ||
|
|
425
|
+
!Number.isSafeInteger(backendStatus.pendingEmbeddings) ||
|
|
426
|
+
backendStatus.pendingEmbeddings === null || backendStatus.pendingEmbeddings < 0);
|
|
427
|
+
return {
|
|
428
|
+
collection: record.collection,
|
|
429
|
+
memoryDir: record.memoryDir,
|
|
430
|
+
available,
|
|
431
|
+
collectionState: collectionState !== "missing" && (statusFailed || versionStatus?.supported === false)
|
|
432
|
+
? "unknown" : collectionState,
|
|
433
|
+
debugStatus: diagnosticBackend.debugStatus(),
|
|
434
|
+
installedVersion: versionStatus?.installedVersion ?? null,
|
|
435
|
+
supportedVersion: versionStatus?.supportedVersion ?? null,
|
|
436
|
+
supported: versionStatus?.supported ?? null,
|
|
437
|
+
upgradeAvailable: versionStatus?.upgradeAvailable ?? null,
|
|
438
|
+
doctorAvailable: versionStatus?.capabilities?.doctor ?? null,
|
|
439
|
+
daemonMode: daemonModeForBackend(diagnosticBackend),
|
|
440
|
+
pendingEmbeddings: backendStatus?.pendingEmbeddings ?? null,
|
|
441
|
+
oldestPendingAgeMs: backendStatus?.oldestPendingAgeMs ?? null,
|
|
442
|
+
embeddingBacklogThreshold: this.config.qmdEmbeddingBacklogThreshold,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
private async operationalHealthForNamespace(
|
|
447
|
+
key: string,
|
|
448
|
+
execution?: SearchExecutionOptions,
|
|
449
|
+
): Promise<(() => NamespaceSearchHealth) | null | undefined> {
|
|
450
|
+
const pending = this.cache.get(key);
|
|
451
|
+
if (!pending) return undefined;
|
|
452
|
+
if (execution?.signal?.aborted || resolveQmdCapabilities(this.config).qmd === false) return null;
|
|
453
|
+
const record = await awaitWithAbort(pending, execution?.signal).catch(() => null);
|
|
454
|
+
if (!record) return null;
|
|
455
|
+
const backend = record.backend;
|
|
456
|
+
const daemonMode = daemonModeForBackend(backend);
|
|
457
|
+
const operationalIdentity = backend.operationalHealthIdentity?.();
|
|
458
|
+
const ownsRecord = () => !execution?.signal?.aborted && this.cache.get(key) === pending &&
|
|
459
|
+
!record.disposed && resolveQmdCapabilities(this.config).qmd !== false && record.backend === backend;
|
|
460
|
+
const current = () => ownsRecord() && record.available && backend.isAvailable() &&
|
|
461
|
+
daemonModeForBackend(backend) === daemonMode &&
|
|
462
|
+
backend.operationalHealthIdentity?.() === operationalIdentity;
|
|
463
|
+
const refused = () => this.describeHealth(
|
|
464
|
+
record, backend, record.collectionState === "missing" ? "missing" : "unknown", null,
|
|
465
|
+
record.available && !record.disposed,
|
|
466
|
+
);
|
|
467
|
+
// A failed initial probe never established an operational connection.
|
|
468
|
+
if (!record.available && record.collectionState === "unknown" && ownsRecord()) return undefined;
|
|
469
|
+
if (!current()) return refused;
|
|
470
|
+
if (!backend.readOperationalHealth) return undefined;
|
|
471
|
+
if (record.collectionState === "missing") return refused;
|
|
472
|
+
const storage = await awaitWithAbort(this.storageRouter.storageFor(key), execution?.signal).catch(() => null);
|
|
473
|
+
if (!current() || !storage) return refused;
|
|
474
|
+
const expectedCollection = () => namespaceCollectionName(this.config.qmdCollection, key, {
|
|
475
|
+
defaultNamespace: this.config.defaultNamespace,
|
|
476
|
+
useLegacyDefaultCollection: key === this.namespaceKey("") && storage.dir === this.config.memoryDir,
|
|
477
|
+
});
|
|
478
|
+
if (record.memoryDir !== storage.dir || record.collection !== expectedCollection()) return refused;
|
|
479
|
+
|
|
480
|
+
let snapshot: OperationalSearchHealth | null | undefined;
|
|
481
|
+
try {
|
|
482
|
+
snapshot = await awaitWithAbort(
|
|
483
|
+
backend.readOperationalHealth(storage.dir, execution), execution?.signal,
|
|
484
|
+
);
|
|
485
|
+
} catch {
|
|
486
|
+
return refused;
|
|
487
|
+
}
|
|
488
|
+
if (snapshot === null) return refused;
|
|
489
|
+
const currentStorage = await awaitWithAbort(
|
|
490
|
+
this.storageRouter.storageFor(key), execution?.signal,
|
|
491
|
+
).catch(() => null);
|
|
492
|
+
const canPublish = () => current() && currentStorage?.dir === storage.dir &&
|
|
493
|
+
record.memoryDir === storage.dir && record.collection === expectedCollection() &&
|
|
494
|
+
snapshot?.isCurrent?.() !== false;
|
|
495
|
+
if (!canPublish()) return refused;
|
|
496
|
+
if (snapshot === undefined) return undefined;
|
|
497
|
+
// The public caller resumes after this helper; invalidation can run in between.
|
|
498
|
+
return () => {
|
|
499
|
+
if (!canPublish()) return refused();
|
|
500
|
+
const health = this.describeHealth(record, backend, snapshot.collectionState, snapshot);
|
|
501
|
+
this.healthResultCache.delete(key);
|
|
502
|
+
this.nativeHealthRevision.set(pending, (this.nativeHealthRevision.get(pending) ?? 0) + 1);
|
|
503
|
+
return health;
|
|
504
|
+
};
|
|
413
505
|
}
|
|
414
506
|
|
|
415
507
|
private async liveCachedRecordForHealth(
|
|
@@ -421,6 +513,7 @@ export class NamespaceSearchRouter {
|
|
|
421
513
|
if (!pending) return null;
|
|
422
514
|
const cachedRecord = await awaitWithAbort(pending, execution?.signal).catch(() => null);
|
|
423
515
|
if (!cachedRecord) return null;
|
|
516
|
+
if (!cachedRecord.available && cachedRecord.collectionState === "unknown" && !cachedRecord.disposed) return null;
|
|
424
517
|
if (cachedRecord.collection !== disposableRecord.collection) return null;
|
|
425
518
|
if (cachedRecord.memoryDir !== disposableRecord.memoryDir) return null;
|
|
426
519
|
return cachedRecord;
|
|
@@ -489,12 +582,16 @@ export class NamespaceSearchRouter {
|
|
|
489
582
|
);
|
|
490
583
|
}
|
|
491
584
|
|
|
585
|
+
private namespaceKey(namespace: string): string {
|
|
586
|
+
return normalizeNamespaceIdentity(namespace) || normalizeNamespaceIdentity(this.config.defaultNamespace);
|
|
587
|
+
}
|
|
588
|
+
|
|
492
589
|
private async backendRecordFor(
|
|
493
590
|
namespace: string,
|
|
494
591
|
execution?: SearchExecutionOptions,
|
|
495
592
|
): Promise<NamespaceBackendRecord> {
|
|
496
593
|
await this.drainPendingDisposals();
|
|
497
|
-
const key =
|
|
594
|
+
const key = this.namespaceKey(namespace);
|
|
498
595
|
const existing = this.cache.get(key);
|
|
499
596
|
if (existing) return await existing;
|
|
500
597
|
|
|
@@ -512,14 +609,13 @@ export class NamespaceSearchRouter {
|
|
|
512
609
|
}
|
|
513
610
|
|
|
514
611
|
private async createBackendRecordFor(
|
|
515
|
-
|
|
612
|
+
key: string,
|
|
516
613
|
execution: SearchExecutionOptions | undefined,
|
|
517
614
|
options: BackendRecordOptions,
|
|
518
615
|
): Promise<NamespaceBackendRecord> {
|
|
519
|
-
const key = namespace.trim() || this.config.defaultNamespace;
|
|
520
616
|
const storage = await this.storageRouter.storageFor(key);
|
|
521
617
|
const useLegacyDefaultCollection =
|
|
522
|
-
key === this.
|
|
618
|
+
key === this.namespaceKey("") && storage.dir === this.config.memoryDir;
|
|
523
619
|
const filtersNestedNamespaces =
|
|
524
620
|
resolveNamespaceCapabilities(this.config).namespaces === true && useLegacyDefaultCollection;
|
|
525
621
|
const rootHostEmbeddingScope =
|
|
@@ -109,8 +109,6 @@ export async function appendInteractionLog(
|
|
|
109
109
|
}
|
|
110
110
|
const e = parsedEntry.data;
|
|
111
111
|
assertCanonicalIsoTimestamp(e.timestamp, "interaction entry timestamp");
|
|
112
|
-
await mkdirPeerDirAtomic(memoryDir, peerId);
|
|
113
|
-
await assertPeerDirNotEscaped(memoryDir, peerId);
|
|
114
112
|
const file = interactionsPath(memoryDir, peerId);
|
|
115
113
|
const line = formatLogEntry(e) + "\n";
|
|
116
114
|
// `appendFile` creates the file if it does not exist. Serialize writes
|
|
@@ -119,8 +117,18 @@ export async function appendInteractionLog(
|
|
|
119
117
|
// unqueued writer could otherwise interleave between them (#3564).
|
|
120
118
|
// The chain tail is kept on a .catch(() => {}) so one failed append
|
|
121
119
|
// does not poison the queue for followers.
|
|
120
|
+
//
|
|
121
|
+
// The queue slot is taken SYNCHRONOUSLY, before the directory awaits:
|
|
122
|
+
// a caller that awaits mkdir first can otherwise reach this block after
|
|
123
|
+
// a later caller (the dir already exists, so its mkdir returns faster),
|
|
124
|
+
// and the later entry would be written first. Taking the slot here makes
|
|
125
|
+
// enqueue order equal call order.
|
|
122
126
|
const prev = appendQueues.get(file) ?? Promise.resolve();
|
|
123
|
-
const write = prev.then(() =>
|
|
127
|
+
const write = prev.then(async () => {
|
|
128
|
+
await mkdirPeerDirAtomic(memoryDir, peerId);
|
|
129
|
+
await assertPeerDirNotEscaped(memoryDir, peerId);
|
|
130
|
+
await appendFileNoFollow(file, line);
|
|
131
|
+
});
|
|
124
132
|
const tail = write.catch(() => {});
|
|
125
133
|
appendQueues.set(file, tail);
|
|
126
134
|
try {
|
package/src/peers/peers.test.ts
CHANGED
|
@@ -327,6 +327,33 @@ test("appendInteractionLog serializes concurrent appends to one peer — #3564",
|
|
|
327
327
|
assert.ok(lines[1].includes("SMALL-END"));
|
|
328
328
|
});
|
|
329
329
|
|
|
330
|
+
test("appendInteractionLog keeps call order when concurrent callers reach the queue at different speeds — #3644", async () => {
|
|
331
|
+
// The queue slot must be taken before the directory awaits: a caller that
|
|
332
|
+
// finds the peer directory already created reaches the queue first, so a
|
|
333
|
+
// later caller could otherwise be written ahead of an earlier one.
|
|
334
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
335
|
+
const dir = await makeTempDir();
|
|
336
|
+
const peerId = "agent.codex";
|
|
337
|
+
const big = `BIG-${"x".repeat(4 << 20)}-BIG-END`;
|
|
338
|
+
const first = appendInteractionLog(dir, peerId, {
|
|
339
|
+
timestamp: "2026-04-25T00:00:01.000Z",
|
|
340
|
+
kind: "message",
|
|
341
|
+
summary: big,
|
|
342
|
+
});
|
|
343
|
+
const second = appendInteractionLog(dir, peerId, {
|
|
344
|
+
timestamp: "2026-04-25T00:00:02.000Z",
|
|
345
|
+
kind: "message",
|
|
346
|
+
summary: "SMALL-END",
|
|
347
|
+
});
|
|
348
|
+
await Promise.all([first, second]);
|
|
349
|
+
const raw = await readInteractionLogRaw(dir, peerId);
|
|
350
|
+
const lines = raw.trim().split("\n");
|
|
351
|
+
assert.equal(lines.length, 2, `attempt ${attempt}: expected 2 intact lines, got ${lines.length}`);
|
|
352
|
+
assert.ok(lines[0].includes("BIG-END"), `attempt ${attempt}: the earlier call's entry must be written first`);
|
|
353
|
+
assert.ok(lines[1].includes("SMALL-END"), `attempt ${attempt}: the later call's entry must be written second`);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
330
357
|
test("appendInteractionLog escapes embedded newlines so each entry stays one line", async () => {
|
|
331
358
|
const dir = await makeTempDir();
|
|
332
359
|
const peerId = "human.alex";
|
package/src/qmd-client.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
|
|
4
|
-
import { QmdClient, parseQmdStatusOutput } from "./qmd.js";
|
|
4
|
+
import { QmdClient, parseQmdStatusOutput, resolveQmdCapabilities } from "./qmd.js";
|
|
5
5
|
import type { QmdSearchResult } from "./types.js";
|
|
6
6
|
|
|
7
7
|
type DaemonCheckInternals = {
|
|
@@ -402,8 +402,15 @@ test("parseQmdStatusOutput returns nulls for unparseable output", () => {
|
|
|
402
402
|
assert.equal(report.oldestPendingAgeMs, null);
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
+
test("an omitted count does not make malformed or unrecognized status healthy", () => {
|
|
406
|
+
const summary = "Total: 1 files indexed\nVectors: 8 embedded";
|
|
407
|
+
assert.equal(parseQmdStatusOutput(summary).pendingEmbeddings, null);
|
|
408
|
+
assert.equal(parseQmdStatusOutput("QMD Status\nTotal: 1 files indexed").pendingEmbeddings, null);
|
|
409
|
+
assert.equal(parseQmdStatusOutput(`QMD Status\n${summary}\nPending: unavailable`).pendingEmbeddings, null);
|
|
410
|
+
});
|
|
411
|
+
|
|
405
412
|
test("QmdClient.status() returns parsed report on success", async () => {
|
|
406
|
-
const client = new QmdClient("test-col", 3);
|
|
413
|
+
const client = new QmdClient("test-col", 3, { qmdSupportedVersion: "2.8.3" });
|
|
407
414
|
const internals = client as unknown as {
|
|
408
415
|
available: boolean;
|
|
409
416
|
qmdCapabilities: { safeStatusDeviceProbe: boolean };
|
|
@@ -411,6 +418,7 @@ test("QmdClient.status() returns parsed report on success", async () => {
|
|
|
411
418
|
};
|
|
412
419
|
internals.available = true;
|
|
413
420
|
internals.qmdCapabilities = { safeStatusDeviceProbe: true };
|
|
421
|
+
Object.assign(client, { cliVersion: "2.8.3" });
|
|
414
422
|
let capturedArgs: string[] = [];
|
|
415
423
|
internals.runQmdCommand = async (args: string[]) => {
|
|
416
424
|
capturedArgs = args;
|
|
@@ -422,15 +430,38 @@ test("QmdClient.status() returns parsed report on success", async () => {
|
|
|
422
430
|
assert.equal(report.oldestPendingAgeMs, 300_000);
|
|
423
431
|
});
|
|
424
432
|
|
|
425
|
-
test("QmdClient.status()
|
|
433
|
+
test("QmdClient.status() explains unavailable counts without resetting flags", async () => {
|
|
426
434
|
const client = new QmdClient("test-col", 3);
|
|
427
435
|
const internals = client as unknown as { available: boolean };
|
|
428
436
|
internals.available = false;
|
|
429
437
|
const report = await client.status();
|
|
430
438
|
assert.equal(report.pendingEmbeddings, null);
|
|
431
439
|
assert.equal(report.oldestPendingAgeMs, null);
|
|
440
|
+
assert.equal(report.error, "qmd unavailable");
|
|
441
|
+
assert.equal(internals.available, false);
|
|
432
442
|
});
|
|
433
443
|
|
|
444
|
+
for (const [version, expectedError] of [
|
|
445
|
+
["2.4.0", "qmd status device probe is unsafe for this version"],
|
|
446
|
+
["2.5.0", "qmd version is unsupported"],
|
|
447
|
+
[null, "qmd status device probe is unsafe for this version"],
|
|
448
|
+
] as const) {
|
|
449
|
+
test(`QmdClient.status() refuses unsafe or unsupported version ${version}`, async () => {
|
|
450
|
+
const client = new QmdClient("test-col", 3, { qmdSupportedVersion: "2.8.3" });
|
|
451
|
+
const capabilities = resolveQmdCapabilities(version);
|
|
452
|
+
Object.assign(client, {
|
|
453
|
+
available: true, daemonAvailable: true, cliVersion: version, qmdCapabilities: capabilities,
|
|
454
|
+
runQmdCommand: async () => { assert.fail("Refused status must not run a command"); },
|
|
455
|
+
});
|
|
456
|
+
const report = await client.status();
|
|
457
|
+
assert.equal(report.error, expectedError);
|
|
458
|
+
assert.equal(report.pendingEmbeddings, null);
|
|
459
|
+
assert.equal(client.isAvailable(), true);
|
|
460
|
+
assert.equal(client.isDaemonMode(), true);
|
|
461
|
+
assert.equal(client.getVersionStatus().capabilities, capabilities);
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
434
465
|
test("QmdClient.embedFiles() runs update then embed", async () => {
|
|
435
466
|
const client = new QmdClient("test-col", 3);
|
|
436
467
|
const internals = client as unknown as {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { abortError, throwIfAborted } from "./abort-error.js";
|
|
2
3
|
import { log } from "./logger.js";
|
|
3
4
|
import { type CommandChildProcess, launchProcess } from "./runtime/child-process.js";
|
|
@@ -6,6 +7,15 @@ import { sleep } from "./utils/sleep.js";
|
|
|
6
7
|
|
|
7
8
|
export type QmdRuntimeEnv = Record<string, string | undefined>;
|
|
8
9
|
|
|
10
|
+
const initializeHealthSchema = z.object({
|
|
11
|
+
isError: z.literal(false).optional(),
|
|
12
|
+
capabilities: z.object({
|
|
13
|
+
experimental: z.object({
|
|
14
|
+
"qmd/healthMetadata": z.strictObject({ schemaVersion: z.literal(1) }).optional(),
|
|
15
|
+
}).optional(),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
|
|
9
19
|
export type QmdDaemonSpawn = (
|
|
10
20
|
command: string,
|
|
11
21
|
args: string[],
|
|
@@ -64,9 +74,13 @@ function isTimeoutMessage(message: string): boolean {
|
|
|
64
74
|
* than the recall budget, and a slow query would then take the warm process
|
|
65
75
|
* down on every timeout.
|
|
66
76
|
*/
|
|
77
|
+
type HealthMetadataCapability = "available" | "absent" | "invalid";
|
|
78
|
+
|
|
67
79
|
export class QmdDaemonSession {
|
|
68
80
|
private child: CommandChildProcess | null = null;
|
|
69
81
|
private initialized = false;
|
|
82
|
+
private processIdentity: object | null = null;
|
|
83
|
+
private healthMetadataCapability: HealthMetadataCapability | null = null;
|
|
70
84
|
private buffer = "";
|
|
71
85
|
private startPromise: Promise<boolean> | null = null;
|
|
72
86
|
private pendingRequests = new Map<number, PendingRequest>();
|
|
@@ -108,6 +122,7 @@ export class QmdDaemonSession {
|
|
|
108
122
|
stdio: ["pipe", "pipe", "pipe"],
|
|
109
123
|
});
|
|
110
124
|
this.child = child;
|
|
125
|
+
this.processIdentity = {};
|
|
111
126
|
this.buffer = "";
|
|
112
127
|
|
|
113
128
|
child.stdout?.on("data", (data: Buffer) => {
|
|
@@ -141,6 +156,7 @@ export class QmdDaemonSession {
|
|
|
141
156
|
log.debug("QMD mcp: process already running, retrying handshake");
|
|
142
157
|
}
|
|
143
158
|
|
|
159
|
+
const processIdentity = this.processIdentity;
|
|
144
160
|
try {
|
|
145
161
|
const result = await this.sendRequest(
|
|
146
162
|
"initialize",
|
|
@@ -151,15 +167,20 @@ export class QmdDaemonSession {
|
|
|
151
167
|
},
|
|
152
168
|
60_000
|
|
153
169
|
);
|
|
170
|
+
if (this.processIdentity !== processIdentity) return false;
|
|
154
171
|
if (!result) {
|
|
155
172
|
this.cleanup({ killChild: true });
|
|
156
173
|
return false;
|
|
157
174
|
}
|
|
158
175
|
this.sendNotification("notifications/initialized");
|
|
176
|
+
const metadata = initializeHealthSchema.safeParse(result).data;
|
|
177
|
+
this.healthMetadataCapability = !metadata ? "invalid"
|
|
178
|
+
: metadata.capabilities.experimental?.["qmd/healthMetadata"] ? "available" : "absent";
|
|
159
179
|
this.initialized = true;
|
|
160
180
|
log.info("QMD mcp: stdio session initialized");
|
|
161
181
|
return true;
|
|
162
182
|
} catch (err) {
|
|
183
|
+
if (this.processIdentity !== processIdentity) return false;
|
|
163
184
|
const msg = err instanceof Error ? err.message : String(err);
|
|
164
185
|
if (isTimeoutMessage(msg)) {
|
|
165
186
|
log.debug("QMD mcp: handshake timed out — process still loading, will retry later");
|
|
@@ -170,7 +191,7 @@ export class QmdDaemonSession {
|
|
|
170
191
|
}
|
|
171
192
|
return false;
|
|
172
193
|
} finally {
|
|
173
|
-
this.startPromise = null;
|
|
194
|
+
if (this.processIdentity === processIdentity) this.startPromise = null;
|
|
174
195
|
}
|
|
175
196
|
})();
|
|
176
197
|
return this.startPromise;
|
|
@@ -226,6 +247,16 @@ export class QmdDaemonSession {
|
|
|
226
247
|
return this.child !== null && !this.child.killed && this.initialized;
|
|
227
248
|
}
|
|
228
249
|
|
|
250
|
+
/** Opaque identity; health readers cannot adopt or restart a different child. */
|
|
251
|
+
activeProcessIdentity(): object | null {
|
|
252
|
+
return this.isActive() ? this.processIdentity : null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Passive, generation-scoped metadata from the operational initialize handshake. */
|
|
256
|
+
getHealthMetadataCapability(): HealthMetadataCapability | null {
|
|
257
|
+
return this.isActive() ? this.healthMetadataCapability : null;
|
|
258
|
+
}
|
|
259
|
+
|
|
229
260
|
/** True while the process is spawned but the MCP handshake has not yet completed. */
|
|
230
261
|
isLoading(): boolean {
|
|
231
262
|
return this.child !== null && !this.child.killed && !this.initialized;
|
|
@@ -361,6 +392,8 @@ export class QmdDaemonSession {
|
|
|
361
392
|
this.pendingRequests.clear();
|
|
362
393
|
this.startPromise = null;
|
|
363
394
|
this.child = null;
|
|
395
|
+
this.processIdentity = null;
|
|
396
|
+
this.healthMetadataCapability = null;
|
|
364
397
|
this.buffer = "";
|
|
365
398
|
}
|
|
366
399
|
}
|