@remnic/core 10.0.131 → 10.0.133
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 +37 -37
- package/dist/access-cli.js +37 -37
- package/dist/access-extraction-force-flush.js +37 -37
- package/dist/access-http-briefing.js +37 -37
- package/dist/access-http-query.js +37 -37
- package/dist/access-http.js +37 -37
- package/dist/access-identity-continuity-surface.js +37 -37
- package/dist/access-lcm-surface.js +37 -37
- package/dist/access-mcp.js +37 -37
- package/dist/access-observe-write-surface.js +37 -37
- package/dist/access-operations-batch.js +37 -37
- package/dist/access-operations.js +37 -37
- package/dist/access-recall-concurrency.js +37 -37
- package/dist/access-recall-diagnostics.js +2 -2
- package/dist/access-recall-response.js +37 -37
- package/dist/access-recall-surface.js +37 -37
- package/dist/access-service.js +37 -37
- package/dist/active-recall.js +3 -3
- package/dist/briefing.js +3 -3
- package/dist/causal-consolidation.js +4 -4
- package/dist/{chunk-BE5F6KFG.js → chunk-45BPRD6P.js} +2 -2
- package/dist/{chunk-3OT6JDMD.js → chunk-45GDXYAW.js} +7 -7
- package/dist/{chunk-W5GGKQVS.js → chunk-5A6HGHTU.js} +3 -3
- package/dist/{chunk-ZCXZNK4G.js → chunk-5RPRVPZU.js} +2 -2
- package/dist/{chunk-ZDCSFRIU.js → chunk-6IPTMGLJ.js} +2 -2
- package/dist/{chunk-3IZQFNIV.js → chunk-7DWLU7GU.js} +1 -1
- package/dist/chunk-7DWLU7GU.js.map +1 -0
- package/dist/{chunk-UPYEFL7J.js → chunk-7OX7U2XB.js} +2 -2
- package/dist/{chunk-N36J3MIB.js → chunk-AGDPIO6J.js} +2 -2
- package/dist/{chunk-RMU3O74L.js → chunk-D4LXRZVD.js} +33 -33
- package/dist/{chunk-RMU3O74L.js.map → chunk-D4LXRZVD.js.map} +1 -1
- package/dist/{chunk-5OW73TEG.js → chunk-ETDVI7JS.js} +2 -2
- package/dist/{chunk-6PQVAYQJ.js → chunk-EVM7JM3U.js} +2 -2
- package/dist/{chunk-7C7M2P43.js → chunk-FASAQQF7.js} +2 -2
- package/dist/{chunk-JHKCS6EN.js → chunk-FEAIHXCI.js} +2 -2
- package/dist/{chunk-FCW4FUF2.js → chunk-G2LJ6KVK.js} +3 -2
- package/dist/chunk-G2LJ6KVK.js.map +1 -0
- package/dist/{chunk-3S7BUGYC.js → chunk-G5RFNMJ2.js} +42 -9
- package/dist/chunk-G5RFNMJ2.js.map +1 -0
- package/dist/{chunk-6P5PIOWW.js → chunk-GQ6MZ43R.js} +2 -2
- package/dist/{chunk-IUVTFQWY.js → chunk-H37DI6HW.js} +2 -2
- package/dist/{chunk-VAMCJPJT.js → chunk-IE3KZVCC.js} +3 -3
- package/dist/{chunk-CFJBSE7J.js → chunk-IP25A6HJ.js} +8 -8
- package/dist/{chunk-SULNVNTU.js → chunk-K4BSIADH.js} +2 -2
- package/dist/{chunk-RXD46MY6.js → chunk-KRMAIJMP.js} +2 -2
- package/dist/{chunk-AAV726HQ.js → chunk-L2NXX7B7.js} +3 -3
- package/dist/{chunk-R6BNDA67.js → chunk-L7V55O3P.js} +2 -2
- package/dist/{chunk-4KWR7M3Q.js → chunk-LAUZ3EQU.js} +2 -2
- package/dist/{chunk-RSKZWXQO.js → chunk-MFPPRA4F.js} +3 -3
- package/dist/{chunk-X7EAMNKR.js → chunk-MKXKED3B.js} +2 -2
- package/dist/{chunk-BOK5D46I.js → chunk-MWDMUMQ6.js} +2 -2
- package/dist/{chunk-NVKWV4W3.js → chunk-P4G6C7XS.js} +2 -2
- package/dist/{chunk-YQXD57ZS.js → chunk-P76WH5JD.js} +2 -2
- package/dist/{chunk-ZMDXISMQ.js → chunk-PK7IEAQB.js} +2 -2
- package/dist/{chunk-CS66BCED.js → chunk-PVCGXXQB.js} +2 -2
- package/dist/{chunk-XUS2UQOO.js → chunk-PWTXXSJ5.js} +2 -2
- package/dist/{chunk-HILGHLPA.js → chunk-SEQ3PEJ4.js} +2 -2
- package/dist/{chunk-GS2TT2YE.js → chunk-SS7CPYWD.js} +2 -2
- package/dist/{chunk-5FWPLAKP.js → chunk-VTL2NQED.js} +2 -2
- package/dist/{chunk-YYHBB565.js → chunk-XMT27576.js} +2 -2
- package/dist/{chunk-YW63C4FO.js → chunk-Z4EIJ6CR.js} +2 -2
- package/dist/{chunk-BAKCGJRQ.js → chunk-ZKYWI3N5.js} +3 -3
- package/dist/cli.js +37 -37
- package/dist/coding/export-okf-codegraph.js +2 -2
- package/dist/compounding/engine.js +4 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -3
- package/dist/connectors/codex-materialize-runner.js +3 -3
- package/dist/connectors/index.js +3 -3
- package/dist/convergence-refresh.js +5 -5
- package/dist/corpus-watermark.js +5 -5
- package/dist/entity-retrieval.js +3 -3
- package/dist/explicit-capture.js +37 -37
- package/dist/extraction.js +3 -3
- package/dist/harmonic-retrieval.d.ts +21 -0
- package/dist/harmonic-retrieval.d.ts.map +1 -1
- package/dist/harmonic-retrieval.js +9 -3
- package/dist/index.js +37 -37
- package/dist/location/index.js +4 -4
- package/dist/maintenance/memory-governance.js +3 -3
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +3 -3
- package/dist/maintenance/rebuild-memory-projection-runner.js +5 -5
- package/dist/maintenance/rebuild-memory-projection.js +4 -4
- package/dist/namespaces/migrate.js +4 -4
- package/dist/namespaces/storage.js +3 -3
- package/dist/operator-doctor-corpus.js +6 -6
- package/dist/operator-toolkit.js +10 -10
- package/dist/orchestration/backlog-scheduler.js +38 -38
- package/dist/orchestration/buffer-drain-runner.js +38 -38
- package/dist/orchestration/maintenance.js +11 -11
- package/dist/orchestrator.js +37 -37
- package/dist/recall-explain-renderer.js +3 -3
- package/dist/recall-navigate-access.js +2 -2
- package/dist/recall-navigate-disclosure.js +2 -2
- package/dist/recall-navigate.js +2 -2
- package/dist/recall-navigation.js +37 -37
- package/dist/recall-xray-cli.js +4 -4
- package/dist/recall-xray-renderer.js +3 -3
- package/dist/recall-xray.js +2 -2
- package/dist/resume-bundles.js +4 -4
- package/dist/semantic-consolidation.js +4 -4
- package/dist/semantic-rule-promotion.js +3 -3
- package/dist/semantic-rule-verifier.js +3 -3
- package/dist/source-agent-qualifier.js +3 -3
- package/dist/standup/build.js +3 -3
- package/dist/storage.js +2 -2
- package/dist/transfer/export-okf.js +3 -3
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/verified-recall.js +3 -3
- package/dist/who-knows-cli.js +4 -4
- package/dist/who-knows.js +3 -3
- package/package.json +2 -2
- package/src/access-trust-principal-header.test.ts +106 -0
- package/src/cli.ts +1 -1
- package/src/config.ts +1 -0
- package/src/harmonic-graph-wait-budget.test.ts +136 -0
- package/src/harmonic-retrieval.ts +68 -7
- package/src/types.ts +3 -7
- package/dist/chunk-3IZQFNIV.js.map +0 -1
- package/dist/chunk-3S7BUGYC.js.map +0 -1
- package/dist/chunk-FCW4FUF2.js.map +0 -1
- /package/dist/{chunk-BE5F6KFG.js.map → chunk-45BPRD6P.js.map} +0 -0
- /package/dist/{chunk-3OT6JDMD.js.map → chunk-45GDXYAW.js.map} +0 -0
- /package/dist/{chunk-W5GGKQVS.js.map → chunk-5A6HGHTU.js.map} +0 -0
- /package/dist/{chunk-ZCXZNK4G.js.map → chunk-5RPRVPZU.js.map} +0 -0
- /package/dist/{chunk-ZDCSFRIU.js.map → chunk-6IPTMGLJ.js.map} +0 -0
- /package/dist/{chunk-UPYEFL7J.js.map → chunk-7OX7U2XB.js.map} +0 -0
- /package/dist/{chunk-N36J3MIB.js.map → chunk-AGDPIO6J.js.map} +0 -0
- /package/dist/{chunk-5OW73TEG.js.map → chunk-ETDVI7JS.js.map} +0 -0
- /package/dist/{chunk-6PQVAYQJ.js.map → chunk-EVM7JM3U.js.map} +0 -0
- /package/dist/{chunk-7C7M2P43.js.map → chunk-FASAQQF7.js.map} +0 -0
- /package/dist/{chunk-JHKCS6EN.js.map → chunk-FEAIHXCI.js.map} +0 -0
- /package/dist/{chunk-6P5PIOWW.js.map → chunk-GQ6MZ43R.js.map} +0 -0
- /package/dist/{chunk-IUVTFQWY.js.map → chunk-H37DI6HW.js.map} +0 -0
- /package/dist/{chunk-VAMCJPJT.js.map → chunk-IE3KZVCC.js.map} +0 -0
- /package/dist/{chunk-CFJBSE7J.js.map → chunk-IP25A6HJ.js.map} +0 -0
- /package/dist/{chunk-SULNVNTU.js.map → chunk-K4BSIADH.js.map} +0 -0
- /package/dist/{chunk-RXD46MY6.js.map → chunk-KRMAIJMP.js.map} +0 -0
- /package/dist/{chunk-AAV726HQ.js.map → chunk-L2NXX7B7.js.map} +0 -0
- /package/dist/{chunk-R6BNDA67.js.map → chunk-L7V55O3P.js.map} +0 -0
- /package/dist/{chunk-4KWR7M3Q.js.map → chunk-LAUZ3EQU.js.map} +0 -0
- /package/dist/{chunk-RSKZWXQO.js.map → chunk-MFPPRA4F.js.map} +0 -0
- /package/dist/{chunk-X7EAMNKR.js.map → chunk-MKXKED3B.js.map} +0 -0
- /package/dist/{chunk-BOK5D46I.js.map → chunk-MWDMUMQ6.js.map} +0 -0
- /package/dist/{chunk-NVKWV4W3.js.map → chunk-P4G6C7XS.js.map} +0 -0
- /package/dist/{chunk-YQXD57ZS.js.map → chunk-P76WH5JD.js.map} +0 -0
- /package/dist/{chunk-ZMDXISMQ.js.map → chunk-PK7IEAQB.js.map} +0 -0
- /package/dist/{chunk-CS66BCED.js.map → chunk-PVCGXXQB.js.map} +0 -0
- /package/dist/{chunk-XUS2UQOO.js.map → chunk-PWTXXSJ5.js.map} +0 -0
- /package/dist/{chunk-HILGHLPA.js.map → chunk-SEQ3PEJ4.js.map} +0 -0
- /package/dist/{chunk-GS2TT2YE.js.map → chunk-SS7CPYWD.js.map} +0 -0
- /package/dist/{chunk-5FWPLAKP.js.map → chunk-VTL2NQED.js.map} +0 -0
- /package/dist/{chunk-YYHBB565.js.map → chunk-XMT27576.js.map} +0 -0
- /package/dist/{chunk-YW63C4FO.js.map → chunk-Z4EIJ6CR.js.map} +0 -0
- /package/dist/{chunk-BAKCGJRQ.js.map → chunk-ZKYWI3N5.js.map} +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// A caller that exceeds the harmonic graph wait budget leaves without the
|
|
2
|
+
// graph. The build it abandoned keeps running and populates the cache, so the
|
|
3
|
+
// next recall does not pay the same wait. Without this bound a write storm —
|
|
4
|
+
// every memory write bumps the version stamp — keeps every recall waiting for
|
|
5
|
+
// a full rebuild until the outer enrichment deadline cuts it off.
|
|
6
|
+
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import test, { type TestContext } from "node:test";
|
|
12
|
+
|
|
13
|
+
import { recordAbstractionNode, type AbstractionNode } from "./abstraction-nodes.js";
|
|
14
|
+
import { bumpMemoryCorpusVersionForDir } from "./memory-corpus-version.js";
|
|
15
|
+
import {
|
|
16
|
+
clearHarmonicGraphCache,
|
|
17
|
+
HarmonicGraphWaitDeadlineError,
|
|
18
|
+
readProjectedHarmonicGraph,
|
|
19
|
+
searchHarmonicRetrieval,
|
|
20
|
+
setHarmonicGraphBuildTestHooks,
|
|
21
|
+
settleHarmonicGraphBuilds,
|
|
22
|
+
} from "./harmonic-retrieval.js";
|
|
23
|
+
import { StorageManager } from "./storage.js";
|
|
24
|
+
|
|
25
|
+
function node(nodeId: string, title: string, sourceMemoryIds: string[]): AbstractionNode {
|
|
26
|
+
return {
|
|
27
|
+
schemaVersion: 1,
|
|
28
|
+
nodeId,
|
|
29
|
+
recordedAt: new Date().toISOString(),
|
|
30
|
+
sessionKey: "agent:test",
|
|
31
|
+
kind: "topic",
|
|
32
|
+
abstractionLevel: "meso",
|
|
33
|
+
title,
|
|
34
|
+
summary: title,
|
|
35
|
+
sourceMemoryIds,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function withDir(run: (memoryDir: string, storage: StorageManager) => Promise<void>) {
|
|
40
|
+
const memoryDir = await mkdtemp(path.join(tmpdir(), "remnic-harmonic-wait-"));
|
|
41
|
+
clearHarmonicGraphCache();
|
|
42
|
+
try {
|
|
43
|
+
const storage = new StorageManager(memoryDir);
|
|
44
|
+
await storage.ensureDirectories();
|
|
45
|
+
await run(memoryDir, storage);
|
|
46
|
+
} finally {
|
|
47
|
+
clearHarmonicGraphCache();
|
|
48
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const read = (memoryDir: string, waitBudgetMs?: number) =>
|
|
53
|
+
readProjectedHarmonicGraph({ memoryDir, anchorsEnabled: true, useCache: true, waitBudgetMs });
|
|
54
|
+
|
|
55
|
+
test("a caller past the wait budget leaves; the build finishes and warms the cache", async (t: TestContext) => {
|
|
56
|
+
await withDir(async (memoryDir, storage) => {
|
|
57
|
+
const memory = await storage.writeMemory("fact", "bounded wait fact", { source: "test" });
|
|
58
|
+
await recordAbstractionNode({ memoryDir, node: node("n1", "bounded wait fact", [memory.id]) });
|
|
59
|
+
await read(memoryDir);
|
|
60
|
+
bumpMemoryCorpusVersionForDir(memoryDir);
|
|
61
|
+
|
|
62
|
+
setHarmonicGraphBuildTestHooks({ buildDelayMs: 250 });
|
|
63
|
+
t.after(() => setHarmonicGraphBuildTestHooks(null));
|
|
64
|
+
|
|
65
|
+
const started = Date.now();
|
|
66
|
+
await assert.rejects(read(memoryDir, 50), HarmonicGraphWaitDeadlineError);
|
|
67
|
+
assert.ok(Date.now() - started < 200, `caller returned after ${Date.now() - started}ms`);
|
|
68
|
+
|
|
69
|
+
// The abandoned build was not cancelled: it completed and stored the graph.
|
|
70
|
+
await settleHarmonicGraphBuilds();
|
|
71
|
+
const graph = await read(memoryDir, 50);
|
|
72
|
+
assert.equal(graph.nodes.length, 1);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("a caller abort still cancels an abandoned build", async (t: TestContext) => {
|
|
77
|
+
await withDir(async (memoryDir, storage) => {
|
|
78
|
+
const memory = await storage.writeMemory("fact", "abort kills build", { source: "test" });
|
|
79
|
+
await recordAbstractionNode({ memoryDir, node: node("n1", "abort kills build", [memory.id]) });
|
|
80
|
+
bumpMemoryCorpusVersionForDir(memoryDir);
|
|
81
|
+
|
|
82
|
+
setHarmonicGraphBuildTestHooks({ buildDelayMs: 250 });
|
|
83
|
+
t.after(() => setHarmonicGraphBuildTestHooks(null));
|
|
84
|
+
|
|
85
|
+
const controller = new AbortController();
|
|
86
|
+
const pending = readProjectedHarmonicGraph({
|
|
87
|
+
memoryDir,
|
|
88
|
+
anchorsEnabled: true,
|
|
89
|
+
useCache: true,
|
|
90
|
+
waitBudgetMs: 5_000,
|
|
91
|
+
abortSignal: controller.signal,
|
|
92
|
+
});
|
|
93
|
+
controller.abort();
|
|
94
|
+
await assert.rejects(pending, (err: Error) => err.name === "AbortError");
|
|
95
|
+
// The build was cancelled: a fresh read starts a new build that still
|
|
96
|
+
// respects the delay hook instead of resolving from the aborted one.
|
|
97
|
+
const started = Date.now();
|
|
98
|
+
await read(memoryDir, 5_000);
|
|
99
|
+
assert.ok(Date.now() - started >= 200);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("searchHarmonicRetrieval fails open past the wait budget", async (t: TestContext) => {
|
|
104
|
+
await withDir(async (memoryDir, storage) => {
|
|
105
|
+
const memory = await storage.writeMemory("fact", "recall fails open", { source: "test" });
|
|
106
|
+
await recordAbstractionNode({ memoryDir, node: node("n1", "recall fails open", [memory.id]) });
|
|
107
|
+
bumpMemoryCorpusVersionForDir(memoryDir);
|
|
108
|
+
|
|
109
|
+
setHarmonicGraphBuildTestHooks({ buildDelayMs: 250 });
|
|
110
|
+
t.after(() => setHarmonicGraphBuildTestHooks(null));
|
|
111
|
+
|
|
112
|
+
await assert.rejects(
|
|
113
|
+
searchHarmonicRetrieval({
|
|
114
|
+
memoryDir,
|
|
115
|
+
query: "recall fails open",
|
|
116
|
+
maxResults: 3,
|
|
117
|
+
anchorsEnabled: true,
|
|
118
|
+
useGraphCache: true,
|
|
119
|
+
waitBudgetMs: 50,
|
|
120
|
+
}),
|
|
121
|
+
HarmonicGraphWaitDeadlineError,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// The build completed behind the rejected call; the same search now answers.
|
|
125
|
+
await settleHarmonicGraphBuilds();
|
|
126
|
+
const results = await searchHarmonicRetrieval({
|
|
127
|
+
memoryDir,
|
|
128
|
+
query: "recall fails open",
|
|
129
|
+
maxResults: 3,
|
|
130
|
+
anchorsEnabled: true,
|
|
131
|
+
useGraphCache: true,
|
|
132
|
+
waitBudgetMs: 50,
|
|
133
|
+
});
|
|
134
|
+
assert.deepEqual(results.map((result) => result.node.nodeId), ["n1"]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -451,6 +451,10 @@ async function buildExpiringHarmonicGraph(options: {
|
|
|
451
451
|
nowMs?: number;
|
|
452
452
|
}): Promise<ExpiringHarmonicGraph> {
|
|
453
453
|
throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
|
|
454
|
+
const buildDelayMs = harmonicGraphBuildTestHooks?.buildDelayMs;
|
|
455
|
+
if (buildDelayMs !== undefined && buildDelayMs > 0) {
|
|
456
|
+
await new Promise((resolve) => setTimeout(resolve, buildDelayMs));
|
|
457
|
+
}
|
|
454
458
|
const nodes = await readAbstractionNodes(options);
|
|
455
459
|
const sourceMemoryIds = [...new Set(nodes.flatMap((node) => node.sourceMemoryIds ?? []))];
|
|
456
460
|
const sourceMemories: SourceMemoryMap = sourceMemoryIds.length > 0
|
|
@@ -562,7 +566,28 @@ async function buildUnexpiredHarmonicGraph(options: GraphReadOptions, abortSigna
|
|
|
562
566
|
}
|
|
563
567
|
}
|
|
564
568
|
/** Counters for tests and diagnostics. `stale` hits also count as `hits`. */
|
|
565
|
-
export const harmonicGraphCacheStats = { hits: 0, misses: 0, stale: 0, shared: 0 };
|
|
569
|
+
export const harmonicGraphCacheStats = { hits: 0, misses: 0, stale: 0, shared: 0, deadlineExits: 0 };
|
|
570
|
+
|
|
571
|
+
/** Default per-caller bound on waiting for a shared graph build (see `waitBudgetMs`). */
|
|
572
|
+
export const HARMONIC_GRAPH_WAIT_BUDGET_MS = 5_000;
|
|
573
|
+
|
|
574
|
+
const HARMONIC_GRAPH_WAIT_DEADLINE_MESSAGE = "harmonic graph wait deadline exceeded";
|
|
575
|
+
|
|
576
|
+
export class HarmonicGraphWaitDeadlineError extends Error {
|
|
577
|
+
constructor() {
|
|
578
|
+
super(HARMONIC_GRAPH_WAIT_DEADLINE_MESSAGE);
|
|
579
|
+
this.name = "HarmonicGraphWaitDeadlineError";
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
interface HarmonicGraphBuildTestHooks {
|
|
584
|
+
/** Extra delay inside every build, for wait-budget tests. */
|
|
585
|
+
buildDelayMs?: number;
|
|
586
|
+
}
|
|
587
|
+
let harmonicGraphBuildTestHooks: HarmonicGraphBuildTestHooks | null = null;
|
|
588
|
+
export function setHarmonicGraphBuildTestHooks(hooks: HarmonicGraphBuildTestHooks | null): void {
|
|
589
|
+
harmonicGraphBuildTestHooks = hooks;
|
|
590
|
+
}
|
|
566
591
|
|
|
567
592
|
/** Freeze records and their nested arrays/objects so a caller cannot corrupt the shared cache. */
|
|
568
593
|
function deepFreeze<T extends object>(value: T): T {
|
|
@@ -623,13 +648,38 @@ function startGraphBuild(key: string, stamp: string, options: GraphReadOptions):
|
|
|
623
648
|
/**
|
|
624
649
|
* Wait for `build` on behalf of one caller. The caller's own signal ends only its own wait. When the last
|
|
625
650
|
* waiting caller has left, the build is cancelled and dropped, so abandoned recalls do not leave full scans running
|
|
626
|
-
* (cancelling a build that already finished does nothing).
|
|
651
|
+
* (cancelling a build that already finished does nothing). A caller that leaves on `waitBudgetMs` is the exception:
|
|
652
|
+
* the build keeps running so its completed graph warms the cache for the next caller.
|
|
627
653
|
*/
|
|
628
|
-
function joinGraphBuild(
|
|
654
|
+
function joinGraphBuild(
|
|
655
|
+
key: string,
|
|
656
|
+
build: GraphBuild,
|
|
657
|
+
signal: AbortSignal | undefined,
|
|
658
|
+
waitBudgetMs?: number,
|
|
659
|
+
): Promise<ProjectedHarmonicGraph> {
|
|
629
660
|
build.waiting++;
|
|
630
|
-
|
|
661
|
+
let timedOut = false;
|
|
662
|
+
let timer: NodeJS.Timeout | undefined;
|
|
663
|
+
const waited =
|
|
664
|
+
waitBudgetMs === undefined || waitBudgetMs <= 0
|
|
665
|
+
? raceAbort(build.promise, signal, "harmonic retrieval aborted")
|
|
666
|
+
: Promise.race([
|
|
667
|
+
raceAbort(build.promise, signal, "harmonic retrieval aborted"),
|
|
668
|
+
new Promise<never>((_resolve, reject) => {
|
|
669
|
+
timer = setTimeout(() => {
|
|
670
|
+
timedOut = true;
|
|
671
|
+
reject(new HarmonicGraphWaitDeadlineError());
|
|
672
|
+
}, waitBudgetMs);
|
|
673
|
+
}),
|
|
674
|
+
]);
|
|
675
|
+
return waited.finally(() => {
|
|
676
|
+
if (timer) clearTimeout(timer);
|
|
631
677
|
build.waiting--;
|
|
632
|
-
|
|
678
|
+
// A caller that left on the wait budget does not cancel the build: it keeps
|
|
679
|
+
// running and stores the fresh graph, so the next caller gets a cache hit
|
|
680
|
+
// instead of restarting the scan a write storm keeps invalidating.
|
|
681
|
+
if (timedOut) harmonicGraphCacheStats.deadlineExits++;
|
|
682
|
+
if (build.waiting > 0 || timedOut) return;
|
|
633
683
|
if (graphBuilds.get(key) === build) graphBuilds.delete(key);
|
|
634
684
|
build.controller.abort();
|
|
635
685
|
});
|
|
@@ -658,6 +708,10 @@ export async function readProjectedHarmonicGraph(options: {
|
|
|
658
708
|
temporalExpiredInInjection?: boolean;
|
|
659
709
|
nowMs?: number;
|
|
660
710
|
useCache?: boolean;
|
|
711
|
+
/** Per-caller bound on joining a shared build, in ms. On expiry the caller
|
|
712
|
+
* leaves with a HarmonicGraphWaitDeadlineError while the build keeps running.
|
|
713
|
+
* `0` or unset waits without a bound. Applies only on the cached path. */
|
|
714
|
+
waitBudgetMs?: number;
|
|
661
715
|
}): Promise<ProjectedHarmonicGraph> {
|
|
662
716
|
if (options.useCache !== true || options.nowMs !== undefined) return buildProjectedHarmonicGraph(options);
|
|
663
717
|
// Same cancellation contract as the builder: a cache hit must not mask an aborted signal.
|
|
@@ -696,9 +750,9 @@ export async function readProjectedHarmonicGraph(options: {
|
|
|
696
750
|
const running = graphBuilds.get(key);
|
|
697
751
|
if (running?.stamp === stamp) {
|
|
698
752
|
harmonicGraphCacheStats.shared++;
|
|
699
|
-
return joinGraphBuild(key, running, options.abortSignal);
|
|
753
|
+
return joinGraphBuild(key, running, options.abortSignal, options.waitBudgetMs);
|
|
700
754
|
}
|
|
701
|
-
return joinGraphBuild(key, startGraphBuild(key, stamp, options), options.abortSignal);
|
|
755
|
+
return joinGraphBuild(key, startGraphBuild(key, stamp, options), options.abortSignal, options.waitBudgetMs);
|
|
702
756
|
}
|
|
703
757
|
|
|
704
758
|
export async function searchHarmonicRetrieval(options: {
|
|
@@ -712,6 +766,11 @@ export async function searchHarmonicRetrieval(options: {
|
|
|
712
766
|
temporalExpiredInInjection?: boolean;
|
|
713
767
|
/** Share one projected graph between recalls until a write bumps a version sentinel (see readProjectedHarmonicGraph). */
|
|
714
768
|
useGraphCache?: boolean;
|
|
769
|
+
/** Bound on waiting for a shared graph build, in ms. Past it the search
|
|
770
|
+
* rejects with a HarmonicGraphWaitDeadlineError so a recall fails open
|
|
771
|
+
* instead of blocking on a rebuild a write storm keeps invalidating.
|
|
772
|
+
* `0` waits without a bound. Defaults to HARMONIC_GRAPH_WAIT_BUDGET_MS. */
|
|
773
|
+
waitBudgetMs?: number;
|
|
715
774
|
}): Promise<HarmonicRetrievalResult[]> {
|
|
716
775
|
throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
|
|
717
776
|
const queryTokens = new Set(normalizeRecallTokens(options.query, ["what", "which"]));
|
|
@@ -722,6 +781,8 @@ export async function searchHarmonicRetrieval(options: {
|
|
|
722
781
|
const { nodes: eligibleNodes, anchors } = await readProjectedHarmonicGraph({
|
|
723
782
|
...options,
|
|
724
783
|
useCache: options.useGraphCache === true,
|
|
784
|
+
waitBudgetMs:
|
|
785
|
+
options.waitBudgetMs === undefined ? HARMONIC_GRAPH_WAIT_BUDGET_MS : options.waitBudgetMs,
|
|
725
786
|
});
|
|
726
787
|
const candidates = new Map<string, HarmonicCandidate>();
|
|
727
788
|
|
package/src/types.ts
CHANGED
|
@@ -92,13 +92,7 @@ export type CodexCompactionFlushMode = "signal" | "heuristic" | "auto";
|
|
|
92
92
|
export type DreamingNarrativePromptStyle = "reflective" | "diary" | "analytical";
|
|
93
93
|
export type HeartbeatDetectionMode = "runtime-signal" | "heuristic" | "auto";
|
|
94
94
|
export type ActiveRecallQueryMode = "message" | "recent" | "full";
|
|
95
|
-
export type ActiveRecallPromptStyle =
|
|
96
|
-
| "balanced"
|
|
97
|
-
| "strict"
|
|
98
|
-
| "contextual"
|
|
99
|
-
| "recall-heavy"
|
|
100
|
-
| "precision-heavy"
|
|
101
|
-
| "preference-only";
|
|
95
|
+
export type ActiveRecallPromptStyle = "balanced" | "strict" | "contextual" | "recall-heavy" | "precision-heavy" | "preference-only";
|
|
102
96
|
export type ActiveRecallThinking = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "adaptive";
|
|
103
97
|
export type ActiveRecallChatType = "direct" | "group" | "channel";
|
|
104
98
|
export type ActiveRecallModelFallbackPolicy = "default-remote" | "resolved-only";
|
|
@@ -303,6 +297,8 @@ export interface AgentAccessHttpConfig {
|
|
|
303
297
|
writeRateLimitMaxRequests: number;
|
|
304
298
|
/** Rolling window for the write rate limit, in ms (issue #1937). */
|
|
305
299
|
writeRateLimitWindowMs: number;
|
|
300
|
+
/** Trust the `x-engram-principal` header for per-request principal resolution (default off; trusted proxies only). */
|
|
301
|
+
trustPrincipalHeader?: boolean;
|
|
306
302
|
}
|
|
307
303
|
|
|
308
304
|
export interface DreamingConfig {
|