@remnic/core 10.0.195 → 10.0.197
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 +18 -18
- package/dist/access-cli.js +18 -18
- package/dist/access-coding-context-resolution.js +2 -2
- package/dist/access-extraction-force-flush-preempt.js +18 -18
- package/dist/access-extraction-force-flush.js +18 -18
- package/dist/access-http-briefing.js +18 -18
- package/dist/access-http-query.js +18 -18
- package/dist/access-http.js +18 -18
- package/dist/access-identity-continuity-surface.js +18 -18
- package/dist/access-lcm-surface.js +18 -18
- package/dist/access-mcp.d.ts.map +1 -1
- package/dist/access-mcp.js +18 -18
- package/dist/access-observe-write-category.js +2 -2
- package/dist/access-observe-write-surface.js +18 -18
- package/dist/access-operations-batch.js +18 -18
- package/dist/access-operations.js +18 -18
- package/dist/access-recall-concurrency.d.ts +4 -0
- package/dist/access-recall-concurrency.d.ts.map +1 -1
- package/dist/access-recall-concurrency.js +18 -18
- package/dist/access-recall-response.d.ts.map +1 -1
- package/dist/access-recall-response.js +18 -18
- package/dist/access-recall-surface.d.ts.map +1 -1
- package/dist/access-recall-surface.js +18 -18
- package/dist/access-schema.d.ts +1 -0
- package/dist/access-schema.d.ts.map +1 -1
- package/dist/access-schema.js +1 -1
- package/dist/access-service.d.ts.map +1 -1
- package/dist/access-service.js +18 -18
- package/dist/buffer.js +3 -3
- package/dist/{chunk-F2MVWUNF.js → chunk-374E2HYZ.js} +10 -2
- package/dist/chunk-374E2HYZ.js.map +1 -0
- package/dist/{chunk-3ZS3NUEI.js → chunk-3DSLTUK6.js} +2 -2
- package/dist/{chunk-Q2GDUJSK.js → chunk-63LN7H2C.js} +4 -4
- package/dist/{chunk-ME63JKWJ.js → chunk-6HF5TRE5.js} +66 -38
- package/dist/chunk-6HF5TRE5.js.map +1 -0
- package/dist/{chunk-CRS2NY44.js → chunk-7O6H7BPW.js} +2 -2
- package/dist/{chunk-76LBLH62.js → chunk-AUDLHIHI.js} +2 -2
- package/dist/{chunk-4GVSMPBP.js → chunk-CRKT2JXN.js} +2 -2
- package/dist/{chunk-JJ42IDJU.js → chunk-FEGQI5KR.js} +2 -2
- package/dist/{chunk-KQIOW3TG.js → chunk-HUDE2SQA.js} +2 -2
- package/dist/{chunk-JKMIGCK6.js → chunk-KDGEEZOI.js} +3 -2
- package/dist/chunk-KDGEEZOI.js.map +1 -0
- package/dist/{chunk-BD26CK6T.js → chunk-ODGVLSCQ.js} +2 -2
- package/dist/{chunk-YCTD3XET.js → chunk-PNDTRIOI.js} +2 -2
- package/dist/{chunk-XDNVWY7I.js → chunk-PX4AMRAN.js} +2 -2
- package/dist/{chunk-QW5LZTKA.js → chunk-QO5QZR2U.js} +2 -2
- package/dist/{chunk-NFQKIZK3.js → chunk-QXEF66SC.js} +2 -2
- package/dist/{chunk-HD7M55OI.js → chunk-VAE6QCZQ.js} +2 -2
- package/dist/{chunk-QZPAOOU7.js → chunk-WLP3XJCO.js} +2 -2
- package/dist/{chunk-SFUS2V2V.js → chunk-XII23FXP.js} +1 -1
- package/dist/chunk-XII23FXP.js.map +1 -0
- package/dist/{chunk-IT4G6HTG.js → chunk-YQUGYQRY.js} +2 -2
- package/dist/cli.js +18 -18
- package/dist/coding/export-okf-codegraph.js +3 -3
- package/dist/deep-recall-http-glue.js +2 -2
- package/dist/eval-trajectory-store.js +2 -2
- package/dist/eval-trajectory.js +2 -2
- package/dist/evals.d.ts.map +1 -1
- package/dist/evals.js +1 -1
- package/dist/explicit-capture.js +18 -18
- package/dist/extraction.js +4 -4
- package/dist/index.js +18 -18
- package/dist/memory-browse.js +3 -3
- package/dist/operator-toolkit.js +2 -2
- package/dist/orchestration/backlog-scheduler.js +19 -19
- package/dist/orchestration/buffer-drain-runner.js +19 -19
- package/dist/orchestration/orchestrator-helpers.d.ts +2 -0
- package/dist/orchestration/orchestrator-helpers.d.ts.map +1 -1
- package/dist/orchestration/orchestrator-init.d.ts.map +1 -1
- package/dist/orchestration/recall-entry.d.ts +2 -2
- package/dist/orchestration/recall-entry.d.ts.map +1 -1
- package/dist/orchestration/recall-internal.d.ts.map +1 -1
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +18 -18
- package/dist/recall-navigation.js +18 -18
- package/dist/recall-state-view-admission.js +3 -3
- package/dist/recall-why-service.js +3 -3
- package/dist/source-agent-qualifier.js +3 -3
- package/package.json +2 -2
- package/src/access-mcp.ts +8 -0
- package/src/access-recall-concurrency.ts +35 -2
- package/src/access-recall-response.ts +3 -1
- package/src/access-recall-surface.ts +1 -0
- package/src/access-schema.ts +8 -0
- package/src/access-service-recall-concurrency.test.ts +65 -0
- package/src/access-service.ts +4 -3
- package/src/evals.ts +6 -6
- package/src/orchestration/orchestrator-helpers.ts +2 -0
- package/src/orchestration/orchestrator-init.ts +1 -2
- package/src/orchestration/recall-entry.ts +7 -7
- package/src/orchestration/recall-internal.ts +14 -4
- package/src/orchestration/startup-search-sync.ts +1 -1
- package/src/orchestrator-startup-ready-path.test.ts +60 -0
- package/src/orchestrator.ts +3 -2
- package/src/recall-client-deadline-trace.test.ts +209 -0
- package/dist/chunk-F2MVWUNF.js.map +0 -1
- package/dist/chunk-JKMIGCK6.js.map +0 -1
- package/dist/chunk-ME63JKWJ.js.map +0 -1
- package/dist/chunk-SFUS2V2V.js.map +0 -1
- /package/dist/{chunk-3ZS3NUEI.js.map → chunk-3DSLTUK6.js.map} +0 -0
- /package/dist/{chunk-Q2GDUJSK.js.map → chunk-63LN7H2C.js.map} +0 -0
- /package/dist/{chunk-CRS2NY44.js.map → chunk-7O6H7BPW.js.map} +0 -0
- /package/dist/{chunk-76LBLH62.js.map → chunk-AUDLHIHI.js.map} +0 -0
- /package/dist/{chunk-4GVSMPBP.js.map → chunk-CRKT2JXN.js.map} +0 -0
- /package/dist/{chunk-JJ42IDJU.js.map → chunk-FEGQI5KR.js.map} +0 -0
- /package/dist/{chunk-KQIOW3TG.js.map → chunk-HUDE2SQA.js.map} +0 -0
- /package/dist/{chunk-BD26CK6T.js.map → chunk-ODGVLSCQ.js.map} +0 -0
- /package/dist/{chunk-YCTD3XET.js.map → chunk-PNDTRIOI.js.map} +0 -0
- /package/dist/{chunk-XDNVWY7I.js.map → chunk-PX4AMRAN.js.map} +0 -0
- /package/dist/{chunk-QW5LZTKA.js.map → chunk-QO5QZR2U.js.map} +0 -0
- /package/dist/{chunk-NFQKIZK3.js.map → chunk-QXEF66SC.js.map} +0 -0
- /package/dist/{chunk-HD7M55OI.js.map → chunk-VAE6QCZQ.js.map} +0 -0
- /package/dist/{chunk-QZPAOOU7.js.map → chunk-WLP3XJCO.js.map} +0 -0
- /package/dist/{chunk-IT4G6HTG.js.map → chunk-YQUGYQRY.js.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remnic/core",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.197",
|
|
4
4
|
"description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -3426,7 +3426,7 @@
|
|
|
3426
3426
|
"core"
|
|
3427
3427
|
],
|
|
3428
3428
|
"peerDependencies": {
|
|
3429
|
-
"@remnic/coding-graph": "^10.0.
|
|
3429
|
+
"@remnic/coding-graph": "^10.0.197"
|
|
3430
3430
|
},
|
|
3431
3431
|
"peerDependenciesMeta": {
|
|
3432
3432
|
"@remnic/coding-graph": {
|
package/src/access-mcp.ts
CHANGED
|
@@ -638,6 +638,14 @@ export class EngramMcpServer {
|
|
|
638
638
|
"Opt in to state-aware recall views (issue #1952); ORs with the recallStateViews config flag.",
|
|
639
639
|
},
|
|
640
640
|
searchOptions: engramRecallSearchOptionsMcpProperty,
|
|
641
|
+
deadlineMs: {
|
|
642
|
+
type: "number", minimum: 0,
|
|
643
|
+
description: "Client deadline (issue #3499): epoch-absolute or ms budget from now; clamps the recall outer deadline.",
|
|
644
|
+
},
|
|
645
|
+
traceId: {
|
|
646
|
+
type: "string", maxLength: 128, pattern: "^[\\w:.-]+$",
|
|
647
|
+
description: "Caller-known trace ID (issue #3499); echoed on response + daemon timing lines for timeout correlation.",
|
|
648
|
+
},
|
|
641
649
|
},
|
|
642
650
|
required: ["query"],
|
|
643
651
|
additionalProperties: false,
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* caller signal / flight object alone).
|
|
15
15
|
*/
|
|
16
16
|
import { abortError, isAbortError, raceAbort, throwIfAborted } from "./abort-error.js";
|
|
17
|
+
import { log } from "./logger.js";
|
|
17
18
|
import { hashAccessIdempotencyPayload } from "./access-idempotency.js";
|
|
18
19
|
import {
|
|
19
20
|
EngramAccessDeadlineExceededError,
|
|
@@ -68,6 +69,10 @@ interface RecallFlight {
|
|
|
68
69
|
promise: Promise<RecallExecResult>;
|
|
69
70
|
controller: AbortController;
|
|
70
71
|
live: number;
|
|
72
|
+
/** The leader's caller-supplied trace ID, when it sent one — used to log the
|
|
73
|
+
* follower->leader association when a coalesced caller attaches with its
|
|
74
|
+
* own ID (issue #3499 review). */
|
|
75
|
+
leaderTraceId?: string;
|
|
71
76
|
/** Set true the instant the shared pipeline acquires its concurrency slot and
|
|
72
77
|
* begins executing. Before this, a KEYED flight whose only caller aborts must
|
|
73
78
|
* cancel (nothing has committed); after it, a keyed flight must persist
|
|
@@ -369,6 +374,13 @@ export async function consumeFlight(
|
|
|
369
374
|
cancelOnAbort: boolean = race,
|
|
370
375
|
): Promise<{ response: EngramAccessRecallResponse; reservation: BudgetReservation | undefined }> {
|
|
371
376
|
const detach = attachFlightAbort(flight, request.abortSignal, cancelOnAbort);
|
|
377
|
+
// Correlation aid (issue #3499 review): a coalesced follower's response
|
|
378
|
+
// echoes its OWN trace ID, but the daemon's start/timing lines carry the
|
|
379
|
+
// leader's — record the follower->leader association at attach, before the
|
|
380
|
+
// deadline wait, so a follower's timed-out call still maps to this run.
|
|
381
|
+
if (request.traceId !== undefined && request.traceId !== flight.leaderTraceId) {
|
|
382
|
+
log.info(`recall follower [${request.traceId}] joined flight under leader [${flight.leaderTraceId ?? "derived"}]`);
|
|
383
|
+
}
|
|
372
384
|
try {
|
|
373
385
|
let result: RecallExecResult;
|
|
374
386
|
try {
|
|
@@ -423,6 +435,10 @@ export async function consumeFlight(
|
|
|
423
435
|
// principal id never reaches the response / cache (round 10 #2).
|
|
424
436
|
response.budgetWarning = toBudgetWarning(ownDecision);
|
|
425
437
|
}
|
|
438
|
+
// A coalesced caller keeps its OWN caller-known trace ID (issue #3499):
|
|
439
|
+
// the shared pipeline ran under the leader's ID, but the follower's
|
|
440
|
+
// response must echo the ID the follower logged before dispatch.
|
|
441
|
+
if (request.traceId !== undefined) response.traceId = request.traceId;
|
|
426
442
|
return { response, reservation };
|
|
427
443
|
} catch (err) {
|
|
428
444
|
// Clone threw on a successful pipeline — release the admission entry
|
|
@@ -527,7 +543,7 @@ async function runRecallDirect(
|
|
|
527
543
|
}
|
|
528
544
|
throw err;
|
|
529
545
|
}
|
|
530
|
-
return response;
|
|
546
|
+
return withCallerTraceId(response, request.traceId);
|
|
531
547
|
}
|
|
532
548
|
|
|
533
549
|
/** Register a single-flight and start its ONE shared pipeline in the
|
|
@@ -573,6 +589,7 @@ export function createAndStartFlight(
|
|
|
573
589
|
controller,
|
|
574
590
|
live: 0,
|
|
575
591
|
committed: false,
|
|
592
|
+
leaderTraceId: normalizedRequest.traceId,
|
|
576
593
|
onIdle: () => {
|
|
577
594
|
const unregister = () => {
|
|
578
595
|
if (host.recallInFlight.get(flightKey) === flight) {
|
|
@@ -777,7 +794,20 @@ export async function leadRecallFlight(
|
|
|
777
794
|
}
|
|
778
795
|
throw err;
|
|
779
796
|
}
|
|
780
|
-
return response;
|
|
797
|
+
return withCallerTraceId(response, request.traceId);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/** An idempotent replay returns the ORIGINAL attempt's stored response, so it
|
|
801
|
+
* echoes the original caller's trace ID. Stamp THIS caller's ID on a shallow
|
|
802
|
+
* copy (issue #3499 review): the stored record stays untouched for the next
|
|
803
|
+
* replay, and a caller that logged an ID before dispatch gets it echoed.
|
|
804
|
+
* Same contract as single-flight followers in consumeFlight. */
|
|
805
|
+
function withCallerTraceId(
|
|
806
|
+
response: EngramAccessRecallResponse,
|
|
807
|
+
traceId: string | undefined,
|
|
808
|
+
): EngramAccessRecallResponse {
|
|
809
|
+
if (traceId === undefined || response.traceId === traceId) return response;
|
|
810
|
+
return { ...response, traceId };
|
|
781
811
|
}
|
|
782
812
|
|
|
783
813
|
/** The degraded response for a recall whose deadline expired at admission,
|
|
@@ -812,6 +842,9 @@ function degradedDeadlineRecallResponse(
|
|
|
812
842
|
fallbackUsed: false,
|
|
813
843
|
sourcesUsed: [],
|
|
814
844
|
disclosure: request.disclosure ?? DEFAULT_RECALL_DISCLOSURE,
|
|
845
|
+
// Echo the caller's trace ID on the timeout path too — that is exactly
|
|
846
|
+
// the response a client has to correlate when its deadline fires.
|
|
847
|
+
traceId: request.traceId,
|
|
815
848
|
};
|
|
816
849
|
}
|
|
817
850
|
|
|
@@ -354,7 +354,9 @@ export async function assembleRecallResponse(
|
|
|
354
354
|
memoryIds: filteredMemoryIds,
|
|
355
355
|
results,
|
|
356
356
|
recordedAt: snapshot?.recordedAt,
|
|
357
|
-
|
|
357
|
+
// Caller-supplied ID echoes even when no matching snapshot exists —
|
|
358
|
+
// sessionless recalls and timed-out recalls never recorded one (#3499).
|
|
359
|
+
traceId: snapshot?.traceId ?? request.traceId,
|
|
358
360
|
plannerMode: snapshot?.plannerMode ?? mode,
|
|
359
361
|
fallbackUsed: snapshot?.fallbackUsed ?? false,
|
|
360
362
|
sourcesUsed: snapshot?.sourcesUsed ?? [],
|
|
@@ -864,6 +864,7 @@ export class AccessRecallSurface {
|
|
|
864
864
|
};
|
|
865
865
|
if (request.searchOptions) recallOptions.searchOptions = request.searchOptions;
|
|
866
866
|
if (request.deadlineMs !== undefined) recallOptions.deadlineMs = request.deadlineMs;
|
|
867
|
+
if (request.traceId !== undefined) recallOptions.traceId = request.traceId;
|
|
867
868
|
const startedAt = Date.now();
|
|
868
869
|
// #1906 atomic budget admission: the peek loop above and this record are
|
|
869
870
|
// one synchronous JS turn (no await between them), so record()'s own
|
package/src/access-schema.ts
CHANGED
|
@@ -188,6 +188,14 @@ export const recallRequestSchema = z.object({
|
|
|
188
188
|
* instead of an answer it can no longer use.
|
|
189
189
|
*/
|
|
190
190
|
deadlineMs: deadlineMsSchema,
|
|
191
|
+
/**
|
|
192
|
+
* Caller-known recall trace ID (issue #3499). When present it becomes
|
|
193
|
+
* the recall's `traceId`, echoed on the response and the daemon's
|
|
194
|
+
* request/timing lines, so a call that times out client-side can still
|
|
195
|
+
* be matched to daemon logs without timestamp correlation. Restricted
|
|
196
|
+
* to word/colon/dot/hyphen characters because it lands in log lines.
|
|
197
|
+
*/
|
|
198
|
+
traceId: z.string().min(1, "traceId is required").max(128).regex(/^[\w:.-]+$/, "traceId may only contain word characters, colon, dot and hyphen").optional(),
|
|
191
199
|
});
|
|
192
200
|
|
|
193
201
|
export const recallExplainRequestSchema = z.object({
|
|
@@ -65,6 +65,13 @@ function stubResponse(results: unknown[]): EngramAccessRecallResponse {
|
|
|
65
65
|
return { results } as unknown as EngramAccessRecallResponse;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// Single trusted cast point for the private seams a stub replaces.
|
|
69
|
+
function asHostSeam<T>(cause: unknown): T {
|
|
70
|
+
// SAFETY: the caller supplies the locally-declared seam contract; the cast
|
|
71
|
+
// re-labels the EngramAccessService prototype instance to that contract.
|
|
72
|
+
return cause as T;
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
function readResults(response: EngramAccessRecallResponse): unknown[] {
|
|
69
76
|
assert.ok(response && typeof response === "object" && "results" in response);
|
|
70
77
|
const { results } = response as { results: unknown[] };
|
|
@@ -2230,3 +2237,61 @@ test("a keyed follower does not inherit its leader's queued-deadline rejection (
|
|
|
2230
2237
|
assert.equal(pipelineRuns, 2, "holder + the one shared pipeline");
|
|
2231
2238
|
await holder;
|
|
2232
2239
|
});
|
|
2240
|
+
|
|
2241
|
+
test("coalesced followers echo their own caller traceId, not the leader's", async () => {
|
|
2242
|
+
const { service } = makeService({
|
|
2243
|
+
limit: 0,
|
|
2244
|
+
singleFlight: true,
|
|
2245
|
+
pipeline: async (request) => ({
|
|
2246
|
+
...stubResponse([{ id: "m1" }]),
|
|
2247
|
+
traceId: request.traceId,
|
|
2248
|
+
}),
|
|
2249
|
+
});
|
|
2250
|
+
|
|
2251
|
+
const req: EngramAccessRecallRequest = { query: "same", sessionKey: "s1" };
|
|
2252
|
+
const [leader, followerA, followerB] = await Promise.all([
|
|
2253
|
+
service.recall({ ...req, traceId: "leader-tid" }),
|
|
2254
|
+
service.recall({ ...req, traceId: "follower-a" }),
|
|
2255
|
+
service.recall({ ...req }),
|
|
2256
|
+
]);
|
|
2257
|
+
|
|
2258
|
+
assert.equal(leader.traceId, "leader-tid");
|
|
2259
|
+
assert.equal(followerA.traceId, "follower-a", "a caller-supplied traceId must survive single-flight coalescing");
|
|
2260
|
+
assert.equal(followerB.traceId, "leader-tid", "a caller without traceId keeps the pipeline's value");
|
|
2261
|
+
});
|
|
2262
|
+
|
|
2263
|
+
test("an idempotent replay echoes the REPLAYING caller's traceId, not the original attempt's", async () => {
|
|
2264
|
+
const store = new Map<string, EngramAccessRecallResponse>();
|
|
2265
|
+
const h = makeService({
|
|
2266
|
+
limit: 0,
|
|
2267
|
+
singleFlight: false,
|
|
2268
|
+
crossNamespace: true,
|
|
2269
|
+
pipeline: async (request) => ({
|
|
2270
|
+
...stubResponse([{ id: "m1" }]),
|
|
2271
|
+
traceId: request.traceId,
|
|
2272
|
+
}),
|
|
2273
|
+
});
|
|
2274
|
+
const host = asHostSeam<{
|
|
2275
|
+
handleIdempotentRead: (options: {
|
|
2276
|
+
idempotencyKey?: string;
|
|
2277
|
+
execute: () => Promise<EngramAccessRecallResponse>;
|
|
2278
|
+
}) => Promise<EngramAccessRecallResponse>;
|
|
2279
|
+
}>(h.service);
|
|
2280
|
+
host.handleIdempotentRead = async (options) => {
|
|
2281
|
+
const key = options.idempotencyKey ?? "";
|
|
2282
|
+
const cached = store.get(key);
|
|
2283
|
+
if (cached) return cached;
|
|
2284
|
+
const response = await options.execute();
|
|
2285
|
+
store.set(key, response);
|
|
2286
|
+
return response;
|
|
2287
|
+
};
|
|
2288
|
+
|
|
2289
|
+
const first = await h.service.recall({ query: "same", idempotencyKey: "k", traceId: "first-tid" });
|
|
2290
|
+
const replay = await h.service.recall({ query: "same", idempotencyKey: "k", traceId: "second-tid" });
|
|
2291
|
+
const replayAgain = await h.service.recall({ query: "same", idempotencyKey: "k", traceId: "third-tid" });
|
|
2292
|
+
|
|
2293
|
+
assert.equal(first.traceId, "first-tid");
|
|
2294
|
+
assert.equal(replay.traceId, "second-tid", "a replay must echo the replaying caller's trace ID");
|
|
2295
|
+
assert.equal(replayAgain.traceId, "third-tid", "an earlier replay's stamp must not corrupt the stored record");
|
|
2296
|
+
assert.equal(store.get("k")!.traceId, "first-tid", "the stored record keeps the original attempt's ID");
|
|
2297
|
+
});
|
package/src/access-service.ts
CHANGED
|
@@ -2640,9 +2640,10 @@ export class EngramAccessService extends SupportPassportAccessServiceBase {
|
|
|
2640
2640
|
const deadlineAtMs = resolveClientDeadlineAtMs(request.deadlineMs, Date.now());
|
|
2641
2641
|
const normalizedRequest = { ...request, query };
|
|
2642
2642
|
if (deadlineAtMs !== null) normalizedRequest.deadlineMs = deadlineAtMs;
|
|
2643
|
-
// `deadlineMs`
|
|
2644
|
-
// carrying different
|
|
2645
|
-
|
|
2643
|
+
// `deadlineMs`/`traceId` are per-call QoS + correlation, not work
|
|
2644
|
+
// identity: two identical recalls carrying different values must still
|
|
2645
|
+
// coalesce (#3514 review, #3499 trace plumbing).
|
|
2646
|
+
const { abortSignal: _abortSignal, deadlineMs: _deadlineMs, traceId: _traceId, ...requestFingerprint } = normalizedRequest;
|
|
2646
2647
|
const authenticatedPrincipal = request.authenticatedPrincipal?.trim();
|
|
2647
2648
|
const principal = this.resolveRequestPrincipal(request.sessionKey, authenticatedPrincipal);
|
|
2648
2649
|
if (resolveNamespaceCapabilities(this.orchestrator.config).namespaces && !principal) {
|
package/src/evals.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { cp, mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
3
4
|
import { listJsonFiles, listNamedFiles, readJsonFile } from "./json-store.js";
|
|
4
5
|
|
|
@@ -925,17 +926,16 @@ export async function importEvalBenchmarkPack(options: {
|
|
|
925
926
|
};
|
|
926
927
|
}
|
|
927
928
|
|
|
928
|
-
export async function recordEvalShadowRecall(
|
|
929
|
-
memoryDir: string;
|
|
930
|
-
|
|
931
|
-
record: EvalShadowRecallRecord;
|
|
932
|
-
}): Promise<string> {
|
|
929
|
+
export async function recordEvalShadowRecall(
|
|
930
|
+
options: { memoryDir: string; evalStoreDir?: string; record: EvalShadowRecallRecord },
|
|
931
|
+
): Promise<string> {
|
|
933
932
|
const rootDir = resolveEvalStoreDir(options.memoryDir, options.evalStoreDir);
|
|
934
933
|
const validated = validateEvalShadowRecallRecord(options.record);
|
|
935
934
|
const day = validated.recordedAt.slice(0, 10);
|
|
936
935
|
const shadowRoot = path.join(rootDir, "shadow");
|
|
937
936
|
const shadowDir = path.join(shadowRoot, day);
|
|
938
|
-
|
|
937
|
+
// Filename is a deterministic hash, not the raw ID: caller-supplied IDs may carry filename-unsafe chars (#3499).
|
|
938
|
+
const targetPath = path.join(shadowDir, `${createHash("sha256").update(validated.traceId).digest("hex").slice(0, 24)}.json`);
|
|
939
939
|
assertPathWithin(shadowRoot, targetPath, "shadow recall record path");
|
|
940
940
|
await mkdir(shadowDir, { recursive: true });
|
|
941
941
|
await writeFile(targetPath, JSON.stringify(validated, null, 2), "utf-8");
|
|
@@ -273,6 +273,8 @@ export interface RecallInvocationOptions {
|
|
|
273
273
|
* an already-passed deadline behaves like a 0-remaining budget.
|
|
274
274
|
*/
|
|
275
275
|
deadlineMs?: number;
|
|
276
|
+
/** Caller-known trace ID (issue #3499); replaces the derived snapshot `traceId`. */
|
|
277
|
+
traceId?: string;
|
|
276
278
|
onContextComposition?: (composition: RecallContextComposition) => void | PromiseLike<void>;
|
|
277
279
|
}
|
|
278
280
|
|
|
@@ -712,11 +712,10 @@ export class OrchestratorInitCoordinator {
|
|
|
712
712
|
// embedding-fallback JSON index so the first real recall is fast.
|
|
713
713
|
const warmupPromises: Promise<void>[] = [];
|
|
714
714
|
if (this.deps.qmd.isAvailable()) {
|
|
715
|
-
const warmupNs = this.deps.config.defaultNamespace;
|
|
716
715
|
log.info("QMD warmup: pre-loading models with a test search");
|
|
717
716
|
warmupPromises.push(
|
|
718
717
|
this.deps.qmd
|
|
719
|
-
.search("warmup",
|
|
718
|
+
.search("warmup", this.deps.config.qmdCollection, 1, undefined, { signal })
|
|
720
719
|
.then(() => {
|
|
721
720
|
log.info("QMD warmup: complete");
|
|
722
721
|
})
|
|
@@ -58,7 +58,7 @@ export interface RecallEntryDeps {
|
|
|
58
58
|
readonly initPromise: Promise<void> | null;
|
|
59
59
|
lastRecallFailureAtMs: number;
|
|
60
60
|
lastRecallFailureLogAtMs: number;
|
|
61
|
-
logRecallFailure(
|
|
61
|
+
logRecallFailure(cause: unknown, traceId?: string): void;
|
|
62
62
|
readonly profiler: ProfilingCollector;
|
|
63
63
|
recallInternal(
|
|
64
64
|
prompt: string,
|
|
@@ -162,7 +162,7 @@ export class RecallEntryCoordinator {
|
|
|
162
162
|
// A fired client deadline is a timeout, not cancellation — the flow
|
|
163
163
|
// below then degrades to the missing-note response instead of "".
|
|
164
164
|
if (gateResult === "aborted" && !clientDeadlineFired) {
|
|
165
|
-
this.deps.logRecallFailure(abortRecallError("recall aborted before init"));
|
|
165
|
+
this.deps.logRecallFailure(abortRecallError("recall aborted before init"), options.traceId);
|
|
166
166
|
if (clientDeadlineHandle) clearTimeout(clientDeadlineHandle);
|
|
167
167
|
return "";
|
|
168
168
|
}
|
|
@@ -305,7 +305,7 @@ export class RecallEntryCoordinator {
|
|
|
305
305
|
|
|
306
306
|
return prefixStandingMemoryBlock(recallResult, standingText, standingBudget);
|
|
307
307
|
} catch (err) {
|
|
308
|
-
this.deps.logRecallFailure(err);
|
|
308
|
+
this.deps.logRecallFailure(err, options.traceId);
|
|
309
309
|
this.deps.profiler.endTrace();
|
|
310
310
|
// A fired client deadline is a timeout, not caller cancellation: the
|
|
311
311
|
// caller still expects the degraded response, not "" (issue #3499).
|
|
@@ -329,9 +329,9 @@ export class RecallEntryCoordinator {
|
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
logRecallFailure(
|
|
332
|
+
logRecallFailure(cause: unknown, traceId?: string): void {
|
|
333
333
|
const now = Date.now();
|
|
334
|
-
const errorMsg =
|
|
334
|
+
const errorMsg = cause instanceof Error ? cause.message : String(cause);
|
|
335
335
|
const LOG_WINDOW_MS = 60_000;
|
|
336
336
|
const idleSinceLastFailureMs = now - this.deps.lastRecallFailureAtMs;
|
|
337
337
|
this.deps.lastRecallFailureAtMs = now;
|
|
@@ -344,14 +344,14 @@ export class RecallEntryCoordinator {
|
|
|
344
344
|
this.deps.suppressedRecallFailures > 0
|
|
345
345
|
? ` (suppressed ${this.deps.suppressedRecallFailures} similar failures in last minute)`
|
|
346
346
|
: "";
|
|
347
|
-
log.warn(`recall timed out or failed: ${errorMsg}${suffix}`);
|
|
347
|
+
log.warn(`recall timed out or failed${traceId ? ` [${traceId}]` : ""}: ${errorMsg}${suffix}`);
|
|
348
348
|
this.deps.lastRecallFailureLogAtMs = now;
|
|
349
349
|
this.deps.suppressedRecallFailures = 0;
|
|
350
350
|
return;
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
this.deps.suppressedRecallFailures += 1;
|
|
354
|
-
log.debug(`recall timed out or failed (suppressed): ${errorMsg}`);
|
|
354
|
+
log.debug(`recall timed out or failed (suppressed)${traceId ? ` [${traceId}]` : ""}: ${errorMsg}`);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
queueEvalShadowRecall(
|
|
@@ -199,10 +199,18 @@ export class RecallInternalCoordinator {
|
|
|
199
199
|
logger: log,
|
|
200
200
|
});
|
|
201
201
|
const promptHash = createHash("sha256").update(prompt).digest("hex");
|
|
202
|
-
|
|
202
|
+
// Caller-supplied traceId (issue #3499) wins: the ID a client logged
|
|
203
|
+
// before dispatch then appears verbatim on response + timing lines.
|
|
204
|
+
const traceId = options.traceId ?? createHash("sha256")
|
|
203
205
|
.update(`${sessionKey ?? "default"}:${recallStart}:${promptHash}`)
|
|
204
206
|
.digest("hex")
|
|
205
207
|
.slice(0, 16);
|
|
208
|
+
// Shadow-eval records are files keyed by this ID; a caller ID reused
|
|
209
|
+
// across runs would overwrite them, so the shadow keeps a per-run key.
|
|
210
|
+
const evalTraceId = `${traceId}-${recallStart}`;
|
|
211
|
+
// Emitted BEFORE the timeout-prone sections so a recall that dies at a
|
|
212
|
+
// deadline still leaves an ID-tagged daemon log line (issue #3499).
|
|
213
|
+
log.info(`recall start [${traceId}]`);
|
|
206
214
|
const sectionBuckets: RecallSectionBuckets = new Map();
|
|
207
215
|
// The effective LCM read session_id SET is computed below from
|
|
208
216
|
// `recallNamespaces` (the SAME read-authorized namespace set normal QMD/file
|
|
@@ -601,7 +609,7 @@ export class RecallInternalCoordinator {
|
|
|
601
609
|
}
|
|
602
610
|
if (sessionKey) {
|
|
603
611
|
this.deps.queueEvalShadowRecall({
|
|
604
|
-
traceId,
|
|
612
|
+
traceId: evalTraceId,
|
|
605
613
|
recordedAt: new Date().toISOString(),
|
|
606
614
|
sessionKey,
|
|
607
615
|
promptHash,
|
|
@@ -4888,7 +4896,9 @@ export class RecallInternalCoordinator {
|
|
|
4888
4896
|
const timingParts = Object.entries(timings)
|
|
4889
4897
|
.map(([k, v]) => `${k}=${v}`)
|
|
4890
4898
|
.join(", ");
|
|
4891
|
-
|
|
4899
|
+
// traceId on the timings line lets a client-side timeout be matched to
|
|
4900
|
+
// this recall by ID, not timestamp proximity (issue #3499).
|
|
4901
|
+
log.info(`recall timings [${traceId}]: ${timingParts}`);
|
|
4892
4902
|
emitRecallTiming(this.deps.config, {
|
|
4893
4903
|
...timings,
|
|
4894
4904
|
...phase2Timings,
|
|
@@ -5268,7 +5278,7 @@ export class RecallInternalCoordinator {
|
|
|
5268
5278
|
}
|
|
5269
5279
|
if (sessionKey) {
|
|
5270
5280
|
this.deps.queueEvalShadowRecall({
|
|
5271
|
-
traceId,
|
|
5281
|
+
traceId: evalTraceId,
|
|
5272
5282
|
recordedAt: new Date().toISOString(),
|
|
5273
5283
|
sessionKey,
|
|
5274
5284
|
promptHash,
|
|
@@ -280,7 +280,7 @@ export class StartupSearchSyncRunner {
|
|
|
280
280
|
try {
|
|
281
281
|
await this.host.deps.qmd.search(
|
|
282
282
|
"warmup",
|
|
283
|
-
this.host.deps.config.
|
|
283
|
+
this.host.deps.config.qmdCollection,
|
|
284
284
|
1,
|
|
285
285
|
undefined,
|
|
286
286
|
{ signal: warmupAbort.controller.signal },
|
|
@@ -95,6 +95,66 @@ test("deferredInitialize resolves without the corpus update and leaves the retry
|
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
test("QMD warmup uses the configured hot collection", async () => {
|
|
99
|
+
const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-warmup-"));
|
|
100
|
+
const config = { ...readyPathConfig(memoryDir), qmdCollection: "synthetic-hot" };
|
|
101
|
+
const orchestrator = new Orchestrator(config);
|
|
102
|
+
const deps = asDeps(orchestrator);
|
|
103
|
+
const collections: string[] = [];
|
|
104
|
+
try {
|
|
105
|
+
deps.qmd = {
|
|
106
|
+
...blockingUpdateQmd([]),
|
|
107
|
+
search: async (_query: string, collection: string) => {
|
|
108
|
+
collections.push(collection);
|
|
109
|
+
return [];
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
stubWarmupDeps(deps);
|
|
113
|
+
|
|
114
|
+
await deps.deferredInitialize(new AbortController().signal);
|
|
115
|
+
|
|
116
|
+
assert.deepEqual(collections, [config.qmdCollection]);
|
|
117
|
+
} finally {
|
|
118
|
+
await orchestrator.destroy().catch(() => undefined);
|
|
119
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("startupSearchSync warmup uses the configured hot collection", async () => {
|
|
124
|
+
const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-sync-warmup-"));
|
|
125
|
+
const config = { ...readyPathConfig(memoryDir), qmdCollection: "synthetic-hot" };
|
|
126
|
+
const orchestrator = new Orchestrator(config);
|
|
127
|
+
const deps = asDeps(orchestrator);
|
|
128
|
+
const collections: string[] = [];
|
|
129
|
+
try {
|
|
130
|
+
deps.qmd = {
|
|
131
|
+
probe: async () => true,
|
|
132
|
+
debugStatus: () => "synthetic-qmd",
|
|
133
|
+
isAvailable: () => true,
|
|
134
|
+
search: async (_query: string, collection: string) => {
|
|
135
|
+
collections.push(collection);
|
|
136
|
+
return [];
|
|
137
|
+
},
|
|
138
|
+
update: async () => {},
|
|
139
|
+
lastUpdateRanAtMs: 1,
|
|
140
|
+
lastUpdateFailedAtMs: null,
|
|
141
|
+
};
|
|
142
|
+
deps.namespaceCatalog.listNamespaces = async () => [{ namespace: "default" }];
|
|
143
|
+
deps.namespaceSearchRouter.clearCache = () => undefined;
|
|
144
|
+
deps.namespaceSearchRouter.ensureNamespaceCollection = async () => "present";
|
|
145
|
+
deps.namespaceSearchRouter.updateNamespacesDetailed = async (ns: string[]) => ({
|
|
146
|
+
backendCount: ns.length,
|
|
147
|
+
eligibleNamespaces: [...ns],
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
assert.equal(await orchestrator.startupSearchSync(new AbortController().signal), true);
|
|
151
|
+
assert.deepEqual(collections, [config.qmdCollection]);
|
|
152
|
+
} finally {
|
|
153
|
+
await orchestrator.destroy().catch(() => undefined);
|
|
154
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
98
158
|
test("startupSearchReadySync probes and ensures collections without running the corpus update", async () => {
|
|
99
159
|
const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-ready-path-"));
|
|
100
160
|
const orchestrator = new Orchestrator(readyPathConfig(memoryDir));
|
package/src/orchestrator.ts
CHANGED
|
@@ -2508,11 +2508,12 @@ export class Orchestrator {
|
|
|
2508
2508
|
);
|
|
2509
2509
|
}
|
|
2510
2510
|
|
|
2511
|
-
private logRecallFailure(
|
|
2511
|
+
private logRecallFailure(cause: unknown, traceId?: string): void {
|
|
2512
2512
|
return (this.recallEntryCoordinator ?? new RecallEntryCoordinator(
|
|
2513
2513
|
selfDeps<ConstructorParameters<typeof RecallEntryCoordinator>[0]>(this),
|
|
2514
2514
|
)).logRecallFailure(
|
|
2515
|
-
|
|
2515
|
+
cause,
|
|
2516
|
+
traceId,
|
|
2516
2517
|
);
|
|
2517
2518
|
}
|
|
2518
2519
|
|