@equationalapplications/core-llm-wiki 8.0.5 → 8.2.0
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/{chunk-GYF5QLYK.mjs → chunk-FOX6TNFO.mjs} +135 -31
- package/dist/chunk-FOX6TNFO.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +142 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -5
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-BPddGTkl.d.mts → testing-D6So3dKX.d.mts} +13 -3
- package/dist/{testing-BPddGTkl.d.ts → testing-D6So3dKX.d.ts} +13 -3
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +132 -28
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-GYF5QLYK.mjs.map +0 -1
|
@@ -802,7 +802,7 @@ type WikiDiagnosticSeverity = 'info' | 'warn' | 'error';
|
|
|
802
802
|
* Closed for this release series, but new codes are added in minor versions:
|
|
803
803
|
* hosts must tolerate codes they do not recognize.
|
|
804
804
|
*/
|
|
805
|
-
type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'contradicts_document' | 'resolve_failed' | 'read_budget' | 'event_retention_held';
|
|
805
|
+
type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'contradicts_document' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'event_created_at_clamped' | 'event_created_at_restamped';
|
|
806
806
|
/** The service run that emitted the diagnostic. */
|
|
807
807
|
type WikiDiagnosticOperation = 'ingest' | 'upsertGraph' | 'librarian' | 'heal' | 'ontologyBackfill' | 'reembed' | 'importDump' | 'write' | 'supersede' | 'remember' | 'read' | 'prune';
|
|
808
808
|
/** `'auto'` when a write threshold started the run (auto-librarian / auto-heal); `'call'` when the host did. */
|
|
@@ -937,6 +937,14 @@ interface MemoryBundle {
|
|
|
937
937
|
edges?: WikiEdge[];
|
|
938
938
|
/** Entity summary prose for OKF profile ≥ 1 round-trip. Omitted = no summary (Clanker default). */
|
|
939
939
|
summary?: string;
|
|
940
|
+
/**
|
|
941
|
+
* The source store's librarian position. Set by export only; the importer
|
|
942
|
+
* trusts events at or before it as consolidated at the source.
|
|
943
|
+
*/
|
|
944
|
+
librarian_watermark?: {
|
|
945
|
+
at: number;
|
|
946
|
+
id: string;
|
|
947
|
+
};
|
|
940
948
|
factScores?: Record<string, number>;
|
|
941
949
|
metadata?: {
|
|
942
950
|
query: string;
|
|
@@ -3034,7 +3042,8 @@ declare class EventRepository extends BaseRepository {
|
|
|
3034
3042
|
* Pass `tx` to participate in a caller-owned transaction; omit to run against the default db.
|
|
3035
3043
|
*/
|
|
3036
3044
|
add(event: WikiEvent, tx?: SQLiteAdapter): Promise<void>;
|
|
3037
|
-
|
|
3045
|
+
/** Insert unless the id already exists. Returns true when a row was inserted. */
|
|
3046
|
+
addIgnoreDuplicate(event: WikiEvent, tx?: SQLiteAdapter): Promise<boolean>;
|
|
3038
3047
|
/**
|
|
3039
3048
|
* Return the most recent events for an entity, newest first.
|
|
3040
3049
|
* Defaults to a limit of 50.
|
|
@@ -3471,7 +3480,8 @@ declare class ImportExportService {
|
|
|
3471
3480
|
private searchService;
|
|
3472
3481
|
private jobManager;
|
|
3473
3482
|
private embeddingService;
|
|
3474
|
-
|
|
3483
|
+
private options;
|
|
3484
|
+
constructor(db: SQLiteAdapter, entryRepo: EntryRepository, taskRepo: TaskRepository, eventRepo: EventRepository, edgeRepo: EdgeRepository, metadataRepo: MetadataRepository, searchService: SearchService, jobManager: JobManager, embeddingService: EmbeddingService, options?: Pick<WikiOptions, 'onDiagnostic'>);
|
|
3475
3485
|
exportDump(entityIds?: string[]): Promise<MemoryDump>;
|
|
3476
3486
|
importDump(dump: MemoryDump, opts?: {
|
|
3477
3487
|
merge?: boolean;
|
|
@@ -802,7 +802,7 @@ type WikiDiagnosticSeverity = 'info' | 'warn' | 'error';
|
|
|
802
802
|
* Closed for this release series, but new codes are added in minor versions:
|
|
803
803
|
* hosts must tolerate codes they do not recognize.
|
|
804
804
|
*/
|
|
805
|
-
type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'contradicts_document' | 'resolve_failed' | 'read_budget' | 'event_retention_held';
|
|
805
|
+
type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'contradicts_document' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'event_created_at_clamped' | 'event_created_at_restamped';
|
|
806
806
|
/** The service run that emitted the diagnostic. */
|
|
807
807
|
type WikiDiagnosticOperation = 'ingest' | 'upsertGraph' | 'librarian' | 'heal' | 'ontologyBackfill' | 'reembed' | 'importDump' | 'write' | 'supersede' | 'remember' | 'read' | 'prune';
|
|
808
808
|
/** `'auto'` when a write threshold started the run (auto-librarian / auto-heal); `'call'` when the host did. */
|
|
@@ -937,6 +937,14 @@ interface MemoryBundle {
|
|
|
937
937
|
edges?: WikiEdge[];
|
|
938
938
|
/** Entity summary prose for OKF profile ≥ 1 round-trip. Omitted = no summary (Clanker default). */
|
|
939
939
|
summary?: string;
|
|
940
|
+
/**
|
|
941
|
+
* The source store's librarian position. Set by export only; the importer
|
|
942
|
+
* trusts events at or before it as consolidated at the source.
|
|
943
|
+
*/
|
|
944
|
+
librarian_watermark?: {
|
|
945
|
+
at: number;
|
|
946
|
+
id: string;
|
|
947
|
+
};
|
|
940
948
|
factScores?: Record<string, number>;
|
|
941
949
|
metadata?: {
|
|
942
950
|
query: string;
|
|
@@ -3034,7 +3042,8 @@ declare class EventRepository extends BaseRepository {
|
|
|
3034
3042
|
* Pass `tx` to participate in a caller-owned transaction; omit to run against the default db.
|
|
3035
3043
|
*/
|
|
3036
3044
|
add(event: WikiEvent, tx?: SQLiteAdapter): Promise<void>;
|
|
3037
|
-
|
|
3045
|
+
/** Insert unless the id already exists. Returns true when a row was inserted. */
|
|
3046
|
+
addIgnoreDuplicate(event: WikiEvent, tx?: SQLiteAdapter): Promise<boolean>;
|
|
3038
3047
|
/**
|
|
3039
3048
|
* Return the most recent events for an entity, newest first.
|
|
3040
3049
|
* Defaults to a limit of 50.
|
|
@@ -3471,7 +3480,8 @@ declare class ImportExportService {
|
|
|
3471
3480
|
private searchService;
|
|
3472
3481
|
private jobManager;
|
|
3473
3482
|
private embeddingService;
|
|
3474
|
-
|
|
3483
|
+
private options;
|
|
3484
|
+
constructor(db: SQLiteAdapter, entryRepo: EntryRepository, taskRepo: TaskRepository, eventRepo: EventRepository, edgeRepo: EdgeRepository, metadataRepo: MetadataRepository, searchService: SearchService, jobManager: JobManager, embeddingService: EmbeddingService, options?: Pick<WikiOptions, 'onDiagnostic'>);
|
|
3475
3485
|
exportDump(entityIds?: string[]): Promise<MemoryDump>;
|
|
3476
3486
|
importDump(dump: MemoryDump, opts?: {
|
|
3477
3487
|
merge?: boolean;
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { aH as EmbeddingService, aI as ImportExportService, aJ as IngestionService, aK as JobManager, aK as JobManagerType, aL as MaintenanceService, aM as RetrievalService, aN as SearchService, aN as SearchServiceType, au as WikiMemoryTestAccess, aO as WriteService } from './testing-
|
|
1
|
+
export { aH as EmbeddingService, aI as ImportExportService, aJ as IngestionService, aK as JobManager, aK as JobManagerType, aL as MaintenanceService, aM as RetrievalService, aN as SearchService, aN as SearchServiceType, au as WikiMemoryTestAccess, aO as WriteService } from './testing-D6So3dKX.mjs';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { aH as EmbeddingService, aI as ImportExportService, aJ as IngestionService, aK as JobManager, aK as JobManagerType, aL as MaintenanceService, aM as RetrievalService, aN as SearchService, aN as SearchServiceType, au as WikiMemoryTestAccess, aO as WriteService } from './testing-
|
|
1
|
+
export { aH as EmbeddingService, aI as ImportExportService, aJ as IngestionService, aK as JobManager, aK as JobManagerType, aL as MaintenanceService, aM as RetrievalService, aN as SearchService, aN as SearchServiceType, au as WikiMemoryTestAccess, aO as WriteService } from './testing-D6So3dKX.js';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.js
CHANGED
|
@@ -712,7 +712,9 @@ var SEVERITY = {
|
|
|
712
712
|
contradicts_document: "warn",
|
|
713
713
|
resolve_failed: "warn",
|
|
714
714
|
read_budget: "info",
|
|
715
|
-
event_retention_held: "info"
|
|
715
|
+
event_retention_held: "info",
|
|
716
|
+
event_created_at_clamped: "warn",
|
|
717
|
+
event_created_at_restamped: "info"
|
|
716
718
|
};
|
|
717
719
|
var MESSAGE = {
|
|
718
720
|
ingest_chunk_failed: "One or more document chunks failed to parse or generate.",
|
|
@@ -734,7 +736,9 @@ var MESSAGE = {
|
|
|
734
736
|
contradicts_document: "A candidate contradicted a document fact and was stored as a draft.",
|
|
735
737
|
resolve_failed: "Reconciliation failed for a candidate; it was stored as a draft.",
|
|
736
738
|
read_budget: "A read was packed to a token budget.",
|
|
737
|
-
event_retention_held: "Event pruning was held back because the librarian has not processed those events yet."
|
|
739
|
+
event_retention_held: "Event pruning was held back because the librarian has not processed those events yet.",
|
|
740
|
+
event_created_at_clamped: "Imported events dated in the future were re-dated just after the current time, or after the librarian position if that is later, keeping their order.",
|
|
741
|
+
event_created_at_restamped: "Imported events that would have sorted behind the librarian position, or had an unusable date, were adjusted: an affected created_at was re-dated just after the current time, or after the librarian position if that is later, keeping their order; an unusable occurred_at was cleared."
|
|
738
742
|
};
|
|
739
743
|
var warnedNonFunction = /* @__PURE__ */ new WeakSet();
|
|
740
744
|
function copyDetail(detail) {
|
|
@@ -1065,11 +1069,92 @@ function entitySummaryMetaKey(entityId) {
|
|
|
1065
1069
|
return `entity_summary:${entityId}`;
|
|
1066
1070
|
}
|
|
1067
1071
|
var START_OF_LOG_WATERMARK = Object.freeze({ at: Number.MIN_SAFE_INTEGER, id: "" });
|
|
1072
|
+
|
|
1073
|
+
// src/services/legacyWatermark.ts
|
|
1074
|
+
async function anchorAtLegacyBoundary(metadataRepo, eventRepo, entityId, checkpoint, total, db) {
|
|
1075
|
+
if (checkpoint <= 0 || total <= 0) return null;
|
|
1076
|
+
const ev = await eventRepo.getAtOffset(entityId, Math.min(checkpoint, total) - 1, db);
|
|
1077
|
+
if (!ev) return null;
|
|
1078
|
+
const wm = { at: ev.created_at, id: ev.id };
|
|
1079
|
+
await metadataRepo.setLibrarianWatermark(entityId, wm, db);
|
|
1080
|
+
return wm;
|
|
1081
|
+
}
|
|
1082
|
+
async function seedLegacyWatermark(metadataRepo, eventRepo, entityId, db) {
|
|
1083
|
+
const existing = await metadataRepo.getLibrarianWatermark(entityId, db);
|
|
1084
|
+
if (existing) return existing;
|
|
1085
|
+
const memory = (await metadataRepo.getCheckpoint(entityId, db)).memory ?? 0;
|
|
1086
|
+
if (memory <= 0) return null;
|
|
1087
|
+
const total = await eventRepo.count(entityId, db);
|
|
1088
|
+
if (memory > total) {
|
|
1089
|
+
await metadataRepo.setLibrarianWatermark(entityId, START_OF_LOG_WATERMARK, db);
|
|
1090
|
+
return START_OF_LOG_WATERMARK;
|
|
1091
|
+
}
|
|
1092
|
+
return anchorAtLegacyBoundary(metadataRepo, eventRepo, entityId, memory, total, db);
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// src/services/importEventStamps.ts
|
|
1096
|
+
var DATE_MAX = 864e13;
|
|
1097
|
+
var DECIMAL_TEXT = /^\s*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?\s*$/;
|
|
1098
|
+
function createdAtValue(v) {
|
|
1099
|
+
if (typeof v === "number") return v;
|
|
1100
|
+
if (typeof v === "string" && DECIMAL_TEXT.test(v)) return Number(v);
|
|
1101
|
+
return NaN;
|
|
1102
|
+
}
|
|
1103
|
+
function isUsableDate(v) {
|
|
1104
|
+
return Number.isFinite(v) && v >= -DATE_MAX && v <= DATE_MAX;
|
|
1105
|
+
}
|
|
1106
|
+
function parseSourceWatermark(raw) {
|
|
1107
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return null;
|
|
1108
|
+
const { at, id } = raw;
|
|
1109
|
+
if (typeof at !== "number" || !Number.isFinite(at) || typeof id !== "string") return null;
|
|
1110
|
+
return { at, id };
|
|
1111
|
+
}
|
|
1112
|
+
var cmp = (a, b) => a === b ? 0 : a < b ? -1 : 1;
|
|
1113
|
+
function planEventStamps(events, ctx) {
|
|
1114
|
+
const { now, floor, merge, localWm, sourceWm } = ctx;
|
|
1115
|
+
const after = (v, id, wm) => v > wm.at || v === wm.at && id > wm.id;
|
|
1116
|
+
const plan = /* @__PURE__ */ new Map();
|
|
1117
|
+
const restamp = [];
|
|
1118
|
+
for (const e of events) {
|
|
1119
|
+
const v = createdAtValue(e.created_at);
|
|
1120
|
+
const o = createdAtValue(e.occurred_at);
|
|
1121
|
+
let occurredAt = null;
|
|
1122
|
+
let occurredInvalid = false;
|
|
1123
|
+
if (e.occurred_at != null) {
|
|
1124
|
+
if (isUsableDate(o)) occurredAt = Math.trunc(o);
|
|
1125
|
+
else occurredInvalid = true;
|
|
1126
|
+
}
|
|
1127
|
+
let reason = null;
|
|
1128
|
+
const invalidCreated = Number.isNaN(v) || v < -DATE_MAX;
|
|
1129
|
+
if (invalidCreated) reason = "invalid";
|
|
1130
|
+
else if (v > now) reason = "future";
|
|
1131
|
+
else if (merge && localWm !== null && Number.isFinite(localWm.at) && !after(v, e.id, localWm) && (sourceWm === null || after(v, e.id, sourceWm))) {
|
|
1132
|
+
reason = "behind_watermark";
|
|
1133
|
+
}
|
|
1134
|
+
if (reason === "behind_watermark" && occurredAt === null && Number.isFinite(v) && v >= 0) {
|
|
1135
|
+
occurredAt = Math.trunc(v);
|
|
1136
|
+
}
|
|
1137
|
+
const stamp = { createdAt: v, occurredAt, reason };
|
|
1138
|
+
if (reason === null && occurredInvalid) stamp.reason = "invalid";
|
|
1139
|
+
plan.set(e, stamp);
|
|
1140
|
+
if (reason !== null) restamp.push({ e, key: invalidCreated ? -Infinity : v, stamp });
|
|
1141
|
+
}
|
|
1142
|
+
restamp.sort((x, y) => cmp(x.key, y.key) || cmp(x.e.id, y.e.id));
|
|
1143
|
+
if (restamp.length > 0 && floor + restamp.length > Number.MAX_SAFE_INTEGER) {
|
|
1144
|
+
throw new RangeError(`importDump: cannot re-date ${restamp.length} event(s): the floor (${floor}) is too close to Number.MAX_SAFE_INTEGER to keep them ordered.`);
|
|
1145
|
+
}
|
|
1146
|
+
restamp.forEach((x, i) => {
|
|
1147
|
+
x.stamp.createdAt = floor + 1 + i;
|
|
1148
|
+
});
|
|
1149
|
+
return plan;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// src/services/ImportExportService.ts
|
|
1068
1153
|
var MAX_EMBEDDING_BLOB_BYTES = 32 * 1024;
|
|
1069
1154
|
var IMPORT_TITLE_MAX = 500;
|
|
1070
1155
|
var IMPORT_BODY_MAX = 8e3;
|
|
1071
1156
|
var ImportExportService = class {
|
|
1072
|
-
constructor(db, entryRepo, taskRepo, eventRepo, edgeRepo, metadataRepo, searchService, jobManager, embeddingService) {
|
|
1157
|
+
constructor(db, entryRepo, taskRepo, eventRepo, edgeRepo, metadataRepo, searchService, jobManager, embeddingService, options = {}) {
|
|
1073
1158
|
this.db = db;
|
|
1074
1159
|
this.entryRepo = entryRepo;
|
|
1075
1160
|
this.taskRepo = taskRepo;
|
|
@@ -1079,6 +1164,7 @@ var ImportExportService = class {
|
|
|
1079
1164
|
this.searchService = searchService;
|
|
1080
1165
|
this.jobManager = jobManager;
|
|
1081
1166
|
this.embeddingService = embeddingService;
|
|
1167
|
+
this.options = options;
|
|
1082
1168
|
}
|
|
1083
1169
|
async exportDump(entityIds) {
|
|
1084
1170
|
let ids;
|
|
@@ -1119,6 +1205,7 @@ var ImportExportService = class {
|
|
|
1119
1205
|
}
|
|
1120
1206
|
}
|
|
1121
1207
|
async getFullBundle(entityId, opts) {
|
|
1208
|
+
const wm = await this.metadataRepo.getLibrarianWatermark(entityId, this.db);
|
|
1122
1209
|
const [factsRaw, tasks, events, edges, summaryValue] = await Promise.all([
|
|
1123
1210
|
opts?.includeBlobs ? this.entryRepo.findAllByEntityIdWithBlobs(entityId) : this.entryRepo.findAllByEntityId(entityId),
|
|
1124
1211
|
this.taskRepo.findAllByEntityId(entityId),
|
|
@@ -1148,7 +1235,8 @@ var ImportExportService = class {
|
|
|
1148
1235
|
tasks,
|
|
1149
1236
|
events,
|
|
1150
1237
|
edges,
|
|
1151
|
-
...summaryValue != null ? { summary: summaryValue } : {}
|
|
1238
|
+
...summaryValue != null ? { summary: summaryValue } : {},
|
|
1239
|
+
...wm ? { librarian_watermark: wm } : {}
|
|
1152
1240
|
};
|
|
1153
1241
|
}
|
|
1154
1242
|
/** Single-entity import transaction + post-processing; package-internal hook for tests. */
|
|
@@ -1159,6 +1247,8 @@ var ImportExportService = class {
|
|
|
1159
1247
|
const preservedBlobDims = /* @__PURE__ */ new Set();
|
|
1160
1248
|
const softDeletedFactIds = [];
|
|
1161
1249
|
const clippedTextByFactId = /* @__PURE__ */ new Map();
|
|
1250
|
+
let clampedEvents = 0;
|
|
1251
|
+
const restamped = { behind_watermark: 0, invalid: 0 };
|
|
1162
1252
|
await this.db.withTransactionAsync(async (tx) => {
|
|
1163
1253
|
if (!merge) {
|
|
1164
1254
|
const deletedLiveFactIds = await this.entryRepo.findIdsBySource(
|
|
@@ -1379,19 +1469,27 @@ var ImportExportService = class {
|
|
|
1379
1469
|
updated_at: safeUpdatedAt
|
|
1380
1470
|
});
|
|
1381
1471
|
}
|
|
1472
|
+
const now = Date.now();
|
|
1473
|
+
const wm = bundle.events.length > 0 ? await seedLegacyWatermark(this.metadataRepo, this.eventRepo, entityId, tx) : await this.metadataRepo.getLibrarianWatermark(entityId, tx);
|
|
1474
|
+
const floor = wm && Number.isFinite(wm.at) && wm.at > now ? wm.at : now;
|
|
1475
|
+
const planned = planEventStamps(bundle.events, { now, floor, merge, localWm: wm, sourceWm: parseSourceWatermark(bundle.librarian_watermark) });
|
|
1382
1476
|
for (const event of bundle.events) {
|
|
1383
|
-
|
|
1477
|
+
const stamp = planned.get(event);
|
|
1478
|
+
const inserted = await this.eventRepo.addIgnoreDuplicate(
|
|
1384
1479
|
{
|
|
1385
1480
|
id: event.id,
|
|
1386
1481
|
entity_id: entityId,
|
|
1387
1482
|
event_type: event.event_type,
|
|
1388
1483
|
summary: event.summary,
|
|
1389
1484
|
related_entry_id: event.related_entry_id ?? null,
|
|
1390
|
-
created_at:
|
|
1391
|
-
occurred_at:
|
|
1485
|
+
created_at: stamp.createdAt,
|
|
1486
|
+
occurred_at: stamp.occurredAt
|
|
1392
1487
|
},
|
|
1393
1488
|
tx
|
|
1394
1489
|
);
|
|
1490
|
+
if (!inserted || stamp.reason === null) continue;
|
|
1491
|
+
if (stamp.reason === "future") clampedEvents++;
|
|
1492
|
+
else restamped[stamp.reason]++;
|
|
1395
1493
|
}
|
|
1396
1494
|
for (const edge of bundle.edges ?? []) {
|
|
1397
1495
|
await this.edgeRepo.addIgnoreDuplicate(
|
|
@@ -1407,6 +1505,26 @@ var ImportExportService = class {
|
|
|
1407
1505
|
);
|
|
1408
1506
|
}
|
|
1409
1507
|
});
|
|
1508
|
+
if (clampedEvents > 0) {
|
|
1509
|
+
emitDiagnostic(this.options, {
|
|
1510
|
+
code: "event_created_at_clamped",
|
|
1511
|
+
operation: "importDump",
|
|
1512
|
+
trigger: "call",
|
|
1513
|
+
entityId,
|
|
1514
|
+
detail: { count: clampedEvents }
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
for (const reason of ["behind_watermark", "invalid"]) {
|
|
1518
|
+
if (restamped[reason] > 0) {
|
|
1519
|
+
emitDiagnostic(this.options, {
|
|
1520
|
+
code: "event_created_at_restamped",
|
|
1521
|
+
operation: "importDump",
|
|
1522
|
+
trigger: "call",
|
|
1523
|
+
entityId,
|
|
1524
|
+
detail: { count: restamped[reason], reason }
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1410
1528
|
if (merge) {
|
|
1411
1529
|
await this.searchService.syncEntries(entityId, [...upsertedFactIds]);
|
|
1412
1530
|
} else {
|
|
@@ -4518,13 +4636,8 @@ var MaintenanceService = class {
|
|
|
4518
4636
|
* nothing and returns null when there is no legacy history or no such
|
|
4519
4637
|
* event; each caller picks its own fallback.
|
|
4520
4638
|
*/
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
const ev = await this.eventRepo.getAtOffset(entityId, Math.min(checkpoint, total) - 1, db);
|
|
4524
|
-
if (!ev) return null;
|
|
4525
|
-
const wm = { at: ev.created_at, id: ev.id };
|
|
4526
|
-
await this.metadataRepo.setLibrarianWatermark(entityId, wm, db);
|
|
4527
|
-
return wm;
|
|
4639
|
+
anchorAtLegacyBoundary(entityId, checkpoint, total, db) {
|
|
4640
|
+
return anchorAtLegacyBoundary(this.metadataRepo, this.eventRepo, entityId, checkpoint, total, db);
|
|
4528
4641
|
}
|
|
4529
4642
|
/**
|
|
4530
4643
|
* Spec §10.3: first ops pass on a legacy DB starts after what the count
|
|
@@ -4534,16 +4647,7 @@ var MaintenanceService = class {
|
|
|
4534
4647
|
* drift and gets {@link START_OF_LOG_WATERMARK} (spec ops-auto-first-batch §2).
|
|
4535
4648
|
*/
|
|
4536
4649
|
async seedLibrarianWatermark(entityId) {
|
|
4537
|
-
|
|
4538
|
-
const cp = await this.metadataRepo.getCheckpoint(entityId, this.db);
|
|
4539
|
-
const memory = cp.memory ?? 0;
|
|
4540
|
-
if (memory <= 0) return;
|
|
4541
|
-
const total = await this.eventRepo.count(entityId, this.db);
|
|
4542
|
-
if (memory > total) {
|
|
4543
|
-
await this.metadataRepo.setLibrarianWatermark(entityId, START_OF_LOG_WATERMARK, this.db);
|
|
4544
|
-
return;
|
|
4545
|
-
}
|
|
4546
|
-
await this.anchorAtLegacyBoundary(entityId, memory, total, this.db);
|
|
4650
|
+
await seedLegacyWatermark(this.metadataRepo, this.eventRepo, entityId, this.db);
|
|
4547
4651
|
}
|
|
4548
4652
|
/**
|
|
4549
4653
|
* Core heal pass (locks handled by {@link runHeal}). Package-internal orchestration hook.
|
|
@@ -5543,7 +5647,7 @@ var RetrievalService = class {
|
|
|
5543
5647
|
if (topK.length < maxBackfill) {
|
|
5544
5648
|
let insertIdx = topK.length;
|
|
5545
5649
|
for (let i = 0; i < topK.length; i++) {
|
|
5546
|
-
const
|
|
5650
|
+
const cmp2 = this._compareScoredRows(
|
|
5547
5651
|
{
|
|
5548
5652
|
id: candidate.row.id,
|
|
5549
5653
|
score: candidate.kwScore,
|
|
@@ -5557,7 +5661,7 @@ var RetrievalService = class {
|
|
|
5557
5661
|
access_count: topK[i].row.access_count
|
|
5558
5662
|
}
|
|
5559
5663
|
);
|
|
5560
|
-
if (
|
|
5664
|
+
if (cmp2 < 0) {
|
|
5561
5665
|
insertIdx = i;
|
|
5562
5666
|
break;
|
|
5563
5667
|
}
|
|
@@ -5581,7 +5685,7 @@ var RetrievalService = class {
|
|
|
5581
5685
|
if (cmpWorst < 0) {
|
|
5582
5686
|
let insertIdx = maxBackfill - 1;
|
|
5583
5687
|
for (let i = 0; i < topK.length; i++) {
|
|
5584
|
-
const
|
|
5688
|
+
const cmp2 = this._compareScoredRows(
|
|
5585
5689
|
{
|
|
5586
5690
|
id: candidate.row.id,
|
|
5587
5691
|
score: candidate.kwScore,
|
|
@@ -5595,7 +5699,7 @@ var RetrievalService = class {
|
|
|
5595
5699
|
access_count: topK[i].row.access_count
|
|
5596
5700
|
}
|
|
5597
5701
|
);
|
|
5598
|
-
if (
|
|
5702
|
+
if (cmp2 < 0) {
|
|
5599
5703
|
insertIdx = i;
|
|
5600
5704
|
break;
|
|
5601
5705
|
}
|