mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 20:29:18 +01:00
Drive bounded run-log and provider trace migration pages during online durable-data preparation. Share the page owner and settled-native archive rules with background migration, preserve active-source and storage-integrity guards, and report fresh page results. Keep canceled transfers owned and tracked until the underlying operation settles. Retain page cursors across the preparation budget. Verified 52 focused tests, including embedded PostgreSQL and object storage, server typechecking, and all 58 successful PR checks. Greptile 5/5 with no unresolved review comments. Co-Authored-By: Paperclip <noreply@paperclip.ing>
37 lines
1.7 KiB
TypeScript
37 lines
1.7 KiB
TypeScript
import type { Db } from "@paperclipai/db";
|
|
import { migrateRunEvidence, type RunEvidenceMigrationItem } from "./run-evidence-migration.js";
|
|
import { beginIdleTrackedWork } from "./task-admission.js";
|
|
|
|
const owners = new WeakSet<Db>();
|
|
const unprovenCoverage = new Set(["native_log_source_coverage_unproven", "native_run_log_source_integrity_error"]);
|
|
type PageOptions = Pick<Parameters<typeof migrateRunEvidence>[1], "afterRunId" | "afterTraceId" | "limit" | "kinds" | "signal">;
|
|
export type RunEvidenceMigrationPage = Awaited<ReturnType<typeof migrateRunEvidence>> & { busy?: boolean };
|
|
|
|
export async function migrateRunEvidencePage(db: Db, options: PageOptions): Promise<RunEvidenceMigrationPage> {
|
|
options.signal?.throwIfAborted();
|
|
if (owners.has(db)) return { items: [], busy: true };
|
|
owners.add(db);
|
|
const settled = beginIdleTrackedWork();
|
|
try {
|
|
const result = await migrateRunEvidence(db, { ...options, apply: true });
|
|
options.signal?.throwIfAborted();
|
|
const items: RunEvidenceMigrationItem[] = [];
|
|
for (const item of result.items) {
|
|
options.signal?.throwIfAborted();
|
|
if (item.kind !== "log" || item.state !== "blocked" || !unprovenCoverage.has(item.reason ?? "")) {
|
|
items.push(item);
|
|
continue;
|
|
}
|
|
const archived = await migrateRunEvidence(db, { apply: true, runId: item.id, kinds: ["log"], limit: 1,
|
|
preserveSettledNativeFiles: true, signal: options.signal });
|
|
options.signal?.throwIfAborted();
|
|
const current = archived.items.find(candidate => candidate.id === item.id);
|
|
if (current) items.push(current);
|
|
}
|
|
return { ...result, items };
|
|
} finally {
|
|
owners.delete(db);
|
|
settled();
|
|
}
|
|
}
|