@remnic/core 10.0.98 → 10.0.100
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 +2 -2
- package/dist/access-cli.js +2 -2
- package/dist/access-extraction-force-flush.js +2 -2
- package/dist/access-http-briefing.js +2 -2
- package/dist/access-http-query.js +2 -2
- package/dist/access-http.js +2 -2
- package/dist/access-identity-continuity-surface.js +2 -2
- package/dist/access-lcm-surface.js +2 -2
- package/dist/access-mcp.js +2 -2
- package/dist/access-observe-write-surface.js +2 -2
- package/dist/access-operations-batch.js +2 -2
- package/dist/access-operations.js +2 -2
- package/dist/access-recall-concurrency.js +2 -2
- package/dist/access-recall-response.js +2 -2
- package/dist/access-recall-surface.js +2 -2
- package/dist/access-service.js +2 -2
- package/dist/{chunk-5DGK7E4W.js → chunk-MMOXCCHF.js} +27 -4
- package/dist/chunk-MMOXCCHF.js.map +1 -0
- package/dist/{chunk-4PXDXCNE.js → chunk-PL36IQPL.js} +47 -15
- package/dist/chunk-PL36IQPL.js.map +1 -0
- package/dist/{chunk-TZKK72BY.js → chunk-QIPDTAWZ.js} +2 -2
- package/dist/cli.js +2 -2
- package/dist/explicit-capture.js +2 -2
- package/dist/harmonic-retrieval.d.ts +5 -4
- package/dist/harmonic-retrieval.d.ts.map +1 -1
- package/dist/harmonic-retrieval.js +1 -1
- package/dist/index.js +2 -2
- package/dist/orchestration/backlog-scheduler.d.ts +6 -1
- package/dist/orchestration/backlog-scheduler.d.ts.map +1 -1
- package/dist/orchestration/backlog-scheduler.js +21 -5
- package/dist/orchestration/backlog-scheduler.js.map +1 -1
- package/dist/orchestration/buffer-drain-runner.js +3 -3
- package/dist/orchestration/task-exit.d.ts +15 -0
- package/dist/orchestration/task-exit.d.ts.map +1 -0
- package/dist/orchestration/turn-ingestion.d.ts +1 -7
- package/dist/orchestration/turn-ingestion.d.ts.map +1 -1
- package/dist/orchestrator.js +2 -2
- package/dist/recall-navigation.js +2 -2
- package/package.json +2 -2
- package/src/backlog-scheduler.test.ts +48 -0
- package/src/harmonic-graph-cache.test.ts +187 -2
- package/src/harmonic-retrieval.ts +77 -19
- package/src/orchestration/backlog-scheduler.ts +23 -2
- package/src/orchestration/extraction-queue-bounded-retention.test.ts +20 -0
- package/src/orchestration/task-exit.ts +27 -0
- package/src/orchestration/turn-ingestion.ts +7 -9
- package/dist/chunk-4PXDXCNE.js.map +0 -1
- package/dist/chunk-5DGK7E4W.js.map +0 -1
- /package/dist/{chunk-TZKK72BY.js.map → chunk-QIPDTAWZ.js.map} +0 -0
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
stripAttributesSuffix
|
|
31
31
|
} from "./chunk-JDSVLVCG.js";
|
|
32
32
|
import {
|
|
33
|
+
raceAbort,
|
|
33
34
|
throwIfAborted
|
|
34
35
|
} from "./chunk-R2MBW2S4.js";
|
|
35
36
|
import {
|
|
@@ -348,7 +349,8 @@ async function buildProjectedHarmonicGraph(options) {
|
|
|
348
349
|
var GRAPH_CACHE_TTL_MS = 3e4;
|
|
349
350
|
var GRAPH_CACHE_MAX_ENTRIES = 8;
|
|
350
351
|
var graphCache = /* @__PURE__ */ new Map();
|
|
351
|
-
var
|
|
352
|
+
var graphBuilds = /* @__PURE__ */ new Map();
|
|
353
|
+
var harmonicGraphCacheStats = { hits: 0, misses: 0, shared: 0 };
|
|
352
354
|
function deepFreeze(value) {
|
|
353
355
|
if (Object.isFrozen(value)) return value;
|
|
354
356
|
Object.freeze(value);
|
|
@@ -357,6 +359,44 @@ function deepFreeze(value) {
|
|
|
357
359
|
}
|
|
358
360
|
function clearHarmonicGraphCache() {
|
|
359
361
|
graphCache.clear();
|
|
362
|
+
graphBuilds.clear();
|
|
363
|
+
}
|
|
364
|
+
function startGraphBuild(key, stamp, options) {
|
|
365
|
+
harmonicGraphCacheStats.misses++;
|
|
366
|
+
const startedAtMs = Date.now();
|
|
367
|
+
const controller = new AbortController();
|
|
368
|
+
const promise = buildProjectedHarmonicGraph({
|
|
369
|
+
memoryDir: options.memoryDir,
|
|
370
|
+
abstractionNodeStoreDir: options.abstractionNodeStoreDir,
|
|
371
|
+
anchorsEnabled: options.anchorsEnabled,
|
|
372
|
+
temporalExpiredInInjection: options.temporalExpiredInInjection,
|
|
373
|
+
abortSignal: controller.signal
|
|
374
|
+
}).then((built) => {
|
|
375
|
+
const graph = { nodes: deepFreeze(built.nodes), anchors: deepFreeze(built.anchors) };
|
|
376
|
+
if (graphBuilds.get(key)?.promise !== promise) return graph;
|
|
377
|
+
graphCache.delete(key);
|
|
378
|
+
graphCache.set(key, { stamp, startedAtMs, graph });
|
|
379
|
+
while (graphCache.size > GRAPH_CACHE_MAX_ENTRIES) {
|
|
380
|
+
const oldest = graphCache.keys().next().value;
|
|
381
|
+
if (oldest === void 0) break;
|
|
382
|
+
graphCache.delete(oldest);
|
|
383
|
+
}
|
|
384
|
+
return graph;
|
|
385
|
+
}).finally(() => {
|
|
386
|
+
if (graphBuilds.get(key)?.promise === promise) graphBuilds.delete(key);
|
|
387
|
+
});
|
|
388
|
+
const build = { stamp, promise, controller, waiting: 0 };
|
|
389
|
+
graphBuilds.set(key, build);
|
|
390
|
+
return build;
|
|
391
|
+
}
|
|
392
|
+
function joinGraphBuild(key, build, signal) {
|
|
393
|
+
build.waiting++;
|
|
394
|
+
return raceAbort(build.promise, signal, "harmonic retrieval aborted").finally(() => {
|
|
395
|
+
build.waiting--;
|
|
396
|
+
if (build.waiting > 0) return;
|
|
397
|
+
if (graphBuilds.get(key) === build) graphBuilds.delete(key);
|
|
398
|
+
build.controller.abort();
|
|
399
|
+
});
|
|
360
400
|
}
|
|
361
401
|
async function readProjectedHarmonicGraph(options) {
|
|
362
402
|
if (options.useCache !== true || options.nowMs !== void 0) return buildProjectedHarmonicGraph(options);
|
|
@@ -377,20 +417,12 @@ async function readProjectedHarmonicGraph(options) {
|
|
|
377
417
|
graphCache.set(key, hit);
|
|
378
418
|
return hit.graph;
|
|
379
419
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
anchors: deepFreeze(built.anchors)
|
|
385
|
-
};
|
|
386
|
-
graphCache.delete(key);
|
|
387
|
-
graphCache.set(key, { stamp, startedAtMs, graph });
|
|
388
|
-
while (graphCache.size > GRAPH_CACHE_MAX_ENTRIES) {
|
|
389
|
-
const oldest = graphCache.keys().next().value;
|
|
390
|
-
if (oldest === void 0) break;
|
|
391
|
-
graphCache.delete(oldest);
|
|
420
|
+
const running = graphBuilds.get(key);
|
|
421
|
+
if (running?.stamp === stamp) {
|
|
422
|
+
harmonicGraphCacheStats.shared++;
|
|
423
|
+
return joinGraphBuild(key, running, options.abortSignal);
|
|
392
424
|
}
|
|
393
|
-
return
|
|
425
|
+
return joinGraphBuild(key, startGraphBuild(key, stamp, options), options.abortSignal);
|
|
394
426
|
}
|
|
395
427
|
async function searchHarmonicRetrieval(options) {
|
|
396
428
|
throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
|
|
@@ -471,4 +503,4 @@ export {
|
|
|
471
503
|
readProjectedHarmonicGraph,
|
|
472
504
|
searchHarmonicRetrieval
|
|
473
505
|
};
|
|
474
|
-
//# sourceMappingURL=chunk-
|
|
506
|
+
//# sourceMappingURL=chunk-PL36IQPL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/harmonic-retrieval.ts"],"sourcesContent":["import path from \"node:path\";\nimport { realpath } from \"node:fs/promises\";\nimport { listJsonFilesStrict, readJsonFile } from \"./json-store.js\";\nimport { raceAbort, throwIfAborted } from \"./abort-error.js\";\nimport { readHarmonicGraphStamp } from \"./harmonic-graph-version.js\";\nimport { inferMemoryStatus, toMemoryPathRel } from \"./memory-lifecycle-ledger-utils.js\";\n import {\n HARMONIC_SOURCE_MEMORY_INSERTED_AT_KEY,\n resolveAbstractionNodeStoreDir,\n validateAbstractionNode,\n type AbstractionNode,\n } from \"./abstraction-nodes.js\";\nimport { resolveCueAnchorStoreDir, validateCueAnchor, type CueAnchor, type CueAnchorType } from \"./cue-anchors.js\";\nimport { compareDeterministicStrings } from \"./deterministic-order.js\";\nimport { countRecallTokenOverlap, normalizeRecallTokens } from \"./recall-tokenization.js\";\nimport { stripAttributesSuffix } from \"./structured-attributes.js\";\nimport { isValidityExpiredNow } from \"./temporal-validity.js\";\nimport { assertSafePathSegment, isRecord } from \"./store-contract.js\";\nimport { isSupportPassportPrivateMemory } from \"./support-passport/card-projection.js\";\nimport type { MemoryFile } from \"./types.js\";\nimport { readProjectedMemoryStates } from \"./memory-projection-batch.js\";\nimport { SecureStoreLockedError } from \"./secure-store/secure-fs.js\";\nimport { StorageManager } from \"./storage.js\";\nimport { RECALL_FALLBACK_DIRS } from \"./utils/category-dir.js\";\nimport { readHarmonicSourceMemory, readUnresolvedHarmonicSources } from \"./harmonic-source-lookup.js\";\n\n\ntype SourceMemoryMap = Map<string, MemoryFile>;\n\n\n// An index older than this is treated as unusable: the date window needed to\n// cover \"created since the last rebuild\" would stop being cheap.\nconst INDEX_MAX_AGE_MS = 7 * 86_400_000;\nconst DAY_MS = 86_400_000;\n\nfunction utcDaysSince(rebuiltMs: number, nowMs: number): string[] {\n const days: string[] = [];\n for (let day = Math.floor((rebuiltMs - DAY_MS) / DAY_MS) * DAY_MS; day <= nowMs; day += DAY_MS) {\n days.push(new Date(day).toISOString().slice(0, 10));\n }\n return days;\n}\n\n\n// Memories the projection has no row for were written after its last rebuild, so\n// their dated directory is normally one of `days`. Hot and cold tiers are probed\n// by exact path. Only recall-corpus categories are probed: `questions/` is a queue\n// and `artifacts/` is outside the recall surface, so neither can be a source.\nfunction unprojectedCandidatePaths(memoryDir: string, id: string, days: string[]): string[] {\n const paths: string[] = [];\n for (const root of [memoryDir, path.join(memoryDir, \"cold\")]) {\n for (const dir of RECALL_FALLBACK_DIRS) {\n paths.push(path.join(root, dir, `${id}.md`));\n for (const day of days) paths.push(path.join(root, dir, day, `${id}.md`));\n }\n }\n return paths;\n}\n\n/** Resolve indexed sources first, then use the durable unresolved-id path cache. */\nasync function readIndexedSourceMemories(options: {\n memoryDir: string;\n abortSignal?: AbortSignal;\n sourceMemoryIds: string[];\n nowMs: number;\n}): Promise<SourceMemoryMap | null> {\n // The ids go to SQL as bound parameters, so any id the projection holds is safe to look up.\n const batch = readProjectedMemoryStates(options.memoryDir, options.sourceMemoryIds);\n const rebuiltMs = Date.parse(batch?.rebuiltAt ?? \"\");\n if (!batch?.complete || !batch.rebuiltAt || !Number.isFinite(rebuiltMs) || options.nowMs - rebuiltMs > INDEX_MAX_AGE_MS) return null;\n const rootReal = await realpath(options.memoryDir).catch(() => null);\n if (rootReal === null) return null;\n\n const storage = new StorageManager(options.memoryDir);\n const days = utcDaysSince(rebuiltMs, options.nowMs);\n const sourceMemories: SourceMemoryMap = new Map();\n const pending: string[] = [];\n for (const id of options.sourceMemoryIds) {\n const state = batch.states.get(id);\n // An id is only ever joined into a path when it is a single safe segment.\n let safeId = true;\n try {\n assertSafePathSegment(id, \"sourceMemoryId\");\n } catch {\n safeId = false;\n }\n // state.path was containment-checked by the projection reader.\n const candidates = state\n ? [state.path, path.join(options.memoryDir, \"cold\", state.pathRel)]\n : safeId ? unprojectedCandidatePaths(options.memoryDir, id, days) : [];\n let found = false;\n for (const candidate of candidates) {\n const memory = await readHarmonicSourceMemory(storage, rootReal, candidate, options.abortSignal);\n if (memory?.frontmatter.id !== id) continue;\n sourceMemories.set(id, memory);\n found = true;\n break;\n }\n if (!found) pending.push(id);\n }\n if (pending.length === 0) return sourceMemories;\n\n const unresolved = await readUnresolvedHarmonicSources({\n storage, rootReal, rebuiltAt: batch.rebuiltAt, sourceMemoryIds: pending,\n nowMs: options.nowMs, abortSignal: options.abortSignal,\n });\n for (const [id, memory] of unresolved) sourceMemories.set(id, memory);\n return sourceMemories;\n}\n\nasync function readCorpusSourceMemories(options: {\n memoryDir: string;\n abortSignal?: AbortSignal;\n}): Promise<SourceMemoryMap> {\n const sourceMemories: SourceMemoryMap = new Map();\n try {\n const storage = new StorageManager(options.memoryDir);\n const [hotMemories, coldMemories] = await Promise.all([\n storage.readAllMemories({ abortSignal: options.abortSignal }),\n storage.readAllColdMemories({ abortSignal: options.abortSignal }),\n ]);\n for (const memory of [...hotMemories, ...coldMemories]) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n sourceMemories.set(memory.frontmatter.id, memory);\n }\n } catch (err) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n if (err instanceof SecureStoreLockedError) return new Map();\n // Source validation fails closed when the authorized memory directory is\n // unreadable. Source-less nodes remain eligible for retrieval.\n sourceMemories.clear();\n }\n return sourceMemories;\n}\n\nasync function readSourceMemories(options: {\n memoryDir: string;\n abortSignal?: AbortSignal;\n sourceMemoryIds: string[];\n nowMs?: number;\n}): Promise<SourceMemoryMap> {\n try {\n const indexed = await readIndexedSourceMemories({\n memoryDir: options.memoryDir,\n abortSignal: options.abortSignal,\n sourceMemoryIds: options.sourceMemoryIds,\n nowMs: options.nowMs ?? Date.now(),\n });\n if (indexed) return indexed;\n } catch (err) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n if (err instanceof SecureStoreLockedError) return new Map();\n }\n return readCorpusSourceMemories(options);\n}\n\nfunction parseSourceMemoryInsertedAt(node: AbstractionNode): Map<string, string> {\n const insertedAtById = new Map<string, string>();\n const insertedAtRaw = node.metadata?.[HARMONIC_SOURCE_MEMORY_INSERTED_AT_KEY];\n if (!insertedAtRaw) return insertedAtById;\n try {\n const parsed = JSON.parse(insertedAtRaw) as unknown;\n if (!isRecord(parsed)) return insertedAtById;\n for (const [memoryId, value] of Object.entries(parsed)) {\n if (typeof value === \"string\") insertedAtById.set(memoryId, value);\n }\n } catch {\n // Malformed insertion metadata leaves ordering on the recordedAt fallback.\n }\n return insertedAtById;\n}\n\nfunction projectSourceBackedNode(\n node: AbstractionNode,\n sourceMemories: SourceMemoryMap,\n memoryDir: string,\n temporalExpiredInInjection: boolean,\n nowMs: number\n): AbstractionNode | null {\n const sourceMemoryIds = node.sourceMemoryIds ?? [];\n if (sourceMemoryIds.length === 0) return node;\n\n const activeSourceMemoryIds = sourceMemoryIds.filter((memoryId) => {\n const memory = sourceMemories.get(memoryId);\n return (\n memory !== undefined &&\n // #2332: a private support-passport record leaves the eligible set the\n // same way a rejected one does — a node title or anchor attribution\n // rebuilt from it would leak governed metadata into the deep-recall\n // frontier (and every other graph reader) before any content check runs.\n !isSupportPassportPrivateMemory(memory) &&\n inferMemoryStatus(memory.frontmatter, toMemoryPathRel(memoryDir, memory.path)) === \"active\" &&\n (temporalExpiredInInjection || !isValidityExpiredNow(memory.frontmatter, nowMs))\n );\n });\n if (activeSourceMemoryIds.length === 0) return null;\n\n // Newest-first source order keeps the projected title and summary on the most\n // recently inserted facts. Equal or missing timestamps fall back to ascending\n // id order, which matches the stored sourceMemoryIds order.\n const insertedAtById = parseSourceMemoryInsertedAt(node);\n const insertedAtMs = (memoryId: string): number => {\n const parsedMs = Date.parse(insertedAtById.get(memoryId) ?? \"\");\n return Number.isFinite(parsedMs) ? parsedMs : Date.parse(node.recordedAt);\n };\n activeSourceMemoryIds.sort(\n (left, right) =>\n insertedAtMs(right) - insertedAtMs(left) || compareDeterministicStrings(left, right)\n );\n\n const activeMemories = activeSourceMemoryIds.flatMap((memoryId) => {\n const memory = sourceMemories.get(memoryId);\n return memory ? [memory] : [];\n });\n const activeContents = activeMemories.map((memory) =>\n memory.frontmatter.structuredAttributes ? stripAttributesSuffix(memory.content) : memory.content\n );\n let metadata: Record<string, string> | undefined;\n const activeInsertedAt = activeSourceMemoryIds.flatMap((memoryId) => {\n const value = insertedAtById.get(memoryId);\n return typeof value === \"string\" ? [[memoryId, value] as const] : [];\n });\n if (activeInsertedAt.length > 0) {\n metadata = {\n [HARMONIC_SOURCE_MEMORY_INSERTED_AT_KEY]: JSON.stringify(Object.fromEntries(activeInsertedAt)),\n };\n }\n\n return {\n ...node,\n sourceMemoryIds: activeSourceMemoryIds,\n title: activeContents[0]?.slice(0, 80) ?? node.title,\n summary: activeContents.slice(0, 3).join(\"; \").slice(0, 400),\n tags: [...new Set(activeMemories.flatMap((memory) => memory.frontmatter.tags))].sort(compareDeterministicStrings),\n entityRefs: [\n ...new Set(\n activeMemories.flatMap((memory) =>\n typeof memory.frontmatter.entityRef === \"string\" ? [memory.frontmatter.entityRef] : []\n )\n ),\n ].sort(compareDeterministicStrings),\n metadata,\n };\n}\n\nfunction anchorMatchesProjectedNode(\n anchor: CueAnchor,\n nodeRef: string,\n node: AbstractionNode,\n allowLegacyAttribution: boolean\n): boolean {\n const activeSourceMemoryIds = node.sourceMemoryIds ?? [];\n if (activeSourceMemoryIds.length === 0) return true;\n if (!anchor.sourceMemoryIdsByNodeRef) return allowLegacyAttribution;\n const anchorSourceMemoryIds = anchor.sourceMemoryIdsByNodeRef[nodeRef] ?? [];\n return anchorSourceMemoryIds.some((sourceMemoryId) => activeSourceMemoryIds.includes(sourceMemoryId));\n}\n\nexport interface HarmonicMatchedAnchor {\n anchorId: string;\n anchorType: CueAnchorType;\n anchorValue: string;\n}\n\nexport interface HarmonicRetrievalResult {\n node: AbstractionNode;\n score: number;\n nodeScore: number;\n anchorScore: number;\n matchedFields: string[];\n matchedAnchors: HarmonicMatchedAnchor[];\n}\n\ninterface HarmonicCandidate {\n node: AbstractionNode;\n nodeScore: number;\n anchorScore: number;\n matchedFields: Set<string>;\n matchedAnchors: Map<string, HarmonicMatchedAnchor>;\n}\n\nfunction scoreNode(node: AbstractionNode, queryTokens: Set<string>): { score: number; matchedFields: string[] } {\n const matchedFields: string[] = [];\n let score = 0;\n\n const titleMatches = countRecallTokenOverlap(queryTokens, node.title);\n if (titleMatches > 0) {\n score += titleMatches * 3;\n matchedFields.push(\"title\");\n }\n\n const summaryMatches = countRecallTokenOverlap(queryTokens, node.summary);\n if (summaryMatches > 0) {\n score += summaryMatches * 3;\n matchedFields.push(\"summary\");\n }\n\n const tagMatches = countRecallTokenOverlap(queryTokens, node.tags?.join(\" \"));\n if (tagMatches > 0) {\n score += tagMatches * 2;\n matchedFields.push(\"tags\");\n }\n\n const entityMatches = countRecallTokenOverlap(queryTokens, node.entityRefs?.join(\" \"));\n if (entityMatches > 0) {\n score += entityMatches * 2;\n matchedFields.push(\"entityRefs\");\n }\n\n const kindMatches = countRecallTokenOverlap(queryTokens, `${node.kind} ${node.abstractionLevel}`);\n if (kindMatches > 0) {\n score += kindMatches;\n matchedFields.push(\"kind\");\n }\n\n return { score, matchedFields };\n}\n\nfunction scoreAnchor(\n anchor: CueAnchor,\n queryTokens: Set<string>,\n eligibleNodeTags: readonly string[]\n): { score: number; matchedFields: string[] } {\n const matchedFields: string[] = [];\n let score = 0;\n\n const valueMatches = countRecallTokenOverlap(queryTokens, anchor.anchorValue);\n const normalizedMatches = countRecallTokenOverlap(queryTokens, anchor.normalizedCue);\n const cueMatches = Math.max(valueMatches, normalizedMatches);\n if (cueMatches > 0) {\n score += cueMatches * 4;\n if (valueMatches > 0) matchedFields.push(\"anchorValue\");\n if (normalizedMatches > 0) matchedFields.push(\"anchor\");\n }\n\n const typeMatches = countRecallTokenOverlap(queryTokens, anchor.anchorType);\n if (typeMatches > 0) {\n score += typeMatches;\n matchedFields.push(\"anchorType\");\n }\n\n const tagMatches = countRecallTokenOverlap(queryTokens, eligibleNodeTags.join(\" \"));\n if (tagMatches > 0) {\n score += tagMatches * 2;\n matchedFields.push(\"anchorTags\");\n }\n\n return { score, matchedFields };\n}\n\nexport async function readAbstractionNodes(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n}): Promise<AbstractionNode[]> {\n const rootDir = resolveAbstractionNodeStoreDir(options.memoryDir, options.abstractionNodeStoreDir);\n const files = await listJsonFilesStrict(path.join(rootDir, \"nodes\"), { allowMissingDirectory: true });\n const nodes: AbstractionNode[] = [];\n for (const filePath of files) {\n try {\n nodes.push(validateAbstractionNode(await readJsonFile(filePath)));\n } catch {\n // fail-open: invalid artifacts stay visible via status tooling instead of recall\n }\n }\n return nodes;\n}\n\nexport async function readCueAnchors(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n}): Promise<CueAnchor[]> {\n const abstractionRoot = resolveAbstractionNodeStoreDir(options.memoryDir, options.abstractionNodeStoreDir);\n const rootDir = resolveCueAnchorStoreDir(abstractionRoot);\n const files = await listJsonFilesStrict(rootDir, { allowMissingDirectory: true });\n const anchors: CueAnchor[] = [];\n for (const filePath of files) {\n try {\n anchors.push(validateCueAnchor(await readJsonFile(filePath)));\n } catch {\n // fail-open: invalid artifacts stay visible via status tooling instead of recall\n }\n }\n return anchors;\n}\n\nexport interface ProjectedHarmonicGraph {\n nodes: AbstractionNode[];\n anchors: CueAnchor[];\n}\n\n/**\n * Read nodes + anchors and project BOTH against the namespace's current active\n * memories. This is the single projection every graph reader shares: a raw\n * `readAbstractionNodes` / `readCueAnchors` pair still carries the stored title,\n * summary, tags, and anchor attribution of a memory that was later rejected,\n * quarantined, or otherwise moved out of the active set, so a second reader\n * that skipped the projection could leak governed metadata even when the\n * memory itself is excluded from the final results.\n *\n * - A node whose every source memory left the active set is dropped.\n * - A surviving node's title/summary/tags/entityRefs are rebuilt from its\n * active sources only.\n * - An anchor keeps a node reference only while its attribution runs through\n * one of that node's surviving active sources, and is dropped once no\n * reference survives.\n */\nasync function buildProjectedHarmonicGraph(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n anchorsEnabled: boolean;\n abortSignal?: AbortSignal;\n temporalExpiredInInjection?: boolean;\n nowMs?: number;\n}): Promise<ProjectedHarmonicGraph> {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodes = await readAbstractionNodes(options);\n const sourceMemoryIds = [...new Set(nodes.flatMap((node) => node.sourceMemoryIds ?? []))];\n const sourceMemories: SourceMemoryMap = sourceMemoryIds.length > 0\n ? await readSourceMemories({\n memoryDir: options.memoryDir,\n abortSignal: options.abortSignal,\n sourceMemoryIds,\n nowMs: options.nowMs,\n })\n : new Map();\n const nowMs = options.nowMs ?? Date.now();\n // A node whose full stored source set survived projection keeps legacy\n // anchor attribution (an anchor written before per-node source ids existed).\n const legacyCompatibleNodeRefs = new Set<string>();\n const projectedNodes = nodes.flatMap((node) => {\n const projected = projectSourceBackedNode(\n node,\n sourceMemories,\n options.memoryDir,\n options.temporalExpiredInInjection === true,\n nowMs\n );\n if (\n projected &&\n (node.sourceMemoryIds?.length ?? 0) > 0 &&\n projected.sourceMemoryIds?.length === node.sourceMemoryIds?.length\n ) {\n legacyCompatibleNodeRefs.add(node.nodeId);\n }\n return projected ? [projected] : [];\n });\n if (!options.anchorsEnabled) return { nodes: projectedNodes, anchors: [] };\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeIndex = new Map(projectedNodes.map((node) => [node.nodeId, node]));\n const anchors = (await readCueAnchors(options)).flatMap((anchor) => {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeRefs = anchor.nodeRefs.filter((nodeRef) => {\n const node = nodeIndex.get(nodeRef);\n return (\n node !== undefined &&\n anchorMatchesProjectedNode(anchor, nodeRef, node, legacyCompatibleNodeRefs.has(nodeRef))\n );\n });\n return nodeRefs.length > 0 ? [{ ...anchor, nodeRefs }] : [];\n });\n return { nodes: projectedNodes, anchors };\n}\n\nconst GRAPH_CACHE_TTL_MS = 30_000;\nconst GRAPH_CACHE_MAX_ENTRIES = 8;\n\ninterface GraphCacheEntry {\n stamp: string;\n startedAtMs: number;\n graph: ProjectedHarmonicGraph;\n}\n\nconst graphCache = new Map<string, GraphCacheEntry>();\n\ninterface GraphBuild {\n stamp: string;\n promise: Promise<ProjectedHarmonicGraph>;\n /** Cancels the build's source scan; fired when no caller is waiting for it. */\n controller: AbortController;\n /** Callers currently waiting for this build. */\n waiting: number;\n}\n\n/** One build per cache key at a time: every recall that lands on a miss waits for the same build. */\nconst graphBuilds = new Map<string, GraphBuild>();\n/** Counters for tests and diagnostics. `shared` counts reads that joined a build already running. */\nexport const harmonicGraphCacheStats = { hits: 0, misses: 0, shared: 0 };\n\n/** Freeze records and their nested arrays/objects so a caller cannot corrupt the shared cache. */\nfunction deepFreeze<T extends object>(value: T): T {\n // isFrozen is true for primitives and null, and a frozen value is not revisited, so this ends on cycles too.\n if (Object.isFrozen(value)) return value;\n Object.freeze(value);\n for (const child of Object.values(value)) deepFreeze(child);\n return value;\n}\n\nexport function clearHarmonicGraphCache(): void {\n graphCache.clear();\n graphBuilds.clear();\n}\n\ntype GraphReadOptions = Parameters<typeof buildProjectedHarmonicGraph>[0];\n\n/**\n * Start the one build for `key`. The build owns an abort controller instead of using one caller's signal,\n * so a caller that leaves does not cancel it for the others; `joinGraphBuild` cancels it when the last caller leaves.\n */\nfunction startGraphBuild(key: string, stamp: string, options: GraphReadOptions): GraphBuild {\n harmonicGraphCacheStats.misses++;\n const startedAtMs = Date.now();\n const controller = new AbortController();\n const promise: Promise<ProjectedHarmonicGraph> = buildProjectedHarmonicGraph({\n memoryDir: options.memoryDir,\n abstractionNodeStoreDir: options.abstractionNodeStoreDir,\n anchorsEnabled: options.anchorsEnabled,\n temporalExpiredInInjection: options.temporalExpiredInInjection,\n abortSignal: controller.signal,\n })\n .then((built) => {\n const graph = { nodes: deepFreeze(built.nodes), anchors: deepFreeze(built.anchors) };\n // A cleared cache or a newer build for this key has replaced this one: do not store a stale graph.\n if (graphBuilds.get(key)?.promise !== promise) return graph;\n graphCache.delete(key);\n graphCache.set(key, { stamp, startedAtMs, graph });\n while (graphCache.size > GRAPH_CACHE_MAX_ENTRIES) {\n const oldest = graphCache.keys().next().value;\n if (oldest === undefined) break;\n graphCache.delete(oldest);\n }\n return graph;\n })\n .finally(() => {\n if (graphBuilds.get(key)?.promise === promise) graphBuilds.delete(key);\n });\n const build: GraphBuild = { stamp, promise, controller, waiting: 0 };\n graphBuilds.set(key, build);\n return build;\n}\n\n/**\n * Wait for `build` on behalf of one caller. The caller's own signal ends only its own wait. When the last\n * waiting caller has left, the build is cancelled and dropped, so abandoned recalls do not leave full scans running\n * (cancelling a build that already finished does nothing).\n */\nfunction joinGraphBuild(key: string, build: GraphBuild, signal: AbortSignal | undefined): Promise<ProjectedHarmonicGraph> {\n build.waiting++;\n return raceAbort(build.promise, signal, \"harmonic retrieval aborted\").finally(() => {\n build.waiting--;\n if (build.waiting > 0) return;\n if (graphBuilds.get(key) === build) graphBuilds.delete(key);\n build.controller.abort();\n });\n}\n\n/**\n * `readProjectedHarmonicGraph` with an opt-in in-memory cache. Every recall used\n * to re-read all nodes, anchors and source memories from disk (about 4.7 s on a\n * 2107 node, 9199 anchor, 4105 source graph). With `useCache` a completed graph is\n * reused while the stamp below is unchanged: the memory corpus, memory status and\n * cold-write version sentinels (bumped by every memory write, in any process) and\n * the graph version sentinel (bumped by node and anchor writes). A stamp read is\n * four stats, not a scan of the memories. The TTL bounds the one input a sentinel\n * cannot see, which is wall-clock validity expiry. Concurrent misses share one\n * build. An explicit `nowMs` bypasses the cache so tests stay deterministic. The\n * cached arrays are frozen: callers must not mutate them.\n */\nexport async function readProjectedHarmonicGraph(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n anchorsEnabled: boolean;\n abortSignal?: AbortSignal;\n temporalExpiredInInjection?: boolean;\n nowMs?: number;\n useCache?: boolean;\n}): Promise<ProjectedHarmonicGraph> {\n if (options.useCache !== true || options.nowMs !== undefined) return buildProjectedHarmonicGraph(options);\n // Same cancellation contract as the builder: a cache hit must not mask an aborted signal.\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeStoreDir = resolveAbstractionNodeStoreDir(options.memoryDir, options.abstractionNodeStoreDir);\n const key = JSON.stringify([\n options.memoryDir,\n nodeStoreDir,\n options.anchorsEnabled === true,\n options.temporalExpiredInInjection === true,\n ]);\n // The stamp is read BEFORE the build, so a write that lands mid-build leaves the\n // entry stale and the next call rebuilds.\n const stamp = readHarmonicGraphStamp(options.memoryDir, nodeStoreDir);\n const startedAtMs = Date.now();\n const hit = graphCache.get(key);\n if (hit && hit.stamp === stamp && startedAtMs - hit.startedAtMs < GRAPH_CACHE_TTL_MS) {\n harmonicGraphCacheStats.hits++;\n graphCache.delete(key);\n graphCache.set(key, hit);\n return hit.graph;\n }\n const running = graphBuilds.get(key);\n if (running?.stamp === stamp) {\n harmonicGraphCacheStats.shared++;\n return joinGraphBuild(key, running, options.abortSignal);\n }\n return joinGraphBuild(key, startGraphBuild(key, stamp, options), options.abortSignal);\n}\n\nexport async function searchHarmonicRetrieval(options: {\n memoryDir: string;\n abstractionNodeStoreDir?: string;\n query: string;\n maxResults: number;\n sessionKey?: string;\n anchorsEnabled: boolean;\n abortSignal?: AbortSignal;\n temporalExpiredInInjection?: boolean;\n /** Share one projected graph between recalls until a write bumps a version sentinel (see readProjectedHarmonicGraph). */\n useGraphCache?: boolean;\n}): Promise<HarmonicRetrievalResult[]> {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const queryTokens = new Set(normalizeRecallTokens(options.query, [\"what\", \"which\"]));\n if (queryTokens.size === 0 || options.maxResults <= 0) return [];\n\n // One projection for every graph reader: nodes and anchors both arrive\n // already narrowed to the namespace's current active memories.\n const { nodes: eligibleNodes, anchors } = await readProjectedHarmonicGraph({\n ...options,\n useCache: options.useGraphCache === true,\n });\n const candidates = new Map<string, HarmonicCandidate>();\n\n for (const node of eligibleNodes) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const { score, matchedFields } = scoreNode(node, queryTokens);\n if (score <= 0) continue;\n candidates.set(node.nodeId, {\n node,\n nodeScore: score,\n anchorScore: 0,\n matchedFields: new Set(matchedFields),\n matchedAnchors: new Map(),\n });\n }\n\n if (options.anchorsEnabled) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n const nodeIndex = new Map(eligibleNodes.map((node) => [node.nodeId, node]));\n for (const anchor of anchors) {\n throwIfAborted(options.abortSignal, \"harmonic retrieval aborted\");\n // `nodeRefs` are the projection's surviving references already.\n const eligibleNodeRefs = anchor.nodeRefs;\n const eligibleNodeTags = new Set(eligibleNodeRefs.flatMap((nodeRef) => nodeIndex.get(nodeRef)?.tags ?? []));\n const eligibleAnchorTags = anchor.tags?.filter((tag) => eligibleNodeTags.has(tag)) ?? [];\n const { score, matchedFields } = scoreAnchor(anchor, queryTokens, eligibleAnchorTags);\n if (score <= 0) continue;\n for (const nodeRef of eligibleNodeRefs) {\n const node = nodeIndex.get(nodeRef);\n if (!node) continue;\n const existing = candidates.get(nodeRef) ?? {\n node,\n nodeScore: 0,\n anchorScore: 0,\n matchedFields: new Set<string>(),\n matchedAnchors: new Map<string, HarmonicMatchedAnchor>(),\n };\n existing.anchorScore += score;\n existing.matchedFields.add(\"anchor\");\n for (const field of matchedFields) existing.matchedFields.add(field);\n existing.matchedAnchors.set(anchor.anchorId, {\n anchorId: anchor.anchorId,\n anchorType: anchor.anchorType,\n anchorValue: anchor.anchorValue,\n });\n candidates.set(nodeRef, existing);\n }\n }\n }\n\n return [...candidates.values()]\n .map((candidate) => {\n let score = candidate.nodeScore + candidate.anchorScore;\n if (options.sessionKey && candidate.node.sessionKey === options.sessionKey) score += 0.5;\n return {\n node: candidate.node,\n score,\n nodeScore: candidate.nodeScore,\n anchorScore: candidate.anchorScore,\n matchedFields: [...candidate.matchedFields].sort(),\n matchedAnchors: [...candidate.matchedAnchors.values()].sort(\n (left, right) =>\n left.anchorType.localeCompare(right.anchorType) || left.anchorValue.localeCompare(right.anchorValue)\n ),\n };\n })\n .filter((result) => result.nodeScore > 0 || result.anchorScore > 0)\n .sort(\n (left, right) =>\n right.score - left.score ||\n right.anchorScore - left.anchorScore ||\n right.node.recordedAt.localeCompare(left.node.recordedAt)\n )\n .slice(0, options.maxResults);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAS,gBAAgB;AA+BzB,IAAM,mBAAmB,IAAI;AAC7B,IAAM,SAAS;AAEf,SAAS,aAAa,WAAmB,OAAyB;AAChE,QAA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,aAAa,UAAU;AAAA,MACvB,eAAe,CAAC,GAAG,UAAU,aAAa,EAAE,KAAK;AAAA,MACjD,gBAAgB,CAAC,GAAG,UAAU,eAAe,OAAO,CAAC,EAAE;AAAA,QACrD,CAAC,MAAM,UACL,KAAK,WAAW,cAAc,MAAM,UAAU,KAAK,KAAK,YAAY,cAAc,MAAM,WAAW;AAAA,MACvG;AAAA,IACF;AAAA,EACF,CAAC,EACA,OAAO,CAAC,WAAW,OAAO,YAAY,KAAK,OAAO,cAAc,CAAC,EACjE;AAAA,IACC,CAAC,MAAM,UACL,MAAM,QAAQ,KAAK,SACnB,MAAM,cAAc,KAAK,eACzB,MAAM,KAAK,WAAW,cAAc,KAAK,KAAK,UAAU;AAAA,EAC5D,EACC,MAAM,GAAG,QAAQ,UAAU;AAChC;","names":[]}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
ExtractionDrain,
|
|
3
3
|
TurnIngestionCoordinator,
|
|
4
4
|
shouldSkipImplicitExtraction
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MMOXCCHF.js";
|
|
6
6
|
import {
|
|
7
7
|
headerConnector,
|
|
8
8
|
renderExtractionConversation,
|
|
@@ -447,4 +447,4 @@ export {
|
|
|
447
447
|
ClaimBufferStorage,
|
|
448
448
|
BufferDrainRunner
|
|
449
449
|
};
|
|
450
|
-
//# sourceMappingURL=chunk-
|
|
450
|
+
//# sourceMappingURL=chunk-QIPDTAWZ.js.map
|
package/dist/cli.js
CHANGED
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
runWorkProductStatusCliCommand,
|
|
92
92
|
runWorkProjectCliCommand,
|
|
93
93
|
runWorkTaskCliCommand
|
|
94
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-MMOXCCHF.js";
|
|
95
95
|
import "./chunk-6P7U3HWG.js";
|
|
96
96
|
import "./chunk-PQM3B54K.js";
|
|
97
97
|
import "./chunk-B3DR2JBZ.js";
|
|
@@ -264,7 +264,7 @@ import "./chunk-MDPT6QFK.js";
|
|
|
264
264
|
import "./chunk-UOBPK2OS.js";
|
|
265
265
|
import "./chunk-2YA5N2BY.js";
|
|
266
266
|
import "./chunk-3HSRWJTC.js";
|
|
267
|
-
import "./chunk-
|
|
267
|
+
import "./chunk-PL36IQPL.js";
|
|
268
268
|
import "./chunk-HUDPXTXW.js";
|
|
269
269
|
import "./chunk-AZEZSQ5R.js";
|
|
270
270
|
import "./chunk-YAZNBMNF.js";
|
package/dist/explicit-capture.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
shouldSkipImplicitExtraction,
|
|
9
9
|
stripInlineExplicitCaptureNotes,
|
|
10
10
|
validateExplicitCaptureInput
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-MMOXCCHF.js";
|
|
12
12
|
import "./chunk-6P7U3HWG.js";
|
|
13
13
|
import "./chunk-PQM3B54K.js";
|
|
14
14
|
import "./chunk-B3DR2JBZ.js";
|
|
@@ -181,7 +181,7 @@ import "./chunk-MDPT6QFK.js";
|
|
|
181
181
|
import "./chunk-UOBPK2OS.js";
|
|
182
182
|
import "./chunk-2YA5N2BY.js";
|
|
183
183
|
import "./chunk-3HSRWJTC.js";
|
|
184
|
-
import "./chunk-
|
|
184
|
+
import "./chunk-PL36IQPL.js";
|
|
185
185
|
import "./chunk-HUDPXTXW.js";
|
|
186
186
|
import "./chunk-AZEZSQ5R.js";
|
|
187
187
|
import "./chunk-YAZNBMNF.js";
|
|
@@ -25,10 +25,11 @@ export interface ProjectedHarmonicGraph {
|
|
|
25
25
|
nodes: AbstractionNode[];
|
|
26
26
|
anchors: CueAnchor[];
|
|
27
27
|
}
|
|
28
|
-
/** Counters for tests and diagnostics. */
|
|
28
|
+
/** Counters for tests and diagnostics. `shared` counts reads that joined a build already running. */
|
|
29
29
|
export declare const harmonicGraphCacheStats: {
|
|
30
30
|
hits: number;
|
|
31
31
|
misses: number;
|
|
32
|
+
shared: number;
|
|
32
33
|
};
|
|
33
34
|
export declare function clearHarmonicGraphCache(): void;
|
|
34
35
|
/**
|
|
@@ -39,9 +40,9 @@ export declare function clearHarmonicGraphCache(): void;
|
|
|
39
40
|
* cold-write version sentinels (bumped by every memory write, in any process) and
|
|
40
41
|
* the graph version sentinel (bumped by node and anchor writes). A stamp read is
|
|
41
42
|
* four stats, not a scan of the memories. The TTL bounds the one input a sentinel
|
|
42
|
-
* cannot see, which is wall-clock validity expiry.
|
|
43
|
-
* cache so tests stay deterministic. The
|
|
44
|
-
* mutate them.
|
|
43
|
+
* cannot see, which is wall-clock validity expiry. Concurrent misses share one
|
|
44
|
+
* build. An explicit `nowMs` bypasses the cache so tests stay deterministic. The
|
|
45
|
+
* cached arrays are frozen: callers must not mutate them.
|
|
45
46
|
*/
|
|
46
47
|
export declare function readProjectedHarmonicGraph(options: {
|
|
47
48
|
memoryDir: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harmonic-retrieval.d.ts","sourceRoot":"","sources":["../src/harmonic-retrieval.ts"],"names":[],"mappings":"AAMC,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AACjC,OAAO,EAA+C,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAsPnH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,aAAa,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,EAAE,qBAAqB,EAAE,CAAC;CACzC;AA+ED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC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AAW,sBAAsB;IACrC,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB;AAiGD,qGAAqG;AACrG,eAAO,MAAM,uBAAuB;;;;CAAoC,CAAC;AAWzE,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C;AAuDD;;;;;;;;;;;GAWG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CA4BlC;AAED,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,yHAAyH;IACzH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAoFrC"}
|
package/dist/index.js
CHANGED
|
@@ -259,7 +259,7 @@ import {
|
|
|
259
259
|
writeManifest,
|
|
260
260
|
writeMeetingEpisodeMemory,
|
|
261
261
|
writeTimelineState
|
|
262
|
-
} from "./chunk-
|
|
262
|
+
} from "./chunk-MMOXCCHF.js";
|
|
263
263
|
import "./chunk-6P7U3HWG.js";
|
|
264
264
|
import "./chunk-PQM3B54K.js";
|
|
265
265
|
import {
|
|
@@ -717,7 +717,7 @@ import {
|
|
|
717
717
|
import "./chunk-UOBPK2OS.js";
|
|
718
718
|
import "./chunk-2YA5N2BY.js";
|
|
719
719
|
import "./chunk-3HSRWJTC.js";
|
|
720
|
-
import "./chunk-
|
|
720
|
+
import "./chunk-PL36IQPL.js";
|
|
721
721
|
import "./chunk-HUDPXTXW.js";
|
|
722
722
|
import "./chunk-AZEZSQ5R.js";
|
|
723
723
|
import "./chunk-YAZNBMNF.js";
|
|
@@ -68,6 +68,8 @@ export interface BacklogSchedulerOptions {
|
|
|
68
68
|
pollMs?: number;
|
|
69
69
|
retryBaseMs?: number;
|
|
70
70
|
retryMaxMs?: number;
|
|
71
|
+
/** Bound on `stop()`'s wait for aborted drains to settle. */
|
|
72
|
+
stopSettleTimeoutMs?: number;
|
|
71
73
|
now?: () => number;
|
|
72
74
|
}
|
|
73
75
|
export interface BacklogSchedulerCounters {
|
|
@@ -113,7 +115,10 @@ export declare class BacklogScheduler {
|
|
|
113
115
|
/** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */
|
|
114
116
|
start(): void;
|
|
115
117
|
/** Idempotent. Stops the timer, aborts in-flight drains (their claims stay
|
|
116
|
-
* retryable) and waits for them to settle.
|
|
118
|
+
* retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A
|
|
119
|
+
* drain that ignores abort is named in a warning and left behind: the
|
|
120
|
+
* caller's later shutdown phases (orchestrator flush and dispose) must
|
|
121
|
+
* still run before the service manager's kill. */
|
|
117
122
|
stop(): Promise<void>;
|
|
118
123
|
/** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */
|
|
119
124
|
snapshot(): BacklogSchedulerSnapshot;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backlog-scheduler.d.ts","sourceRoot":"","sources":["../../src/orchestration/backlog-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,M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
|
|
5
5
|
import "../chunk-6P7U3HWG.js";
|
|
6
6
|
import "../chunk-PQM3B54K.js";
|
|
7
7
|
import "../chunk-B3DR2JBZ.js";
|
|
@@ -174,7 +174,7 @@ import "../chunk-MDPT6QFK.js";
|
|
|
174
174
|
import "../chunk-UOBPK2OS.js";
|
|
175
175
|
import "../chunk-2YA5N2BY.js";
|
|
176
176
|
import "../chunk-3HSRWJTC.js";
|
|
177
|
-
import "../chunk-
|
|
177
|
+
import "../chunk-PL36IQPL.js";
|
|
178
178
|
import "../chunk-HUDPXTXW.js";
|
|
179
179
|
import "../chunk-AZEZSQ5R.js";
|
|
180
180
|
import "../chunk-YAZNBMNF.js";
|
|
@@ -571,6 +571,7 @@ import { hostname } from "os";
|
|
|
571
571
|
var DEFAULT_POLL_MS = 15e3;
|
|
572
572
|
var DEFAULT_RETRY_BASE_MS = 3e4;
|
|
573
573
|
var DEFAULT_RETRY_MAX_MS = 15 * 6e4;
|
|
574
|
+
var DEFAULT_STOP_SETTLE_TIMEOUT_MS = 3e4;
|
|
574
575
|
var BacklogScheduler = class {
|
|
575
576
|
deps;
|
|
576
577
|
options;
|
|
@@ -596,6 +597,7 @@ var BacklogScheduler = class {
|
|
|
596
597
|
pollMs: options.pollMs ?? DEFAULT_POLL_MS,
|
|
597
598
|
retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,
|
|
598
599
|
retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,
|
|
600
|
+
stopSettleTimeoutMs: options.stopSettleTimeoutMs ?? DEFAULT_STOP_SETTLE_TIMEOUT_MS,
|
|
599
601
|
now: options.now
|
|
600
602
|
};
|
|
601
603
|
}
|
|
@@ -608,7 +610,10 @@ var BacklogScheduler = class {
|
|
|
608
610
|
void this.tick();
|
|
609
611
|
}
|
|
610
612
|
/** Idempotent. Stops the timer, aborts in-flight drains (their claims stay
|
|
611
|
-
* retryable) and waits for them to settle.
|
|
613
|
+
* retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A
|
|
614
|
+
* drain that ignores abort is named in a warning and left behind: the
|
|
615
|
+
* caller's later shutdown phases (orchestrator flush and dispose) must
|
|
616
|
+
* still run before the service manager's kill. */
|
|
612
617
|
async stop() {
|
|
613
618
|
if (this.stopped) return;
|
|
614
619
|
this.stopped = true;
|
|
@@ -621,7 +626,18 @@ var BacklogScheduler = class {
|
|
|
621
626
|
entry.controller.abort(new Error("backlog scheduler stopping"));
|
|
622
627
|
aborts.push(entry.settled);
|
|
623
628
|
}
|
|
624
|
-
|
|
629
|
+
const bound = Promise.withResolvers();
|
|
630
|
+
const boundTimer = setTimeout(() => bound.resolve("timeout"), this.options.stopSettleTimeoutMs);
|
|
631
|
+
try {
|
|
632
|
+
const result = await Promise.race([Promise.allSettled(aborts), bound.promise]);
|
|
633
|
+
if (result === "timeout") {
|
|
634
|
+
log.warn(
|
|
635
|
+
`backlog scheduler stop: ${this.inFlight.size} drain(s) ignored abort for ${this.options.stopSettleTimeoutMs}ms; continuing shutdown (stuck keys: ${[...this.inFlight.keys()].join(", ")})`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
} finally {
|
|
639
|
+
clearTimeout(boundTimer);
|
|
640
|
+
}
|
|
625
641
|
}
|
|
626
642
|
/** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */
|
|
627
643
|
snapshot() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/orchestration/backlog-scheduler.ts"],"sourcesContent":["/**\n * Daemon-owned extraction backlog scheduler.\n *\n * ONE bounded in-process loop that owns ALL persisted extraction backlog:\n * at startup (existing drain claims + buffered sessions), on every poll tick\n * (new persisted work), and by retrying keys that are still pending — with\n * bounded memory (per-key COUNTS only; candidate scans never retain turn\n * payloads) and bounded outstanding work (the extraction queue's own\n * maxConcurrency gates submissions, so live foreground work keeps its share\n * of the queue).\n *\n * Claim authority: an existing claim — including an EMPTY ack tombstone — is\n * authoritative over the live buffer's in-memory copy. A tombstoned key is\n * never re-claimed or counted as work; new ingress consumes the tombstone\n * through the native save handover, which is what makes the key a candidate\n * again. Claim creation is fenced: the key is reserved synchronously on the\n * extraction queue BEFORE the async claim decision, so a queued live task for\n * the same key cannot start past the claimed-session gate until the decision\n * settles; live capture continues via the native merge-into-claim protocol.\n *\n * Failed, deferred, or policy-denied outcomes keep their turns durable in the\n * claim and re-submit after backoff (exponential from `retryBaseMs` to\n * `retryMaxMs`, reset by progress; denials wait the full max) — never a busy\n * retry. `stop()` aborts in-flight drains at their chunk boundary and leaves\n * every claim retryable; a restarted daemon's scheduler adopts them.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { hostname } from \"node:os\";\nimport { log } from \"../logger.js\";\nimport type { Orchestrator } from \"../orchestrator.js\";\nimport type { BufferDrainClaims, DrainLease } from \"../storage/buffer-drain-claims.js\";\nimport { BufferDrainRunner } from \"./buffer-drain-runner.js\";\nimport type { DrainRunnerEvent, DrainSessionOutcome } from \"./buffer-drain-runner.js\";\nimport type { ExtractionQueueCoordinator } from \"./extraction-queue-coordinator.js\";\nimport type { ProviderBreakerSnapshot } from \"./provider-breaker.js\";\n\n/** What the scheduler needs from its host (structurally satisfied by the\n * orchestrator wiring); injectable so tests drive ticks deterministically. */\nexport interface BacklogSchedulerDeps {\n queue: Pick<ExtractionQueueCoordinator, \"tryReserveKey\" | \"releaseKeyReservation\" | \"maxConcurrency\">;\n claims: Pick<BufferDrainClaims, \"list\" | \"listPage\" | \"claimFromSessionFile\" | \"isClaimed\">;\n /** Live per-key pending counts (counts only — never turn payloads). May be\n * async: hosts with a lazily-loaded buffer load it here (idempotent). */\n liveBufferCounts():\n | Map<string, { turns: number; retainedTurns: number }>\n | Promise<Map<string, { turns: number; retainedTurns: number }>>;\n /** Create a fresh lease for a unique owner token. */\n lease(ownerId: string): DrainLease;\n /** Drain one key to quiescence (BufferDrainRunner.drainSession). */\n drainKey(\n key: string,\n options: { ownerId: string; signal: AbortSignal; onEvent?: (event: DrainRunnerEvent) => void }\n ): Promise<DrainSessionOutcome>;\n /** Shared provider circuit-breaker snapshot (the same instance the run\n * coordinator gates attempts on). While OPEN inside its cooldown window\n * the scheduler skips submission entirely — claims stay durable, and the\n * breaker's single half-open probe (one attempt through once the window\n * lapses) keeps recovery automatic. Optional: hosts without a breaker\n * never skip. */\n breakerSnapshot?(): ProviderBreakerSnapshot;\n /** Test seam: monotonic-ish clock for backoff windows. */\n now?(): number;\n}\n\nexport interface BacklogSchedulerOptions {\n /** Optional label prefix; each scheduler instance adds a unique token. */\n ownerId?: string;\n /** Scan cadence in ms (startup + new-work + retry checks). */\n pollMs?: number;\n retryBaseMs?: number;\n retryMaxMs?: number;\n now?: () => number;\n}\n\nexport interface BacklogSchedulerCounters {\n /** Keys submitted to the drain (claimed or adopted) this process lifetime. */\n claimed: number;\n /** Outcomes with genuinely empty claims (durable outputs preceded ack). */\n processed: number;\n /** Sum of durable outputs (memories + entities) across processed drains. */\n durableOutputs: number;\n /** Re-submissions after a failed/deferred/denied outcome. */\n retried: number;\n denied: { keys: number; turns: number };\n failed: number;\n}\n\nexport type BacklogKeyState = \"inflight\" | \"backoff\" | \"denied\";\n\nexport interface BacklogKeySnapshot {\n key: string;\n state: BacklogKeyState;\n turnsRemaining?: number;\n reason?: string;\n}\n\nexport interface BacklogSchedulerSnapshot {\n counters: BacklogSchedulerCounters;\n inFlight: string[];\n reservedKeys: string[];\n keys: BacklogKeySnapshot[];\n}\n\ninterface KeyState {\n state: BacklogKeyState;\n nextAttemptMs: number;\n /** Last observed remaining turns; progress resets the backoff exponent. */\n turnsRemaining: number;\n reason?: string;\n backoffExponent: number;\n}\n\nconst DEFAULT_POLL_MS = 15_000;\nconst DEFAULT_RETRY_BASE_MS = 30_000;\nconst DEFAULT_RETRY_MAX_MS = 15 * 60_000;\n\nexport class BacklogScheduler {\n private readonly deps: BacklogSchedulerDeps;\n private readonly options: Required<Omit<BacklogSchedulerOptions, \"now\">> & Pick<BacklogSchedulerOptions, \"now\">;\n private readonly keys = new Map<string, KeyState>();\n private readonly inFlight = new Map<string, { controller: AbortController; settled: Promise<void> }>();\n private readonly reserved = new Set<string>();\n private readonly counters: BacklogSchedulerCounters = {\n claimed: 0,\n processed: 0,\n durableOutputs: 0,\n retried: 0,\n denied: { keys: 0, turns: 0 },\n failed: 0,\n };\n private claimCursor: string | undefined;\n private timer: ReturnType<typeof setInterval> | undefined;\n private ticking = false;\n private stopped = true;\n\n constructor(deps: BacklogSchedulerDeps, options: BacklogSchedulerOptions = {}) {\n this.deps = deps;\n this.options = {\n ownerId: `${options.ownerId ?? \"daemon-drain\"}-${randomUUID()}`,\n pollMs: options.pollMs ?? DEFAULT_POLL_MS,\n retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,\n retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,\n now: options.now,\n };\n }\n\n /** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */\n start(): void {\n if (!this.stopped) return;\n this.stopped = false;\n this.timer = setInterval(() => void this.tick(), this.options.pollMs);\n this.timer.unref?.();\n void this.tick();\n }\n\n /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay\n * retryable) and waits for them to settle. */\n async stop(): Promise<void> {\n if (this.stopped) return;\n this.stopped = true;\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n const aborts: Promise<void>[] = [];\n for (const entry of this.inFlight.values()) {\n entry.controller.abort(new Error(\"backlog scheduler stopping\"));\n aborts.push(entry.settled);\n }\n await Promise.allSettled(aborts);\n }\n\n /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */\n snapshot(): BacklogSchedulerSnapshot {\n return {\n counters: {\n claimed: this.counters.claimed,\n processed: this.counters.processed,\n durableOutputs: this.counters.durableOutputs,\n retried: this.counters.retried,\n denied: { ...this.counters.denied },\n failed: this.counters.failed,\n },\n inFlight: [...this.inFlight.keys()],\n reservedKeys: [...this.reserved],\n keys: [...this.keys.entries()].map(([key, state]) => ({\n key,\n state: state.state,\n turnsRemaining: state.turnsRemaining,\n reason: state.reason,\n })),\n };\n }\n\n /** One scan+submit pass (tests drive this instead of the timer). Waits out\n * any in-progress tick first so the pass always actually scans. */\n async tickForTest(): Promise<void> {\n // setImmediate: yields to the event loop so pending I/O (a slow first\n // scan) can finish; a microtask spin would starve it.\n while (this.ticking) await new Promise((resolve) => setImmediate(resolve));\n await this.tick();\n }\n\n /** Await the settle (slot release) of everything currently in flight,\n * optionally excluding one still-gated key (tests). */\n async settleForTest(exclude?: string): Promise<void> {\n for (;;) {\n const pending = [...this.inFlight.entries()].filter(([key]) => key !== exclude).map(([, entry]) => entry.settled);\n if (pending.length === 0) return;\n await Promise.allSettled(pending);\n }\n }\n\n private now(): number {\n return this.options.now?.() ?? Date.now();\n }\n\n private async tick(): Promise<void> {\n if (this.ticking || this.stopped) return;\n this.ticking = true;\n const cursorBeforeTick = this.claimCursor;\n try {\n // Fast bail: a breaker already open must not pay discovery I/O\n // (listPage reads and parses claim bodies on every poll). The\n // submitCandidates guard below still catches a breaker that opens\n // while discovery awaits.\n const breakerBeforeDiscovery = this.deps.breakerSnapshot?.();\n if (\n breakerBeforeDiscovery &&\n breakerBeforeDiscovery.state === \"open\" &&\n this.now() < breakerBeforeDiscovery.openUntilMs\n ) {\n return;\n }\n // stop() may land while discovery's I/O is pending: re-check before\n // submitting anything, and again per candidate.\n // A discovery failure (EACCES/EIO on the claims dir) must not reject\n // into a detached timer callback: it would be an unhandled rejection\n // that terminates the server. Log, skip this pass, retry next poll.\n let candidates: { key: string; needsClaim: boolean }[];\n try {\n candidates = await this.discoverCandidates();\n } catch (err) {\n // Discovery may have listed a page before it failed: the page cursor\n // already moved, so restore it — otherwise those claims wait for the\n // cursor to wrap instead of the next poll.\n this.claimCursor = cursorBeforeTick;\n log.warn(\n `backlog drain: discovery failed; retrying next poll: ${err instanceof Error ? err.message : String(err)}`\n );\n return;\n }\n if (this.stopped) return;\n const dropped = this.submitCandidates(candidates);\n // The concurrency bound stopped submission mid-page: rewind the page\n // cursor so the unsubmitted claims are re-listed on the next tick\n // (already-submitted ones are gated by inFlight and key backoff).\n if (dropped) this.claimCursor = cursorBeforeTick;\n } finally {\n this.ticking = false;\n }\n }\n\n /** Bounded discovery: ONE page of existing claims with pending turns */\n private async discoverCandidates(): Promise<{ key: string; needsClaim: boolean }[]> {\n const out: { key: string; needsClaim: boolean }[] = [];\n const seen = new Set<string>();\n const pageLimit = Math.max(this.submissionLimit() * 4, 16);\n const page = await this.deps.claims.listPage(this.claimCursor, pageLimit);\n for (const listed of page.entries) {\n seen.add(listed.key);\n out.push({ key: listed.key, needsClaim: false });\n }\n this.claimCursor = page.nextCursor;\n for (const [key, counts] of await this.deps.liveBufferCounts()) {\n if (counts.turns + counts.retainedTurns <= 0) continue;\n if (seen.has(key) || this.deps.claims.isClaimed(key)) continue;\n seen.add(key);\n out.push({ key, needsClaim: true });\n }\n return out;\n }\n\n /** Submission bound: the queue's own concurrency limit, read with the\n * documented \"0 disables\" contract — a zero limit submits nothing. */\n private submissionLimit(): number {\n if (this.deps.queue.maxConcurrency <= 0) return 0;\n return this.deps.queue.maxConcurrency;\n }\n\n /** Submit discovery candidates within the queue's concurrency bound. */\n private submitCandidates(candidates: { key: string; needsClaim: boolean }[]): boolean {\n // Breaker-open churn guard: a full attempt reads the claim, rebuilds the\n // buffer/coordinator and re-renders chunks before the breaker fails it\n // fast — pure heap pressure per poll during a provider stall. Skip while\n // the window is open; once it lapses, submissions resume and the\n // breaker's half-open probe runs as usual.\n const breaker = this.deps.breakerSnapshot?.();\n if (breaker && breaker.state === \"open\" && this.now() < breaker.openUntilMs) {\n return true;\n }\n let dropped = false;\n for (const candidate of candidates) {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) {\n dropped = true;\n break;\n }\n if (!this.candidateEligible(candidate)) continue;\n // Fence the claim decision: reserve the key synchronously BEFORE the\n // async rename so no queued task for it can pass the claimed gate in\n // the meantime. Release happens when the decision settles.\n if (candidate.needsClaim) {\n if (!this.deps.queue.tryReserveKey(candidate.key)) continue;\n this.reserved.add(candidate.key);\n }\n void this.submit(candidate.key, candidate.needsClaim);\n }\n return dropped;\n }\n\n /** inFlight is the authority for \"already submitted\" — key state only\n * exists once an outcome landed (backoff/denied gating below). */\n private candidateEligible(candidate: { key: string; needsClaim: boolean }): boolean {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) return false;\n if (this.inFlight.has(candidate.key)) return false;\n const state = this.keys.get(candidate.key);\n return !(state && this.now() < state.nextAttemptMs);\n }\n\n /** Claim (when needed), then drain one key; the reservation spans the async\n * claim decision, the queue entry carries the key afterwards. */\n private async submit(key: string, needsClaim: boolean): Promise<void> {\n const controller = new AbortController();\n const { promise: settled, resolve: settle } = Promise.withResolvers<void>();\n this.inFlight.set(key, { controller, settled });\n try {\n if (!(await this.claimForSubmit(key, needsClaim, this.options.ownerId))) return;\n // Stopped between the claim decision and the task: leave the claim\n // with its lease (it expires; the next start adopts) — never drain.\n if (this.stopped) return;\n await this.drainClaimedKey(key, controller.signal, this.options.ownerId);\n } catch (err) {\n // Claim/drain failures are scheduler-level: the claim content is\n // untouched — count failed and back off (never an unhandled rejection\n // in the detached submission).\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} submission failed: ${message}`);\n } finally {\n this.inFlight.delete(key);\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n settle();\n }\n }\n\n /** after all — the key goes quiet without a task. \"claimed\": ours. */\n private async claimForSubmit(key: string, needsClaim: boolean, ownerId: string): Promise<boolean> {\n if (!needsClaim) return true;\n try {\n const outcome = await this.deps.claims.claimFromSessionFile(key, this.deps.lease(ownerId));\n if (outcome === \"empty\") {\n this.keys.delete(key);\n return false;\n }\n return true;\n } finally {\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n }\n }\n\n /** Drain one claimed key. drainKey reports failures as outcomes; a thrown\n * error still means the claim content is intact — count it failed and\n * back off. */\n private async drainClaimedKey(key: string, signal: AbortSignal, ownerId: string): Promise<void> {\n this.counters.claimed += 1;\n try {\n const outcome = await this.deps.drainKey(key, {\n ownerId,\n signal,\n });\n this.applyOutcome(key, outcome);\n } catch (err) {\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} threw: ${message}`);\n }\n }\n\n private applyOutcome(key: string, outcome: DrainSessionOutcome): void {\n const deniedTurns = outcome.denied?.reduce((sum, entry) => sum + entry.turns, 0) ?? 0;\n const previous = this.keys.get(key);\n const progressed = outcome.turnsRemaining < (previous?.turnsRemaining ?? Number.POSITIVE_INFINITY);\n if (outcome.status === \"drained\") {\n // The claim is now an empty tombstone: authoritative, nothing pending.\n // New ingress consumes it via the native save path and re-candidates.\n this.keys.delete(key);\n this.counters.processed += 1;\n this.counters.durableOutputs += outcome.durableOutputCount;\n log.info(\n `backlog drain: ${key} drained (${outcome.turnsAtStart} turn(s), ${outcome.durableOutputCount} durable output(s))`\n );\n return;\n }\n this.recordNonDrainedCounters(previous, outcome, deniedTurns);\n const denied = deniedTurns > 0 && outcome.turnsRemaining > 0;\n this.keys.set(key, this.nextKeyState(previous, outcome, denied, progressed));\n log.info(\n `backlog drain: ${key} ${outcome.status} (${outcome.turnsRemaining} turn(s) remaining` +\n `${denied ? `, denied: ${deniedTurns}` : \"\"}${outcome.reason ? `, ${outcome.reason}` : \"\"})`\n );\n }\n\n /** Denied backlog counters for a non-drained outcome. */\n private recordNonDrainedCounters(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n deniedTurns: number\n ): void {\n if (deniedTurns > 0) {\n this.counters.denied.keys += 1;\n this.counters.denied.turns += deniedTurns;\n }\n if (outcome.status === \"failed\") this.counters.failed += 1;\n else if (previous !== undefined && (previous.state === \"backoff\" || previous.state === \"denied\"))\n this.counters.retried += 1;\n }\n\n /** The post-drain key state: denial waits the full max window (its content\n * is valid but currently unauthorized); progress resets the exponent. */\n private nextKeyState(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n denied: boolean,\n progressed: boolean\n ): KeyState {\n return {\n state: denied ? \"denied\" : \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, progressed && !denied),\n turnsRemaining: outcome.turnsRemaining,\n reason: outcome.reason,\n backoffExponent: this.nextBackoffExponent(denied, progressed, previous),\n };\n }\n\n private nextBackoffExponent(denied: boolean, progressed: boolean, previous: KeyState | undefined): number {\n return denied || !progressed ? (previous?.backoffExponent ?? 0) + 1 : 0;\n }\n\n private backoffMs(previous: KeyState | undefined, progressed: boolean): number {\n if (previous?.state === \"denied\") return this.options.retryMaxMs;\n const exponent = progressed ? 0 : (previous?.backoffExponent ?? 0) + 1;\n return Math.min(this.options.retryBaseMs * 2 ** exponent, this.options.retryMaxMs);\n }\n\n private setBackoff(key: string, turnsRemaining: number, reason: string): void {\n const previous = this.keys.get(key);\n this.keys.set(key, {\n state: \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, false),\n turnsRemaining,\n reason,\n backoffExponent: (previous?.backoffExponent ?? 0) + 1,\n });\n }\n}\n\n/** Lease lifetime for claims the scheduler takes (matches the runner default). */\nconst SCHEDULER_LEASE_MS = 120_000;\n\n/** Wire the scheduler to an orchestrator's own queue, claim store, live buffer\n * counts and drain runner — the daemon's single ownership point. */\nexport function wireBacklogScheduler(\n orchestrator: Orchestrator,\n options: BacklogSchedulerOptions = {}\n): BacklogScheduler {\n const runner = new BufferDrainRunner(orchestrator);\n return new BacklogScheduler(\n {\n queue: orchestrator.extractionQueueCoordinator,\n claims: orchestrator.storage.bufferDrainClaims(),\n liveBufferCounts: async () => {\n // The daemon's buffer may be lazy: ensure the persisted state is in\n // memory before counting (load is guarded/idempotent).\n await orchestrator.buffer.load();\n return orchestrator.buffer.entryCounts();\n },\n lease: (ownerId) => {\n const now = new Date().toISOString();\n return {\n ownerId,\n pid: process.pid,\n host: hostname(),\n acquiredAt: now,\n heartbeatAt: now,\n leaseMs: SCHEDULER_LEASE_MS,\n };\n },\n drainKey: (key, drainOptions) => runner.drainSession(key, drainOptions),\n // The orchestrator's one shared provider breaker (foreground and every\n // claim-backed drain accumulate toward the same threshold).\n breakerSnapshot: () => orchestrator.getExtractionResilienceStatus().breaker,\n },\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAqFzB,IAAM,kBAAkB;AACxB,IAAM,wBAAwB;AAC9B,IAAM,uBAAuB,KAAK;AAE3B,IAAM,mBAAN,MAAuB;A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AU,CAAC,KAAK,iBAAiB,OAAO,aAAa,KAAK,YAAY;AAAA;AAAA;AAAA,MAGtE,iBAAiB,MAAM,aAAa,8BAA8B,EAAE;AAAA,IACtE;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/orchestration/backlog-scheduler.ts"],"sourcesContent":["/**\n * Daemon-owned extraction backlog scheduler.\n *\n * ONE bounded in-process loop that owns ALL persisted extraction backlog:\n * at startup (existing drain claims + buffered sessions), on every poll tick\n * (new persisted work), and by retrying keys that are still pending — with\n * bounded memory (per-key COUNTS only; candidate scans never retain turn\n * payloads) and bounded outstanding work (the extraction queue's own\n * maxConcurrency gates submissions, so live foreground work keeps its share\n * of the queue).\n *\n * Claim authority: an existing claim — including an EMPTY ack tombstone — is\n * authoritative over the live buffer's in-memory copy. A tombstoned key is\n * never re-claimed or counted as work; new ingress consumes the tombstone\n * through the native save handover, which is what makes the key a candidate\n * again. Claim creation is fenced: the key is reserved synchronously on the\n * extraction queue BEFORE the async claim decision, so a queued live task for\n * the same key cannot start past the claimed-session gate until the decision\n * settles; live capture continues via the native merge-into-claim protocol.\n *\n * Failed, deferred, or policy-denied outcomes keep their turns durable in the\n * claim and re-submit after backoff (exponential from `retryBaseMs` to\n * `retryMaxMs`, reset by progress; denials wait the full max) — never a busy\n * retry. `stop()` aborts in-flight drains at their chunk boundary and leaves\n * every claim retryable; a restarted daemon's scheduler adopts them.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { hostname } from \"node:os\";\nimport { log } from \"../logger.js\";\nimport type { Orchestrator } from \"../orchestrator.js\";\nimport type { BufferDrainClaims, DrainLease } from \"../storage/buffer-drain-claims.js\";\nimport { BufferDrainRunner } from \"./buffer-drain-runner.js\";\nimport type { DrainRunnerEvent, DrainSessionOutcome } from \"./buffer-drain-runner.js\";\nimport type { ExtractionQueueCoordinator } from \"./extraction-queue-coordinator.js\";\nimport type { ProviderBreakerSnapshot } from \"./provider-breaker.js\";\n\n/** What the scheduler needs from its host (structurally satisfied by the\n * orchestrator wiring); injectable so tests drive ticks deterministically. */\nexport interface BacklogSchedulerDeps {\n queue: Pick<ExtractionQueueCoordinator, \"tryReserveKey\" | \"releaseKeyReservation\" | \"maxConcurrency\">;\n claims: Pick<BufferDrainClaims, \"list\" | \"listPage\" | \"claimFromSessionFile\" | \"isClaimed\">;\n /** Live per-key pending counts (counts only — never turn payloads). May be\n * async: hosts with a lazily-loaded buffer load it here (idempotent). */\n liveBufferCounts():\n | Map<string, { turns: number; retainedTurns: number }>\n | Promise<Map<string, { turns: number; retainedTurns: number }>>;\n /** Create a fresh lease for a unique owner token. */\n lease(ownerId: string): DrainLease;\n /** Drain one key to quiescence (BufferDrainRunner.drainSession). */\n drainKey(\n key: string,\n options: { ownerId: string; signal: AbortSignal; onEvent?: (event: DrainRunnerEvent) => void }\n ): Promise<DrainSessionOutcome>;\n /** Shared provider circuit-breaker snapshot (the same instance the run\n * coordinator gates attempts on). While OPEN inside its cooldown window\n * the scheduler skips submission entirely — claims stay durable, and the\n * breaker's single half-open probe (one attempt through once the window\n * lapses) keeps recovery automatic. Optional: hosts without a breaker\n * never skip. */\n breakerSnapshot?(): ProviderBreakerSnapshot;\n /** Test seam: monotonic-ish clock for backoff windows. */\n now?(): number;\n}\n\nexport interface BacklogSchedulerOptions {\n /** Optional label prefix; each scheduler instance adds a unique token. */\n ownerId?: string;\n /** Scan cadence in ms (startup + new-work + retry checks). */\n pollMs?: number;\n retryBaseMs?: number;\n retryMaxMs?: number;\n /** Bound on `stop()`'s wait for aborted drains to settle. */\n stopSettleTimeoutMs?: number;\n now?: () => number;\n}\n\nexport interface BacklogSchedulerCounters {\n /** Keys submitted to the drain (claimed or adopted) this process lifetime. */\n claimed: number;\n /** Outcomes with genuinely empty claims (durable outputs preceded ack). */\n processed: number;\n /** Sum of durable outputs (memories + entities) across processed drains. */\n durableOutputs: number;\n /** Re-submissions after a failed/deferred/denied outcome. */\n retried: number;\n denied: { keys: number; turns: number };\n failed: number;\n}\n\nexport type BacklogKeyState = \"inflight\" | \"backoff\" | \"denied\";\n\nexport interface BacklogKeySnapshot {\n key: string;\n state: BacklogKeyState;\n turnsRemaining?: number;\n reason?: string;\n}\n\nexport interface BacklogSchedulerSnapshot {\n counters: BacklogSchedulerCounters;\n inFlight: string[];\n reservedKeys: string[];\n keys: BacklogKeySnapshot[];\n}\n\ninterface KeyState {\n state: BacklogKeyState;\n nextAttemptMs: number;\n /** Last observed remaining turns; progress resets the backoff exponent. */\n turnsRemaining: number;\n reason?: string;\n backoffExponent: number;\n}\n\nconst DEFAULT_POLL_MS = 15_000;\nconst DEFAULT_RETRY_BASE_MS = 30_000;\nconst DEFAULT_RETRY_MAX_MS = 15 * 60_000;\n// Aborted drains normally settle within seconds (a chunk boundary); this only\n// bounds the pathological case, well inside the daemon's stop budget.\nconst DEFAULT_STOP_SETTLE_TIMEOUT_MS = 30_000;\n\nexport class BacklogScheduler {\n private readonly deps: BacklogSchedulerDeps;\n private readonly options: Required<Omit<BacklogSchedulerOptions, \"now\">> & Pick<BacklogSchedulerOptions, \"now\">;\n private readonly keys = new Map<string, KeyState>();\n private readonly inFlight = new Map<string, { controller: AbortController; settled: Promise<void> }>();\n private readonly reserved = new Set<string>();\n private readonly counters: BacklogSchedulerCounters = {\n claimed: 0,\n processed: 0,\n durableOutputs: 0,\n retried: 0,\n denied: { keys: 0, turns: 0 },\n failed: 0,\n };\n private claimCursor: string | undefined;\n private timer: ReturnType<typeof setInterval> | undefined;\n private ticking = false;\n private stopped = true;\n\n constructor(deps: BacklogSchedulerDeps, options: BacklogSchedulerOptions = {}) {\n this.deps = deps;\n this.options = {\n ownerId: `${options.ownerId ?? \"daemon-drain\"}-${randomUUID()}`,\n pollMs: options.pollMs ?? DEFAULT_POLL_MS,\n retryBaseMs: options.retryBaseMs ?? DEFAULT_RETRY_BASE_MS,\n retryMaxMs: options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS,\n stopSettleTimeoutMs: options.stopSettleTimeoutMs ?? DEFAULT_STOP_SETTLE_TIMEOUT_MS,\n now: options.now,\n };\n }\n\n /** Idempotent. Starts the poll timer (unref'd) and runs an initial tick. */\n start(): void {\n if (!this.stopped) return;\n this.stopped = false;\n this.timer = setInterval(() => void this.tick(), this.options.pollMs);\n this.timer.unref?.();\n void this.tick();\n }\n\n /** Idempotent. Stops the timer, aborts in-flight drains (their claims stay\n * retryable) and waits up to `stopSettleTimeoutMs` for them to settle. A\n * drain that ignores abort is named in a warning and left behind: the\n * caller's later shutdown phases (orchestrator flush and dispose) must\n * still run before the service manager's kill. */\n async stop(): Promise<void> {\n if (this.stopped) return;\n this.stopped = true;\n if (this.timer) {\n clearInterval(this.timer);\n this.timer = undefined;\n }\n const aborts: Promise<void>[] = [];\n for (const entry of this.inFlight.values()) {\n entry.controller.abort(new Error(\"backlog scheduler stopping\"));\n aborts.push(entry.settled);\n }\n const bound = Promise.withResolvers<\"timeout\">();\n const boundTimer = setTimeout(() => bound.resolve(\"timeout\"), this.options.stopSettleTimeoutMs);\n try {\n const result = await Promise.race([Promise.allSettled(aborts), bound.promise]);\n if (result === \"timeout\") {\n log.warn(\n `backlog scheduler stop: ${this.inFlight.size} drain(s) ignored abort for ${this.options.stopSettleTimeoutMs}ms; ` +\n `continuing shutdown (stuck keys: ${[...this.inFlight.keys()].join(\", \")})`,\n );\n }\n } finally {\n clearTimeout(boundTimer);\n }\n }\n\n /** Bounded snapshot for ops/watchers: counters + per-key states + live sets. */\n snapshot(): BacklogSchedulerSnapshot {\n return {\n counters: {\n claimed: this.counters.claimed,\n processed: this.counters.processed,\n durableOutputs: this.counters.durableOutputs,\n retried: this.counters.retried,\n denied: { ...this.counters.denied },\n failed: this.counters.failed,\n },\n inFlight: [...this.inFlight.keys()],\n reservedKeys: [...this.reserved],\n keys: [...this.keys.entries()].map(([key, state]) => ({\n key,\n state: state.state,\n turnsRemaining: state.turnsRemaining,\n reason: state.reason,\n })),\n };\n }\n\n /** One scan+submit pass (tests drive this instead of the timer). Waits out\n * any in-progress tick first so the pass always actually scans. */\n async tickForTest(): Promise<void> {\n // setImmediate: yields to the event loop so pending I/O (a slow first\n // scan) can finish; a microtask spin would starve it.\n while (this.ticking) await new Promise((resolve) => setImmediate(resolve));\n await this.tick();\n }\n\n /** Await the settle (slot release) of everything currently in flight,\n * optionally excluding one still-gated key (tests). */\n async settleForTest(exclude?: string): Promise<void> {\n for (;;) {\n const pending = [...this.inFlight.entries()].filter(([key]) => key !== exclude).map(([, entry]) => entry.settled);\n if (pending.length === 0) return;\n await Promise.allSettled(pending);\n }\n }\n\n private now(): number {\n return this.options.now?.() ?? Date.now();\n }\n\n private async tick(): Promise<void> {\n if (this.ticking || this.stopped) return;\n this.ticking = true;\n const cursorBeforeTick = this.claimCursor;\n try {\n // Fast bail: a breaker already open must not pay discovery I/O\n // (listPage reads and parses claim bodies on every poll). The\n // submitCandidates guard below still catches a breaker that opens\n // while discovery awaits.\n const breakerBeforeDiscovery = this.deps.breakerSnapshot?.();\n if (\n breakerBeforeDiscovery &&\n breakerBeforeDiscovery.state === \"open\" &&\n this.now() < breakerBeforeDiscovery.openUntilMs\n ) {\n return;\n }\n // stop() may land while discovery's I/O is pending: re-check before\n // submitting anything, and again per candidate.\n // A discovery failure (EACCES/EIO on the claims dir) must not reject\n // into a detached timer callback: it would be an unhandled rejection\n // that terminates the server. Log, skip this pass, retry next poll.\n let candidates: { key: string; needsClaim: boolean }[];\n try {\n candidates = await this.discoverCandidates();\n } catch (err) {\n // Discovery may have listed a page before it failed: the page cursor\n // already moved, so restore it — otherwise those claims wait for the\n // cursor to wrap instead of the next poll.\n this.claimCursor = cursorBeforeTick;\n log.warn(\n `backlog drain: discovery failed; retrying next poll: ${err instanceof Error ? err.message : String(err)}`\n );\n return;\n }\n if (this.stopped) return;\n const dropped = this.submitCandidates(candidates);\n // The concurrency bound stopped submission mid-page: rewind the page\n // cursor so the unsubmitted claims are re-listed on the next tick\n // (already-submitted ones are gated by inFlight and key backoff).\n if (dropped) this.claimCursor = cursorBeforeTick;\n } finally {\n this.ticking = false;\n }\n }\n\n /** Bounded discovery: ONE page of existing claims with pending turns */\n private async discoverCandidates(): Promise<{ key: string; needsClaim: boolean }[]> {\n const out: { key: string; needsClaim: boolean }[] = [];\n const seen = new Set<string>();\n const pageLimit = Math.max(this.submissionLimit() * 4, 16);\n const page = await this.deps.claims.listPage(this.claimCursor, pageLimit);\n for (const listed of page.entries) {\n seen.add(listed.key);\n out.push({ key: listed.key, needsClaim: false });\n }\n this.claimCursor = page.nextCursor;\n for (const [key, counts] of await this.deps.liveBufferCounts()) {\n if (counts.turns + counts.retainedTurns <= 0) continue;\n if (seen.has(key) || this.deps.claims.isClaimed(key)) continue;\n seen.add(key);\n out.push({ key, needsClaim: true });\n }\n return out;\n }\n\n /** Submission bound: the queue's own concurrency limit, read with the\n * documented \"0 disables\" contract — a zero limit submits nothing. */\n private submissionLimit(): number {\n if (this.deps.queue.maxConcurrency <= 0) return 0;\n return this.deps.queue.maxConcurrency;\n }\n\n /** Submit discovery candidates within the queue's concurrency bound. */\n private submitCandidates(candidates: { key: string; needsClaim: boolean }[]): boolean {\n // Breaker-open churn guard: a full attempt reads the claim, rebuilds the\n // buffer/coordinator and re-renders chunks before the breaker fails it\n // fast — pure heap pressure per poll during a provider stall. Skip while\n // the window is open; once it lapses, submissions resume and the\n // breaker's half-open probe runs as usual.\n const breaker = this.deps.breakerSnapshot?.();\n if (breaker && breaker.state === \"open\" && this.now() < breaker.openUntilMs) {\n return true;\n }\n let dropped = false;\n for (const candidate of candidates) {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) {\n dropped = true;\n break;\n }\n if (!this.candidateEligible(candidate)) continue;\n // Fence the claim decision: reserve the key synchronously BEFORE the\n // async rename so no queued task for it can pass the claimed gate in\n // the meantime. Release happens when the decision settles.\n if (candidate.needsClaim) {\n if (!this.deps.queue.tryReserveKey(candidate.key)) continue;\n this.reserved.add(candidate.key);\n }\n void this.submit(candidate.key, candidate.needsClaim);\n }\n return dropped;\n }\n\n /** inFlight is the authority for \"already submitted\" — key state only\n * exists once an outcome landed (backoff/denied gating below). */\n private candidateEligible(candidate: { key: string; needsClaim: boolean }): boolean {\n if (this.stopped || this.inFlight.size >= this.submissionLimit()) return false;\n if (this.inFlight.has(candidate.key)) return false;\n const state = this.keys.get(candidate.key);\n return !(state && this.now() < state.nextAttemptMs);\n }\n\n /** Claim (when needed), then drain one key; the reservation spans the async\n * claim decision, the queue entry carries the key afterwards. */\n private async submit(key: string, needsClaim: boolean): Promise<void> {\n const controller = new AbortController();\n const { promise: settled, resolve: settle } = Promise.withResolvers<void>();\n this.inFlight.set(key, { controller, settled });\n try {\n if (!(await this.claimForSubmit(key, needsClaim, this.options.ownerId))) return;\n // Stopped between the claim decision and the task: leave the claim\n // with its lease (it expires; the next start adopts) — never drain.\n if (this.stopped) return;\n await this.drainClaimedKey(key, controller.signal, this.options.ownerId);\n } catch (err) {\n // Claim/drain failures are scheduler-level: the claim content is\n // untouched — count failed and back off (never an unhandled rejection\n // in the detached submission).\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} submission failed: ${message}`);\n } finally {\n this.inFlight.delete(key);\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n settle();\n }\n }\n\n /** after all — the key goes quiet without a task. \"claimed\": ours. */\n private async claimForSubmit(key: string, needsClaim: boolean, ownerId: string): Promise<boolean> {\n if (!needsClaim) return true;\n try {\n const outcome = await this.deps.claims.claimFromSessionFile(key, this.deps.lease(ownerId));\n if (outcome === \"empty\") {\n this.keys.delete(key);\n return false;\n }\n return true;\n } finally {\n this.reserved.delete(key);\n this.deps.queue.releaseKeyReservation(key);\n }\n }\n\n /** Drain one claimed key. drainKey reports failures as outcomes; a thrown\n * error still means the claim content is intact — count it failed and\n * back off. */\n private async drainClaimedKey(key: string, signal: AbortSignal, ownerId: string): Promise<void> {\n this.counters.claimed += 1;\n try {\n const outcome = await this.deps.drainKey(key, {\n ownerId,\n signal,\n });\n this.applyOutcome(key, outcome);\n } catch (err) {\n this.counters.failed += 1;\n const message = err instanceof Error ? err.message : String(err);\n // SAFETY: a thrown non-Error (incl. null) carries no retry hint; the\n // optional chain reads the hint off Error throws only.\n this.setBackoff(key, (err as { turnsRemaining?: number } | null | undefined)?.turnsRemaining ?? 0, message);\n log.warn(`backlog drain: ${key} threw: ${message}`);\n }\n }\n\n private applyOutcome(key: string, outcome: DrainSessionOutcome): void {\n const deniedTurns = outcome.denied?.reduce((sum, entry) => sum + entry.turns, 0) ?? 0;\n const previous = this.keys.get(key);\n const progressed = outcome.turnsRemaining < (previous?.turnsRemaining ?? Number.POSITIVE_INFINITY);\n if (outcome.status === \"drained\") {\n // The claim is now an empty tombstone: authoritative, nothing pending.\n // New ingress consumes it via the native save path and re-candidates.\n this.keys.delete(key);\n this.counters.processed += 1;\n this.counters.durableOutputs += outcome.durableOutputCount;\n log.info(\n `backlog drain: ${key} drained (${outcome.turnsAtStart} turn(s), ${outcome.durableOutputCount} durable output(s))`\n );\n return;\n }\n this.recordNonDrainedCounters(previous, outcome, deniedTurns);\n const denied = deniedTurns > 0 && outcome.turnsRemaining > 0;\n this.keys.set(key, this.nextKeyState(previous, outcome, denied, progressed));\n log.info(\n `backlog drain: ${key} ${outcome.status} (${outcome.turnsRemaining} turn(s) remaining` +\n `${denied ? `, denied: ${deniedTurns}` : \"\"}${outcome.reason ? `, ${outcome.reason}` : \"\"})`\n );\n }\n\n /** Denied backlog counters for a non-drained outcome. */\n private recordNonDrainedCounters(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n deniedTurns: number\n ): void {\n if (deniedTurns > 0) {\n this.counters.denied.keys += 1;\n this.counters.denied.turns += deniedTurns;\n }\n if (outcome.status === \"failed\") this.counters.failed += 1;\n else if (previous !== undefined && (previous.state === \"backoff\" || previous.state === \"denied\"))\n this.counters.retried += 1;\n }\n\n /** The post-drain key state: denial waits the full max window (its content\n * is valid but currently unauthorized); progress resets the exponent. */\n private nextKeyState(\n previous: KeyState | undefined,\n outcome: DrainSessionOutcome,\n denied: boolean,\n progressed: boolean\n ): KeyState {\n return {\n state: denied ? \"denied\" : \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, progressed && !denied),\n turnsRemaining: outcome.turnsRemaining,\n reason: outcome.reason,\n backoffExponent: this.nextBackoffExponent(denied, progressed, previous),\n };\n }\n\n private nextBackoffExponent(denied: boolean, progressed: boolean, previous: KeyState | undefined): number {\n return denied || !progressed ? (previous?.backoffExponent ?? 0) + 1 : 0;\n }\n\n private backoffMs(previous: KeyState | undefined, progressed: boolean): number {\n if (previous?.state === \"denied\") return this.options.retryMaxMs;\n const exponent = progressed ? 0 : (previous?.backoffExponent ?? 0) + 1;\n return Math.min(this.options.retryBaseMs * 2 ** exponent, this.options.retryMaxMs);\n }\n\n private setBackoff(key: string, turnsRemaining: number, reason: string): void {\n const previous = this.keys.get(key);\n this.keys.set(key, {\n state: \"backoff\",\n nextAttemptMs: this.now() + this.backoffMs(previous, false),\n turnsRemaining,\n reason,\n backoffExponent: (previous?.backoffExponent ?? 0) + 1,\n });\n }\n}\n\n/** Lease lifetime for claims the scheduler takes (matches the runner default). */\nconst SCHEDULER_LEASE_MS = 120_000;\n\n/** Wire the scheduler to an orchestrator's own queue, claim store, live buffer\n * counts and drain runner — the daemon's single ownership point. */\nexport function wireBacklogScheduler(\n orchestrator: Orchestrator,\n options: BacklogSchedulerOptions = {}\n): BacklogScheduler {\n const runner = new BufferDrainRunner(orchestrator);\n return new BacklogScheduler(\n {\n queue: orchestrator.extractionQueueCoordinator,\n claims: orchestrator.storage.bufferDrainClaims(),\n liveBufferCounts: async () => {\n // The daemon's buffer may be lazy: ensure the persisted state is in\n // memory before counting (load is guarded/idempotent).\n await orchestrator.buffer.load();\n return orchestrator.buffer.entryCounts();\n },\n lease: (ownerId) => {\n const now = new Date().toISOString();\n return {\n ownerId,\n pid: process.pid,\n host: hostname(),\n acquiredAt: now,\n heartbeatAt: now,\n leaseMs: SCHEDULER_LEASE_MS,\n };\n },\n drainKey: (key, drainOptions) => runner.drainSession(key, drainOptions),\n // The orchestrator's one shared provider breaker (foreground and every\n // claim-backed drain accumulate toward the same threshold).\n breakerSnapshot: () => orchestrator.getExtractionResilienceStatus().breaker,\n },\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAuFzB,IAAM,kBAAkB;AACxB,IAAM,wBAAwB;AAC9B,IAAM,uBAAuB,KAAK;AAGlC,IAAM,iCAAiC;AAEhC,IAAM,mBAAN,MAAuB;AAAA,EACX;AAAA,EACA;AAAA,EACA,OAAO,oBAAI,IAAsB;AAAA,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SAAO,IAAI;AAAA,IACT;AAAA,MACE,OAAO,aAAa;AAAA,MACpB,QAAQ,aAAa,QAAQ,kBAAkB;AAAA,MAC/C,kBAAkB,YAAY;AAG5B,cAAM,aAAa,OAAO,KAAK;AAC/B,eAAO,aAAa,OAAO,YAAY;AAAA,MACzC;AAAA,MACA,OAAO,CAAC,YAAY;AAClB,cAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,eAAO;AAAA,UACL;AAAA,UACA,KAAK,QAAQ;AAAA,UACb,MAAM,SAAS;AAAA,UACf,YAAY;AAAA,UACZ,aAAa;AAAA,UACb,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,UAAU,CAAC,KAAK,iBAAiB,OAAO,aAAa,KAAK,YAAY;AAAA;AAAA;AAAA,MAGtE,iBAAiB,MAAM,aAAa,8BAA8B,EAAE;AAAA,IACtE;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BufferDrainRunner,
|
|
3
3
|
ClaimBufferStorage
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-QIPDTAWZ.js";
|
|
5
|
+
import "../chunk-MMOXCCHF.js";
|
|
6
6
|
import "../chunk-6P7U3HWG.js";
|
|
7
7
|
import "../chunk-PQM3B54K.js";
|
|
8
8
|
import "../chunk-B3DR2JBZ.js";
|
|
@@ -175,7 +175,7 @@ import "../chunk-MDPT6QFK.js";
|
|
|
175
175
|
import "../chunk-UOBPK2OS.js";
|
|
176
176
|
import "../chunk-2YA5N2BY.js";
|
|
177
177
|
import "../chunk-3HSRWJTC.js";
|
|
178
|
-
import "../chunk-
|
|
178
|
+
import "../chunk-PL36IQPL.js";
|
|
179
179
|
import "../chunk-HUDPXTXW.js";
|
|
180
180
|
import "../chunk-AZEZSQ5R.js";
|
|
181
181
|
import "../chunk-YAZNBMNF.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit-once bookkeeping for a queued extraction task (`onTaskExit`).
|
|
3
|
+
*
|
|
4
|
+
* A task settled (abort, queue deadline) before its closure ever ran has
|
|
5
|
+
* nothing to exit, so `settled()` reports exit at once; a claim-lease owner
|
|
6
|
+
* waiting on the exit is then not held behind an unrelated running extraction.
|
|
7
|
+
* A closure that did start reports exit when it finishes. Either way the
|
|
8
|
+
* callback fires exactly once.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTaskExit(onExit?: () => void): {
|
|
11
|
+
start: () => void;
|
|
12
|
+
settled: () => void;
|
|
13
|
+
report: () => void;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=task-exit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-exit.d.ts","sourceRoot":"","sources":["../../src/orchestration/task-exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI;;;kBAG7B,IAAI;EAcxB"}
|