niceeval 0.16.2-canary.98 → 0.16.2
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/inspection/facts.cjs +86 -31
- package/dist/inspection/facts.cjs.map +1 -1
- package/dist/inspection/facts.d.cts +2 -2
- package/dist/inspection/facts.d.mts +2 -2
- package/dist/inspection/facts.d.ts +2 -2
- package/dist/inspection/overview.cjs +2 -1
- package/dist/inspection/overview.cjs.map +1 -1
- package/dist/inspection/project-source.cjs +28 -19
- package/dist/inspection/project-source.cjs.map +1 -1
- package/dist/inspection/protocol.d.cts +17 -17
- package/dist/inspection/protocol.d.mts +17 -17
- package/dist/inspection/protocol.d.ts +17 -17
- package/dist/inspection/select.cjs +10 -6
- package/dist/inspection/select.cjs.map +1 -1
- package/dist/inspection/source.cjs +4 -2
- package/dist/inspection/source.cjs.map +1 -1
- package/dist/inspection/source.d.cts +1 -0
- package/dist/inspection/source.d.mts +1 -0
- package/dist/inspection/source.d.ts +1 -0
- package/dist/record/sqlite/database.cjs +2 -8
- package/dist/record/sqlite/database.cjs.map +1 -1
- package/dist/record/sqlite/index.cjs +13 -11
- package/dist/record/sqlite/index.cjs.map +1 -1
- package/dist/record/sqlite/index.d.cts +4 -2
- package/dist/record/sqlite/index.d.mts +4 -2
- package/dist/record/sqlite/index.d.ts +4 -2
- package/dist/record/sqlite/storage.cjs +118 -64
- package/dist/record/sqlite/storage.cjs.map +1 -1
- package/dist/record/sqlite/storage.d.cts +12 -5
- package/dist/record/sqlite/storage.d.mts +12 -5
- package/dist/record/sqlite/storage.d.ts +12 -5
- package/dist/record/sqlite/storage.js +48 -44
- package/dist/record/sqlite/types.cjs.map +1 -1
- package/dist/record/sqlite/types.d.cts +1 -1
- package/dist/record/sqlite/types.d.mts +1 -1
- package/dist/record/sqlite/types.d.ts +1 -1
- package/dist/view/cli/contribution.cjs +3 -2
- package/dist/view/cli/contribution.cjs.map +1 -1
- package/dist/view/function-runtime.mjs +251 -464
- package/package.json +1 -1
|
@@ -10344,6 +10344,7 @@ Object.freeze({
|
|
|
10344
10344
|
//#region src/record/sqlite/types.ts
|
|
10345
10345
|
var RECORD_SQLITE_FORMAT = "niceeval.project-database/0.18";
|
|
10346
10346
|
var RECORD_SQLITE_MAX_ROW_BYTES = 1048576;
|
|
10347
|
+
var RECORD_SQLITE_MAX_VALIDATION_RUNS = 1e5;
|
|
10347
10348
|
var RECORD_SQLITE_VALIDATION_DEADLINE_MS = 3e4;
|
|
10348
10349
|
//#endregion
|
|
10349
10350
|
//#region src/coordination/platform/node-process-identity.ts
|
|
@@ -10797,9 +10798,6 @@ function openRecordReaderAfterRuntimeAdmission(path) {
|
|
|
10797
10798
|
db.setAuthorizer(readerAuthorizer);
|
|
10798
10799
|
validateExactSchema(connection);
|
|
10799
10800
|
requireMigrationReady(connection);
|
|
10800
|
-
const integrity = currentStatement(db, "PRAGMA quick_check").get();
|
|
10801
|
-
if (integrity === void 0 || decodeText(integrity.quick_check, "quick_check") !== "ok") throw sqliteError("record-database-invalid", "open", "ProjectDatabase integrity check failed");
|
|
10802
|
-
if (currentStatement(db, "PRAGMA foreign_key_check").get() !== void 0) throw sqliteError("record-database-invalid", "open", "ProjectDatabase foreign key closure is invalid");
|
|
10803
10801
|
return connection;
|
|
10804
10802
|
} catch (cause) {
|
|
10805
10803
|
db.close();
|
|
@@ -11003,137 +11001,8 @@ function hashCanonicalTuple(domain, parts) {
|
|
|
11003
11001
|
for (const part of parts) updatePart(hash, part);
|
|
11004
11002
|
return hash.digest("hex");
|
|
11005
11003
|
}
|
|
11006
|
-
/** Durable Record identities keep both their domain and canonical tuple order here. */
|
|
11007
|
-
function attachmentId(input) {
|
|
11008
|
-
return hashCanonicalTuple("niceeval.record.attachment-id/v1", [
|
|
11009
|
-
input.runId,
|
|
11010
|
-
input.owner,
|
|
11011
|
-
input.owner === "attempt" ? input.attemptId ?? null : null,
|
|
11012
|
-
input.family
|
|
11013
|
-
]);
|
|
11014
|
-
}
|
|
11015
|
-
function contentId(attachment, logicalHandle) {
|
|
11016
|
-
return hashCanonicalTuple("niceeval.record.content-id/v1", [attachment, logicalHandle]);
|
|
11017
|
-
}
|
|
11018
|
-
function attachmentLogicalIdentity(attachment, canonicalDigest, inventoryDigest) {
|
|
11019
|
-
return hashCanonicalTuple("niceeval.record.attachment-logical-identity/v1", [
|
|
11020
|
-
attachment,
|
|
11021
|
-
canonicalDigest,
|
|
11022
|
-
inventoryDigest
|
|
11023
|
-
]);
|
|
11024
|
-
}
|
|
11025
|
-
function collectionItemLogicalIdentity(ordinal, canonicalDigest) {
|
|
11026
|
-
return hashCanonicalTuple("niceeval.record.collection-item-logical-identity/v1", [ordinal, canonicalDigest]);
|
|
11027
|
-
}
|
|
11028
|
-
function entry(kind, identity, closure) {
|
|
11029
|
-
return Object.freeze({
|
|
11030
|
-
kind,
|
|
11031
|
-
logicalIdentity: hashCanonicalTuple(`niceeval.record.seal.${kind}.identity/v1`, identity),
|
|
11032
|
-
digest: hashCanonicalTuple(`niceeval.record.seal.${kind}.closure/v1`, closure)
|
|
11033
|
-
});
|
|
11034
|
-
}
|
|
11035
|
-
var recordSealEntry = (recordDigest) => entry("record", ["record"], [recordDigest]);
|
|
11036
|
-
var runSealEntry = (input) => entry("run", [input.runId], [
|
|
11037
|
-
input.writerGeneration,
|
|
11038
|
-
input.startedAt,
|
|
11039
|
-
input.coreDigest
|
|
11040
|
-
]);
|
|
11041
|
-
var slotSealEntry = (runId, slot) => entry("slot", [runId, slot.slotId], [slot.ordinal, slot.coreDigest]);
|
|
11042
|
-
var attemptSealEntry = (runId, attemptId, attemptLocator, coreDigest) => entry("attempt", [runId, attemptId], [attemptLocator, coreDigest]);
|
|
11043
|
-
var memberSealEntry = (runId, member) => entry("member", [runId, member.slotId], [
|
|
11044
|
-
member.originRunId ?? null,
|
|
11045
|
-
member.attemptId ?? null,
|
|
11046
|
-
member.action,
|
|
11047
|
-
member.coreDigest
|
|
11048
|
-
]);
|
|
11049
|
-
var attachmentSealEntry = (input) => entry("attachment", [input.attachmentId], [
|
|
11050
|
-
input.ownerKind,
|
|
11051
|
-
input.ownerRunId,
|
|
11052
|
-
input.ownerAttemptId ?? null,
|
|
11053
|
-
input.family,
|
|
11054
|
-
input.familyRevision,
|
|
11055
|
-
input.logicalIdentity,
|
|
11056
|
-
input.canonicalDigest,
|
|
11057
|
-
input.inventoryDigest
|
|
11058
|
-
]);
|
|
11059
|
-
var referenceSealEntry = (attachmentId, reference) => entry("attachment-reference", [attachmentId, reference.ordinal], [
|
|
11060
|
-
reference.owner,
|
|
11061
|
-
reference.family,
|
|
11062
|
-
reference.referenceDigest
|
|
11063
|
-
]);
|
|
11064
|
-
var collectionItemSealEntry = (attachmentId, item) => entry("collection-item", [attachmentId, item.ordinal], [item.logicalIdentity, item.canonicalDigest]);
|
|
11065
|
-
var contentSealEntry = (attachmentId, content) => entry("content", [content.contentId], [
|
|
11066
|
-
attachmentId,
|
|
11067
|
-
content.logicalHandle,
|
|
11068
|
-
content.byteLength,
|
|
11069
|
-
content.digest,
|
|
11070
|
-
content.chunkCount
|
|
11071
|
-
]);
|
|
11072
|
-
var contentChunkSealEntry = (contentId, ordinal, chunkDigest) => entry("content-chunk", [contentId, ordinal], [chunkDigest]);
|
|
11073
|
-
/** Hashes an already canonically ordered iterator without materializing it. */
|
|
11074
|
-
function exactLogicalSealIdentityFromOrdered(entries, count) {
|
|
11075
|
-
if (!Number.isSafeInteger(count) || count < 0) throw new TypeError("logical Seal entry count is invalid");
|
|
11076
|
-
const hash = createHash("sha256");
|
|
11077
|
-
updatePart(hash, "niceeval.record.logical-seal/v1");
|
|
11078
|
-
updatePart(hash, count);
|
|
11079
|
-
let observed = 0;
|
|
11080
|
-
for (const value of entries) {
|
|
11081
|
-
updatePart(hash, value.kind);
|
|
11082
|
-
updatePart(hash, value.logicalIdentity);
|
|
11083
|
-
updatePart(hash, value.digest);
|
|
11084
|
-
observed += 1;
|
|
11085
|
-
}
|
|
11086
|
-
if (observed !== count) throw new TypeError("logical Seal ordered iterator count changed");
|
|
11087
|
-
return hash.digest("hex");
|
|
11088
|
-
}
|
|
11089
11004
|
//#endregion
|
|
11090
11005
|
//#region src/record/sqlite/storage.ts
|
|
11091
|
-
var DIGEST = /^[0-9a-f]{64}$/u;
|
|
11092
|
-
function ensurePreparedSealTables(connection) {
|
|
11093
|
-
if (connection.mode !== "reader") connection.db.exec(RECORD_SQLITE_PREPARED_SEAL_TEMP_SQL);
|
|
11094
|
-
}
|
|
11095
|
-
function spillPreparedSealEntries(connection, runId, visitClosure) {
|
|
11096
|
-
ensurePreparedSealTables(connection);
|
|
11097
|
-
connection.db.exec("SAVEPOINT niceeval_prepare_seal");
|
|
11098
|
-
try {
|
|
11099
|
-
recordStatement(connection, "DELETE FROM temp.niceeval_prepared_seal_raw WHERE run_id=?").run(runId);
|
|
11100
|
-
recordStatement(connection, "DELETE FROM temp.niceeval_prepared_seal_ordered WHERE run_id=?").run(runId);
|
|
11101
|
-
const insertRaw = recordStatement(connection, `INSERT INTO temp.niceeval_prepared_seal_raw
|
|
11102
|
-
(run_id,entry_kind,logical_identity,digest) VALUES (?,?,?,?)`);
|
|
11103
|
-
let count = 0;
|
|
11104
|
-
visitClosure((entry) => {
|
|
11105
|
-
insertRaw.run(runId, entry.kind, entry.logicalIdentity, entry.digest);
|
|
11106
|
-
count += 1;
|
|
11107
|
-
});
|
|
11108
|
-
const insertOrdered = recordStatement(connection, `INSERT INTO temp.niceeval_prepared_seal_ordered
|
|
11109
|
-
(run_id,ordinal,entry_kind,logical_identity,digest) VALUES (?,?,?,?,?)`);
|
|
11110
|
-
const orderedRows = recordStatement(connection, `SELECT entry_kind,logical_identity,digest
|
|
11111
|
-
FROM temp.niceeval_prepared_seal_raw WHERE run_id=? ORDER BY entry_kind,logical_identity,digest`).iterate(runId);
|
|
11112
|
-
function* ordered() {
|
|
11113
|
-
let ordinal = 0;
|
|
11114
|
-
for (const row of orderedRows) {
|
|
11115
|
-
const entry = Object.freeze({
|
|
11116
|
-
kind: sealEntryKind(row, "entry_kind"),
|
|
11117
|
-
logicalIdentity: text$2(row, "logical_identity"),
|
|
11118
|
-
digest: text$2(row, "digest")
|
|
11119
|
-
});
|
|
11120
|
-
insertOrdered.run(runId, ordinal, entry.kind, entry.logicalIdentity, entry.digest);
|
|
11121
|
-
ordinal += 1;
|
|
11122
|
-
yield entry;
|
|
11123
|
-
}
|
|
11124
|
-
}
|
|
11125
|
-
const identity = exactLogicalSealIdentityFromOrdered(ordered(), count);
|
|
11126
|
-
recordStatement(connection, "DELETE FROM temp.niceeval_prepared_seal_raw WHERE run_id=?").run(runId);
|
|
11127
|
-
connection.db.exec("RELEASE niceeval_prepare_seal");
|
|
11128
|
-
return Object.freeze({
|
|
11129
|
-
identity,
|
|
11130
|
-
count
|
|
11131
|
-
});
|
|
11132
|
-
} catch (cause) {
|
|
11133
|
-
connection.db.exec("ROLLBACK TO niceeval_prepare_seal; RELEASE niceeval_prepare_seal");
|
|
11134
|
-
throw cause;
|
|
11135
|
-
}
|
|
11136
|
-
}
|
|
11137
11006
|
function text$2(row, field) {
|
|
11138
11007
|
const value = row[field];
|
|
11139
11008
|
if (typeof value !== "string") throw sqliteError("record-database-invalid", "decode-row", `${field} is not text`);
|
|
@@ -11186,11 +11055,6 @@ function absenceMember(row) {
|
|
|
11186
11055
|
coreDigest: digestBytes(coreBytes)
|
|
11187
11056
|
});
|
|
11188
11057
|
}
|
|
11189
|
-
function sealEntryKind(row, field) {
|
|
11190
|
-
const value = text$2(row, field);
|
|
11191
|
-
if (value !== "record" && value !== "run" && value !== "slot" && value !== "member" && value !== "attempt" && value !== "attachment" && value !== "attachment-reference" && value !== "collection-item" && value !== "content" && value !== "content-chunk") throw sqliteError("record-database-invalid", "decode-row", `${field} is not a Seal entry kind`);
|
|
11192
|
-
return value;
|
|
11193
|
-
}
|
|
11194
11058
|
function bytes(row, field) {
|
|
11195
11059
|
const value = row[field];
|
|
11196
11060
|
if (!(value instanceof Uint8Array)) throw sqliteError("record-database-invalid", "decode-row", `${field} is not bytes`);
|
|
@@ -11202,9 +11066,6 @@ function digestBytes(value) {
|
|
|
11202
11066
|
function transferableBytes(value) {
|
|
11203
11067
|
return value.buffer instanceof ArrayBuffer && value.byteOffset === 0 && value.byteLength === value.buffer.byteLength ? value : Uint8Array.from(value);
|
|
11204
11068
|
}
|
|
11205
|
-
function requireDigest(value, field) {
|
|
11206
|
-
if (!DIGEST.test(value)) throw sqliteError("record-content-invalid", "persist-sealed-run", `${field} is not a lowercase sha256 digest`);
|
|
11207
|
-
}
|
|
11208
11069
|
function requireIdentity$1(value, field) {
|
|
11209
11070
|
try {
|
|
11210
11071
|
assertCanonicalIdentity(value, field);
|
|
@@ -11212,269 +11073,112 @@ function requireIdentity$1(value, field) {
|
|
|
11212
11073
|
throw sqliteError("record-content-invalid", "persist-sealed-run", cause instanceof Error ? cause.message : `${field} is invalid`);
|
|
11213
11074
|
}
|
|
11214
11075
|
}
|
|
11215
|
-
function requireAttemptLocator(attemptId, locator, operation = "persist-sealed-run") {
|
|
11216
|
-
if (!parseAttemptLocator(locator).valid || encodeAttemptLocator(attemptId) !== locator) throw sqliteError("record-content-invalid", operation, `Attempt ${attemptId} locator is not its canonical projection`);
|
|
11217
|
-
}
|
|
11218
11076
|
function rows(connection, sql, ...parameters) {
|
|
11219
11077
|
return recordStatement(connection, sql).all(...parameters);
|
|
11220
11078
|
}
|
|
11221
|
-
function visitRunSealEntries(connection, runId, visit, verifyPayloadBytes = true, verifyContentChunkBytes = verifyPayloadBytes) {
|
|
11222
|
-
const verified = (row, digestField, payloadField) => {
|
|
11223
|
-
const value = text$2(row, digestField);
|
|
11224
|
-
requireDigest(value, digestField);
|
|
11225
|
-
if (verifyPayloadBytes && digestBytes(bytes(row, payloadField)) !== value) throw sqliteError("record-seal-incomplete", "verify-seal", `${payloadField} does not match ${digestField}`);
|
|
11226
|
-
return value;
|
|
11227
|
-
};
|
|
11228
|
-
visit(recordSealEntry(verified(recordStatement(connection, "SELECT record_payload,record_digest FROM ne18_record_metadata WHERE singleton=1").get(), "record_digest", "record_payload")));
|
|
11229
|
-
const run = recordStatement(connection, `SELECT run_id,writer_generation,started_at,core_payload,core_digest FROM ne18_runs WHERE run_id=?`).get(runId);
|
|
11230
|
-
if (run === void 0) throw sqliteError("record-seal-incomplete", "verify-seal", `Run ${runId} is missing`);
|
|
11231
|
-
visit(runSealEntry({
|
|
11232
|
-
runId: text$2(run, "run_id"),
|
|
11233
|
-
writerGeneration: text$2(run, "writer_generation"),
|
|
11234
|
-
startedAt: text$2(run, "started_at"),
|
|
11235
|
-
coreDigest: verified(run, "core_digest", "core_payload")
|
|
11236
|
-
}));
|
|
11237
|
-
for (const row of recordStatement(connection, "SELECT slot_id,ordinal,core_payload,core_digest FROM ne18_slots WHERE run_id=?").iterate(runId)) visit(slotSealEntry(runId, {
|
|
11238
|
-
slotId: text$2(row, "slot_id"),
|
|
11239
|
-
ordinal: integer$1(row, "ordinal"),
|
|
11240
|
-
coreDigest: verified(row, "core_digest", "core_payload")
|
|
11241
|
-
}));
|
|
11242
|
-
for (const row of recordStatement(connection, "SELECT attempt_id,attempt_locator,core_payload,core_digest FROM ne18_attempts WHERE origin_run_id=?").iterate(runId)) visit(attemptSealEntry(runId, text$2(row, "attempt_id"), text$2(row, "attempt_locator"), verified(row, "core_digest", "core_payload")));
|
|
11243
|
-
for (const row of recordStatement(connection, `SELECT slot_id,origin_run_id,attempt_id,action,core_payload,core_digest FROM ne18_members WHERE target_run_id=?`).iterate(runId)) visit(memberSealEntry(runId, {
|
|
11244
|
-
slotId: text$2(row, "slot_id"),
|
|
11245
|
-
originRunId: optionalText$1(row, "origin_run_id"),
|
|
11246
|
-
attemptId: optionalText$1(row, "attempt_id"),
|
|
11247
|
-
action: memberAction(row, "action"),
|
|
11248
|
-
coreDigest: verified(row, "core_digest", "core_payload")
|
|
11249
|
-
}));
|
|
11250
|
-
for (const row of recordStatement(connection, `SELECT attachment_id,owner_kind,owner_run_id,owner_attempt_id,family,family_revision,logical_identity,
|
|
11251
|
-
canonical_payload,canonical_digest,logical_inventory,inventory_digest FROM ne18_attachments WHERE owner_run_id=?`).iterate(runId)) {
|
|
11252
|
-
const canonicalDigest = verified(row, "canonical_digest", "canonical_payload");
|
|
11253
|
-
const inventoryDigest = verified(row, "inventory_digest", "logical_inventory");
|
|
11254
|
-
visit(attachmentSealEntry({
|
|
11255
|
-
attachmentId: text$2(row, "attachment_id"),
|
|
11256
|
-
ownerKind: ownerKind(row, "owner_kind"),
|
|
11257
|
-
ownerRunId: text$2(row, "owner_run_id"),
|
|
11258
|
-
ownerAttemptId: optionalText$1(row, "owner_attempt_id"),
|
|
11259
|
-
family: text$2(row, "family"),
|
|
11260
|
-
familyRevision: integer$1(row, "family_revision"),
|
|
11261
|
-
logicalIdentity: text$2(row, "logical_identity"),
|
|
11262
|
-
canonicalDigest,
|
|
11263
|
-
inventoryDigest
|
|
11264
|
-
}));
|
|
11265
|
-
}
|
|
11266
|
-
for (const row of recordStatement(connection, `SELECT r.attachment_id,r.ordinal,r.target_owner_kind,r.target_family,r.canonical_payload,r.reference_digest
|
|
11267
|
-
FROM ne18_attachment_references r JOIN ne18_attachments a ON a.attachment_id=r.attachment_id WHERE a.owner_run_id=?`).iterate(runId)) visit(referenceSealEntry(text$2(row, "attachment_id"), {
|
|
11268
|
-
ordinal: integer$1(row, "ordinal"),
|
|
11269
|
-
owner: ownerKind(row, "target_owner_kind"),
|
|
11270
|
-
family: text$2(row, "target_family"),
|
|
11271
|
-
referenceDigest: verified(row, "reference_digest", "canonical_payload")
|
|
11272
|
-
}));
|
|
11273
|
-
for (const row of recordStatement(connection, `SELECT i.attachment_id,i.ordinal,i.logical_identity,i.canonical_payload,i.canonical_digest
|
|
11274
|
-
FROM ne18_collection_items i JOIN ne18_attachments a ON a.attachment_id=i.attachment_id WHERE a.owner_run_id=?`).iterate(runId)) visit(collectionItemSealEntry(text$2(row, "attachment_id"), {
|
|
11275
|
-
ordinal: integer$1(row, "ordinal"),
|
|
11276
|
-
logicalIdentity: text$2(row, "logical_identity"),
|
|
11277
|
-
canonicalDigest: verified(row, "canonical_digest", "canonical_payload")
|
|
11278
|
-
}));
|
|
11279
|
-
for (const row of recordStatement(connection, `SELECT c.content_id,c.attachment_id,c.logical_handle,c.byte_length,c.overall_digest,c.chunk_count
|
|
11280
|
-
FROM ne18_contents c JOIN ne18_attachments a ON a.attachment_id=c.attachment_id WHERE a.owner_run_id=?`).iterate(runId)) visit(contentSealEntry(text$2(row, "attachment_id"), {
|
|
11281
|
-
contentId: text$2(row, "content_id"),
|
|
11282
|
-
logicalHandle: text$2(row, "logical_handle"),
|
|
11283
|
-
byteLength: integer$1(row, "byte_length"),
|
|
11284
|
-
digest: text$2(row, "overall_digest"),
|
|
11285
|
-
chunkCount: integer$1(row, "chunk_count")
|
|
11286
|
-
}));
|
|
11287
|
-
const chunkSql = verifyContentChunkBytes ? `SELECT c.content_id,c.ordinal,c.bytes,c.chunk_digest FROM ne18_content_chunks c
|
|
11288
|
-
JOIN ne18_contents n ON n.content_id=c.content_id JOIN ne18_attachments a ON a.attachment_id=n.attachment_id WHERE a.owner_run_id=?` : `SELECT c.content_id,c.ordinal,c.chunk_digest FROM ne18_content_chunks c
|
|
11289
|
-
JOIN ne18_contents n ON n.content_id=c.content_id JOIN ne18_attachments a ON a.attachment_id=n.attachment_id WHERE a.owner_run_id=?`;
|
|
11290
|
-
for (const row of recordStatement(connection, chunkSql).iterate(runId)) {
|
|
11291
|
-
const chunkDigest = text$2(row, "chunk_digest");
|
|
11292
|
-
requireDigest(chunkDigest, "chunk_digest");
|
|
11293
|
-
if (verifyContentChunkBytes && digestBytes(bytes(row, "bytes")) !== chunkDigest) throw sqliteError("record-seal-incomplete", "verify-seal", "bytes does not match chunk_digest");
|
|
11294
|
-
visit(contentChunkSealEntry(text$2(row, "content_id"), integer$1(row, "ordinal"), chunkDigest));
|
|
11295
|
-
}
|
|
11296
|
-
}
|
|
11297
|
-
function runRow(connection, runId) {
|
|
11298
|
-
return recordStatement(connection, `SELECT run_id,status,writer_generation,started_at,core_payload,core_digest,mutation_sequence,
|
|
11299
|
-
candidate_seal_identity,candidate_seal_entry_count,candidate_seal_staged_count,logical_seal_identity FROM ne18_runs WHERE run_id=?`).get(runId);
|
|
11300
|
-
}
|
|
11301
11079
|
function assertBoundedBatch(operation, rowCount, byteCount) {
|
|
11302
11080
|
if (!Number.isSafeInteger(rowCount) || rowCount < 0 || !Number.isSafeInteger(byteCount) || byteCount < 0 || rowCount > 4096 || byteCount > 8388608) throw sqliteError("record-resource-limit-exceeded", operation, `staging batch exceeds its bound (${rowCount} rows, ${byteCount} bytes)`);
|
|
11303
11081
|
}
|
|
11304
|
-
|
|
11305
|
-
ensurePreparedSealTables(connection);
|
|
11306
|
-
try {
|
|
11307
|
-
verifyRunPayloadClosures(connection, runId, true);
|
|
11308
|
-
const actual = spillPreparedSealEntries(connection, runId, (visit) => visitRunSealEntries(connection, runId, visit, true, false));
|
|
11309
|
-
if (actual.count !== expectedCount || actual.identity !== identity) throw sqliteError("record-seal-incomplete", "verify-seal", `Run ${runId} exact Seal identity or count differs from its closure`);
|
|
11310
|
-
const statement = recordStatement(connection, `SELECT entry_kind,logical_identity,digest FROM ne18_run_seal_entries
|
|
11311
|
-
WHERE run_id=? AND ordinal=?`);
|
|
11312
|
-
let ordinal = 0;
|
|
11313
|
-
for (const row of recordStatement(connection, `SELECT ordinal,entry_kind,logical_identity,digest
|
|
11314
|
-
FROM temp.niceeval_prepared_seal_ordered WHERE run_id=? ORDER BY ordinal`).iterate(runId)) {
|
|
11315
|
-
if (integer$1(row, "ordinal") !== ordinal) throw sqliteError("record-seal-incomplete", "verify-seal", `Run ${runId} prepared Seal ordinals are not contiguous`);
|
|
11316
|
-
const entry = {
|
|
11317
|
-
kind: sealEntryKind(row, "entry_kind"),
|
|
11318
|
-
logicalIdentity: text$2(row, "logical_identity"),
|
|
11319
|
-
digest: text$2(row, "digest")
|
|
11320
|
-
};
|
|
11321
|
-
const stored = statement.get(runId, ordinal);
|
|
11322
|
-
if (stored === void 0 || sealEntryKind(stored, "entry_kind") !== entry.kind || text$2(stored, "logical_identity") !== entry.logicalIdentity || text$2(stored, "digest") !== entry.digest) throw sqliteError("record-seal-incomplete", "verify-seal", `Run ${runId} Seal entry ${ordinal} differs from its closure`);
|
|
11323
|
-
ordinal += 1;
|
|
11324
|
-
}
|
|
11325
|
-
const storedCount = recordStatement(connection, "SELECT count(*) AS count FROM ne18_run_seal_entries WHERE run_id=?").get(runId);
|
|
11326
|
-
if (ordinal !== expectedCount || integer$1(storedCount, "count") !== ordinal) throw sqliteError("record-seal-incomplete", "verify-seal", `Run ${runId} exact Seal does not match its closure`);
|
|
11327
|
-
} finally {
|
|
11328
|
-
recordStatement(connection, "DELETE FROM temp.niceeval_prepared_seal_raw WHERE run_id=?").run(runId);
|
|
11329
|
-
recordStatement(connection, "DELETE FROM temp.niceeval_prepared_seal_ordered WHERE run_id=?").run(runId);
|
|
11330
|
-
}
|
|
11331
|
-
}
|
|
11332
|
-
function verifyAllSealedRuns(connection, requireSealedOnly = false, deadlineEpochMs = Date.now() + RECORD_SQLITE_VALIDATION_DEADLINE_MS) {
|
|
11333
|
-
const checkDeadline = () => {
|
|
11334
|
-
if (!Number.isSafeInteger(deadlineEpochMs) || Date.now() >= deadlineEpochMs) throw sqliteError("record-resource-limit-exceeded", "verify-database", "Record validation exceeded its deadline");
|
|
11335
|
-
};
|
|
11336
|
-
checkDeadline();
|
|
11337
|
-
const admission = recordStatement(connection, `SELECT
|
|
11338
|
-
(SELECT count(*) FROM ne18_runs) run_count,
|
|
11339
|
-
(SELECT count(*) FROM ne18_runs)+(SELECT count(*) FROM ne18_slots)+(SELECT count(*) FROM ne18_attempts)+(SELECT count(*) FROM ne18_members)+
|
|
11340
|
-
(SELECT count(*) FROM ne18_attachments)+(SELECT count(*) FROM ne18_attachment_references)+(SELECT count(*) FROM ne18_collection_items)+
|
|
11341
|
-
(SELECT count(*) FROM ne18_contents)+(SELECT count(*) FROM ne18_content_chunks)+(SELECT count(*) FROM ne18_run_seal_entries) row_count`).get();
|
|
11342
|
-
if (integer$1(admission, "run_count") > 1e5 || integer$1(admission, "row_count") > 2e6) throw sqliteError("record-resource-limit-exceeded", "verify-database", "Record validation inventory exceeds its hostile-input ceiling");
|
|
11343
|
-
const integrity = recordStatement(connection, "PRAGMA quick_check").all();
|
|
11344
|
-
checkDeadline();
|
|
11345
|
-
if (integrity.length !== 1 || text$2(integrity[0], "quick_check") !== "ok") throw sqliteError("record-database-invalid", "verify-database", "SQLite quick_check failed");
|
|
11346
|
-
if (recordStatement(connection, "PRAGMA foreign_key_check").all().length !== 0) throw sqliteError("record-database-invalid", "verify-database", "foreign key check failed");
|
|
11347
|
-
const runRows = recordStatement(connection, "SELECT run_id,status,logical_seal_identity FROM ne18_runs ORDER BY run_id").iterate();
|
|
11348
|
-
let sealed = 0;
|
|
11349
|
-
for (const row of runRows) {
|
|
11350
|
-
checkDeadline();
|
|
11351
|
-
const runId = text$2(row, "run_id");
|
|
11352
|
-
if (text$2(row, "status") !== "sealed") {
|
|
11353
|
-
if (requireSealedOnly) throw sqliteError("record-database-invalid", "verify-database", `database contains unpublished run ${runId}`);
|
|
11354
|
-
continue;
|
|
11355
|
-
}
|
|
11356
|
-
sealed += 1;
|
|
11357
|
-
const header = runRow(connection, runId);
|
|
11358
|
-
if (integer$1(header, "candidate_seal_staged_count") !== integer$1(header, "candidate_seal_entry_count")) throw sqliteError("record-seal-incomplete", "verify-database", `Run ${runId} staged Seal inventory is incomplete`);
|
|
11359
|
-
verifyStoredSealStreaming(connection, runId, text$2(row, "logical_seal_identity"), integer$1(header, "candidate_seal_entry_count"));
|
|
11360
|
-
}
|
|
11361
|
-
checkDeadline();
|
|
11362
|
-
return sealed;
|
|
11363
|
-
}
|
|
11364
|
-
function verifyRunPayloadClosures(connection, runId, verifyPayloadBytes = true) {
|
|
11365
|
-
const attempts = recordStatement(connection, "SELECT attempt_id,attempt_locator FROM ne18_attempts WHERE origin_run_id=?").iterate(runId);
|
|
11366
|
-
for (const attempt of attempts) {
|
|
11367
|
-
const attemptId = text$2(attempt, "attempt_id");
|
|
11368
|
-
const locator = text$2(attempt, "attempt_locator");
|
|
11369
|
-
try {
|
|
11370
|
-
requireAttemptLocator(attemptId, locator, "verify-seal");
|
|
11371
|
-
} catch (cause) {
|
|
11372
|
-
throw sqliteError("record-seal-incomplete", "verify-seal", cause instanceof Error ? cause.message : `Attempt ${attemptId} locator is invalid`);
|
|
11373
|
-
}
|
|
11374
|
-
}
|
|
11375
|
-
const attachments = recordStatement(connection, `SELECT attachment_id,owner_kind,owner_run_id,owner_attempt_id,family,family_revision,
|
|
11376
|
-
logical_identity,canonical_digest,logical_inventory,inventory_digest FROM ne18_attachments WHERE owner_run_id=?`).iterate(runId);
|
|
11377
|
-
for (const attachment of attachments) {
|
|
11378
|
-
const attachmentId$1 = text$2(attachment, "attachment_id");
|
|
11379
|
-
if (digestBytes(bytes(attachment, "logical_inventory")) !== text$2(attachment, "inventory_digest")) throw sqliteError("record-seal-incomplete", "verify-seal", `attachment ${attachmentId$1} inventory digest is invalid`);
|
|
11380
|
-
const owner = ownerKind(attachment, "owner_kind");
|
|
11381
|
-
const expectedAttachmentId = attachmentId({
|
|
11382
|
-
runId: text$2(attachment, "owner_run_id"),
|
|
11383
|
-
owner,
|
|
11384
|
-
...owner === "attempt" ? { attemptId: optionalText$1(attachment, "owner_attempt_id") ?? void 0 } : {},
|
|
11385
|
-
family: text$2(attachment, "family")
|
|
11386
|
-
});
|
|
11387
|
-
const expectedLogicalIdentity = attachmentLogicalIdentity(attachmentId$1, text$2(attachment, "canonical_digest"), text$2(attachment, "inventory_digest"));
|
|
11388
|
-
if (attachmentId$1 !== expectedAttachmentId || text$2(attachment, "logical_identity") !== expectedLogicalIdentity || integer$1(attachment, "family_revision") < 1) throw sqliteError("record-seal-incomplete", "verify-seal", `attachment ${attachmentId$1} logical identity is invalid`);
|
|
11389
|
-
for (const [label, counts] of [["reference", recordStatement(connection, "SELECT count(*) AS count,min(ordinal) AS minimum,max(ordinal) AS maximum FROM ne18_attachment_references WHERE attachment_id=?").get(attachmentId$1)], ["collection item", recordStatement(connection, "SELECT count(*) AS count,min(ordinal) AS minimum,max(ordinal) AS maximum FROM ne18_collection_items WHERE attachment_id=?").get(attachmentId$1)]]) {
|
|
11390
|
-
const decoded = counts;
|
|
11391
|
-
const count = integer$1(decoded, "count");
|
|
11392
|
-
if (count > 0 && (optionalInteger(decoded, "minimum") !== 0 || optionalInteger(decoded, "maximum") !== count - 1)) throw sqliteError("record-seal-incomplete", "verify-seal", `attachment ${attachmentId$1} ${label} ordinals are not contiguous`);
|
|
11393
|
-
}
|
|
11394
|
-
}
|
|
11395
|
-
const items = recordStatement(connection, `SELECT i.attachment_id,i.ordinal,i.logical_identity,i.canonical_digest FROM ne18_collection_items i
|
|
11396
|
-
JOIN ne18_attachments a ON a.attachment_id=i.attachment_id WHERE a.owner_run_id=?`).iterate(runId);
|
|
11397
|
-
for (const item of items) {
|
|
11398
|
-
const expected = collectionItemLogicalIdentity(integer$1(item, "ordinal"), text$2(item, "canonical_digest"));
|
|
11399
|
-
if (text$2(item, "logical_identity") !== expected) throw sqliteError("record-seal-incomplete", "verify-seal", `collection item ${text$2(item, "attachment_id")}/${integer$1(item, "ordinal")} logical identity is invalid`);
|
|
11400
|
-
}
|
|
11401
|
-
const coverage = recordStatement(connection, `SELECT
|
|
11402
|
-
(SELECT count(*) FROM ne18_slots WHERE run_id=?) slot_count,
|
|
11403
|
-
(SELECT count(*) FROM ne18_members WHERE target_run_id=?) member_count,
|
|
11404
|
-
(SELECT count(*) FROM ne18_slots s LEFT JOIN ne18_members m ON m.target_run_id=s.run_id AND m.slot_id=s.slot_id
|
|
11405
|
-
WHERE s.run_id=? AND m.slot_id IS NULL) missing_count`).get(runId, runId, runId);
|
|
11406
|
-
if (integer$1(coverage, "slot_count") !== integer$1(coverage, "member_count") || integer$1(coverage, "missing_count") !== 0) throw sqliteError("record-seal-incomplete", "verify-seal", `Run ${runId} does not have exactly one Member per Slot`);
|
|
11407
|
-
const references = recordStatement(connection, `SELECT r.attachment_id,r.ordinal,r.target_owner_kind,r.target_family,
|
|
11408
|
-
a.owner_kind source_owner_kind,a.owner_run_id,a.owner_attempt_id FROM ne18_attachment_references r
|
|
11409
|
-
JOIN ne18_attachments a ON a.attachment_id=r.attachment_id WHERE a.owner_run_id=?`).iterate(runId);
|
|
11410
|
-
for (const reference of references) {
|
|
11411
|
-
const targetOwner = text$2(reference, "target_owner_kind");
|
|
11412
|
-
const sourceOwner = text$2(reference, "source_owner_kind");
|
|
11413
|
-
if (targetOwner === "attempt" && sourceOwner !== "attempt") throw sqliteError("record-seal-incomplete", "verify-seal", `run-owned attachment ${text$2(reference, "attachment_id")} cannot resolve an attempt reference`);
|
|
11414
|
-
if (integer$1(targetOwner === "run" ? recordStatement(connection, `SELECT count(*) AS count FROM ne18_attachments WHERE owner_kind='run' AND owner_run_id=? AND family=?`).get(text$2(reference, "owner_run_id"), text$2(reference, "target_family")) : recordStatement(connection, `SELECT count(*) AS count FROM ne18_attachments WHERE owner_kind='attempt' AND owner_run_id=? AND owner_attempt_id=? AND family=?`).get(text$2(reference, "owner_run_id"), text$2(reference, "owner_attempt_id"), text$2(reference, "target_family")), "count") !== 1) throw sqliteError("record-seal-incomplete", "verify-seal", `reference ${text$2(reference, "attachment_id")}/${integer$1(reference, "ordinal")} target family is missing`);
|
|
11415
|
-
}
|
|
11416
|
-
const contents = recordStatement(connection, `SELECT c.content_id,c.attachment_id,c.logical_handle,c.byte_length,c.overall_digest,c.chunk_count FROM ne18_contents c
|
|
11417
|
-
JOIN ne18_attachments a ON a.attachment_id=c.attachment_id WHERE a.owner_run_id=?`).iterate(runId);
|
|
11418
|
-
for (const content of contents) {
|
|
11419
|
-
const contentId$1 = text$2(content, "content_id");
|
|
11420
|
-
if (contentId$1 !== contentId(text$2(content, "attachment_id"), text$2(content, "logical_handle"))) throw sqliteError("record-seal-incomplete", "verify-seal", `content ${contentId$1} logical handle is invalid`);
|
|
11421
|
-
if (verifyPayloadBytes) {
|
|
11422
|
-
const hash = createHash("sha256");
|
|
11423
|
-
let byteLength = 0;
|
|
11424
|
-
let ordinal = 0;
|
|
11425
|
-
const chunks = recordStatement(connection, "SELECT ordinal,bytes,chunk_digest FROM ne18_content_chunks WHERE content_id=? ORDER BY ordinal").iterate(contentId$1);
|
|
11426
|
-
for (const chunk of chunks) {
|
|
11427
|
-
if (integer$1(chunk, "ordinal") !== ordinal) throw sqliteError("record-seal-incomplete", "verify-seal", `content ${contentId$1} chunk ordinals are invalid`);
|
|
11428
|
-
const value = bytes(chunk, "bytes");
|
|
11429
|
-
if (digestBytes(value) !== text$2(chunk, "chunk_digest")) throw sqliteError("record-seal-incomplete", "verify-seal", `content ${contentId$1}/${ordinal} digest is invalid`);
|
|
11430
|
-
hash.update(value);
|
|
11431
|
-
byteLength += value.byteLength;
|
|
11432
|
-
ordinal += 1;
|
|
11433
|
-
}
|
|
11434
|
-
if (ordinal !== integer$1(content, "chunk_count") || byteLength !== integer$1(content, "byte_length") || hash.digest("hex") !== text$2(content, "overall_digest")) throw sqliteError("record-seal-incomplete", "verify-seal", `content ${contentId$1} whole digest is invalid`);
|
|
11435
|
-
} else {
|
|
11436
|
-
const aggregate = recordStatement(connection, `SELECT count(*) AS count,min(ordinal) AS minimum,max(ordinal) AS maximum,
|
|
11437
|
-
coalesce(sum(length(bytes)),0) AS byte_length FROM ne18_content_chunks WHERE content_id=?`).get(contentId$1);
|
|
11438
|
-
const chunkCount = integer$1(content, "chunk_count");
|
|
11439
|
-
if (integer$1(aggregate, "count") !== chunkCount || integer$1(aggregate, "byte_length") !== integer$1(content, "byte_length") || chunkCount > 0 && (optionalInteger(aggregate, "minimum") !== 0 || optionalInteger(aggregate, "maximum") !== chunkCount - 1)) throw sqliteError("record-seal-incomplete", "verify-seal", `content ${contentId$1} durable chunk closure is invalid`);
|
|
11440
|
-
for (const chunk of recordStatement(connection, "SELECT chunk_digest FROM ne18_content_chunks WHERE content_id=?").iterate(contentId$1)) requireDigest(text$2(chunk, "chunk_digest"), `content ${contentId$1} chunk digest`);
|
|
11441
|
-
}
|
|
11442
|
-
}
|
|
11443
|
-
}
|
|
11082
|
+
/** Summary metadata never materializes Core, Attachment payload or collection rows. */
|
|
11444
11083
|
function readSealedRunSummary(connection, runId) {
|
|
11445
|
-
const
|
|
11446
|
-
|
|
11447
|
-
|
|
11084
|
+
const row = recordStatement(connection, `SELECT r.run_id,r.writer_generation,r.started_at,
|
|
11085
|
+
coalesce(r.logical_seal_identity,'published:' || (SELECT max(p.published_revision)
|
|
11086
|
+
FROM ne18_attempt_publications p WHERE p.origin_run_id=r.run_id)) logical_seal_identity,
|
|
11087
|
+
(SELECT count(*) FROM ne18_slots WHERE run_id=r.run_id) slot_count,
|
|
11088
|
+
CASE WHEN EXISTS (SELECT 1 FROM ne18_run_resources WHERE run_id=r.run_id) THEN
|
|
11089
|
+
(SELECT count(*) FROM ne18_run_slot_bindings WHERE target_run_id=r.run_id)+
|
|
11090
|
+
(SELECT count(*) FROM ne18_run_slot_absences WHERE run_id=r.run_id)
|
|
11091
|
+
ELSE (SELECT count(*) FROM ne18_members WHERE target_run_id=r.run_id) END member_count,
|
|
11092
|
+
(SELECT count(*) FROM ne18_attempts a WHERE a.origin_run_id=r.run_id AND
|
|
11093
|
+
(NOT EXISTS (SELECT 1 FROM ne18_run_resources WHERE run_id=r.run_id) OR EXISTS
|
|
11094
|
+
(SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=a.origin_run_id AND p.attempt_id=a.attempt_id))) attempt_count,
|
|
11095
|
+
(SELECT count(*) FROM ne18_attachments a WHERE a.owner_run_id=r.run_id AND a.canonical_payload IS NOT NULL AND
|
|
11096
|
+
(a.owner_kind='run' OR NOT EXISTS (SELECT 1 FROM ne18_run_resources WHERE run_id=r.run_id) OR EXISTS
|
|
11097
|
+
(SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=a.owner_run_id AND p.attempt_id=a.owner_attempt_id))) attachment_count,
|
|
11098
|
+
(SELECT count(*) FROM ne18_contents c JOIN ne18_attachments a ON a.attachment_id=c.attachment_id
|
|
11099
|
+
WHERE a.owner_run_id=r.run_id AND a.canonical_payload IS NOT NULL AND
|
|
11100
|
+
(a.owner_kind='run' OR NOT EXISTS (SELECT 1 FROM ne18_run_resources WHERE run_id=r.run_id) OR EXISTS
|
|
11101
|
+
(SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=a.owner_run_id AND p.attempt_id=a.owner_attempt_id))) content_count,
|
|
11102
|
+
(SELECT coalesce(sum(c.byte_length),0) FROM ne18_contents c JOIN ne18_attachments a ON a.attachment_id=c.attachment_id
|
|
11103
|
+
WHERE a.owner_run_id=r.run_id AND a.canonical_payload IS NOT NULL AND
|
|
11104
|
+
(a.owner_kind='run' OR NOT EXISTS (SELECT 1 FROM ne18_run_resources WHERE run_id=r.run_id) OR EXISTS
|
|
11105
|
+
(SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=a.owner_run_id AND p.attempt_id=a.owner_attempt_id))) content_bytes,
|
|
11106
|
+
(SELECT count(*) FROM ne18_run_seal_entries WHERE run_id=r.run_id) seal_count
|
|
11107
|
+
FROM ne18_runs r WHERE r.run_id=? AND NOT EXISTS
|
|
11108
|
+
(SELECT 1 FROM ne18_run_deletion_tombstones d WHERE d.run_id=r.run_id)
|
|
11109
|
+
AND (r.status='sealed' OR EXISTS (SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=r.run_id))`).get(runId);
|
|
11110
|
+
if (row === void 0) return void 0;
|
|
11111
|
+
return Object.freeze({
|
|
11112
|
+
runId: text$2(row, "run_id"),
|
|
11113
|
+
writerGeneration: text$2(row, "writer_generation"),
|
|
11114
|
+
startedAt: text$2(row, "started_at"),
|
|
11115
|
+
logicalSealIdentity: text$2(row, "logical_seal_identity"),
|
|
11116
|
+
slotCount: integer$1(row, "slot_count"),
|
|
11117
|
+
memberCount: integer$1(row, "member_count"),
|
|
11118
|
+
attemptCount: integer$1(row, "attempt_count"),
|
|
11119
|
+
attachmentCount: integer$1(row, "attachment_count"),
|
|
11120
|
+
contentCount: integer$1(row, "content_count"),
|
|
11121
|
+
contentByteLength: integer$1(row, "content_bytes"),
|
|
11122
|
+
sealEntryCount: integer$1(row, "seal_count")
|
|
11123
|
+
});
|
|
11124
|
+
}
|
|
11125
|
+
/** Pinned publication identity, plus a metadata-only count; no Seal hashing. */
|
|
11126
|
+
function readSealedRunCutoff(connection, identity) {
|
|
11127
|
+
const row = recordStatement(connection, `SELECT count(*) count FROM ne18_runs r
|
|
11128
|
+
WHERE NOT EXISTS (SELECT 1 FROM ne18_run_deletion_tombstones d WHERE d.run_id=r.run_id)
|
|
11129
|
+
AND (status='sealed' OR EXISTS (SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=r.run_id))`).get();
|
|
11130
|
+
return Object.freeze({
|
|
11131
|
+
identity,
|
|
11132
|
+
runCount: integer$1(row, "count")
|
|
11133
|
+
});
|
|
11134
|
+
}
|
|
11135
|
+
/** Filter lightweight Run metadata before loading any selected Core or payload. */
|
|
11136
|
+
function findExperimentRunIds(connection, experimentId) {
|
|
11137
|
+
requireIdentity$1(experimentId, "experimentId");
|
|
11138
|
+
const selected = rows(connection, `SELECT r.run_id FROM ne18_runs r
|
|
11139
|
+
LEFT JOIN ne18_run_resources resource ON resource.run_id=r.run_id
|
|
11140
|
+
WHERE coalesce(resource.experiment_id,json_extract(r.core_payload,'$.experimentId'))=?
|
|
11141
|
+
AND NOT EXISTS (SELECT 1 FROM ne18_run_deletion_tombstones d WHERE d.run_id=r.run_id)
|
|
11142
|
+
AND (r.status='sealed' OR EXISTS (SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=r.run_id))
|
|
11143
|
+
ORDER BY r.run_id LIMIT ?`, experimentId, RECORD_SQLITE_MAX_VALIDATION_RUNS + 1);
|
|
11144
|
+
if (selected.length > 1e5) throw sqliteError("record-resource-limit-exceeded", "find-experiment-runs", "Experiment exceeds its Run ceiling");
|
|
11145
|
+
return Object.freeze(selected.map((row) => text$2(row, "run_id")));
|
|
11448
11146
|
}
|
|
11449
11147
|
/**
|
|
11450
11148
|
* Computes the stable sealed cutoff without retaining the inventory, then
|
|
11451
11149
|
* returns one bounded page from the same caller-owned read transaction.
|
|
11452
11150
|
*/
|
|
11453
|
-
function readSealedRunSummaryPage(connection, afterRunId = "", pageSize = 100, expectedCutoffIdentity, deadlineEpochMs = Date.now() + RECORD_SQLITE_VALIDATION_DEADLINE_MS) {
|
|
11151
|
+
function readSealedRunSummaryPage(connection, afterRunId = "", pageSize = 100, expectedCutoffIdentity, deadlineEpochMs = Date.now() + RECORD_SQLITE_VALIDATION_DEADLINE_MS, pinnedCutoff) {
|
|
11454
11152
|
requireIdentity$1(afterRunId === "" ? "start" : afterRunId, "afterRunId");
|
|
11455
11153
|
if (!Number.isSafeInteger(pageSize) || pageSize < 1 || pageSize > 256) throw sqliteError("record-resource-limit-exceeded", "page-sealed-runs", "page size must be between 1 and 256");
|
|
11456
|
-
const
|
|
11457
|
-
|
|
11458
|
-
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
(
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
|
|
11468
|
-
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11154
|
+
const { identity, runCount } = pinnedCutoff ?? (() => {
|
|
11155
|
+
const cutoffHash = createHash("sha256");
|
|
11156
|
+
cutoffHash.update("[");
|
|
11157
|
+
let runCount = 0;
|
|
11158
|
+
const inventory = recordStatement(connection, `SELECT run_id,
|
|
11159
|
+
coalesce(logical_seal_identity,'published:' || (SELECT max(p.published_revision) FROM ne18_attempt_publications p
|
|
11160
|
+
WHERE p.origin_run_id=ne18_runs.run_id)) logical_seal_identity
|
|
11161
|
+
FROM ne18_runs WHERE NOT EXISTS (SELECT 1 FROM ne18_run_deletion_tombstones d WHERE d.run_id=ne18_runs.run_id)
|
|
11162
|
+
AND (status='sealed' OR EXISTS
|
|
11163
|
+
(SELECT 1 FROM ne18_attempt_publications p WHERE p.origin_run_id=ne18_runs.run_id))
|
|
11164
|
+
ORDER BY run_id`).iterate();
|
|
11165
|
+
for (const row of inventory) {
|
|
11166
|
+
if (runCount >= 1e5) throw sqliteError("record-resource-limit-exceeded", "page-sealed-runs", "sealed cutoff exceeds its Run ceiling");
|
|
11167
|
+
if ((runCount & 255) === 0 && Date.now() >= deadlineEpochMs) throw sqliteError("record-resource-limit-exceeded", "page-sealed-runs", "sealed cutoff exceeded its deadline");
|
|
11168
|
+
if (runCount > 0) cutoffHash.update(",");
|
|
11169
|
+
cutoffHash.update(JSON.stringify({
|
|
11170
|
+
runId: text$2(row, "run_id"),
|
|
11171
|
+
logicalSealIdentity: text$2(row, "logical_seal_identity")
|
|
11172
|
+
}));
|
|
11173
|
+
runCount += 1;
|
|
11174
|
+
}
|
|
11175
|
+
cutoffHash.update("]");
|
|
11176
|
+
const identity = cutoffHash.digest("hex");
|
|
11177
|
+
return Object.freeze({
|
|
11178
|
+
identity,
|
|
11179
|
+
runCount
|
|
11180
|
+
});
|
|
11181
|
+
})();
|
|
11478
11182
|
if (expectedCutoffIdentity !== void 0 && expectedCutoffIdentity !== identity) throw sqliteError("record-command-conflict", "page-sealed-runs", "sealed cutoff changed; restart pagination");
|
|
11479
11183
|
const pageRows = rows(connection, `SELECT run_id FROM ne18_runs WHERE run_id>?
|
|
11480
11184
|
AND NOT EXISTS (SELECT 1 FROM ne18_run_deletion_tombstones d WHERE d.run_id=ne18_runs.run_id)
|
|
@@ -11593,8 +11297,15 @@ function readCollectionItemPage(connection, attachmentId, afterOrdinal, pageSize
|
|
|
11593
11297
|
nextOrdinal
|
|
11594
11298
|
});
|
|
11595
11299
|
}
|
|
11596
|
-
|
|
11597
|
-
|
|
11300
|
+
function memoRecordRead(read, defer) {
|
|
11301
|
+
if (defer === void 0) {
|
|
11302
|
+
const value = read();
|
|
11303
|
+
return () => value;
|
|
11304
|
+
}
|
|
11305
|
+
let cached;
|
|
11306
|
+
return () => defer(() => (cached ??= { value: read() }).value);
|
|
11307
|
+
}
|
|
11308
|
+
function readPublishedSealedRun(connection, runId, defer) {
|
|
11598
11309
|
const run = recordStatement(connection, `SELECT run_id,writer_generation,started_at,status,
|
|
11599
11310
|
coalesce(logical_seal_identity,'published:' || (SELECT max(p.published_revision) FROM ne18_attempt_publications p
|
|
11600
11311
|
WHERE p.origin_run_id=ne18_runs.run_id)) logical_seal_identity,core_payload,core_digest,
|
|
@@ -11706,30 +11417,42 @@ function readPublishedSealedRun(connection, runId) {
|
|
|
11706
11417
|
});
|
|
11707
11418
|
});
|
|
11708
11419
|
const attachments = rows(connection, `SELECT attachment_id,owner_kind,owner_run_id,owner_attempt_id,family,family_revision,
|
|
11709
|
-
logical_identity,
|
|
11710
|
-
(SELECT count(*) FROM ne18_collection_items i WHERE i.attachment_id=a.attachment_id) item_count,
|
|
11711
|
-
(SELECT coalesce(sum(length(i.canonical_payload)),0) FROM ne18_collection_items i WHERE i.attachment_id=a.attachment_id) item_bytes
|
|
11420
|
+
logical_identity,canonical_digest,inventory_digest
|
|
11712
11421
|
FROM ne18_attachments a WHERE owner_run_id=?${publicationManaged ? ` AND canonical_payload IS NOT NULL AND
|
|
11713
11422
|
(owner_kind='run' OR EXISTS (SELECT 1 FROM ne18_attempt_publications p
|
|
11714
11423
|
WHERE p.origin_run_id=a.owner_run_id AND p.attempt_id=a.owner_attempt_id))` : ""} ORDER BY attachment_id`, runId).map((row) => {
|
|
11715
11424
|
const attachmentId = text$2(row, "attachment_id");
|
|
11716
|
-
|
|
11717
|
-
|
|
11425
|
+
const payload = memoRecordRead(() => {
|
|
11426
|
+
const stored = recordStatement(connection, `SELECT canonical_payload,logical_inventory FROM ne18_attachments WHERE attachment_id=?`).get(attachmentId);
|
|
11427
|
+
return {
|
|
11428
|
+
canonicalBytes: transferableBytes(bytes(stored, "canonical_payload")),
|
|
11429
|
+
logicalInventoryBytes: transferableBytes(bytes(stored, "logical_inventory"))
|
|
11430
|
+
};
|
|
11431
|
+
}, defer);
|
|
11432
|
+
const references = memoRecordRead(() => Object.freeze(rows(connection, `SELECT ordinal,target_owner_kind,target_family,canonical_payload,reference_digest
|
|
11718
11433
|
FROM ne18_attachment_references WHERE attachment_id=? ORDER BY ordinal`, attachmentId).map((reference) => Object.freeze({
|
|
11719
11434
|
ordinal: integer$1(reference, "ordinal"),
|
|
11720
11435
|
owner: ownerKind(reference, "target_owner_kind"),
|
|
11721
11436
|
family: text$2(reference, "target_family"),
|
|
11722
11437
|
canonicalBytes: transferableBytes(bytes(reference, "canonical_payload")),
|
|
11723
11438
|
referenceDigest: text$2(reference, "reference_digest")
|
|
11724
|
-
}));
|
|
11725
|
-
const contents = rows(connection, `SELECT content_id,logical_handle,byte_length,overall_digest,chunk_count
|
|
11439
|
+
}))), defer);
|
|
11440
|
+
const contents = memoRecordRead(() => Object.freeze(rows(connection, `SELECT content_id,logical_handle,byte_length,overall_digest,chunk_count
|
|
11726
11441
|
FROM ne18_contents WHERE attachment_id=? ORDER BY content_id`, attachmentId).map((content) => Object.freeze({
|
|
11727
11442
|
contentId: text$2(content, "content_id"),
|
|
11728
11443
|
logicalHandle: text$2(content, "logical_handle"),
|
|
11729
11444
|
byteLength: integer$1(content, "byte_length"),
|
|
11730
11445
|
digest: text$2(content, "overall_digest"),
|
|
11731
11446
|
chunkCount: integer$1(content, "chunk_count")
|
|
11732
|
-
}));
|
|
11447
|
+
}))), defer);
|
|
11448
|
+
const collection = memoRecordRead(() => {
|
|
11449
|
+
const aggregate = recordStatement(connection, `SELECT count(*) item_count,coalesce(sum(length(canonical_payload)),0) item_bytes
|
|
11450
|
+
FROM ne18_collection_items WHERE attachment_id=?`).get(attachmentId);
|
|
11451
|
+
return {
|
|
11452
|
+
count: integer$1(aggregate, "item_count"),
|
|
11453
|
+
byteLength: integer$1(aggregate, "item_bytes")
|
|
11454
|
+
};
|
|
11455
|
+
}, defer);
|
|
11733
11456
|
return Object.freeze({
|
|
11734
11457
|
attachmentId,
|
|
11735
11458
|
ownerKind: ownerKind(row, "owner_kind"),
|
|
@@ -11738,14 +11461,26 @@ function readPublishedSealedRun(connection, runId) {
|
|
|
11738
11461
|
family: text$2(row, "family"),
|
|
11739
11462
|
familyRevision: integer$1(row, "family_revision"),
|
|
11740
11463
|
logicalIdentity: text$2(row, "logical_identity"),
|
|
11741
|
-
canonicalBytes
|
|
11464
|
+
get canonicalBytes() {
|
|
11465
|
+
return payload().canonicalBytes;
|
|
11466
|
+
},
|
|
11742
11467
|
canonicalDigest: text$2(row, "canonical_digest"),
|
|
11743
|
-
logicalInventoryBytes
|
|
11468
|
+
get logicalInventoryBytes() {
|
|
11469
|
+
return payload().logicalInventoryBytes;
|
|
11470
|
+
},
|
|
11744
11471
|
inventoryDigest: text$2(row, "inventory_digest"),
|
|
11745
|
-
references
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
contents
|
|
11472
|
+
get references() {
|
|
11473
|
+
return references();
|
|
11474
|
+
},
|
|
11475
|
+
get contents() {
|
|
11476
|
+
return contents();
|
|
11477
|
+
},
|
|
11478
|
+
get collectionItemCount() {
|
|
11479
|
+
return collection().count;
|
|
11480
|
+
},
|
|
11481
|
+
get collectionItemByteLength() {
|
|
11482
|
+
return collection().byteLength;
|
|
11483
|
+
}
|
|
11749
11484
|
});
|
|
11750
11485
|
});
|
|
11751
11486
|
const core = Object.freeze({
|
|
@@ -11766,30 +11501,16 @@ function readPublishedSealedRun(connection, runId) {
|
|
|
11766
11501
|
members: Object.freeze(members),
|
|
11767
11502
|
attachments: Object.freeze(attachments)
|
|
11768
11503
|
});
|
|
11769
|
-
const contentCount = core.attachments.reduce((count, attachment) => count + attachment.contents.length, 0);
|
|
11770
|
-
const contentByteLength = core.attachments.reduce((count, attachment) => count + attachment.contents.reduce((subtotal, content) => subtotal + content.byteLength, 0), 0);
|
|
11771
|
-
const seal = recordStatement(connection, "SELECT count(*) seal_count FROM ne18_run_seal_entries WHERE run_id=?").get(runId);
|
|
11772
|
-
const summary = Object.freeze({
|
|
11773
|
-
runId: core.runId,
|
|
11774
|
-
writerGeneration: core.writerGeneration,
|
|
11775
|
-
startedAt: core.startedAt,
|
|
11776
|
-
logicalSealIdentity: core.logicalSealIdentity,
|
|
11777
|
-
slotCount: core.slots.length,
|
|
11778
|
-
memberCount: core.members.length,
|
|
11779
|
-
attemptCount: core.attempts.length,
|
|
11780
|
-
attachmentCount: core.attachments.length,
|
|
11781
|
-
contentCount,
|
|
11782
|
-
contentByteLength,
|
|
11783
|
-
sealEntryCount: integer$1(seal, "seal_count")
|
|
11784
|
-
});
|
|
11785
11504
|
return Object.freeze({
|
|
11786
11505
|
core,
|
|
11787
|
-
summary
|
|
11506
|
+
get summary() {
|
|
11507
|
+
return readSealedRunSummary(connection, runId);
|
|
11508
|
+
}
|
|
11788
11509
|
});
|
|
11789
11510
|
}
|
|
11790
|
-
/**
|
|
11791
|
-
function readSealedRunCore(connection, runId) {
|
|
11792
|
-
return readPublishedSealedRun(connection, runId)?.core;
|
|
11511
|
+
/** Inspection may defer Attachment reads within its existing pinned session. */
|
|
11512
|
+
function readSealedRunCore(connection, runId, defer) {
|
|
11513
|
+
return readPublishedSealedRun(connection, runId, defer)?.core;
|
|
11793
11514
|
}
|
|
11794
11515
|
/** Fixed, decoded projection sufficient to rebuild sealed Core and attachment metadata. */
|
|
11795
11516
|
function readSealedRunDocument(connection, runId) {
|
|
@@ -12670,7 +12391,7 @@ function publicationCutoffIdentity(cutoff) {
|
|
|
12670
12391
|
}
|
|
12671
12392
|
//#endregion
|
|
12672
12393
|
//#region src/record/sqlite/index.ts
|
|
12673
|
-
function openPinnedRecordReadSession(path, kind, deadlineEpochMs
|
|
12394
|
+
function openPinnedRecordReadSession(path, kind, deadlineEpochMs) {
|
|
12674
12395
|
if (!Number.isSafeInteger(deadlineEpochMs) || deadlineEpochMs <= Date.now()) throw sqliteError("record-resource-limit-exceeded", "open-read-session", "pinned read deadline must be a future safe integer");
|
|
12675
12396
|
const connection = openImmutableRecordReader(path);
|
|
12676
12397
|
let closed = false;
|
|
@@ -12701,13 +12422,15 @@ function openPinnedRecordReadSession(path, kind, deadlineEpochMs, validation = "
|
|
|
12701
12422
|
const publicationCutoff = currentPublicationCutoffOnConnection(connection);
|
|
12702
12423
|
const cutoffIdentity = publicationCutoffIdentity(publicationCutoff);
|
|
12703
12424
|
validateExactSchema(connection);
|
|
12704
|
-
|
|
12705
|
-
|
|
12425
|
+
let sealedCutoff;
|
|
12426
|
+
const readCutoff = () => sealedCutoff ??= readBounded("read-sealed-cutoff", () => readSealedRunCutoff(connection, cutoffIdentity));
|
|
12706
12427
|
assertUsable("open-read-session");
|
|
12707
12428
|
return Object.freeze({
|
|
12708
12429
|
kind,
|
|
12709
12430
|
deadlineEpochMs,
|
|
12710
12431
|
publicationCutoff: () => publicationCutoff,
|
|
12432
|
+
sealedCutoff: readCutoff,
|
|
12433
|
+
findExperimentRunIds: (experimentId) => readBounded("find-experiment-runs", () => findExperimentRunIds(connection, experimentId)),
|
|
12711
12434
|
readRunResource: (runId) => readBounded("read-run-resource", () => readRunResourceOnConnection(connection, runId, publicationCutoff)),
|
|
12712
12435
|
listRunResources: (input) => readBounded("list-run-resources", () => listRunResourcesOnConnection(connection, {
|
|
12713
12436
|
...input,
|
|
@@ -12716,7 +12439,7 @@ function openPinnedRecordReadSession(path, kind, deadlineEpochMs, validation = "
|
|
|
12716
12439
|
readSealedRunSummary: (runId) => readBounded("read-sealed-run-summary", () => readSealedRunSummary(connection, runId)),
|
|
12717
12440
|
readSealedRunSummaryPage: (afterRunId = "", pageSize = 100, expectedCutoffIdentity) => readBounded("page-sealed-runs", () => {
|
|
12718
12441
|
if (expectedCutoffIdentity !== void 0 && expectedCutoffIdentity !== cutoffIdentity) throw sqliteError("record-command-conflict", "page-sealed-runs", "publication cutoff changed; restart pagination");
|
|
12719
|
-
const page = readSealedRunSummaryPage(connection, afterRunId, pageSize, void 0, deadlineEpochMs);
|
|
12442
|
+
const page = readSealedRunSummaryPage(connection, afterRunId, pageSize, void 0, deadlineEpochMs, readCutoff());
|
|
12720
12443
|
return Object.freeze({
|
|
12721
12444
|
...page,
|
|
12722
12445
|
cutoff: Object.freeze({
|
|
@@ -12727,7 +12450,7 @@ function openPinnedRecordReadSession(path, kind, deadlineEpochMs, validation = "
|
|
|
12727
12450
|
}),
|
|
12728
12451
|
findAttemptLocatorCandidates: (locator, maximumCandidateRuns) => readBounded("find-attempt-locator", () => findAttemptLocatorCandidates(connection, locator, maximumCandidateRuns)),
|
|
12729
12452
|
readSealedRunDocument: (runId) => readBounded("read-sealed-run-document", () => readSealedRunDocument(connection, runId)),
|
|
12730
|
-
readSealedRunCore: (runId) => readBounded("read-sealed-run-core", () => readSealedRunCore(connection, runId)),
|
|
12453
|
+
readSealedRunCore: (runId, lazyAttachments = false) => readBounded("read-sealed-run-core", () => readSealedRunCore(connection, runId, lazyAttachments ? (read) => readBounded("read-sealed-attachment", read) : void 0)),
|
|
12731
12454
|
readContentChunkPage: (contentId, afterOrdinal, pageSize) => readBounded("read-content-page", () => readContentChunkPage(connection, contentId, afterOrdinal, pageSize)),
|
|
12732
12455
|
readCollectionItemPage: (attachmentId, afterOrdinal, pageSize) => readBounded("read-collection-page", () => readCollectionItemPage(connection, attachmentId, afterOrdinal, pageSize)),
|
|
12733
12456
|
close
|
|
@@ -12764,7 +12487,7 @@ Effect.fn("acquireProjectRecordReadSession")(function* (recordStorageRoot) {
|
|
|
12764
12487
|
});
|
|
12765
12488
|
/** Opens only a private generation already admitted by the hostile importer. */
|
|
12766
12489
|
function openHostOwnedRecordReadSession(generationPath, deadlineEpochMs = Date.now() + RECORD_SQLITE_VALIDATION_DEADLINE_MS) {
|
|
12767
|
-
return openPinnedRecordReadSession(generationPath, "private-generation", deadlineEpochMs
|
|
12490
|
+
return openPinnedRecordReadSession(generationPath, "private-generation", deadlineEpochMs);
|
|
12768
12491
|
}
|
|
12769
12492
|
//#endregion
|
|
12770
12493
|
//#region src/inspection/source.ts
|
|
@@ -12797,11 +12520,12 @@ function sessionFacts(session, kind) {
|
|
|
12797
12520
|
const readPage = (afterRunId = "", pageSize = 100, expectedCutoffIdentity) => remember(session.readSealedRunSummaryPage(afterRunId, pageSize, expectedCutoffIdentity ?? observedCutoff?.identity));
|
|
12798
12521
|
return Object.freeze({
|
|
12799
12522
|
kind,
|
|
12800
|
-
cutoff: () => observedCutoff
|
|
12523
|
+
cutoff: () => observedCutoff ??= session.sealedCutoff(),
|
|
12524
|
+
findExperimentRunIds: session.findExperimentRunIds,
|
|
12801
12525
|
readRunResource: (runId) => session.readRunResource(runId),
|
|
12802
12526
|
readSealedRunSummaryPage: readPage,
|
|
12803
12527
|
findAttemptLocatorCandidates: (locator, maximumCandidateRuns) => session.findAttemptLocatorCandidates(locator, maximumCandidateRuns),
|
|
12804
|
-
readSealedRunCore: (runId) => session.readSealedRunCore(runId),
|
|
12528
|
+
readSealedRunCore: (runId) => session.readSealedRunCore(runId, true),
|
|
12805
12529
|
readContentPage: (contentId, afterOrdinal, pageSize) => session.readContentChunkPage(contentId, afterOrdinal, pageSize),
|
|
12806
12530
|
readCollectionPage: (attachmentId, afterOrdinal, pageSize) => session.readCollectionItemPage(attachmentId, afterOrdinal, pageSize)
|
|
12807
12531
|
});
|
|
@@ -13723,6 +13447,18 @@ var NiceEvalCurrentRecordAttachments = Object.freeze({
|
|
|
13723
13447
|
var RUN_PAGE_SIZE = 100;
|
|
13724
13448
|
var ATTEMPT_CANDIDATE_RUN_LIMIT = 64;
|
|
13725
13449
|
var ATTEMPT_TARGET_MEMBER_LIMIT = 256;
|
|
13450
|
+
var decodedRuns = /* @__PURE__ */ new WeakMap();
|
|
13451
|
+
function readInspectionRun(source, runId) {
|
|
13452
|
+
let cache = decodedRuns.get(source);
|
|
13453
|
+
if (cache === void 0) decodedRuns.set(source, cache = /* @__PURE__ */ new Map());
|
|
13454
|
+
const cached = cache.get(runId);
|
|
13455
|
+
if (cached !== void 0) return cached;
|
|
13456
|
+
const physical = source.readSealedRunCore(runId);
|
|
13457
|
+
if (physical === void 0) return void 0;
|
|
13458
|
+
const decoded = decodeInspectionRun(source, physical);
|
|
13459
|
+
cache.set(runId, decoded);
|
|
13460
|
+
return decoded;
|
|
13461
|
+
}
|
|
13726
13462
|
/**
|
|
13727
13463
|
* Pins the source cutoff, exhausts the fixed Run-summary pagination, then
|
|
13728
13464
|
* reads and strictly decodes every Run Core in that exact sealed generation.
|
|
@@ -13749,9 +13485,9 @@ function loadInspectionRuns(source) {
|
|
|
13749
13485
|
}
|
|
13750
13486
|
if (summaries.length !== cutoff.runCount) throw factsError("Run pagination did not close the pinned sealed cutoff");
|
|
13751
13487
|
return Object.freeze(summaries.map((summary) => {
|
|
13752
|
-
const
|
|
13753
|
-
if (
|
|
13754
|
-
return
|
|
13488
|
+
const run = readInspectionRun(source, summary.runId);
|
|
13489
|
+
if (run === void 0) throw factsError(`Sealed Run ${summary.runId} disappeared from the pinned cutoff`);
|
|
13490
|
+
return run;
|
|
13755
13491
|
}));
|
|
13756
13492
|
}
|
|
13757
13493
|
/** Reads a bounded, explicit Run selection without changing its caller order. */
|
|
@@ -13759,8 +13495,8 @@ function loadSelectedInspectionRuns(source, runIds) {
|
|
|
13759
13495
|
const cutoff = source.cutoff();
|
|
13760
13496
|
const loaded = [];
|
|
13761
13497
|
for (const runId of new Set(runIds)) {
|
|
13762
|
-
const
|
|
13763
|
-
if (
|
|
13498
|
+
const run = readInspectionRun(source, runId);
|
|
13499
|
+
if (run !== void 0) loaded.push(run);
|
|
13764
13500
|
}
|
|
13765
13501
|
requireCutoff(source.cutoff(), cutoff);
|
|
13766
13502
|
return Object.freeze(loaded);
|
|
@@ -13770,8 +13506,7 @@ function loadInspectionRunResource(source, runId) {
|
|
|
13770
13506
|
const cutoff = source.cutoff();
|
|
13771
13507
|
const resource = source.readRunResource(runId);
|
|
13772
13508
|
if (resource === void 0) return void 0;
|
|
13773
|
-
const
|
|
13774
|
-
const published = physical === void 0 ? void 0 : decodeInspectionRun(source, physical);
|
|
13509
|
+
const published = readInspectionRun(source, runId);
|
|
13775
13510
|
requireCutoff(source.cutoff(), cutoff);
|
|
13776
13511
|
if (resource.published > 0 && published === void 0) throw factsError(`Run ${runId} has published bindings without a readable Core`);
|
|
13777
13512
|
if (published !== void 0) validateRunResourceCore(resource, published);
|
|
@@ -13789,23 +13524,23 @@ function validateRunResourceCore(resource, published) {
|
|
|
13789
13524
|
if (expected === void 0 || slot.slotId !== expected.slotId || slot.evalId !== expected.evalId || slot.attemptOrdinal !== expected.attemptOrdinal || slot.executionIdentityDigest !== expected.executionIdentityDigest) throw factsError(`Run ${resource.runId} expected Slot does not match its published Core`);
|
|
13790
13525
|
}
|
|
13791
13526
|
}
|
|
13792
|
-
/** Strictly decodes
|
|
13527
|
+
/** Strictly decodes Core, then decodes each Attachment only on first use. */
|
|
13793
13528
|
function decodeInspectionRun(source, physical) {
|
|
13794
|
-
const run = decodedRight(decodeRunDocument(
|
|
13529
|
+
const run = decodedRight(decodeRunDocument(parseVerifiedJson(physical.runCoreBytes, physical.runCoreDigest, "Run Core")), "Run Core is invalid");
|
|
13795
13530
|
if (run.runId !== physical.runId) throw factsError("Run Core identity does not match its sealed row");
|
|
13796
13531
|
if (physical.slots.length !== run.expectedSlots.length) throw factsError("Run Core Slot rows do not match its expected denominator");
|
|
13797
13532
|
for (const [index, stored] of physical.slots.entries()) {
|
|
13798
|
-
const slot = decodedRight(Schema.decodeUnknownResult(RecordSlotIdentitySchema, RecordExactParseOptions)(
|
|
13533
|
+
const slot = decodedRight(Schema.decodeUnknownResult(RecordSlotIdentitySchema, RecordExactParseOptions)(parseVerifiedJson(stored.coreBytes, stored.coreDigest, "Slot Core")), "Slot Core is invalid");
|
|
13799
13534
|
const expected = run.expectedSlots[index];
|
|
13800
13535
|
if (expected === void 0 || stored.ordinal !== index || stored.slotId !== slot.slotId || slot.slotId !== expected.slotId || slot.evalId !== expected.evalId || slot.attemptOrdinal !== expected.attemptOrdinal || slot.executionIdentityDigest !== expected.executionIdentityDigest) throw factsError("Slot Core does not match its sealed Run denominator");
|
|
13801
13536
|
}
|
|
13802
13537
|
const members = physical.members.map((stored) => {
|
|
13803
|
-
const member = decodedRight(decodeMemberDocument(
|
|
13538
|
+
const member = decodedRight(decodeMemberDocument(parseVerifiedJson(stored.coreBytes, stored.coreDigest, "Member Core")), "Member Core is invalid");
|
|
13804
13539
|
if (member.slotId !== stored.slotId || member.action !== stored.action || (member.attempt?.originRunId ?? void 0) !== stored.originRunId || (member.attempt?.attemptId ?? void 0) !== stored.attemptId) throw factsError("Member Core does not match its sealed row");
|
|
13805
13540
|
return member;
|
|
13806
13541
|
});
|
|
13807
13542
|
const attempts = physical.attempts.map((stored) => {
|
|
13808
|
-
const attempt = decodedRight(decodeAttemptDocument(
|
|
13543
|
+
const attempt = decodedRight(decodeAttemptDocument(parseVerifiedJson(stored.coreBytes, stored.coreDigest, "Attempt Core")), "Attempt Core is invalid");
|
|
13809
13544
|
if (attempt.attemptId !== stored.attemptId || attempt.originRunId !== run.runId || encodeAttemptLocator(attempt.attemptId) !== stored.attemptLocator) throw factsError("Attempt Core does not match its sealed row");
|
|
13810
13545
|
return attempt;
|
|
13811
13546
|
});
|
|
@@ -13813,9 +13548,19 @@ function decodeInspectionRun(source, physical) {
|
|
|
13813
13548
|
const localAttemptIds = new Set(attempts.map(({ attemptId }) => attemptId));
|
|
13814
13549
|
const attachments = physical.attachments.map((attachment) => {
|
|
13815
13550
|
if (attachment.ownerRunId !== run.runId || attachment.ownerKind === "run" && attachment.ownerAttemptId !== void 0 || attachment.ownerKind === "attempt" && (attachment.ownerAttemptId === void 0 || !localAttemptIds.has(attachment.ownerAttemptId))) throw factsError("Attachment ownership does not match its sealed Run");
|
|
13551
|
+
let value;
|
|
13552
|
+
let decoded = false;
|
|
13816
13553
|
return Object.freeze({
|
|
13817
13554
|
physical: attachment,
|
|
13818
|
-
value
|
|
13555
|
+
get value() {
|
|
13556
|
+
if (!decoded) {
|
|
13557
|
+
verifyDigest(attachment.canonicalBytes, attachment.canonicalDigest, "Attachment");
|
|
13558
|
+
verifyDigest(attachment.logicalInventoryBytes, attachment.inventoryDigest, "Attachment inventory");
|
|
13559
|
+
value = parseInspectionJson(attachment.canonicalBytes, "Attachment");
|
|
13560
|
+
decoded = true;
|
|
13561
|
+
}
|
|
13562
|
+
return value;
|
|
13563
|
+
}
|
|
13819
13564
|
});
|
|
13820
13565
|
});
|
|
13821
13566
|
return Object.freeze({
|
|
@@ -13861,23 +13606,51 @@ function resolveInspectionAttempt(source, locator) {
|
|
|
13861
13606
|
targets: Object.freeze(targets)
|
|
13862
13607
|
});
|
|
13863
13608
|
}
|
|
13864
|
-
|
|
13609
|
+
var memberIndexes = /* @__PURE__ */ new WeakMap();
|
|
13610
|
+
function memberIndex(runs) {
|
|
13611
|
+
const cached = memberIndexes.get(runs);
|
|
13612
|
+
if (cached !== void 0) return cached;
|
|
13613
|
+
const origins = new Map(runs.map((run) => [run.run.runId, {
|
|
13614
|
+
run,
|
|
13615
|
+
attempts: new Map(run.attempts.map((attempt) => [attempt.attemptId, attempt])),
|
|
13616
|
+
members: new Map(run.members.map((member) => [member.slotId, member]))
|
|
13617
|
+
}]));
|
|
13618
|
+
const targets = /* @__PURE__ */ new Map();
|
|
13619
|
+
for (const run of runs) for (const member of run.members) {
|
|
13620
|
+
if (member.attempt === null) continue;
|
|
13621
|
+
const { originRunId, attemptId } = member.attempt;
|
|
13622
|
+
let byAttempt = targets.get(originRunId);
|
|
13623
|
+
if (byAttempt === void 0) targets.set(originRunId, byAttempt = /* @__PURE__ */ new Map());
|
|
13624
|
+
let members = byAttempt.get(attemptId);
|
|
13625
|
+
if (members === void 0) byAttempt.set(attemptId, members = []);
|
|
13626
|
+
members.push(Object.freeze({
|
|
13627
|
+
run,
|
|
13628
|
+
member
|
|
13629
|
+
}));
|
|
13630
|
+
}
|
|
13631
|
+
for (const byAttempt of targets.values()) for (const members of byAttempt.values()) Object.freeze(members);
|
|
13632
|
+
const index = {
|
|
13633
|
+
origins,
|
|
13634
|
+
targets
|
|
13635
|
+
};
|
|
13636
|
+
memberIndexes.set(runs, index);
|
|
13637
|
+
return index;
|
|
13638
|
+
}
|
|
13639
|
+
/** Resolves already loaded facts through one shared identity index. */
|
|
13865
13640
|
function resolveInspectionMemberAttempt(runs, target, member) {
|
|
13866
13641
|
if (member.attempt === null) return void 0;
|
|
13867
|
-
const
|
|
13868
|
-
const
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
const targets =
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
})));
|
|
13875
|
-
if (!targets.some(({ run, member: candidate }) => run.run.runId === target.run.runId && candidate.slotId === member.slotId)) return;
|
|
13642
|
+
const index = memberIndex(runs);
|
|
13643
|
+
const origin = index.origins.get(member.attempt.originRunId);
|
|
13644
|
+
const attempt = origin?.attempts.get(member.attempt.attemptId);
|
|
13645
|
+
if (origin === void 0 || attempt === void 0 || attempt.originRunId !== member.attempt.originRunId) return void 0;
|
|
13646
|
+
const targets = index.targets.get(attempt.originRunId)?.get(attempt.attemptId) ?? [];
|
|
13647
|
+
const targetMember = index.origins.get(target.run.runId)?.members.get(member.slotId);
|
|
13648
|
+
if (targetMember?.attempt?.originRunId !== attempt.originRunId || targetMember.attempt.attemptId !== attempt.attemptId) return void 0;
|
|
13876
13649
|
return Object.freeze({
|
|
13877
13650
|
attempt,
|
|
13878
|
-
origin,
|
|
13879
|
-
locator,
|
|
13880
|
-
targets
|
|
13651
|
+
origin: origin.run,
|
|
13652
|
+
locator: encodeAttemptLocator(attempt.attemptId),
|
|
13653
|
+
targets
|
|
13881
13654
|
});
|
|
13882
13655
|
}
|
|
13883
13656
|
function attemptAttachment(resolved, family) {
|
|
@@ -14027,6 +13800,13 @@ function factsError(reason, cause) {
|
|
|
14027
13800
|
function compareText$1(left, right) {
|
|
14028
13801
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
14029
13802
|
}
|
|
13803
|
+
function verifyDigest(bytes, digest, label) {
|
|
13804
|
+
if (new RecordSha256().update(bytes).digestHex() !== digest) throw factsError(`${label} digest is invalid`);
|
|
13805
|
+
}
|
|
13806
|
+
function parseVerifiedJson(bytes, digest, label) {
|
|
13807
|
+
verifyDigest(bytes, digest, label);
|
|
13808
|
+
return parseJson$1(bytes, label);
|
|
13809
|
+
}
|
|
14030
13810
|
//#endregion
|
|
14031
13811
|
//#region src/shared/types.ts
|
|
14032
13812
|
/** 一次 Attempt 的互斥终态;跳过是已结束但不构成可执行结论的结果。 */
|
|
@@ -16112,6 +15892,7 @@ function isLoadedInspectionRuns(facts) {
|
|
|
16112
15892
|
return Array.isArray(facts);
|
|
16113
15893
|
}
|
|
16114
15894
|
function selectLatestSlots(runs, resolutionRuns = runs) {
|
|
15895
|
+
const membersByRun = new Map(runs.map((run) => [run, new Map(run.members.map((member) => [member.slotId, member]))]));
|
|
16115
15896
|
const latest = /* @__PURE__ */ new Map();
|
|
16116
15897
|
for (const target of runs) for (const slot of target.run.expectedSlots) {
|
|
16117
15898
|
const key = `${target.run.experimentId}\u0000${slot.evalId}\u0000${slot.attemptOrdinal}`;
|
|
@@ -16122,7 +15903,7 @@ function selectLatestSlots(runs, resolutionRuns = runs) {
|
|
|
16122
15903
|
}));
|
|
16123
15904
|
}
|
|
16124
15905
|
return Object.freeze([...latest.values()].sort((left, right) => compareText(left.target.run.experimentId, right.target.run.experimentId) || compareText(left.slot.evalId, right.slot.evalId) || left.slot.attemptOrdinal - right.slot.attemptOrdinal || compareText(left.target.run.runId, right.target.run.runId)).map(({ target, slot }) => {
|
|
16125
|
-
const member =
|
|
15906
|
+
const member = membersByRun.get(target)?.get(slot.slotId);
|
|
16126
15907
|
const resolved = member === void 0 ? void 0 : resolveInspectionMemberAttempt(resolutionRuns, target, member);
|
|
16127
15908
|
return Object.freeze({
|
|
16128
15909
|
experimentId: target.run.experimentId,
|
|
@@ -19066,8 +18847,9 @@ function selectOperation(source, operation) {
|
|
|
19066
18847
|
});
|
|
19067
18848
|
}
|
|
19068
18849
|
case "experiment.get": {
|
|
19069
|
-
const
|
|
19070
|
-
const
|
|
18850
|
+
const matching = loadSelectedInspectionRuns(source, source.findExperimentRunIds(operation.experimentId));
|
|
18851
|
+
const selected = loadReferencedOrigins(source, matching);
|
|
18852
|
+
const overview = selectInspectionOverview(matching, selected);
|
|
19071
18853
|
const experiment = overview.experiments.find(({ experimentId }) => experimentId === operation.experimentId);
|
|
19072
18854
|
if (experiment === void 0) throw selectionMissing(operation.kind, `Experiment ${operation.experimentId} was not found`);
|
|
19073
18855
|
const experimentCells = Object.freeze(overview.cells.filter(({ experimentId }) => experimentId === operation.experimentId));
|
|
@@ -19075,6 +18857,10 @@ function selectOperation(source, operation) {
|
|
|
19075
18857
|
let unresolvedAttemptCount = 0;
|
|
19076
18858
|
let selectedSlotCount = 0;
|
|
19077
18859
|
let resolvedSlotCount = 0;
|
|
18860
|
+
const origins = new Map(selected.map((origin) => [origin.run.runId, {
|
|
18861
|
+
origin,
|
|
18862
|
+
attempts: new Map(origin.attempts.map((attempt) => [attempt.attemptId, attempt]))
|
|
18863
|
+
}]));
|
|
19078
18864
|
for (const cell of experimentCells) for (const member of cell.members) {
|
|
19079
18865
|
selectedSlotCount++;
|
|
19080
18866
|
if (member.publication.state !== "published") {
|
|
@@ -19082,8 +18868,9 @@ function selectOperation(source, operation) {
|
|
|
19082
18868
|
continue;
|
|
19083
18869
|
}
|
|
19084
18870
|
const identity = member.publication;
|
|
19085
|
-
const
|
|
19086
|
-
const
|
|
18871
|
+
const indexed = origins.get(identity.originRunId);
|
|
18872
|
+
const origin = indexed?.origin;
|
|
18873
|
+
const attempt = indexed?.attempts.get(identity.attemptId);
|
|
19087
18874
|
if (origin === void 0 || attempt === void 0) {
|
|
19088
18875
|
unresolvedAttemptCount++;
|
|
19089
18876
|
continue;
|