@remnic/core 9.3.769 → 9.3.771
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 +34 -34
- package/dist/access-boundary.d.ts +2 -1
- package/dist/access-boundary.js +35 -35
- package/dist/access-cli.js +103 -100
- package/dist/access-cli.js.map +1 -1
- package/dist/access-errors.d.ts +5 -0
- package/dist/access-errors.js +8 -0
- package/dist/access-errors.js.map +1 -0
- package/dist/access-http.js +46 -43
- package/dist/access-identity-continuity-surface.js +34 -34
- package/dist/access-lcm-surface.js +34 -34
- package/dist/access-mcp-output-schemas.d.ts +20 -0
- package/dist/access-mcp-output-schemas.js +8 -0
- package/dist/access-mcp-output-schemas.js.map +1 -0
- package/dist/access-mcp.js +43 -40
- package/dist/access-observe-write-surface.js +34 -34
- package/dist/access-operations-batch.js +39 -37
- package/dist/access-operations.js +41 -39
- package/dist/access-recall-surface.js +34 -34
- package/dist/access-schema.js +3 -3
- package/dist/access-service.js +34 -34
- package/dist/access-surface-catalog.js +1 -0
- package/dist/access-surface-catalog.js.map +1 -1
- package/dist/active-recall.js +5 -5
- package/dist/adapters/index.js +4 -4
- package/dist/adapters/registry.js +2 -2
- package/dist/auto-sync-2SOUW4JW.js +1 -1
- package/dist/briefing.js +8 -8
- package/dist/causal-behavior.js +5 -5
- package/dist/causal-chain.js +3 -3
- package/dist/causal-consolidation.js +12 -12
- package/dist/causal-retrieval.js +3 -3
- package/dist/causal-trajectory.js +1 -1
- package/dist/{chunk-IGVKWKR2.js → chunk-27CQIO7T.js} +13 -13
- package/dist/{chunk-GLERZDM7.js → chunk-27TJRC2Y.js} +29 -7
- package/dist/chunk-27TJRC2Y.js.map +1 -0
- package/dist/{chunk-VKHZFF5P.js → chunk-44YXWE35.js} +2 -2
- package/dist/chunk-5RUE3GHQ.js +445 -0
- package/dist/chunk-5RUE3GHQ.js.map +1 -0
- package/dist/{chunk-R3K4CXPR.js → chunk-6QODJKOV.js} +2 -2
- package/dist/{chunk-ORAK3LNZ.js → chunk-6SHAUM5S.js} +5 -5
- package/dist/{chunk-2MR3MFQB.js → chunk-6Y4JTNX7.js} +2 -2
- package/dist/{chunk-CKNAVW34.js → chunk-7OSULYN2.js} +2 -2
- package/dist/{chunk-6T4LTI2F.js → chunk-7XH7VJN4.js} +4 -4
- package/dist/{chunk-JBPKEARU.js → chunk-AU7Q3LSC.js} +4 -4
- package/dist/{chunk-U5GFYMV7.js → chunk-BKTC7JCA.js} +3 -3
- package/dist/{chunk-AS2NRB45.js → chunk-BMANIB5B.js} +2 -2
- package/dist/{chunk-OAREUC7N.js → chunk-C2DDH5UN.js} +34 -34
- package/dist/{chunk-YDYC6PIS.js → chunk-CXBFYSQY.js} +2 -2
- package/dist/{chunk-DTTVX6EO.js → chunk-EGLUVV6B.js} +12 -12
- package/dist/{chunk-YNDLCWXS.js → chunk-EZ25VE3G.js} +4 -4
- package/dist/chunk-FTYDWKO6.js +101 -0
- package/dist/chunk-FTYDWKO6.js.map +1 -0
- package/dist/{chunk-SFNQDXXL.js → chunk-J2QYB2D5.js} +3 -3
- package/dist/{chunk-SQNED75R.js → chunk-KYC3RLYJ.js} +1 -1
- package/dist/{chunk-OX272PBW.js → chunk-L42FA4BU.js} +2 -2
- package/dist/{chunk-NDXJJKT2.js → chunk-LU7ATMRV.js} +2 -2
- package/dist/{chunk-V5RVMULT.js → chunk-LZ73Y56P.js} +10 -10
- package/dist/{chunk-IVFIYAIP.js → chunk-MJE4XV4A.js} +5 -5
- package/dist/{chunk-N4ZA2I7M.js → chunk-OTMAYEY5.js} +2 -2
- package/dist/{chunk-FLVL4L3L.js → chunk-OUXPVWTZ.js} +5 -5
- package/dist/{chunk-PA5ALD3S.js → chunk-OW4UXZNP.js} +129 -109
- package/dist/chunk-OW4UXZNP.js.map +1 -0
- package/dist/{chunk-4HYFKIGH.js → chunk-PSNMICC2.js} +4 -4
- package/dist/chunk-RANHFI3P.js +8 -0
- package/dist/chunk-RANHFI3P.js.map +1 -0
- package/dist/{chunk-CNXMWYLA.js → chunk-RFZW7NID.js} +165 -75
- package/dist/chunk-RFZW7NID.js.map +1 -0
- package/dist/{chunk-4JG55YV3.js → chunk-TECYUPFB.js} +4 -4
- package/dist/{chunk-EVXI2I6G.js → chunk-U3TRHUSJ.js} +64 -64
- package/dist/{chunk-SIPZ5UMK.js → chunk-U5HD7BB2.js} +27 -6
- package/dist/chunk-U5HD7BB2.js.map +1 -0
- package/dist/{chunk-X7HTU4HO.js → chunk-VFHDUFH5.js} +2 -2
- package/dist/{chunk-CVINPTKG.js → chunk-X5NUL5N4.js} +5 -5
- package/dist/{chunk-NFWTMM2M.js → chunk-XNWLD3RR.js} +2 -2
- package/dist/{chunk-QPTP6SKC.js → chunk-YOELDDBF.js} +2 -2
- package/dist/{chunk-2RLECZ6J.js → chunk-YRZMCPC5.js} +2 -2
- package/dist/{chunk-MSGPLITO.js → chunk-ZI3YYOOV.js} +2 -2
- package/dist/{chunk-MSGPLITO.js.map → chunk-ZI3YYOOV.js.map} +1 -1
- package/dist/cli.js +70 -67
- package/dist/compounding/engine.js +8 -8
- package/dist/config.js +2 -2
- package/dist/connectors/codex-materialize-runner.js +8 -8
- package/dist/connectors/index.js +8 -8
- package/dist/consolidation-provenance-check.js +2 -2
- package/dist/dashboard-runtime.js +2 -2
- package/dist/entity-retrieval.js +8 -8
- package/dist/extraction.js +1 -1
- package/dist/{forget-WYLR4ZFV.js → forget-OEE5OELK.js} +2 -2
- package/dist/index.js +175 -172
- package/dist/lcm/engine.js +4 -4
- package/dist/lcm/index.js +11 -11
- package/dist/maintenance/memory-governance.js +9 -9
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +8 -8
- package/dist/maintenance/rebuild-memory-projection.js +10 -10
- package/dist/namespaces/migrate.js +13 -13
- package/dist/namespaces/search.js +4 -4
- package/dist/namespaces/storage.js +8 -8
- package/dist/operator-toolkit.js +19 -19
- package/dist/orchestration/maintenance.js +10 -10
- package/dist/orchestrator.js +103 -100
- package/dist/recall-timings.d.ts +26 -0
- package/dist/recall-timings.js +16 -0
- package/dist/recall-timings.js.map +1 -0
- package/dist/resume-bundles.js +3 -3
- package/dist/search/factory.js +3 -3
- package/dist/search/index.js +7 -7
- package/dist/semantic-consolidation.js +11 -11
- package/dist/semantic-rule-promotion.js +8 -8
- package/dist/semantic-rule-verifier.js +9 -9
- package/dist/storage.js +8 -8
- package/dist/transfer/autodetect.js +1 -1
- package/dist/transfer/backup.js +1 -1
- package/dist/transfer/capsule-export.js +2 -2
- package/dist/verified-recall.js +9 -9
- package/package.json +2 -2
- package/src/access-boundary.ts +2 -0
- package/src/access-errors.ts +2 -0
- package/src/access-http.ts +32 -1
- package/src/access-mcp-output-schemas.ts +472 -0
- package/src/access-mcp.ts +235 -143
- package/src/access-operations-batch.ts +19 -0
- package/src/access-surface-catalog.ts +1 -0
- package/src/orchestration/recall-internal.ts +21 -3
- package/src/recall-timings-access.test.ts +301 -0
- package/src/recall-timings.ts +141 -0
- package/dist/chunk-CNXMWYLA.js.map +0 -1
- package/dist/chunk-GLERZDM7.js.map +0 -1
- package/dist/chunk-PA5ALD3S.js.map +0 -1
- package/dist/chunk-SIPZ5UMK.js.map +0 -1
- /package/dist/{chunk-IGVKWKR2.js.map → chunk-27CQIO7T.js.map} +0 -0
- /package/dist/{chunk-VKHZFF5P.js.map → chunk-44YXWE35.js.map} +0 -0
- /package/dist/{chunk-R3K4CXPR.js.map → chunk-6QODJKOV.js.map} +0 -0
- /package/dist/{chunk-ORAK3LNZ.js.map → chunk-6SHAUM5S.js.map} +0 -0
- /package/dist/{chunk-2MR3MFQB.js.map → chunk-6Y4JTNX7.js.map} +0 -0
- /package/dist/{chunk-CKNAVW34.js.map → chunk-7OSULYN2.js.map} +0 -0
- /package/dist/{chunk-6T4LTI2F.js.map → chunk-7XH7VJN4.js.map} +0 -0
- /package/dist/{chunk-JBPKEARU.js.map → chunk-AU7Q3LSC.js.map} +0 -0
- /package/dist/{chunk-U5GFYMV7.js.map → chunk-BKTC7JCA.js.map} +0 -0
- /package/dist/{chunk-AS2NRB45.js.map → chunk-BMANIB5B.js.map} +0 -0
- /package/dist/{chunk-OAREUC7N.js.map → chunk-C2DDH5UN.js.map} +0 -0
- /package/dist/{chunk-YDYC6PIS.js.map → chunk-CXBFYSQY.js.map} +0 -0
- /package/dist/{chunk-DTTVX6EO.js.map → chunk-EGLUVV6B.js.map} +0 -0
- /package/dist/{chunk-YNDLCWXS.js.map → chunk-EZ25VE3G.js.map} +0 -0
- /package/dist/{chunk-SFNQDXXL.js.map → chunk-J2QYB2D5.js.map} +0 -0
- /package/dist/{chunk-SQNED75R.js.map → chunk-KYC3RLYJ.js.map} +0 -0
- /package/dist/{chunk-OX272PBW.js.map → chunk-L42FA4BU.js.map} +0 -0
- /package/dist/{chunk-NDXJJKT2.js.map → chunk-LU7ATMRV.js.map} +0 -0
- /package/dist/{chunk-V5RVMULT.js.map → chunk-LZ73Y56P.js.map} +0 -0
- /package/dist/{chunk-IVFIYAIP.js.map → chunk-MJE4XV4A.js.map} +0 -0
- /package/dist/{chunk-N4ZA2I7M.js.map → chunk-OTMAYEY5.js.map} +0 -0
- /package/dist/{chunk-FLVL4L3L.js.map → chunk-OUXPVWTZ.js.map} +0 -0
- /package/dist/{chunk-4HYFKIGH.js.map → chunk-PSNMICC2.js.map} +0 -0
- /package/dist/{chunk-4JG55YV3.js.map → chunk-TECYUPFB.js.map} +0 -0
- /package/dist/{chunk-EVXI2I6G.js.map → chunk-U3TRHUSJ.js.map} +0 -0
- /package/dist/{chunk-X7HTU4HO.js.map → chunk-VFHDUFH5.js.map} +0 -0
- /package/dist/{chunk-CVINPTKG.js.map → chunk-X5NUL5N4.js.map} +0 -0
- /package/dist/{chunk-NFWTMM2M.js.map → chunk-XNWLD3RR.js.map} +0 -0
- /package/dist/{chunk-QPTP6SKC.js.map → chunk-YOELDDBF.js.map} +0 -0
- /package/dist/{chunk-2RLECZ6J.js.map → chunk-YRZMCPC5.js.map} +0 -0
- /package/dist/{forget-WYLR4ZFV.js.map → forget-OEE5OELK.js.map} +0 -0
|
@@ -14,10 +14,12 @@ import { z } from "zod";
|
|
|
14
14
|
import type { DreamsPhase, RecallDisclosure, RecallPlanMode } from "./types.js";
|
|
15
15
|
import type { RemnicChatGptMemoryInspectorInput } from "./mcp-memory-inspector-app.js";
|
|
16
16
|
import { defineOperation } from "./access-boundary.js";
|
|
17
|
+
import { EngramAccessForbiddenError } from "./access-errors.js";
|
|
17
18
|
import { EngramAccessInputError, type EngramAccessService } from "./access-service.js";
|
|
18
19
|
import { projectTagProjectId } from "./coding/coding-namespace.js";
|
|
19
20
|
import { expandTildePath } from "./utils/path.js";
|
|
20
21
|
import { resolvePrincipal } from "./namespaces/principal.js";
|
|
22
|
+
import { getRecallTimingStatus, isRecallTimingsOperator } from "./recall-timings.js";
|
|
21
23
|
import { validateBriefingFormat } from "./briefing.js";
|
|
22
24
|
import {
|
|
23
25
|
buildChatGptMemoryInspectorActionRequest,
|
|
@@ -254,6 +256,23 @@ defineOperation({ name: "offline_sync_apply_file_content", description: "Apply f
|
|
|
254
256
|
defineOperation({ name: "offline_sync_apply", description: "Apply sync.", schema: strictSchema({ changeset: z.unknown().optional(), namespace: S.str }), handler: async (input, ctx) => ({ result: await ctx.service.offlineSyncApply({ changeset: input.changeset, namespace: optStr(input.namespace), principal: ctx.authenticatedPrincipal }) }) });
|
|
255
257
|
defineOperation({ name: "lcm_status", description: "LCM status.", schema: strictSchema({}), handler: async (_i, ctx) => ({ result: await ctx.service.lcmStatus() }) });
|
|
256
258
|
defineOperation({ name: "memory_list", description: "List memories.", schema: strictSchema({}), handler: async (_i, ctx) => ({ result: await ctx.service.memoryBrowse() }) });
|
|
259
|
+
defineOperation({
|
|
260
|
+
name: "recall_timings",
|
|
261
|
+
description: "List recent recall timings.",
|
|
262
|
+
schema: strictSchema({}),
|
|
263
|
+
handler: async (_input, ctx) => {
|
|
264
|
+
if (
|
|
265
|
+
!isRecallTimingsOperator(
|
|
266
|
+
ctx.service.configRef,
|
|
267
|
+
ctx.authenticatedPrincipal,
|
|
268
|
+
ctx.operatorPrincipal,
|
|
269
|
+
)
|
|
270
|
+
) {
|
|
271
|
+
throw new EngramAccessForbiddenError("recall timings require the configured operator principal");
|
|
272
|
+
}
|
|
273
|
+
return { result: getRecallTimingStatus(ctx.service.configRef) };
|
|
274
|
+
},
|
|
275
|
+
});
|
|
257
276
|
defineOperation({ name: "entity_list", description: "List entities.", schema: strictSchema({}), handler: async (_i, ctx) => ({ result: await ctx.service.entityList() }) });
|
|
258
277
|
defineOperation({ name: "maintenance_status", description: "Maintenance status.", schema: strictSchema({}), handler: async (_i, ctx) => ({ result: await ctx.service.maintenance() }) });
|
|
259
278
|
defineOperation({ name: "quality_status", description: "Quality status.", schema: strictSchema({}), handler: async (_i, ctx) => ({ result: await ctx.service.quality() }) });
|
|
@@ -200,6 +200,7 @@ export const HTTP_ROUTES: readonly HttpRouteEntry[] = [
|
|
|
200
200
|
{ method: "POST", pathname: "/engram/v1/coding/delta", operation: "coding_delta" },
|
|
201
201
|
{ method: "POST", pathname: "/engram/v1/suggestions", operation: "suggestion_submit" },
|
|
202
202
|
{ method: "GET", pathname: "/engram/v1/memories", operation: "memory_list" },
|
|
203
|
+
{ method: "GET", pathname: "/engram/v1/recall/timings", operation: "recall_timings" },
|
|
203
204
|
{ method: "GET", pathname: "/engram/v1/memories/:id", operation: "memory_get" },
|
|
204
205
|
{ method: "GET", pathname: "/engram/v1/memories/:id/timeline", operation: "memory_timeline" },
|
|
205
206
|
{ method: "GET", pathname: "/engram/v1/entities", operation: "entity_list" },
|
|
@@ -51,6 +51,7 @@ import { createRecallSectionMetricRecorder } from "../recall-qos.js";
|
|
|
51
51
|
import { buildRecallQueryPolicy } from "../recall-query-policy.js";
|
|
52
52
|
import { type GraphRecallExpandedEntry, type LastRecallBudgetSummary, type LastRecallSnapshot, LastRecallStore, RecallHandleHistoryStore } from "../recall-state.js";
|
|
53
53
|
import { type RecallFilterTrace, type RecallXrayResult, type RecallXrayScoreDecomposition, type RecallXraySnapshot, buildXraySnapshot } from "../recall-xray.js";
|
|
54
|
+
import { recordRecallTiming } from "../recall-timings.js";
|
|
54
55
|
import { findUnresolvedEntityRefs } from "../reconstruct.js";
|
|
55
56
|
import { RerankCache, rerankLocalOrNoop } from "../rerank.js";
|
|
56
57
|
import { buildResponseGuidanceRecallSection, shouldRecallResponseGuidance } from "../response-guidance-recall.js";
|
|
@@ -752,6 +753,9 @@ export class RecallInternalCoordinator {
|
|
|
752
753
|
// Catalog read touch (issue #1499) is recorded LATER — after the Phase 1
|
|
753
754
|
// abort gate — so it fires only when retrieval actually runs, not for
|
|
754
755
|
// aborted / short-circuited recalls.
|
|
756
|
+
const codingContext = sessionKey
|
|
757
|
+
? this.deps.getCodingContextForSession(sessionKey)
|
|
758
|
+
: null;
|
|
755
759
|
const scopePlan = resolveScopePlan({
|
|
756
760
|
config: this.deps.config,
|
|
757
761
|
sessionKey,
|
|
@@ -761,9 +765,7 @@ export class RecallInternalCoordinator {
|
|
|
761
765
|
&& options.principalOverride.length > 0
|
|
762
766
|
? options.principalOverride
|
|
763
767
|
: undefined,
|
|
764
|
-
codingContext
|
|
765
|
-
? this.deps.getCodingContextForSession(sessionKey)
|
|
766
|
-
: null,
|
|
768
|
+
codingContext,
|
|
767
769
|
namespacesEnabled,
|
|
768
770
|
});
|
|
769
771
|
const {
|
|
@@ -867,6 +869,14 @@ export class RecallInternalCoordinator {
|
|
|
867
869
|
const earlySessionKey = sessionKey ?? "default";
|
|
868
870
|
this.deps._recallWorkspaceOverrides.delete(earlySessionKey);
|
|
869
871
|
timings.total = `${Date.now() - recallStart}ms`;
|
|
872
|
+
recordRecallTiming(this.deps.config, {
|
|
873
|
+
...timings,
|
|
874
|
+
timestamp: new Date().toISOString(),
|
|
875
|
+
namespace: selfNamespace,
|
|
876
|
+
total: timings.total,
|
|
877
|
+
recallPlan: timings.recallPlan,
|
|
878
|
+
queryPolicy: timings.queryPolicy,
|
|
879
|
+
});
|
|
870
880
|
// X-ray capture for the `no_recall` early-return path
|
|
871
881
|
// (issue #570 PR 1). `no_recall` skips retrieval entirely, so
|
|
872
882
|
// the snapshot carries zero results and an empty-budget accounting
|
|
@@ -5146,6 +5156,14 @@ export class RecallInternalCoordinator {
|
|
|
5146
5156
|
.map(([k, v]) => `${k}=${v}`)
|
|
5147
5157
|
.join(", ");
|
|
5148
5158
|
log.info(`recall timings: ${timingParts}`);
|
|
5159
|
+
recordRecallTiming(this.deps.config, {
|
|
5160
|
+
...timings,
|
|
5161
|
+
timestamp: new Date().toISOString(),
|
|
5162
|
+
namespace: selfNamespace,
|
|
5163
|
+
total: timings.total,
|
|
5164
|
+
recallPlan: timings.recallPlan,
|
|
5165
|
+
queryPolicy: timings.queryPolicy,
|
|
5166
|
+
});
|
|
5149
5167
|
|
|
5150
5168
|
const assembledRecall = this.deps.assembleRecallSections(
|
|
5151
5169
|
sectionBuckets,
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
|
|
7
|
+
import { getOperation } from "./access-boundary.js";
|
|
8
|
+
import { EngramAccessHttpServer } from "./access-http.js";
|
|
9
|
+
import { EngramAccessService } from "./access-service.js";
|
|
10
|
+
import { parseConfig } from "./config.js";
|
|
11
|
+
import { Orchestrator } from "./orchestrator.js";
|
|
12
|
+
import {
|
|
13
|
+
getRecallTimings,
|
|
14
|
+
getRecallTimingStatus,
|
|
15
|
+
recordRecallTiming,
|
|
16
|
+
resolveRecallTimingsOperatorPrincipal,
|
|
17
|
+
type RecallTimingRecord,
|
|
18
|
+
} from "./recall-timings.js";
|
|
19
|
+
|
|
20
|
+
function makeConfig(memoryDir: string, overrides: Record<string, unknown> = {}) {
|
|
21
|
+
return parseConfig({
|
|
22
|
+
openaiApiKey: "sk-test",
|
|
23
|
+
memoryDir,
|
|
24
|
+
workspaceDir: path.join(memoryDir, "workspace"),
|
|
25
|
+
qmdEnabled: false,
|
|
26
|
+
embeddingFallbackEnabled: false,
|
|
27
|
+
recallPlannerEnabled: false,
|
|
28
|
+
sharedContextEnabled: false,
|
|
29
|
+
initGateTimeoutMs: 1000,
|
|
30
|
+
...overrides,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test("authenticated recall timings route returns two recalls without user-correlatable inputs", async () => {
|
|
35
|
+
const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-recall-timings-"));
|
|
36
|
+
const config = makeConfig(memoryDir);
|
|
37
|
+
const orchestrator = new Orchestrator(config);
|
|
38
|
+
const service = new EngramAccessService(orchestrator);
|
|
39
|
+
const server = new EngramAccessHttpServer({
|
|
40
|
+
service,
|
|
41
|
+
host: "127.0.0.1",
|
|
42
|
+
port: 0,
|
|
43
|
+
authToken: "secret-token",
|
|
44
|
+
principal: "operator",
|
|
45
|
+
trustPrincipalHeader: true,
|
|
46
|
+
maxBodyBytes: 1024,
|
|
47
|
+
});
|
|
48
|
+
const started = await server.start();
|
|
49
|
+
const url = `http://${started.host}:${started.port}/engram/v1/recall/timings`;
|
|
50
|
+
try {
|
|
51
|
+
await orchestrator.recall("private first query", "private:first:session");
|
|
52
|
+
await orchestrator.recall("private second query", "private:second:session", { mode: "no_recall" });
|
|
53
|
+
|
|
54
|
+
const denied = await fetch(url);
|
|
55
|
+
assert.equal(denied.status, 401);
|
|
56
|
+
|
|
57
|
+
const nonOperator = await fetch(url, {
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: "Bearer secret-token",
|
|
60
|
+
"X-Engram-Principal": "reader",
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
assert.equal(nonOperator.status, 403);
|
|
64
|
+
assert.equal(nonOperator.headers.get("cache-control"), "no-store");
|
|
65
|
+
|
|
66
|
+
const response = await fetch(url, {
|
|
67
|
+
headers: {
|
|
68
|
+
Authorization: "Bearer secret-token",
|
|
69
|
+
"X-Engram-Principal": "operator",
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
assert.equal(response.status, 200);
|
|
73
|
+
assert.equal(response.headers.get("cache-control"), "no-store");
|
|
74
|
+
const payload = await response.json() as {
|
|
75
|
+
generatedAt: string;
|
|
76
|
+
processStartedAt: string;
|
|
77
|
+
capacity: number;
|
|
78
|
+
count: number;
|
|
79
|
+
order: string;
|
|
80
|
+
records: RecallTimingRecord[];
|
|
81
|
+
};
|
|
82
|
+
assert.ok(Number.isFinite(Date.parse(payload.generatedAt)));
|
|
83
|
+
assert.ok(Number.isFinite(Date.parse(payload.processStartedAt)));
|
|
84
|
+
assert.ok(Date.parse(payload.processStartedAt) <= Date.parse(payload.generatedAt));
|
|
85
|
+
assert.equal(payload.capacity, 50);
|
|
86
|
+
assert.equal(payload.order, "newest-first");
|
|
87
|
+
assert.equal(payload.count, 2);
|
|
88
|
+
assert.equal(payload.records.length, 2);
|
|
89
|
+
const operation = getOperation("recall_timings");
|
|
90
|
+
assert.ok(operation);
|
|
91
|
+
await assert.rejects(
|
|
92
|
+
operation.run({}, {
|
|
93
|
+
service,
|
|
94
|
+
authenticatedPrincipal: "reader",
|
|
95
|
+
operatorPrincipal: "operator",
|
|
96
|
+
}),
|
|
97
|
+
/configured operator principal/,
|
|
98
|
+
);
|
|
99
|
+
const operationOutput = await operation.run({}, {
|
|
100
|
+
service,
|
|
101
|
+
authenticatedPrincipal: "operator",
|
|
102
|
+
operatorPrincipal: "operator",
|
|
103
|
+
}) as { result: { count: number; records: RecallTimingRecord[] } };
|
|
104
|
+
// generatedAt legitimately differs between the two calls; the data must not.
|
|
105
|
+
assert.equal(operationOutput.result.count, payload.count);
|
|
106
|
+
assert.deepEqual(operationOutput.result.records, payload.records);
|
|
107
|
+
for (const record of payload.records) {
|
|
108
|
+
assert.equal(record.namespace, "default");
|
|
109
|
+
assert.ok(Number.isFinite(Date.parse(record.timestamp)));
|
|
110
|
+
assert.equal(typeof record.timingsMs.total, "number");
|
|
111
|
+
assert.ok(record.timingsMs.total >= 0);
|
|
112
|
+
assert.equal(typeof record.recallPlan, "string");
|
|
113
|
+
assert.equal(typeof record.queryPolicy, "string");
|
|
114
|
+
assert.equal("query" in record, false);
|
|
115
|
+
assert.equal("prompt" in record, false);
|
|
116
|
+
assert.equal("sessionKey" in record, false);
|
|
117
|
+
assert.equal("retrievalQuery" in record, false);
|
|
118
|
+
assert.equal("query" in record.timingsMs, false);
|
|
119
|
+
assert.equal("prompt" in record.timingsMs, false);
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
await server.stop();
|
|
123
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("recall timing history keeps only the newest 50 records", () => {
|
|
128
|
+
const config = makeConfig(path.join(os.tmpdir(), "remnic-recall-timing-ring"));
|
|
129
|
+
for (let index = 0; index < 51; index += 1) {
|
|
130
|
+
recordRecallTiming(config, {
|
|
131
|
+
timestamp: new Date(index * 1000).toISOString(),
|
|
132
|
+
namespace: "default",
|
|
133
|
+
total: index,
|
|
134
|
+
recallPlan: "full",
|
|
135
|
+
queryPolicy: "general/full",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const records = getRecallTimings(config);
|
|
140
|
+
assert.equal(records.length, 50);
|
|
141
|
+
assert.equal(records[0]?.timingsMs.total, 50);
|
|
142
|
+
assert.equal(records[49]?.timingsMs.total, 1);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("operator principal resolution agrees for standalone and embedded access", () => {
|
|
146
|
+
const standaloneConfig = makeConfig(path.join(os.tmpdir(), "remnic-recall-timing-standalone"));
|
|
147
|
+
assert.equal(
|
|
148
|
+
resolveRecallTimingsOperatorPrincipal(standaloneConfig, "standalone-operator"),
|
|
149
|
+
"standalone-operator",
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const embeddedConfig = makeConfig(path.join(os.tmpdir(), "remnic-recall-timing-embedded"), {
|
|
153
|
+
agentAccessHttp: {
|
|
154
|
+
enabled: true,
|
|
155
|
+
host: "127.0.0.1",
|
|
156
|
+
port: 0,
|
|
157
|
+
principal: "embedded-operator",
|
|
158
|
+
maxBodyBytes: 1024,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
assert.equal(
|
|
162
|
+
resolveRecallTimingsOperatorPrincipal(embeddedConfig),
|
|
163
|
+
"embedded-operator",
|
|
164
|
+
);
|
|
165
|
+
assert.equal(
|
|
166
|
+
resolveRecallTimingsOperatorPrincipal(
|
|
167
|
+
embeddedConfig,
|
|
168
|
+
"fallback-transport-principal",
|
|
169
|
+
),
|
|
170
|
+
"embedded-operator",
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("recall timing records expose only the fixed telemetry schema", () => {
|
|
175
|
+
const config = makeConfig(path.join(os.tmpdir(), "remnic-recall-timing-schema"));
|
|
176
|
+
recordRecallTiming(config, {
|
|
177
|
+
timestamp: new Date(0).toISOString(),
|
|
178
|
+
namespace: "default",
|
|
179
|
+
total: "7ms",
|
|
180
|
+
qmd: "3ms",
|
|
181
|
+
qmdPost: "2ms-cache",
|
|
182
|
+
recallPlan: "full",
|
|
183
|
+
queryPolicy: "general/full",
|
|
184
|
+
queryAware: "1ms;helped=private prompt detail",
|
|
185
|
+
prompt: "private prompt",
|
|
186
|
+
sessionKey: "user-session",
|
|
187
|
+
unknownTiming: "9ms",
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const record = getRecallTimings(config)[0];
|
|
191
|
+
assert.deepEqual(record, {
|
|
192
|
+
timestamp: new Date(0).toISOString(),
|
|
193
|
+
namespace: "default",
|
|
194
|
+
recallPlan: "full",
|
|
195
|
+
queryPolicy: "general/full",
|
|
196
|
+
timingsMs: {
|
|
197
|
+
total: 7,
|
|
198
|
+
qmd: 3,
|
|
199
|
+
qmdPost: 2,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("phases that did not run are omitted while measured zeros survive", () => {
|
|
205
|
+
const config = makeConfig(path.join(os.tmpdir(), "remnic-recall-timing-phases"));
|
|
206
|
+
recordRecallTiming(config, {
|
|
207
|
+
timestamp: new Date(0).toISOString(),
|
|
208
|
+
namespace: "default",
|
|
209
|
+
total: "5ms",
|
|
210
|
+
qmd: "0ms",
|
|
211
|
+
recallPlan: "full",
|
|
212
|
+
queryPolicy: "general/full",
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const record = getRecallTimings(config)[0];
|
|
216
|
+
assert.ok(record);
|
|
217
|
+
assert.equal(record.timingsMs.qmd, 0);
|
|
218
|
+
assert.equal("qmdPost" in record.timingsMs, false);
|
|
219
|
+
assert.equal("ki" in record.timingsMs, false);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test("status envelope reports a stable process start and live generation time", () => {
|
|
223
|
+
const config = makeConfig(path.join(os.tmpdir(), "remnic-recall-timing-envelope"));
|
|
224
|
+
const first = getRecallTimingStatus(config);
|
|
225
|
+
const second = getRecallTimingStatus(config);
|
|
226
|
+
assert.equal(first.processStartedAt, second.processStartedAt);
|
|
227
|
+
assert.ok(Number.isFinite(Date.parse(first.processStartedAt)));
|
|
228
|
+
assert.ok(Date.parse(first.processStartedAt) <= Date.now());
|
|
229
|
+
assert.equal(first.capacity, 50);
|
|
230
|
+
assert.equal(first.order, "newest-first");
|
|
231
|
+
assert.equal(first.count, 0);
|
|
232
|
+
assert.deepEqual(first.records, []);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("configured operator principal outranks a divergent server principal override", async () => {
|
|
236
|
+
const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-recall-timings-div-"));
|
|
237
|
+
const config = makeConfig(memoryDir, {
|
|
238
|
+
agentAccessHttp: {
|
|
239
|
+
enabled: true,
|
|
240
|
+
host: "127.0.0.1",
|
|
241
|
+
port: 0,
|
|
242
|
+
principal: "config-operator",
|
|
243
|
+
maxBodyBytes: 1024,
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
const orchestrator = new Orchestrator(config);
|
|
247
|
+
const service = new EngramAccessService(orchestrator);
|
|
248
|
+
const server = new EngramAccessHttpServer({
|
|
249
|
+
service,
|
|
250
|
+
host: "127.0.0.1",
|
|
251
|
+
port: 0,
|
|
252
|
+
authToken: "secret-token",
|
|
253
|
+
principal: "cli-override",
|
|
254
|
+
trustPrincipalHeader: true,
|
|
255
|
+
maxBodyBytes: 1024,
|
|
256
|
+
});
|
|
257
|
+
const started = await server.start();
|
|
258
|
+
const url = `http://${started.host}:${started.port}/engram/v1/recall/timings`;
|
|
259
|
+
try {
|
|
260
|
+
// The server's own default identity is NOT the operator when the config
|
|
261
|
+
// explicitly names a different one. Settled precedence: config first.
|
|
262
|
+
const overrideOnly = await fetch(url, {
|
|
263
|
+
headers: { Authorization: "Bearer secret-token" },
|
|
264
|
+
});
|
|
265
|
+
assert.equal(overrideOnly.status, 403);
|
|
266
|
+
|
|
267
|
+
const configOperator = await fetch(url, {
|
|
268
|
+
headers: {
|
|
269
|
+
Authorization: "Bearer secret-token",
|
|
270
|
+
"X-Engram-Principal": "config-operator",
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
assert.equal(configOperator.status, 200);
|
|
274
|
+
} finally {
|
|
275
|
+
await server.stop();
|
|
276
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("batch context without transport operator fails closed when config names no operator", async () => {
|
|
281
|
+
const config = makeConfig(path.join(os.tmpdir(), "remnic-recall-timing-batch-closed"));
|
|
282
|
+
const orchestrator = new Orchestrator(config);
|
|
283
|
+
const service = new EngramAccessService(orchestrator);
|
|
284
|
+
const operation = getOperation("recall_timings");
|
|
285
|
+
assert.ok(operation);
|
|
286
|
+
// No config principal and no transport operator: nobody can pass the gate,
|
|
287
|
+
// not even a caller whose authenticated principal would match elsewhere.
|
|
288
|
+
await assert.rejects(
|
|
289
|
+
operation.run({}, { service, authenticatedPrincipal: "operator" }),
|
|
290
|
+
/configured operator principal/,
|
|
291
|
+
);
|
|
292
|
+
// The same caller passes once the transport supplies the operator context,
|
|
293
|
+
// as the HTTP route does by dispatching with operatorPrincipal set to the
|
|
294
|
+
// server's own principal.
|
|
295
|
+
const output = await operation.run({}, {
|
|
296
|
+
service,
|
|
297
|
+
authenticatedPrincipal: "operator",
|
|
298
|
+
operatorPrincipal: "operator",
|
|
299
|
+
}) as { result: { count: number } };
|
|
300
|
+
assert.equal(output.result.count, 0);
|
|
301
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { PluginConfig } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export interface RecallTimingRecord {
|
|
4
|
+
readonly timestamp: string;
|
|
5
|
+
readonly namespace: string;
|
|
6
|
+
readonly recallPlan: string;
|
|
7
|
+
readonly queryPolicy: string;
|
|
8
|
+
readonly timingsMs: Readonly<Record<string, number>>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RecallTimingStatus {
|
|
12
|
+
readonly generatedAt: string;
|
|
13
|
+
readonly processStartedAt: string;
|
|
14
|
+
readonly capacity: number;
|
|
15
|
+
readonly count: number;
|
|
16
|
+
readonly order: "newest-first";
|
|
17
|
+
readonly records: RecallTimingRecord[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const RECALL_TIMING_HISTORY_LIMIT = 50;
|
|
21
|
+
const TIMING_FIELD_ALLOWLIST = [
|
|
22
|
+
"total",
|
|
23
|
+
"sharedCtx",
|
|
24
|
+
"profile",
|
|
25
|
+
"peerProfile",
|
|
26
|
+
"identityContinuity",
|
|
27
|
+
"entityRetrieval",
|
|
28
|
+
"ki",
|
|
29
|
+
"artifacts",
|
|
30
|
+
"objectiveState",
|
|
31
|
+
"causalTrajectories",
|
|
32
|
+
"cmcCausalChains",
|
|
33
|
+
"calibrationRules",
|
|
34
|
+
"trustZones",
|
|
35
|
+
"harmonicRetrieval",
|
|
36
|
+
"verifiedRecall",
|
|
37
|
+
"verifiedRules",
|
|
38
|
+
"workProducts",
|
|
39
|
+
"qmd",
|
|
40
|
+
"transcript",
|
|
41
|
+
"summaries",
|
|
42
|
+
"nativeKnowledge",
|
|
43
|
+
"convRecall",
|
|
44
|
+
"compounding",
|
|
45
|
+
"graphShadow",
|
|
46
|
+
"qmdPost",
|
|
47
|
+
] as const;
|
|
48
|
+
// The ring buffer is process-local: a daemon restart or haproxy failover to
|
|
49
|
+
// the other backend starts an empty history. processStartedAt lets consumers
|
|
50
|
+
// detect that discontinuity. Derived from the process time origin, not module
|
|
51
|
+
// initialization, so lazy imports cannot skew it.
|
|
52
|
+
const PROCESS_STARTED_AT = new Date(Date.now() - process.uptime() * 1000).toISOString();
|
|
53
|
+
const histories = new WeakMap<PluginConfig, RecallTimingRecord[]>();
|
|
54
|
+
|
|
55
|
+
function numericMilliseconds(value: unknown): number | undefined {
|
|
56
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
if (typeof value !== "string") return undefined;
|
|
60
|
+
const match = /^(\d+)ms/.exec(value);
|
|
61
|
+
return match ? Number(match[1]) : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function sanitizeRecallTiming(
|
|
65
|
+
input: Record<string, unknown>,
|
|
66
|
+
): RecallTimingRecord {
|
|
67
|
+
// Serialization boundary: ONLY allowlisted numeric phases reach timingsMs,
|
|
68
|
+
// and the four dimension strings are copied field-by-field. Never spread
|
|
69
|
+
// the internal record into the public shape.
|
|
70
|
+
const timingsMs: Record<string, number> = {
|
|
71
|
+
total: numericMilliseconds(input.total) ?? 0,
|
|
72
|
+
};
|
|
73
|
+
for (const field of TIMING_FIELD_ALLOWLIST) {
|
|
74
|
+
if (field === "total") continue;
|
|
75
|
+
const value = numericMilliseconds(input[field]);
|
|
76
|
+
// Phases that did not run are omitted; 0 means "ran, measured zero".
|
|
77
|
+
if (value !== undefined) timingsMs[field] = value;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
timestamp: typeof input.timestamp === "string" ? input.timestamp : "",
|
|
81
|
+
namespace: typeof input.namespace === "string" ? input.namespace : "",
|
|
82
|
+
recallPlan: typeof input.recallPlan === "string" ? input.recallPlan : "",
|
|
83
|
+
queryPolicy: typeof input.queryPolicy === "string" ? input.queryPolicy : "",
|
|
84
|
+
timingsMs,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function recordRecallTiming(
|
|
89
|
+
config: PluginConfig,
|
|
90
|
+
input: Record<string, unknown>,
|
|
91
|
+
): void {
|
|
92
|
+
const history = histories.get(config) ?? [];
|
|
93
|
+
history.push(sanitizeRecallTiming(input));
|
|
94
|
+
if (history.length > RECALL_TIMING_HISTORY_LIMIT) history.shift();
|
|
95
|
+
histories.set(config, history);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function resolveRecallTimingsOperatorPrincipal(
|
|
99
|
+
config: PluginConfig,
|
|
100
|
+
transportPrincipal?: string,
|
|
101
|
+
): string | undefined {
|
|
102
|
+
return config.agentAccessHttp.principal?.trim()
|
|
103
|
+
|| transportPrincipal?.trim()
|
|
104
|
+
|| undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function isRecallTimingsOperator(
|
|
108
|
+
config: PluginConfig,
|
|
109
|
+
authenticatedPrincipal?: string,
|
|
110
|
+
transportPrincipal?: string,
|
|
111
|
+
): boolean {
|
|
112
|
+
const operatorPrincipal = resolveRecallTimingsOperatorPrincipal(
|
|
113
|
+
config,
|
|
114
|
+
transportPrincipal,
|
|
115
|
+
);
|
|
116
|
+
return Boolean(
|
|
117
|
+
operatorPrincipal
|
|
118
|
+
&& authenticatedPrincipal
|
|
119
|
+
&& authenticatedPrincipal === operatorPrincipal,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function getRecallTimings(config: PluginConfig): RecallTimingRecord[] {
|
|
124
|
+
const history = histories.get(config) ?? [];
|
|
125
|
+
return history.slice().reverse().map((record) => ({
|
|
126
|
+
...record,
|
|
127
|
+
timingsMs: { ...record.timingsMs },
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function getRecallTimingStatus(config: PluginConfig): RecallTimingStatus {
|
|
132
|
+
const records = getRecallTimings(config);
|
|
133
|
+
return {
|
|
134
|
+
generatedAt: new Date().toISOString(),
|
|
135
|
+
processStartedAt: PROCESS_STARTED_AT,
|
|
136
|
+
capacity: RECALL_TIMING_HISTORY_LIMIT,
|
|
137
|
+
count: records.length,
|
|
138
|
+
order: "newest-first",
|
|
139
|
+
records,
|
|
140
|
+
};
|
|
141
|
+
}
|