@bastani/atomic 0.9.83 → 0.9.84
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/CHANGELOG.md +40 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/cli/storage-command.d.ts +12 -1
- package/dist/cli/storage-command.d.ts.map +1 -1
- package/dist/cli/storage-command.js +210 -47
- package/dist/cli/storage-command.js.map +1 -1
- package/dist/core/session-transfer.d.ts +84 -0
- package/dist/core/session-transfer.d.ts.map +1 -0
- package/dist/core/session-transfer.js +270 -0
- package/dist/core/session-transfer.js.map +1 -0
- package/dist/core/storage/journal-transfer.d.ts +74 -35
- package/dist/core/storage/journal-transfer.d.ts.map +1 -1
- package/dist/core/storage/journal-transfer.js +384 -278
- package/dist/core/storage/journal-transfer.js.map +1 -1
- package/dist/core/storage/transfer-files.d.ts +75 -0
- package/dist/core/storage/transfer-files.d.ts.map +1 -0
- package/dist/core/storage/transfer-files.js +170 -0
- package/dist/core/storage/transfer-files.js.map +1 -0
- package/dist/core/storage-transfer.d.ts +30 -0
- package/dist/core/storage-transfer.d.ts.map +1 -0
- package/dist/core/storage-transfer.js +49 -0
- package/dist/core/storage-transfer.js.map +1 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +7 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +21 -1
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +1 -0
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/docs/reference/cli.md +31 -3
- package/docs/storage.md +81 -17
- package/npm-shrinkwrap.json +38 -38
- package/package.json +3 -3
|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,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC5B,IAAI,CAAC;oBACJ,QAAQ,GAAG,MAAM,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,MAAM,eAAe,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,KAAc,CAAC,CAAC;gBACxD,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAClC,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;gBACtD,MAAM,sBAAsB,CAAC,EAAE,CAAC,CAAC;gBACjC,OAAO,WAAW,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5C,CAAC,EAAE,oBAAoB,CAAC,CAAC;YACzB,IAAI,MAAM,KAAK,WAAW;gBAAE,MAAM,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACnE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvB,CAAC;IACF,CAAC,EACD,KAAK,IAAI,EAAE;QACV,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACjC,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC,CACD,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * Workflow runs as versioned JSONL files (#4716): `exportWorkflowRuns` writes each run of a local workflow journal to\n * `<dir>/<runId>.jsonl`, and `importWorkflowRuns` restores such files into one. The journal stays the working store;\n * the files are the form runs take at rest, so a host that persists only files can carry them between machines.\n *\n * Line 1 of a file is the run's header: the row of the journal's runs table. Every later line is one row of its\n * events table, in sequence order, with its payload as a JSON value instead of JSON text. Leases, local-worker pool\n * state and worktree snapshot blobs are not exported: they belong to the machine that wrote them.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { existsSync } from \"node:fs\";\nimport { mkdir, open, readdir, readFile, rename, rm } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { closeEach, withCleanup } from \"./cleanup.js\";\nimport type { SqliteDatabase, SqliteExecutor, SqliteRow, SqliteValue } from \"./database.js\";\nimport { StorageError, type StorageFailureCause } from \"./errors.js\";\nimport {\n\tdiscoverLegacyJournal,\n\tensureRunJournalSchema,\n\ttype JournalEventTableRow,\n\ttype JournalLeaseTableRow,\n\ttype JournalRunTableRow,\n\tlegacyDefaultJournalPath,\n\trunJournalTables,\n} from \"./journal-adoption.js\";\nimport {\n\tisFinishedJournalStatus,\n\tJOURNAL_CATALOG_FILE,\n\tJournalCatalog,\n\ttype JournalCatalogRun,\n\ttype JournalShardRecord,\n} from \"./journal-catalog.js\";\nimport { openNodeSqliteDatabase } from \"./node-sqlite.js\";\nimport { RUN_EVENT_TYPES, RUN_JOURNAL_SCHEMA_VERSION } from \"./run-journal.js\";\n\n/** The `type` of an export file's header line. */\nexport const WORKFLOW_RUN_EXPORT_TYPE = \"atomic.workflow-run\";\n/** The export format version this Atomic writes and reads. */\nexport const WORKFLOW_RUN_EXPORT_VERSION = 1;\n/** The file name extension of an exported run; import reads every file with it and ignores the rest. */\nexport const WORKFLOW_RUN_EXPORT_EXTENSION = \".jsonl\";\n/**\n * A lease renewed this recently belongs to a process that may still be running the run on this machine, so an import\n * does not add events to that run. It matches the window in which the workflows runtime treats a running run's owner\n * as live.\n */\nexport const WORKFLOW_RUN_IMPORT_LIVE_LEASE_MS = 120_000;\n\n/** A JSON value as an export file holds it. */\nexport type WorkflowRunExportValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| readonly WorkflowRunExportValue[]\n\t| { readonly [key: string]: WorkflowRunExportValue };\n\n/** Line 1 of an export file. */\nexport interface WorkflowRunExportHeader {\n\treadonly type: typeof WORKFLOW_RUN_EXPORT_TYPE;\n\treadonly version: typeof WORKFLOW_RUN_EXPORT_VERSION;\n\treadonly runId: string;\n\treadonly name: string;\n\treadonly cwd: string;\n\treadonly createdAt: number;\n\t/** The run's latest status. */\n\treadonly status: string;\n\t/** How many event lines follow. */\n\treadonly events: number;\n\t/** The run header the journal recorded when the run was created. */\n\treadonly header: { readonly [key: string]: WorkflowRunExportValue };\n}\n\n/** One event line of an export file: one journal entry. */\nexport interface WorkflowRunExportEvent {\n\treadonly type: string;\n\treadonly seq: number;\n\treadonly epoch: number;\n\treadonly key: string | null;\n\treadonly at: number;\n\treadonly payload: WorkflowRunExportValue;\n}\n\n/** The local workflow journal storage that runs are exported from and imported into. */\nexport type WorkflowRunTransferStorage =\n\t| { readonly kind: \"store\"; readonly directory: string }\n\t| { readonly kind: \"sqlite\"; readonly path: string; readonly prefix?: string };\n\nexport interface WorkflowRunTransferErrorInit {\n\t/** The file or storage location the error is about. */\n\treadonly path: string;\n\t/** The 1-based line of `path`. */\n\treadonly line?: number;\n\treadonly runId?: string;\n\treadonly reason: string;\n\treadonly cause?: StorageFailureCause;\n}\n\n/** An export or import that could not be done; an import that fails this way changed nothing. */\nexport class WorkflowRunTransferError extends StorageError {\n\toverride readonly name = \"WorkflowRunTransferError\" as const;\n\treadonly path: string;\n\treadonly line: number | undefined;\n\treadonly runId: string | undefined;\n\treadonly reason: string;\n\n\tconstructor(init: WorkflowRunTransferErrorInit) {\n\t\tsuper(`${init.path}${init.line === undefined ? \"\" : `:${init.line}`}: ${init.reason}`, { cause: init.cause });\n\t\tthis.path = init.path;\n\t\tthis.line = init.line;\n\t\tthis.runId = init.runId;\n\t\tthis.reason = init.reason;\n\t}\n}\n\nexport function isWorkflowRunTransferError(value: unknown): value is WorkflowRunTransferError {\n\tif (value instanceof WorkflowRunTransferError) return true;\n\treturn (\n\t\ttypeof value === \"object\" && value !== null && (value as { name?: unknown }).name === \"WorkflowRunTransferError\"\n\t);\n}\n\nexport interface WorkflowRunExportOptions {\n\t/** Only these runs; a run the storage does not hold fails the export before any file is written. */\n\treadonly runs?: readonly string[];\n\t/** Only runs that are not completed, failed or cancelled. */\n\treadonly unfinished?: boolean;\n\t/** At most this many runs, newest first. */\n\treadonly limit?: number;\n}\n\nexport interface WorkflowRunExportReport {\n\t/** Runs whose file was written. */\n\treadonly written: readonly string[];\n\t/** Runs whose file already held exactly this export, left untouched. */\n\treadonly unchanged: readonly string[];\n\t/** Journal files that could not be read, and runs the catalog lists that no readable journal holds. */\n\treadonly skipped: readonly { readonly path: string; readonly runId?: string; readonly reason: string }[];\n}\n\nexport interface WorkflowRunImportReport {\n\t/** Runs the storage did not hold. */\n\treadonly added: readonly string[];\n\t/** Runs the storage held an earlier part of, which now have the file's later events. */\n\treadonly updated: readonly string[];\n\t/** Runs the storage already held every event of. */\n\treadonly unchanged: readonly string[];\n}\n\nconst STORE_NOW = \"CAST(unixepoch('subsec') * 1000 AS INTEGER)\";\nconst TRANSFER_TRANSACTION = { lockWaitMs: 10 * 60_000 } as const;\nconst EVENT_TYPES: ReadonlySet<string> = new Set(Object.values(RUN_EVENT_TYPES));\nconst HEADER_FIELDS = [\"type\", \"version\", \"runId\", \"name\", \"cwd\", \"createdAt\", \"status\", \"events\", \"header\"] as const;\nconst EVENT_FIELDS = [\"type\", \"seq\", \"epoch\", \"key\", \"at\", \"payload\"] as const;\n\ntype JsonObject = { readonly [key: string]: WorkflowRunExportValue };\ntype Tables = ReturnType<typeof runJournalTables>;\n\n/** The file an exported run is written to in `directory`. */\nexport function workflowRunExportFile(directory: string, runId: string): string {\n\treturn join(directory, `${encodeURIComponent(runId)}${WORKFLOW_RUN_EXPORT_EXTENSION}`);\n}\n\nfunction storageLocation(storage: WorkflowRunTransferStorage): string {\n\treturn storage.kind === \"store\" ? storage.directory : storage.path;\n}\n\nfunction parseStored(text: string, path: string, runId: string, what: string): WorkflowRunExportValue {\n\ttry {\n\t\treturn JSON.parse(text) as WorkflowRunExportValue;\n\t} catch (cause) {\n\t\tthrow new WorkflowRunTransferError({\n\t\t\tpath,\n\t\t\trunId,\n\t\t\treason: `run ${runId} has ${what} that is not valid JSON`,\n\t\t\tcause: cause as StorageFailureCause,\n\t\t});\n\t}\n}\n\n/** A run and its events as the lines of its export file, newline-terminated. */\nfunction exportText(run: JournalRunTableRow, events: readonly JournalEventTableRow[], path: string): string {\n\tconst header = parseStored(run.header_json, path, run.run_id, \"a header\");\n\tif (!isObject(header))\n\t\tthrow new WorkflowRunTransferError({\n\t\t\tpath,\n\t\t\trunId: run.run_id,\n\t\t\treason: `run ${run.run_id} has a header that is not an object`,\n\t\t});\n\tconst lines = [\n\t\tJSON.stringify({\n\t\t\ttype: WORKFLOW_RUN_EXPORT_TYPE,\n\t\t\tversion: WORKFLOW_RUN_EXPORT_VERSION,\n\t\t\trunId: run.run_id,\n\t\t\tname: run.name,\n\t\t\tcwd: run.cwd,\n\t\t\tcreatedAt: Number(run.created_at),\n\t\t\tstatus: run.status,\n\t\t\tevents: events.length,\n\t\t\theader,\n\t\t} satisfies WorkflowRunExportHeader),\n\t];\n\tfor (const event of events)\n\t\tlines.push(\n\t\t\tJSON.stringify({\n\t\t\t\ttype: event.type,\n\t\t\t\tseq: Number(event.seq),\n\t\t\t\tepoch: Number(event.epoch),\n\t\t\t\tkey: event.key,\n\t\t\t\tat: Number(event.at),\n\t\t\t\tpayload: parseStored(event.payload, path, run.run_id, `event ${event.seq} with a payload`),\n\t\t\t} satisfies WorkflowRunExportEvent),\n\t\t);\n\treturn `${lines.join(\"\\n\")}\\n`;\n}\n\n/**\n * Writes `content` to `file` through a temporary file in the same directory that is flushed and then renamed over it,\n * so `file` holds either its earlier content or all of `content`. A file that already holds `content` is left alone.\n */\nasync function writeAtomically(file: string, content: string): Promise<\"written\" | \"unchanged\"> {\n\tconst existing = await readFile(file, \"utf8\").catch(() => undefined);\n\tif (existing === content) return \"unchanged\";\n\tconst temporary = join(resolve(file, \"..\"), `.${randomUUID()}.tmp`);\n\ttry {\n\t\tconst handle = await open(temporary, \"wx\");\n\t\tawait withCleanup(\n\t\t\tasync () => {\n\t\t\t\tawait handle.writeFile(content, \"utf8\");\n\t\t\t\tawait handle.sync();\n\t\t\t},\n\t\t\t() => handle.close(),\n\t\t);\n\t\tawait rename(temporary, file);\n\t} catch (error) {\n\t\tawait rm(temporary, { force: true }).catch(() => undefined);\n\t\tthrow new WorkflowRunTransferError({\n\t\t\tpath: file,\n\t\t\treason: `cannot write the export file: ${(error as Error).message}`,\n\t\t\tcause: error as StorageFailureCause,\n\t\t});\n\t}\n\treturn \"written\";\n}\n\nasync function hasTables(executor: SqliteExecutor, t: Tables): Promise<boolean> {\n\tconst rows = await executor.all<SqliteRow & { name: string }>(\n\t\t\"SELECT name FROM sqlite_master WHERE type = 'table' AND name IN (?, ?, ?)\",\n\t\tt.meta,\n\t\tt.runs,\n\t\tt.events,\n\t);\n\treturn rows.length === 3;\n}\n\nasync function schemaVersion(executor: SqliteExecutor, t: Tables): Promise<SqliteValue | undefined> {\n\tconst rows = await executor.all<SqliteRow & { schema_version: SqliteValue }>(`SELECT schema_version FROM ${t.meta}`);\n\treturn rows.length === 1 ? rows[0]!.schema_version : undefined;\n}\n\n/** One journal file an export reads, inside one read transaction, so every run it holds is read as of one moment. */\ninterface ExportSource {\n\treadonly path: string;\n\treadonly shardId?: number;\n\treadonly database: SqliteDatabase;\n\treadonly runs: readonly JournalRunTableRow[];\n}\n\n/** Opens a journal file for an export and begins its read transaction; undefined, with the reason, when it cannot. */\nasync function openExportSource(\n\tpath: string,\n\tt: Tables,\n\tshardId: number | undefined,\n): Promise<ExportSource | { readonly path: string; readonly reason: string }> {\n\tif (!existsSync(path)) return { path, reason: \"the journal file no longer exists\" };\n\tlet database: SqliteDatabase;\n\ttry {\n\t\tdatabase = await openNodeSqliteDatabase(path, { readOnly: true });\n\t} catch (error) {\n\t\treturn { path, reason: `the journal file cannot be opened: ${(error as Error).message}` };\n\t}\n\ttry {\n\t\tawait database.exec(\"BEGIN\");\n\t\tif (!(await hasTables(database, t))) {\n\t\t\tawait database.exec(\"COMMIT\");\n\t\t\tawait database.close();\n\t\t\treturn { path, reason: \"it has no workflow runs in the current journal format\" };\n\t\t}\n\t\tconst version = await schemaVersion(database, t);\n\t\tif (version !== RUN_JOURNAL_SCHEMA_VERSION) {\n\t\t\tawait database.exec(\"COMMIT\");\n\t\t\tawait database.close();\n\t\t\treturn { path, reason: `unsupported journal schema version ${String(version)}` };\n\t\t}\n\t\tconst runs = await database.all<JournalRunTableRow>(`SELECT * FROM ${t.runs} ORDER BY run_id`);\n\t\treturn { path, database, runs, ...(shardId === undefined ? {} : { shardId }) };\n\t} catch (error) {\n\t\tawait database.close().catch(() => undefined);\n\t\treturn { path, reason: `the journal file cannot be read: ${(error as Error).message}` };\n\t}\n}\n\n/**\n * Adopts the default journal of Atomic before the journal store, as opening the store does, so its runs are exported\n * and compared like every other run; whether the store has a catalog.\n */\nasync function adoptLegacyJournal(directory: string): Promise<boolean> {\n\tif (existsSync(legacyDefaultJournalPath(directory))) {\n\t\tconst catalog = await JournalCatalog.open(directory);\n\t\tawait withCleanup(\n\t\t\tasync () => {\n\t\t\t\tawait discoverLegacyJournal(catalog, legacyDefaultJournalPath(directory));\n\t\t\t},\n\t\t\t() => catalog.close(),\n\t\t);\n\t}\n\treturn existsSync(join(directory, JOURNAL_CATALOG_FILE));\n}\n\nfunction newestFirst(left: JournalRunTableRow, right: JournalRunTableRow): number {\n\tconst created = Number(right.created_at) - Number(left.created_at);\n\tif (created !== 0) return created;\n\treturn left.run_id < right.run_id ? -1 : left.run_id > right.run_id ? 1 : 0;\n}\n\n/**\n * Exports runs of a local workflow journal to `<directory>/<runId>.jsonl`, one file per run. Each journal file is read\n * in one read transaction, and each export file is written whole or not at all. The same journal state gives the same\n * bytes, and a file that already holds them is not rewritten.\n */\nexport async function exportWorkflowRuns(\n\tstorage: WorkflowRunTransferStorage,\n\tdirectory: string,\n\toptions: WorkflowRunExportOptions = {},\n): Promise<WorkflowRunExportReport> {\n\tconst t = runJournalTables(storage.kind === \"sqlite\" ? storage.prefix : undefined);\n\tconst skipped: { path: string; runId?: string; reason: string }[] = [];\n\tconst sources: ExportSource[] = [];\n\tlet owners: ReadonlyMap<string, number> | undefined;\n\tlet catalogued: readonly JournalCatalogRun[] = [];\n\tconst add = (opened: Awaited<ReturnType<typeof openExportSource>>) => {\n\t\tif (\"database\" in opened) sources.push(opened);\n\t\telse skipped.push(opened);\n\t};\n\treturn withCleanup(\n\t\tasync () => {\n\t\t\tif (storage.kind === \"sqlite\") {\n\t\t\t\tif (existsSync(storage.path)) add(await openExportSource(storage.path, t, undefined));\n\t\t\t} else if (await adoptLegacyJournal(storage.directory)) {\n\t\t\t\tconst catalog = await JournalCatalog.open(storage.directory);\n\t\t\t\tlet shards: readonly JournalShardRecord[];\n\t\t\t\tawait withCleanup(\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tshards = await catalog.shards();\n\t\t\t\t\t\tcatalogued = await catalog.runs();\n\t\t\t\t\t\towners = new Map(catalogued.map((run) => [run.runId, run.shard]));\n\t\t\t\t\t},\n\t\t\t\t\t() => catalog.close(),\n\t\t\t\t);\n\t\t\t\tfor (const shard of shards!) add(await openExportSource(shard.path, t, shard.id));\n\t\t\t}\n\t\t\tconst listed = new Map<string, { readonly source: ExportSource; readonly run: JournalRunTableRow }>();\n\t\t\tfor (const source of sources)\n\t\t\t\tfor (const run of source.runs) {\n\t\t\t\t\tconst owner = owners?.get(run.run_id);\n\t\t\t\t\tif (owner === undefined ? listed.has(run.run_id) : owner !== source.shardId) continue;\n\t\t\t\t\tlisted.set(run.run_id, { source, run });\n\t\t\t\t}\n\t\t\t// A consolidation that moved a run between reading the catalog and opening the journal files leaves it only in\n\t\t\t// a file the catalog did not name then: that copy is the run. A run whose named file could not be read is not\n\t\t\t// taken from another file, which may hold an older copy an interrupted consolidation left behind.\n\t\t\tconst readable = new Set(sources.map((source) => source.shardId));\n\t\t\tfor (const source of sources)\n\t\t\t\tfor (const run of source.runs) {\n\t\t\t\t\tconst owner = owners?.get(run.run_id);\n\t\t\t\t\tif (listed.has(run.run_id) || (owner !== undefined && !readable.has(owner))) continue;\n\t\t\t\t\tlisted.set(run.run_id, { source, run });\n\t\t\t\t}\n\t\t\t// A run whose journal file was read but does not hold it in the current tables is in the pre-0.9.38 format;\n\t\t\t// the runs of a journal file that could not be read are covered by that file's own entry, and a root that is\n\t\t\t// only reserved (no status yet) has nothing to export.\n\t\t\tif (options.runs === undefined)\n\t\t\t\tfor (const entry of catalogued) {\n\t\t\t\t\tconst source = sources.find((candidate) => candidate.shardId === entry.shard);\n\t\t\t\t\tif (!listed.has(entry.runId) && source !== undefined && entry.status !== undefined)\n\t\t\t\t\t\tskipped.push({\n\t\t\t\t\t\t\tpath: source.path,\n\t\t\t\t\t\t\trunId: entry.runId,\n\t\t\t\t\t\t\treason: \"it is in the journal format of Atomic before 0.9.38; resume it once to convert it\",\n\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\tlet selected = [...listed.values()];\n\t\t\tif (options.runs !== undefined) {\n\t\t\t\tconst missing = options.runs.find((runId) => !listed.has(runId));\n\t\t\t\tif (missing !== undefined)\n\t\t\t\t\tthrow new WorkflowRunTransferError({\n\t\t\t\t\t\tpath: storageLocation(storage),\n\t\t\t\t\t\trunId: missing,\n\t\t\t\t\t\treason: `run ${missing} is not in this workflow journal`,\n\t\t\t\t\t});\n\t\t\t\tselected = [...new Set(options.runs)].map((runId) => listed.get(runId)!);\n\t\t\t}\n\t\t\tif (options.unfinished) selected = selected.filter(({ run }) => !isFinishedJournalStatus(run.status));\n\t\t\tselected.sort((left, right) => newestFirst(left.run, right.run));\n\t\t\tif (options.limit !== undefined) selected = selected.slice(0, options.limit);\n\t\t\tawait mkdir(directory, { recursive: true });\n\t\t\tconst written: string[] = [];\n\t\t\tconst unchanged: string[] = [];\n\t\t\tfor (const { source, run } of selected) {\n\t\t\t\tconst events = await source.database.all<JournalEventTableRow>(\n\t\t\t\t\t`SELECT * FROM ${t.events} WHERE run_id = ? ORDER BY seq`,\n\t\t\t\t\trun.run_id,\n\t\t\t\t);\n\t\t\t\tconst file = workflowRunExportFile(directory, run.run_id);\n\t\t\t\tconst outcome = await writeAtomically(file, exportText(run, events, source.path));\n\t\t\t\t(outcome === \"written\" ? written : unchanged).push(run.run_id);\n\t\t\t}\n\t\t\treturn { written, unchanged, skipped };\n\t\t},\n\t\tasync () => {\n\t\t\tawait Promise.allSettled(sources.map((source) => source.database.exec(\"COMMIT\")));\n\t\t\tawait closeEach(sources.map((source) => source.database));\n\t\t},\n\t);\n}\n\n/** A run read from an export file and checked: everything an import writes for it. */\ninterface ParsedRun {\n\treadonly file: string;\n\treadonly header: WorkflowRunExportHeader;\n\treadonly events: readonly WorkflowRunExportEvent[];\n}\n\nfunction isObject(value: WorkflowRunExportValue | undefined): value is JsonObject {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction invalidText(value: string): string | undefined {\n\tif (value.includes(\"\\u0000\")) return \"contains a NUL character\";\n\tif (/\\p{Surrogate}/u.test(value)) return \"is not well-formed Unicode\";\n\treturn undefined;\n}\n\nfunction counter(value: WorkflowRunExportValue | undefined, minimum: number): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= minimum;\n}\n\n/** Checks that a line has exactly `fields`; the reason when it does not. */\nfunction fieldsReason(line: JsonObject, fields: readonly string[]): string | undefined {\n\tfor (const field of fields) if (!(field in line)) return `has no \"${field}\" field`;\n\tfor (const field of Object.keys(line)) if (!fields.includes(field)) return `has an unexpected \"${field}\" field`;\n\treturn undefined;\n}\n\n/** Reads and checks one export file, throwing a `WorkflowRunTransferError` that names the file and line. */\nfunction parseExportFile(file: string, bytes: Buffer): ParsedRun {\n\tconst fail = (line: number | undefined, reason: string, runId?: string): never => {\n\t\tthrow new WorkflowRunTransferError({ path: file, ...(line === undefined ? {} : { line }), runId, reason });\n\t};\n\tlet text: string;\n\ttry {\n\t\ttext = new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n\t} catch {\n\t\treturn fail(undefined, \"is not valid UTF-8 text\");\n\t}\n\tconst lines = text.split(\"\\n\");\n\tif (lines.at(-1) === \"\") lines.pop();\n\tif (lines.length === 0) return fail(1, \"is empty; expected a workflow run header\");\n\tconst parse = (index: number): JsonObject => {\n\t\tconst line = lines[index]!;\n\t\tif (line.trim() === \"\") return fail(index + 1, \"is empty\");\n\t\tlet value: WorkflowRunExportValue;\n\t\ttry {\n\t\t\tvalue = JSON.parse(line) as WorkflowRunExportValue;\n\t\t} catch (error) {\n\t\t\treturn fail(index + 1, `is not valid JSON (${(error as Error).message})`);\n\t\t}\n\t\tif (!isObject(value)) return fail(index + 1, \"is not a JSON object\");\n\t\tif (typeof value.type !== \"string\") return fail(index + 1, 'has no string \"type\"');\n\t\treturn value;\n\t};\n\tconst first = parse(0);\n\tif (first.type !== WORKFLOW_RUN_EXPORT_TYPE)\n\t\tfail(1, `is not an Atomic workflow run export: its type is \"${first.type}\", not \"${WORKFLOW_RUN_EXPORT_TYPE}\"`);\n\tif (first.version !== WORKFLOW_RUN_EXPORT_VERSION)\n\t\tfail(\n\t\t\t1,\n\t\t\t`has unsupported export version ${JSON.stringify(first.version ?? null)}; this Atomic reads version ${WORKFLOW_RUN_EXPORT_VERSION}`,\n\t\t);\n\tconst headerFields = fieldsReason(first, HEADER_FIELDS);\n\tif (headerFields !== undefined) fail(1, headerFields);\n\tfor (const field of [\"runId\", \"name\", \"cwd\", \"status\"] as const) {\n\t\tconst value = first[field];\n\t\tif (typeof value !== \"string\") fail(1, `has a \"${field}\" that is not a string`);\n\t\tconst reason = invalidText(value as string);\n\t\tif (reason !== undefined) fail(1, `has a \"${field}\" that ${reason}`);\n\t}\n\tconst runId = first.runId as string;\n\tif (runId === \"\") fail(1, 'has an empty \"runId\"');\n\tif (!counter(first.createdAt, Number.MIN_SAFE_INTEGER)) fail(1, 'has a \"createdAt\" that is not an integer', runId);\n\tif (!counter(first.events, 0)) fail(1, 'has an \"events\" count that is not a non-negative integer', runId);\n\tif (!isObject(first.header)) fail(1, 'has a \"header\" that is not an object', runId);\n\tif ((first.header as JsonObject).runId !== runId)\n\t\tfail(1, `has a \"header\" whose runId is not the run's ID ${runId}`, runId);\n\tconst events: WorkflowRunExportEvent[] = [];\n\tconst keys = new Map<string, number>();\n\tfor (let index = 1; index < lines.length; index++) {\n\t\tconst line = index + 1;\n\t\tconst event = parse(index);\n\t\tconst reason = fieldsReason(event, EVENT_FIELDS);\n\t\tif (reason !== undefined) fail(line, reason, runId);\n\t\tif (!EVENT_TYPES.has(event.type as string)) fail(line, `has unknown event type \"${event.type}\"`, runId);\n\t\tif (event.seq !== index) fail(line, `has seq ${JSON.stringify(event.seq)}; expected ${index}`, runId);\n\t\tif (!counter(event.epoch, 0)) fail(line, 'has an \"epoch\" that is not a non-negative integer', runId);\n\t\tif (!counter(event.at, Number.MIN_SAFE_INTEGER)) fail(line, 'has an \"at\" that is not an integer', runId);\n\t\tconst key = event.key;\n\t\tif (key !== null) {\n\t\t\tif (typeof key !== \"string\") fail(line, 'has a \"key\" that is neither a string nor null', runId);\n\t\t\tconst keyReason = invalidText(key as string);\n\t\t\tif (keyReason !== undefined) fail(line, `has a \"key\" that ${keyReason}`, runId);\n\t\t\tconst earlier = keys.get(key as string);\n\t\t\tif (earlier !== undefined) fail(line, `repeats the key of line ${earlier}`, runId);\n\t\t\tkeys.set(key as string, line);\n\t\t}\n\t\tif (event.type === RUN_EVENT_TYPES.statusChanged) {\n\t\t\tconst status = isObject(event.payload) ? event.payload.status : undefined;\n\t\t\tif (typeof status !== \"string\")\n\t\t\t\tfail(line, 'is a StatusChanged event whose payload has no string \"status\"', runId);\n\t\t\tconst statusReason = invalidText(status as string);\n\t\t\tif (statusReason !== undefined) fail(line, `has a status that ${statusReason}`, runId);\n\t\t}\n\t\tevents.push({\n\t\t\ttype: event.type as string,\n\t\t\tseq: event.seq as number,\n\t\t\tepoch: event.epoch as number,\n\t\t\tkey: key as string | null,\n\t\t\tat: event.at as number,\n\t\t\tpayload: event.payload!,\n\t\t});\n\t}\n\tif (lines.length - 1 !== first.events)\n\t\tfail(1, `says the run has ${first.events} events, but the file has ${lines.length - 1} event lines`, runId);\n\tconst header: WorkflowRunExportHeader = {\n\t\ttype: WORKFLOW_RUN_EXPORT_TYPE,\n\t\tversion: WORKFLOW_RUN_EXPORT_VERSION,\n\t\trunId,\n\t\tname: first.name as string,\n\t\tcwd: first.cwd as string,\n\t\tcreatedAt: first.createdAt as number,\n\t\tstatus: first.status as string,\n\t\tevents: first.events as number,\n\t\theader: first.header as JsonObject,\n\t};\n\treturn { file, header, events };\n}\n\n/** The fields import checks against a stored run: everything but string content, which a tool may redact. */\nfunction sameEntry(stored: JournalEventTableRow, exported: WorkflowRunExportEvent): boolean {\n\treturn (\n\t\tNumber(stored.seq) === exported.seq &&\n\t\tNumber(stored.epoch) === exported.epoch &&\n\t\tstored.key === exported.key &&\n\t\tstored.type === exported.type &&\n\t\tNumber(stored.at) === exported.at\n\t);\n}\n\ninterface StoredRun {\n\treadonly run: JournalRunTableRow;\n\treadonly events: readonly JournalEventTableRow[];\n\treadonly lease?: JournalLeaseTableRow & { readonly age_ms: number };\n}\n\nasync function readStoredRun(executor: SqliteExecutor, t: Tables, runId: string): Promise<StoredRun | undefined> {\n\tif (!(await hasTables(executor, t))) return undefined;\n\tconst run = await executor.get<JournalRunTableRow>(`SELECT * FROM ${t.runs} WHERE run_id = ?`, runId);\n\tif (run === undefined) return undefined;\n\tconst events = await executor.all<JournalEventTableRow>(\n\t\t`SELECT * FROM ${t.events} WHERE run_id = ? ORDER BY seq`,\n\t\trunId,\n\t);\n\tconst leases = await executor.get(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?`, t.leases);\n\tconst lease =\n\t\tleases === undefined\n\t\t\t? undefined\n\t\t\t: await executor.get<JournalLeaseTableRow & { age_ms: number }>(\n\t\t\t\t\t`SELECT *, MAX(0, ${STORE_NOW} - renewed_at) AS age_ms FROM ${t.leases} WHERE run_id = ?`,\n\t\t\t\t\trunId,\n\t\t\t\t);\n\treturn { run, events, ...(lease === undefined ? {} : { lease }) };\n}\n\ntype ImportAction = \"add\" | \"update\" | \"unchanged\";\n\n/**\n * What importing `parsed` does to the run as `stored` holds it: add it, add the file's later events, or nothing when\n * the storage already holds every event of the file. A run whose history differs from the file's, or that a process\n * here may still be running, fails with the file and line.\n */\nfunction importAction(parsed: ParsedRun, stored: StoredRun | undefined, location: string): ImportAction {\n\tif (stored === undefined) return \"add\";\n\tconst { header, events, file } = parsed;\n\tconst fail = (line: number, reason: string): never => {\n\t\tthrow new WorkflowRunTransferError({ path: file, line, runId: header.runId, reason });\n\t};\n\tif (Number(stored.run.created_at) !== header.createdAt)\n\t\tfail(1, `run ${header.runId} in ${location} was created at another time; it is a different run with the same ID`);\n\tconst shared = Math.min(stored.events.length, events.length);\n\tfor (let index = 0; index < shared; index++)\n\t\tif (!sameEntry(stored.events[index]!, events[index]!))\n\t\t\tfail(\n\t\t\t\tindex + 2,\n\t\t\t\t`event ${index + 1} differs from event ${index + 1} of run ${header.runId} in ${location}: the run continued differently there`,\n\t\t\t);\n\tif (events.length <= stored.events.length) return \"unchanged\";\n\tconst lease = stored.lease;\n\tif (lease !== undefined && lease.holder_id !== null && Number(lease.age_ms) < WORKFLOW_RUN_IMPORT_LIVE_LEASE_MS)\n\t\tfail(\n\t\t\t1,\n\t\t\t`run ${header.runId} is held by ${lease.holder_id} in ${location}, which may still be running it; stop it and import again`,\n\t\t);\n\treturn \"update\";\n}\n\n/**\n * Writes the part of `parsed` that `stored` lacks inside the caller's transaction: the run row when it is new, the\n * events after the stored ones, the latest status, and an unheld lease at an epoch above every epoch the run's events\n * and any earlier holder used, so no holder from another machine is imported and a stale one here is fenced.\n */\nasync function applyImport(tx: SqliteExecutor, t: Tables, parsed: ParsedRun, location: string): Promise<ImportAction> {\n\tconst { header, events } = parsed;\n\tconst action = importAction(parsed, await readStoredRun(tx, t, header.runId), location);\n\tif (action === \"unchanged\") return action;\n\tif (action === \"add\")\n\t\tawait tx.run(\n\t\t\t`INSERT INTO ${t.runs}(run_id, name, cwd, created_at, status, header_json) VALUES (?, ?, ?, ?, ?, ?)`,\n\t\t\theader.runId,\n\t\t\theader.name,\n\t\t\theader.cwd,\n\t\t\theader.createdAt,\n\t\t\theader.status,\n\t\t\tJSON.stringify(header.header),\n\t\t);\n\telse await tx.run(`UPDATE ${t.runs} SET status = ? WHERE run_id = ?`, header.status, header.runId);\n\tconst stored =\n\t\taction === \"add\"\n\t\t\t? 0\n\t\t\t: Number(\n\t\t\t\t\t(await tx.get<SqliteRow & { seq: number }>(\n\t\t\t\t\t\t`SELECT COALESCE(MAX(seq), 0) AS seq FROM ${t.events} WHERE run_id = ?`,\n\t\t\t\t\t\theader.runId,\n\t\t\t\t\t))!.seq,\n\t\t\t\t);\n\tfor (const event of events.slice(stored))\n\t\tawait tx.run(\n\t\t\t`INSERT INTO ${t.events}(run_id, seq, epoch, key, type, payload, at) VALUES (?, ?, ?, ?, ?, ?, ?)`,\n\t\t\theader.runId,\n\t\t\tevent.seq,\n\t\t\tevent.epoch,\n\t\t\tevent.key,\n\t\t\tevent.type,\n\t\t\tJSON.stringify(event.payload),\n\t\t\tevent.at,\n\t\t);\n\tconst epoch = events.reduce((highest, event) => Math.max(highest, event.epoch), 0);\n\tawait tx.run(\n\t\t`INSERT INTO ${t.leases}(run_id, holder_id, epoch, renewed_at) VALUES (?, NULL, ?, ${STORE_NOW})\n\t\tON CONFLICT(run_id) DO UPDATE SET holder_id = NULL, renewed_at = excluded.renewed_at,\n\t\t\tepoch = MAX(excluded.epoch, ${t.leases}.epoch + (CASE WHEN ${t.leases}.holder_id IS NULL THEN 0 ELSE 1 END))`,\n\t\theader.runId,\n\t\tepoch,\n\t);\n\treturn action;\n}\n\n/** Reads and checks every export file in `directory`; nothing is written. */\nasync function readExportDirectory(directory: string): Promise<ParsedRun[]> {\n\tlet names: string[];\n\ttry {\n\t\tnames = await readdir(directory);\n\t} catch (error) {\n\t\tthrow new WorkflowRunTransferError({\n\t\t\tpath: directory,\n\t\t\treason: `cannot read the directory: ${(error as Error).message}`,\n\t\t\tcause: error as StorageFailureCause,\n\t\t});\n\t}\n\tconst parsed: ParsedRun[] = [];\n\tconst files = new Map<string, string>();\n\tfor (const name of names.filter((entry) => entry.endsWith(WORKFLOW_RUN_EXPORT_EXTENSION)).sort()) {\n\t\tconst file = join(directory, name);\n\t\tlet bytes: Buffer;\n\t\ttry {\n\t\t\tbytes = await readFile(file);\n\t\t} catch (error) {\n\t\t\tthrow new WorkflowRunTransferError({\n\t\t\t\tpath: file,\n\t\t\t\treason: `cannot read the file: ${(error as Error).message}`,\n\t\t\t\tcause: error as StorageFailureCause,\n\t\t\t});\n\t\t}\n\t\tconst run = parseExportFile(file, bytes);\n\t\tconst earlier = files.get(run.header.runId);\n\t\tif (earlier !== undefined)\n\t\t\tthrow new WorkflowRunTransferError({\n\t\t\t\tpath: file,\n\t\t\t\tline: 1,\n\t\t\t\trunId: run.header.runId,\n\t\t\t\treason: `run ${run.header.runId} is also in ${earlier}; keep one file per run`,\n\t\t\t});\n\t\tfiles.set(run.header.runId, file);\n\t\tparsed.push(run);\n\t}\n\treturn parsed;\n}\n\n/** A journal file an import reads its runs from while it decides what to write: read-only, opened once. */\nclass ReadOnlyFiles {\n\tprivate readonly opened = new Map<string, Promise<SqliteDatabase>>();\n\n\tread(path: string): Promise<SqliteDatabase> {\n\t\tlet database = this.opened.get(path);\n\t\tif (database === undefined) {\n\t\t\tdatabase = openNodeSqliteDatabase(path, { readOnly: true });\n\t\t\tthis.opened.set(path, database);\n\t\t}\n\t\treturn database;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst settled = await Promise.allSettled(this.opened.values());\n\t\tawait closeEach(settled.flatMap((result) => (result.status === \"fulfilled\" ? [result.value] : [])));\n\t}\n}\n\nfunction unreadableShard(parsed: ParsedRun, path: string, error: Error): WorkflowRunTransferError {\n\treturn new WorkflowRunTransferError({\n\t\tpath: parsed.file,\n\t\tline: 1,\n\t\trunId: parsed.header.runId,\n\t\treason: `run ${parsed.header.runId} is in the journal file ${path}, which cannot be read: ${error.message}`,\n\t\tcause: error,\n\t});\n}\n\n/** The journal file of a store holding `runId`: the one the catalog names, else an adopted journal that holds it. */\nasync function storedShard(\n\tcatalog: JournalCatalog,\n\tfiles: ReadOnlyFiles,\n\tt: Tables,\n\trunId: string,\n): Promise<JournalShardRecord | undefined> {\n\tconst found = await catalog.locate(runId);\n\tif (found !== undefined) return found.shard;\n\tfor (const shard of await catalog.shards()) {\n\t\tif (shard.kind !== \"adopted\" || !existsSync(shard.path)) continue;\n\t\ttry {\n\t\t\tconst database = await files.read(shard.path);\n\t\t\tif ((await hasTables(database, t)) && (await database.get(`SELECT 1 FROM ${t.runs} WHERE run_id = ?`, runId)))\n\t\t\t\treturn shard;\n\t\t} catch {}\n\t}\n\treturn undefined;\n}\n\n/**\n * Imports every `<name>.jsonl` export file in `directory` into a local workflow journal. Every file is read and checked,\n * and every run compared with the storage's copy, before anything is written: a malformed file, an unsupported version,\n * a run that continued differently here, or a run a process here may still be running fails the import with the file\n * and line, and nothing changes. A run the storage does not hold is added; one whose earlier events it holds gets the\n * file's later ones; one it holds every event of is left as it is, so importing again changes nothing. String values\n * inside the records are not compared, so a file whose strings a tool redacted imports as the run it was exported from.\n */\nexport async function importWorkflowRuns(\n\tstorage: WorkflowRunTransferStorage,\n\tdirectory: string,\n): Promise<WorkflowRunImportReport> {\n\tconst runs = await readExportDirectory(directory);\n\tconst t = runJournalTables(storage.kind === \"sqlite\" ? storage.prefix : undefined);\n\tconst location = storageLocation(storage);\n\tconst files = new ReadOnlyFiles();\n\tconst actions: { readonly run: ParsedRun; readonly action: ImportAction; readonly shard?: JournalShardRecord }[] =\n\t\t[];\n\tawait withCleanup(\n\t\tasync () => {\n\t\t\tconst catalogExists = storage.kind === \"store\" && (await adoptLegacyJournal(storage.directory));\n\t\t\tconst catalog = catalogExists ? await JournalCatalog.open(storage.directory) : undefined;\n\t\t\tawait withCleanup(\n\t\t\t\tasync () => {\n\t\t\t\t\tfor (const run of runs) {\n\t\t\t\t\t\tconst shard =\n\t\t\t\t\t\t\tcatalog === undefined ? undefined : await storedShard(catalog, files, t, run.header.runId);\n\t\t\t\t\t\tlet path = shard?.path;\n\t\t\t\t\t\tif (storage.kind === \"sqlite\") path = existsSync(storage.path) ? storage.path : undefined;\n\t\t\t\t\t\tlet stored: StoredRun | undefined;\n\t\t\t\t\t\tif (path !== undefined) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tstored = await readStoredRun(await files.read(path), t, run.header.runId);\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tthrow unreadableShard(run, path, error as Error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tactions.push({\n\t\t\t\t\t\t\trun,\n\t\t\t\t\t\t\taction: importAction(run, stored, path ?? location),\n\t\t\t\t\t\t\t...(shard === undefined ? {} : { shard }),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tasync () => catalog?.close(),\n\t\t\t);\n\t\t},\n\t\t() => files.close(),\n\t);\n\tconst report = { added: [] as string[], updated: [] as string[], unchanged: [] as string[] };\n\tconst record = (runId: string, action: ImportAction) =>\n\t\t(action === \"add\" ? report.added : action === \"update\" ? report.updated : report.unchanged).push(runId);\n\tconst pending = actions.filter(({ action, run }) => {\n\t\tif (action === \"unchanged\") record(run.header.runId, action);\n\t\treturn action !== \"unchanged\";\n\t});\n\tif (pending.length === 0) return report;\n\tif (storage.kind === \"sqlite\") {\n\t\tconst database = await openNodeSqliteDatabase(storage.path);\n\t\tawait withCleanup(\n\t\t\tasync () => {\n\t\t\t\tfor (const { run } of pending)\n\t\t\t\t\trecord(\n\t\t\t\t\t\trun.header.runId,\n\t\t\t\t\t\tawait database.transaction(async (tx) => {\n\t\t\t\t\t\t\tawait ensureRunJournalSchema(tx, storage.prefix);\n\t\t\t\t\t\t\treturn applyImport(tx, t, run, location);\n\t\t\t\t\t\t}, TRANSFER_TRANSACTION),\n\t\t\t\t\t);\n\t\t\t},\n\t\t\t() => database.close(),\n\t\t);\n\t\treturn report;\n\t}\n\tconst catalog = await JournalCatalog.open(storage.directory);\n\tconst shards = new Map<string, SqliteDatabase>();\n\tawait withCleanup(\n\t\tasync () => {\n\t\t\tfor (const { run, shard: stored } of pending) {\n\t\t\t\tconst { runId, name, cwd, status } = run.header;\n\t\t\t\t// A new run goes to the shard its ID hashes to, as a consolidated run does: it writes nothing until it is\n\t\t\t\t// resumed, so it never makes a shard busy for new roots.\n\t\t\t\tconst shard = await catalog.shard(\n\t\t\t\t\tawait catalog.index((stored ?? (await catalog.homeShard(runId))).id, { runId, name, cwd, status }),\n\t\t\t\t);\n\t\t\t\tif (shard === undefined)\n\t\t\t\t\tthrow new WorkflowRunTransferError({\n\t\t\t\t\t\tpath: run.file,\n\t\t\t\t\t\tline: 1,\n\t\t\t\t\t\trunId,\n\t\t\t\t\t\treason: `cannot place run ${runId} in ${location}`,\n\t\t\t\t\t});\n\t\t\t\tlet database = shards.get(shard.path);\n\t\t\t\tif (database === undefined) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdatabase = await openNodeSqliteDatabase(shard.path);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthrow unreadableShard(run, shard.path, error as Error);\n\t\t\t\t\t}\n\t\t\t\t\tshards.set(shard.path, database);\n\t\t\t\t}\n\t\t\t\tconst action = await database.transaction(async (tx) => {\n\t\t\t\t\tawait ensureRunJournalSchema(tx);\n\t\t\t\t\treturn applyImport(tx, t, run, shard.path);\n\t\t\t\t}, TRANSFER_TRANSACTION);\n\t\t\t\tif (action !== \"unchanged\") await catalog.setStatus(runId, status);\n\t\t\t\trecord(runId, action);\n\t\t\t}\n\t\t},\n\t\tasync () => {\n\t\t\tawait closeEach(shards.values());\n\t\t\tawait catalog.close();\n\t\t},\n\t);\n\treturn report;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"journal-transfer.js","sourceRoot":"","sources":["../../../src/core/storage/journal-transfer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,EACN,qBAAqB,EACrB,sBAAsB,EAItB,wBAAwB,EACxB,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,uBAAuB,EACvB,oBAAoB,EACpB,cAAc,GAGd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EACN,qBAAqB,EACrB,4BAA4B,EAC5B,oBAAoB,EAEpB,YAAY,EACZ,oBAAoB,GACpB,MAAM,qBAAqB,CAAC;AAE7B,kDAAkD;AAClD,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAC9D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,OAAO,CAAC;AACzD;;;GAGG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AAqExD,MAAM,SAAS,GAAG,6CAA6C,CAAC;AAChE,MAAM,oBAAoB,GAAG,EAAE,UAAU,EAAE,EAAE,GAAG,MAAM,EAAW,CAAC;AAClE,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAC,MAAM,CAAC,MAA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ned JSONL files (#4716, #4720): `exportWorkflowRuns` writes each run of a local workflow\n * journal to `<dir>/<runId>.jsonl`, and the import functions restore such files into one. The journal stays the\n * working store; the files are the form runs take at rest, so a host that persists only files can carry them between\n * machines. `atomic storage export` and `import` use `<exportDir>/workflows` as `<dir>`.\n *\n * Line 1 of a file is the run's header: the row of the journal's runs table. Every later line is one row of its\n * events table, in sequence order, with its payload as a JSON value instead of JSON text. Leases, local-worker pool\n * state and worktree snapshot blobs are not exported: they belong to the machine that wrote them.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { closeEach, withCleanup } from \"./cleanup.js\";\nimport type { SqliteDatabase, SqliteExecutor, SqliteRow, SqliteValue } from \"./database.js\";\nimport type { StorageFailureCause } from \"./errors.js\";\nimport {\n\tdiscoverLegacyJournal,\n\tensureRunJournalSchema,\n\ttype JournalEventTableRow,\n\ttype JournalLeaseTableRow,\n\ttype JournalRunTableRow,\n\tlegacyDefaultJournalPath,\n\trunJournalTables,\n} from \"./journal-adoption.js\";\nimport {\n\tisFinishedJournalStatus,\n\tJOURNAL_CATALOG_FILE,\n\tJournalCatalog,\n\ttype JournalCatalogRun,\n\ttype JournalShardRecord,\n} from \"./journal-catalog.js\";\nimport { openNodeSqliteDatabase } from \"./node-sqlite.js\";\nimport { RUN_EVENT_TYPES, RUN_JOURNAL_SCHEMA_VERSION } from \"./run-journal.js\";\nimport {\n\treadTransferDirectory,\n\tStorageImportIncompleteError,\n\tStorageTransferError,\n\ttype TransferFileLines,\n\ttransferFile,\n\twriteLinesAtomically,\n} from \"./transfer-files.js\";\n\n/** The `type` of an export file's header line. */\nexport const WORKFLOW_RUN_EXPORT_TYPE = \"atomic.workflow-run\";\n/** The export format version this Atomic writes and reads. */\nexport const WORKFLOW_RUN_EXPORT_VERSION = 1;\n/**\n * A lease renewed this recently belongs to a process that may still be running the run on this machine, so an import\n * does not add events to that run. It matches the window in which the workflows runtime treats a running run's owner\n * as live.\n */\nexport const WORKFLOW_RUN_IMPORT_LIVE_LEASE_MS = 120_000;\n/**\n * How many times an export reads the catalog again after reading the journal files, for runs a consolidation moved\n * in between; a run still not found where the catalog names it after the last read is reported with its reason.\n */\nexport const WORKFLOW_RUN_EXPORT_PLACEMENT_ATTEMPTS = 5;\n\n/** A JSON value as an export file holds it. */\nexport type WorkflowRunExportValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| readonly WorkflowRunExportValue[]\n\t| { readonly [key: string]: WorkflowRunExportValue };\n\n/** Line 1 of an export file. */\nexport interface WorkflowRunExportHeader {\n\treadonly type: typeof WORKFLOW_RUN_EXPORT_TYPE;\n\treadonly version: typeof WORKFLOW_RUN_EXPORT_VERSION;\n\treadonly runId: string;\n\treadonly name: string;\n\treadonly cwd: string;\n\treadonly createdAt: number;\n\t/** The run's latest status. */\n\treadonly status: string;\n\t/** How many event lines follow. */\n\treadonly events: number;\n\t/** The run header the journal recorded when the run was created. */\n\treadonly header: { readonly [key: string]: WorkflowRunExportValue };\n}\n\n/** One event line of an export file: one journal entry. */\nexport interface WorkflowRunExportEvent {\n\treadonly type: string;\n\treadonly seq: number;\n\treadonly epoch: number;\n\treadonly key: string | null;\n\treadonly at: number;\n\treadonly payload: WorkflowRunExportValue;\n}\n\n/** The local workflow journal storage that runs are exported from and imported into. */\nexport type WorkflowRunTransferStorage =\n\t| { readonly kind: \"store\"; readonly directory: string }\n\t| { readonly kind: \"sqlite\"; readonly path: string; readonly prefix?: string };\n\nexport interface WorkflowRunExportOptions {\n\t/** Only these runs; a run the storage does not hold fails the export before any file is written. */\n\treadonly runs?: readonly string[];\n\t/** Only runs that are not completed, failed or cancelled. */\n\treadonly unfinished?: boolean;\n\t/** At most this many runs, newest first. */\n\treadonly limit?: number;\n}\n\nexport interface WorkflowRunExportReport {\n\t/** Runs whose file was written. */\n\treadonly written: readonly string[];\n\t/** Runs whose file already held exactly this export, left untouched. */\n\treadonly unchanged: readonly string[];\n\t/** Journal files that could not be read, and catalogued runs that could not be exported, with the reason. */\n\treadonly skipped: readonly { readonly path: string; readonly runId?: string; readonly reason: string }[];\n}\n\nexport interface WorkflowRunImportReport {\n\t/** Runs the storage did not hold. */\n\treadonly added: readonly string[];\n\t/** Runs the storage held an earlier part of, which now have the file's later events. */\n\treadonly updated: readonly string[];\n\t/** Runs the storage already held every event of. */\n\treadonly unchanged: readonly string[];\n}\n\nconst STORE_NOW = \"CAST(unixepoch('subsec') * 1000 AS INTEGER)\";\nconst TRANSFER_TRANSACTION = { lockWaitMs: 10 * 60_000 } as const;\nconst EVENT_TYPES: ReadonlySet<string> = new Set(Object.values(RUN_EVENT_TYPES));\nconst HEADER_FIELDS = [\"type\", \"version\", \"runId\", \"name\", \"cwd\", \"createdAt\", \"status\", \"events\", \"header\"] as const;\nconst EVENT_FIELDS = [\"type\", \"seq\", \"epoch\", \"key\", \"at\", \"payload\"] as const;\n/** The runs table of the journal format before 0.9.38, which an export cannot read. */\nconst LEGACY_RUNS_TABLE = \"runs\";\nconst OLD_FORMAT_REASON = \"it is in the journal format of Atomic before 0.9.38; resume it once to convert it\";\n\ntype JsonObject = { readonly [key: string]: WorkflowRunExportValue };\ntype Tables = ReturnType<typeof runJournalTables>;\n\nfunction storageLocation(storage: WorkflowRunTransferStorage): string {\n\treturn storage.kind === \"store\" ? storage.directory : storage.path;\n}\n\nfunction parseStored(text: string, path: string, runId: string, what: string): WorkflowRunExportValue {\n\ttry {\n\t\treturn JSON.parse(text) as WorkflowRunExportValue;\n\t} catch (cause) {\n\t\tthrow new StorageTransferError({\n\t\t\tpath,\n\t\t\tid: runId,\n\t\t\treason: `run ${runId} has ${what} that is not valid JSON`,\n\t\t\tcause: cause as StorageFailureCause,\n\t\t});\n\t}\n}\n\n/** A run and its events as the lines of its export file. */\nfunction exportLines(run: JournalRunTableRow, events: readonly JournalEventTableRow[], path: string): string[] {\n\tconst header = parseStored(run.header_json, path, run.run_id, \"a header\");\n\tif (!isObject(header))\n\t\tthrow new StorageTransferError({\n\t\t\tpath,\n\t\t\tid: run.run_id,\n\t\t\treason: `run ${run.run_id} has a header that is not an object`,\n\t\t});\n\tconst lines = [\n\t\tJSON.stringify({\n\t\t\ttype: WORKFLOW_RUN_EXPORT_TYPE,\n\t\t\tversion: WORKFLOW_RUN_EXPORT_VERSION,\n\t\t\trunId: run.run_id,\n\t\t\tname: run.name,\n\t\t\tcwd: run.cwd,\n\t\t\tcreatedAt: Number(run.created_at),\n\t\t\tstatus: run.status,\n\t\t\tevents: events.length,\n\t\t\theader,\n\t\t} satisfies WorkflowRunExportHeader),\n\t];\n\tfor (const event of events)\n\t\tlines.push(\n\t\t\tJSON.stringify({\n\t\t\t\ttype: event.type,\n\t\t\t\tseq: Number(event.seq),\n\t\t\t\tepoch: Number(event.epoch),\n\t\t\t\tkey: event.key,\n\t\t\t\tat: Number(event.at),\n\t\t\t\tpayload: parseStored(event.payload, path, run.run_id, `event ${event.seq} with a payload`),\n\t\t\t} satisfies WorkflowRunExportEvent),\n\t\t);\n\treturn lines;\n}\n\nasync function hasTables(executor: SqliteExecutor, t: Tables): Promise<boolean> {\n\tconst rows = await executor.all<SqliteRow & { name: string }>(\n\t\t\"SELECT name FROM sqlite_master WHERE type = 'table' AND name IN (?, ?, ?)\",\n\t\tt.meta,\n\t\tt.runs,\n\t\tt.events,\n\t);\n\treturn rows.length === 3;\n}\n\nasync function hasTable(executor: SqliteExecutor, name: string): Promise<boolean> {\n\treturn (await executor.get(\"SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?\", name)) !== undefined;\n}\n\nasync function schemaVersion(executor: SqliteExecutor, t: Tables): Promise<SqliteValue | undefined> {\n\tconst rows = await executor.all<SqliteRow & { schema_version: SqliteValue }>(`SELECT schema_version FROM ${t.meta}`);\n\treturn rows.length === 1 ? rows[0]!.schema_version : undefined;\n}\n\n/** One journal file an export reads, inside one read transaction, so every run it holds is read as of one moment. */\ninterface ExportSource {\n\treadonly path: string;\n\treadonly shardId?: number;\n\treadonly database: SqliteDatabase;\n\treadonly runs: readonly JournalRunTableRow[];\n\treadonly byId: ReadonlyMap<string, JournalRunTableRow>;\n}\n\n/** A journal file an export could not read, and whether that is because it holds only the format before 0.9.38. */\ninterface UnreadableSource {\n\treadonly path: string;\n\treadonly reason: string;\n\treadonly oldFormat: boolean;\n}\n\n/** Opens a journal file for an export and begins its read transaction; the reason when it cannot. */\nasync function openExportSource(\n\tpath: string,\n\tt: Tables,\n\tshardId: number | undefined,\n): Promise<ExportSource | UnreadableSource> {\n\tif (!existsSync(path)) return { path, reason: \"the journal file no longer exists\", oldFormat: false };\n\tlet database: SqliteDatabase;\n\ttry {\n\t\tdatabase = await openNodeSqliteDatabase(path, { readOnly: true });\n\t} catch (error) {\n\t\treturn { path, reason: `the journal file cannot be opened: ${(error as Error).message}`, oldFormat: false };\n\t}\n\ttry {\n\t\tawait database.exec(\"BEGIN\");\n\t\tif (!(await hasTables(database, t))) {\n\t\t\tawait database.exec(\"COMMIT\");\n\t\t\tawait database.close();\n\t\t\treturn { path, reason: \"it has no workflow runs in the current journal format\", oldFormat: true };\n\t\t}\n\t\tconst version = await schemaVersion(database, t);\n\t\tif (version !== RUN_JOURNAL_SCHEMA_VERSION) {\n\t\t\tawait database.exec(\"COMMIT\");\n\t\t\tawait database.close();\n\t\t\treturn { path, reason: `unsupported journal schema version ${String(version)}`, oldFormat: false };\n\t\t}\n\t\tconst runs = await database.all<JournalRunTableRow>(`SELECT * FROM ${t.runs} ORDER BY run_id`);\n\t\treturn {\n\t\t\tpath,\n\t\t\tdatabase,\n\t\t\truns,\n\t\t\tbyId: new Map(runs.map((run) => [run.run_id, run])),\n\t\t\t...(shardId === undefined ? {} : { shardId }),\n\t\t};\n\t} catch (error) {\n\t\tawait database.close().catch(() => undefined);\n\t\treturn { path, reason: `the journal file cannot be read: ${(error as Error).message}`, oldFormat: false };\n\t}\n}\n\nasync function closeExportSource(source: ExportSource): Promise<void> {\n\tawait source.database.exec(\"COMMIT\").catch(() => undefined);\n\tawait source.database.close();\n}\n\n/**\n * Adopts the default journal of Atomic before the journal store, as opening the store does, so its runs are exported\n * and compared like every other run; whether the store has a catalog.\n */\nasync function adoptLegacyJournal(directory: string): Promise<boolean> {\n\tif (existsSync(legacyDefaultJournalPath(directory))) {\n\t\tconst catalog = await JournalCatalog.open(directory);\n\t\tawait withCleanup(\n\t\t\tasync () => {\n\t\t\t\tawait discoverLegacyJournal(catalog, legacyDefaultJournalPath(directory));\n\t\t\t},\n\t\t\t() => catalog.close(),\n\t\t);\n\t}\n\treturn existsSync(join(directory, JOURNAL_CATALOG_FILE));\n}\n\n/** What the catalog of a journal store says at one moment: its shards, and its runs with the shard each is on. */\ninterface CatalogView {\n\treadonly shards: readonly JournalShardRecord[];\n\treadonly runs: readonly JournalCatalogRun[];\n\treadonly owners: ReadonlyMap<string, number>;\n}\n\nasync function readCatalog(directory: string): Promise<CatalogView> {\n\tconst catalog = await JournalCatalog.open(directory);\n\treturn withCleanup(\n\t\tasync () => {\n\t\t\tconst shards = await catalog.shards();\n\t\t\tconst runs = await catalog.runs();\n\t\t\treturn { shards, runs, owners: new Map(runs.map((run) => [run.runId, run.shard])) };\n\t\t},\n\t\t() => catalog.close(),\n\t);\n}\n\nfunction newestFirst(left: JournalRunTableRow, right: JournalRunTableRow): number {\n\tconst created = Number(right.created_at) - Number(left.created_at);\n\tif (created !== 0) return created;\n\treturn left.run_id < right.run_id ? -1 : left.run_id > right.run_id ? 1 : 0;\n}\n\n/** The journal files of a store an export reads, by shard, kept open in their read transactions until it finishes. */\nclass ExportSources {\n\treadonly opened = new Map<number, ExportSource>();\n\treadonly unreadable = new Map<number, UnreadableSource>();\n\n\tprivate readonly t: Tables;\n\n\tconstructor(t: Tables) {\n\t\tthis.t = t;\n\t}\n\n\t/** Opens every shard of `view` not opened yet, and opens `fresh` again with a new snapshot. */\n\tasync open(view: CatalogView, fresh: ReadonlySet<number> = new Set()): Promise<void> {\n\t\tfor (const shard of view.shards) {\n\t\t\tconst current = this.opened.get(shard.id);\n\t\t\tif (current !== undefined && !fresh.has(shard.id)) continue;\n\t\t\tif (current === undefined && this.unreadable.has(shard.id) && !fresh.has(shard.id)) continue;\n\t\t\tif (current !== undefined) {\n\t\t\t\tthis.opened.delete(shard.id);\n\t\t\t\tawait closeExportSource(current);\n\t\t\t}\n\t\t\tthis.unreadable.delete(shard.id);\n\t\t\tconst source = await openExportSource(shard.path, this.t, shard.id);\n\t\t\tif (\"database\" in source) this.opened.set(shard.id, source);\n\t\t\telse this.unreadable.set(shard.id, source);\n\t\t}\n\t}\n\n\t/** The catalogued runs of `view` that the snapshot of the shard the catalog names for them does not hold. */\n\tmissing(view: CatalogView): JournalCatalogRun[] {\n\t\treturn view.runs.filter((run) => {\n\t\t\tconst source = this.opened.get(run.shard);\n\t\t\treturn run.status !== undefined && source !== undefined && !source.byId.has(run.runId);\n\t\t});\n\t}\n\n\tclose(): Promise<void> {\n\t\treturn closeEach([...this.opened.values()].map((source) => ({ close: () => closeExportSource(source) })));\n\t}\n}\n\n/**\n * Reads a journal store's catalog and opens its shards, then reads the catalog again for every run the shard it named\n * did not hold: a consolidation may have moved the run between the two reads, into an existing shard or one it\n * created. The shard the run moved to is read again, and so on until the placements agree or the attempts run out.\n */\nasync function settleExportSources(directory: string, sources: ExportSources): Promise<CatalogView> {\n\tlet view = await readCatalog(directory);\n\tawait sources.open(view);\n\tfor (let attempt = 1; attempt < WORKFLOW_RUN_EXPORT_PLACEMENT_ATTEMPTS; attempt++) {\n\t\tconst missing = sources.missing(view);\n\t\tif (missing.length === 0) return view;\n\t\tconst next = await readCatalog(directory);\n\t\tconst moved = new Set<number>();\n\t\tfor (const run of missing) {\n\t\t\tconst now = next.owners.get(run.runId);\n\t\t\tif (now !== undefined && now !== run.shard) moved.add(now);\n\t\t}\n\t\tconst added = next.shards.some((shard) => !sources.opened.has(shard.id) && !sources.unreadable.has(shard.id));\n\t\tview = next;\n\t\tif (moved.size === 0 && !added) return view;\n\t\tawait sources.open(view, moved);\n\t}\n\treturn view;\n}\n\n/** Why a catalogued run that its shard's snapshot does not hold, or whose shard could not be read, is not exported. */\nasync function missingRunReason(\n\trun: JournalCatalogRun,\n\tview: CatalogView,\n\tsources: ExportSources,\n): Promise<{ path: string; runId: string; reason: string }> {\n\tconst unreadable = sources.unreadable.get(run.shard);\n\tif (unreadable !== undefined)\n\t\treturn {\n\t\t\tpath: unreadable.path,\n\t\t\trunId: run.runId,\n\t\t\treason: unreadable.oldFormat ? OLD_FORMAT_REASON : `its journal file cannot be read: ${unreadable.reason}`,\n\t\t};\n\tconst source = sources.opened.get(run.shard);\n\tif (source === undefined) {\n\t\tconst path = view.shards.find((shard) => shard.id === run.shard)?.path ?? `shard ${run.shard}`;\n\t\treturn { path, runId: run.runId, reason: `the catalog names shard ${run.shard} for it, which it does not list` };\n\t}\n\tif (\n\t\t(await hasTable(source.database, LEGACY_RUNS_TABLE)) &&\n\t\t(await source.database.get(`SELECT 1 AS found FROM ${LEGACY_RUNS_TABLE} WHERE run_id = ?`, run.runId))\n\t)\n\t\treturn { path: source.path, runId: run.runId, reason: OLD_FORMAT_REASON };\n\treturn {\n\t\tpath: source.path,\n\t\trunId: run.runId,\n\t\treason:\n\t\t\t\"the journal file the catalog names for it does not hold it; it was moved or deleted while the export ran, so export again\",\n\t};\n}\n\n/**\n * Exports runs of a local workflow journal to `<directory>/<runId>.jsonl`, one file per run. Each journal file is read\n * in one read transaction, and each export file is written whole or not at all. The same journal state gives the same\n * bytes, and a file that already holds them is not rewritten. A run the store's catalog lists is taken only from the\n * shard the catalog names for it, read again when a consolidation moved it while the export ran; one that cannot be\n * exported is reported with the reason.\n */\nexport async function exportWorkflowRuns(\n\tstorage: WorkflowRunTransferStorage,\n\tdirectory: string,\n\toptions: WorkflowRunExportOptions = {},\n): Promise<WorkflowRunExportReport> {\n\tconst t = runJournalTables(storage.kind === \"sqlite\" ? storage.prefix : undefined);\n\tconst skipped: { path: string; runId?: string; reason: string }[] = [];\n\tconst sources = new ExportSources(t);\n\tlet single: ExportSource | undefined;\n\treturn withCleanup(\n\t\tasync () => {\n\t\t\tconst listed = new Map<string, { readonly source: ExportSource; readonly run: JournalRunTableRow }>();\n\t\t\tconst unexported = new Map<string, { path: string; runId: string; reason: string }>();\n\t\t\tif (storage.kind === \"sqlite\") {\n\t\t\t\tif (existsSync(storage.path)) {\n\t\t\t\t\tconst opened = await openExportSource(storage.path, t, undefined);\n\t\t\t\t\tif (\"database\" in opened) single = opened;\n\t\t\t\t\telse skipped.push({ path: opened.path, reason: opened.reason });\n\t\t\t\t}\n\t\t\t\tfor (const run of single?.runs ?? []) listed.set(run.run_id, { source: single!, run });\n\t\t\t} else if (await adoptLegacyJournal(storage.directory)) {\n\t\t\t\tconst view = await settleExportSources(storage.directory, sources);\n\t\t\t\tconst catalogued = new Set<number>(view.runs.map((run) => run.shard));\n\t\t\t\tfor (const [id, unreadable] of sources.unreadable)\n\t\t\t\t\tif (!catalogued.has(id)) skipped.push({ path: unreadable.path, reason: unreadable.reason });\n\t\t\t\tfor (const run of view.runs) {\n\t\t\t\t\tconst source = sources.opened.get(run.shard);\n\t\t\t\t\tconst row = source?.byId.get(run.runId);\n\t\t\t\t\tif (source !== undefined && row !== undefined) listed.set(run.runId, { source, run: row });\n\t\t\t\t\telse if (run.status !== undefined) unexported.set(run.runId, await missingRunReason(run, view, sources));\n\t\t\t\t}\n\t\t\t\t// A run no catalog entry names yet (another process wrote it to a shard) is taken from the first shard\n\t\t\t\t// holding it. A catalogued run is never taken from another shard, which may hold an older copy an\n\t\t\t\t// interrupted consolidation left behind.\n\t\t\t\tfor (const source of sources.opened.values())\n\t\t\t\t\tfor (const run of source.runs)\n\t\t\t\t\t\tif (!view.owners.has(run.run_id) && !listed.has(run.run_id)) listed.set(run.run_id, { source, run });\n\t\t\t}\n\t\t\tlet selected = [...listed.values()];\n\t\t\tif (options.runs !== undefined) {\n\t\t\t\tfor (const runId of options.runs) {\n\t\t\t\t\tif (listed.has(runId)) continue;\n\t\t\t\t\tconst reason = unexported.get(runId);\n\t\t\t\t\tthrow new StorageTransferError({\n\t\t\t\t\t\tpath: reason?.path ?? storageLocation(storage),\n\t\t\t\t\t\tid: runId,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\treason === undefined\n\t\t\t\t\t\t\t\t? `run ${runId} is not in this workflow journal`\n\t\t\t\t\t\t\t\t: `run ${runId} cannot be exported: ${reason.reason}`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tselected = [...new Set(options.runs)].map((runId) => listed.get(runId)!);\n\t\t\t} else skipped.push(...unexported.values());\n\t\t\tif (options.unfinished) selected = selected.filter(({ run }) => !isFinishedJournalStatus(run.status));\n\t\t\tselected.sort((left, right) => newestFirst(left.run, right.run));\n\t\t\tif (options.limit !== undefined) selected = selected.slice(0, options.limit);\n\t\t\tawait mkdir(directory, { recursive: true });\n\t\t\tconst written: string[] = [];\n\t\t\tconst unchanged: string[] = [];\n\t\t\tfor (const { source, run } of selected) {\n\t\t\t\tconst events = await source.database.all<JournalEventTableRow>(\n\t\t\t\t\t`SELECT * FROM ${t.events} WHERE run_id = ? ORDER BY seq`,\n\t\t\t\t\trun.run_id,\n\t\t\t\t);\n\t\t\t\tconst outcome = await writeLinesAtomically(\n\t\t\t\t\ttransferFile(directory, run.run_id),\n\t\t\t\t\texportLines(run, events, source.path),\n\t\t\t\t);\n\t\t\t\t(outcome === \"written\" ? written : unchanged).push(run.run_id);\n\t\t\t}\n\t\t\treturn { written, unchanged, skipped };\n\t\t},\n\t\tasync () => {\n\t\t\tawait sources.close();\n\t\t\tif (single !== undefined) await closeExportSource(single);\n\t\t},\n\t);\n}\n\n/** A run read from an export file and checked: everything an import writes for it. */\nexport interface ParsedWorkflowRun {\n\treadonly file: string;\n\treadonly header: WorkflowRunExportHeader;\n\treadonly events: readonly WorkflowRunExportEvent[];\n}\n\nfunction isObject(value: WorkflowRunExportValue | undefined): value is JsonObject {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction invalidText(value: string): string | undefined {\n\tif (value.includes(\"\\u0000\")) return \"contains a NUL character\";\n\tif (/\\p{Surrogate}/u.test(value)) return \"is not well-formed Unicode\";\n\treturn undefined;\n}\n\nfunction counter(value: WorkflowRunExportValue | undefined, minimum: number): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value >= minimum;\n}\n\n/** Checks that a line has exactly `fields`; the reason when it does not. */\nfunction fieldsReason(line: JsonObject, fields: readonly string[]): string | undefined {\n\tfor (const field of fields) if (!(field in line)) return `has no \"${field}\" field`;\n\tfor (const field of Object.keys(line)) if (!fields.includes(field)) return `has an unexpected \"${field}\" field`;\n\treturn undefined;\n}\n\n/** Checks one export file, throwing a `StorageTransferError` that names the file and line. */\nfunction parseExportFile({ file, lines }: TransferFileLines): ParsedWorkflowRun {\n\tconst fail = (line: number | undefined, reason: string, runId?: string): never => {\n\t\tthrow new StorageTransferError({ path: file, ...(line === undefined ? {} : { line }), id: runId, reason });\n\t};\n\tif (lines.length === 0) return fail(1, \"is empty; expected a workflow run header\");\n\tconst parse = (index: number): JsonObject => {\n\t\tconst line = lines[index]!.text;\n\t\tif (line.trim() === \"\") return fail(index + 1, \"is empty\");\n\t\tlet value: WorkflowRunExportValue;\n\t\ttry {\n\t\t\tvalue = JSON.parse(line) as WorkflowRunExportValue;\n\t\t} catch (error) {\n\t\t\treturn fail(index + 1, `is not valid JSON (${(error as Error).message})`);\n\t\t}\n\t\tif (!isObject(value)) return fail(index + 1, \"is not a JSON object\");\n\t\tif (typeof value.type !== \"string\") return fail(index + 1, 'has no string \"type\"');\n\t\treturn value;\n\t};\n\tconst first = parse(0);\n\tif (first.type !== WORKFLOW_RUN_EXPORT_TYPE)\n\t\tfail(1, `is not an Atomic workflow run export: its type is \"${first.type}\", not \"${WORKFLOW_RUN_EXPORT_TYPE}\"`);\n\tif (first.version !== WORKFLOW_RUN_EXPORT_VERSION)\n\t\tfail(\n\t\t\t1,\n\t\t\t`has unsupported export version ${JSON.stringify(first.version ?? null)}; this Atomic reads version ${WORKFLOW_RUN_EXPORT_VERSION}`,\n\t\t);\n\tconst headerFields = fieldsReason(first, HEADER_FIELDS);\n\tif (headerFields !== undefined) fail(1, headerFields);\n\tfor (const field of [\"runId\", \"name\", \"cwd\", \"status\"] as const) {\n\t\tconst value = first[field];\n\t\tif (typeof value !== \"string\") fail(1, `has a \"${field}\" that is not a string`);\n\t\tconst reason = invalidText(value as string);\n\t\tif (reason !== undefined) fail(1, `has a \"${field}\" that ${reason}`);\n\t}\n\tconst runId = first.runId as string;\n\tif (runId === \"\") fail(1, 'has an empty \"runId\"');\n\tif (!counter(first.createdAt, Number.MIN_SAFE_INTEGER)) fail(1, 'has a \"createdAt\" that is not an integer', runId);\n\tif (!counter(first.events, 0)) fail(1, 'has an \"events\" count that is not a non-negative integer', runId);\n\tif (!isObject(first.header)) fail(1, 'has a \"header\" that is not an object', runId);\n\tif ((first.header as JsonObject).runId !== runId)\n\t\tfail(1, `has a \"header\" whose runId is not the run's ID ${runId}`, runId);\n\tconst events: WorkflowRunExportEvent[] = [];\n\tconst keys = new Map<string, number>();\n\tfor (let index = 1; index < lines.length; index++) {\n\t\tconst line = index + 1;\n\t\tconst event = parse(index);\n\t\tconst reason = fieldsReason(event, EVENT_FIELDS);\n\t\tif (reason !== undefined) fail(line, reason, runId);\n\t\tif (!EVENT_TYPES.has(event.type as string)) fail(line, `has unknown event type \"${event.type}\"`, runId);\n\t\tif (event.seq !== index) fail(line, `has seq ${JSON.stringify(event.seq)}; expected ${index}`, runId);\n\t\tif (!counter(event.epoch, 0)) fail(line, 'has an \"epoch\" that is not a non-negative integer', runId);\n\t\tif (!counter(event.at, Number.MIN_SAFE_INTEGER)) fail(line, 'has an \"at\" that is not an integer', runId);\n\t\tconst key = event.key;\n\t\tif (key !== null) {\n\t\t\tif (typeof key !== \"string\") fail(line, 'has a \"key\" that is neither a string nor null', runId);\n\t\t\tconst keyReason = invalidText(key as string);\n\t\t\tif (keyReason !== undefined) fail(line, `has a \"key\" that ${keyReason}`, runId);\n\t\t\tconst earlier = keys.get(key as string);\n\t\t\tif (earlier !== undefined) fail(line, `repeats the key of line ${earlier}`, runId);\n\t\t\tkeys.set(key as string, line);\n\t\t}\n\t\tif (event.type === RUN_EVENT_TYPES.statusChanged) {\n\t\t\tconst status = isObject(event.payload) ? event.payload.status : undefined;\n\t\t\tif (typeof status !== \"string\")\n\t\t\t\tfail(line, 'is a StatusChanged event whose payload has no string \"status\"', runId);\n\t\t\tconst statusReason = invalidText(status as string);\n\t\t\tif (statusReason !== undefined) fail(line, `has a status that ${statusReason}`, runId);\n\t\t}\n\t\tevents.push({\n\t\t\ttype: event.type as string,\n\t\t\tseq: event.seq as number,\n\t\t\tepoch: event.epoch as number,\n\t\t\tkey: key as string | null,\n\t\t\tat: event.at as number,\n\t\t\tpayload: event.payload!,\n\t\t});\n\t}\n\tif (lines.length - 1 !== first.events)\n\t\tfail(1, `says the run has ${first.events} events, but the file has ${lines.length - 1} event lines`, runId);\n\tconst header: WorkflowRunExportHeader = {\n\t\ttype: WORKFLOW_RUN_EXPORT_TYPE,\n\t\tversion: WORKFLOW_RUN_EXPORT_VERSION,\n\t\trunId,\n\t\tname: first.name as string,\n\t\tcwd: first.cwd as string,\n\t\tcreatedAt: first.createdAt as number,\n\t\tstatus: first.status as string,\n\t\tevents: first.events as number,\n\t\theader: first.header as JsonObject,\n\t};\n\treturn { file, header, events };\n}\n\n/**\n * Reads and checks every `*.jsonl` export file in `directory`; nothing is written. A directory that does not exist\n * holds no runs. Throws `StorageTransferError` with the file and line for the first file that is not a valid export.\n */\nexport async function readWorkflowRunExports(directory: string): Promise<ParsedWorkflowRun[]> {\n\tconst parsed: ParsedWorkflowRun[] = [];\n\tconst files = new Map<string, string>();\n\tfor (const lines of await readTransferDirectory(directory)) {\n\t\tconst run = parseExportFile(lines);\n\t\tconst earlier = files.get(run.header.runId);\n\t\tif (earlier !== undefined)\n\t\t\tthrow new StorageTransferError({\n\t\t\t\tpath: run.file,\n\t\t\t\tline: 1,\n\t\t\t\tid: run.header.runId,\n\t\t\t\treason: `run ${run.header.runId} is also in ${earlier}; keep one file per run`,\n\t\t\t});\n\t\tfiles.set(run.header.runId, run.file);\n\t\tparsed.push(run);\n\t}\n\treturn parsed;\n}\n\n/** The fields import checks against a stored run: everything but string content, which a tool may redact. */\nfunction sameEntry(stored: JournalEventTableRow, exported: WorkflowRunExportEvent): boolean {\n\treturn (\n\t\tNumber(stored.seq) === exported.seq &&\n\t\tNumber(stored.epoch) === exported.epoch &&\n\t\tstored.key === exported.key &&\n\t\tstored.type === exported.type &&\n\t\tNumber(stored.at) === exported.at\n\t);\n}\n\ninterface StoredRun {\n\treadonly run: JournalRunTableRow;\n\treadonly events: readonly JournalEventTableRow[];\n\treadonly lease?: JournalLeaseTableRow & { readonly age_ms: number };\n}\n\nasync function readStoredRun(executor: SqliteExecutor, t: Tables, runId: string): Promise<StoredRun | undefined> {\n\tif (!(await hasTables(executor, t))) return undefined;\n\tconst run = await executor.get<JournalRunTableRow>(`SELECT * FROM ${t.runs} WHERE run_id = ?`, runId);\n\tif (run === undefined) return undefined;\n\tconst events = await executor.all<JournalEventTableRow>(\n\t\t`SELECT * FROM ${t.events} WHERE run_id = ? ORDER BY seq`,\n\t\trunId,\n\t);\n\tconst lease = (await hasTable(executor, t.leases))\n\t\t? await executor.get<JournalLeaseTableRow & { age_ms: number }>(\n\t\t\t\t`SELECT *, MAX(0, ${STORE_NOW} - renewed_at) AS age_ms FROM ${t.leases} WHERE run_id = ?`,\n\t\t\t\trunId,\n\t\t\t)\n\t\t: undefined;\n\treturn { run, events, ...(lease === undefined ? {} : { lease }) };\n}\n\n/**\n * What of a stored run an import depends on: its status, how many events it has and the last of them, and its lease.\n * A run whose fingerprint differs from the one the import checked was changed by another process in between.\n */\nfunction fingerprint(stored: StoredRun | undefined): string {\n\tif (stored === undefined) return \"absent\";\n\tconst last = stored.events.at(-1);\n\tconst lease = stored.lease;\n\treturn JSON.stringify([\n\t\tstored.run.status,\n\t\tNumber(stored.run.created_at),\n\t\tstored.events.length,\n\t\tlast === undefined ? null : [Number(last.seq), Number(last.epoch), last.key, last.type, Number(last.at)],\n\t\tlease === undefined ? null : [lease.holder_id, Number(lease.epoch), Number(lease.renewed_at)],\n\t]);\n}\n\n/** What an import does to one run. */\nexport type WorkflowRunImportAction = \"add\" | \"update\" | \"unchanged\";\n\n/**\n * What importing `parsed` does to the run as `stored` holds it: add it, add the file's later events, or nothing when\n * the storage already holds every event of the file. A run whose history differs from the file's, or that a process\n * here may still be running, fails with the file and line.\n */\nfunction importAction(\n\tparsed: ParsedWorkflowRun,\n\tstored: StoredRun | undefined,\n\tlocation: string,\n): WorkflowRunImportAction {\n\tif (stored === undefined) return \"add\";\n\tconst { header, events, file } = parsed;\n\tconst fail = (line: number, reason: string): never => {\n\t\tthrow new StorageTransferError({ path: file, line, id: header.runId, reason });\n\t};\n\tif (Number(stored.run.created_at) !== header.createdAt)\n\t\tfail(1, `run ${header.runId} in ${location} was created at another time; it is a different run with the same ID`);\n\tconst shared = Math.min(stored.events.length, events.length);\n\tfor (let index = 0; index < shared; index++)\n\t\tif (!sameEntry(stored.events[index]!, events[index]!))\n\t\t\tfail(\n\t\t\t\tindex + 2,\n\t\t\t\t`event ${index + 1} differs from event ${index + 1} of run ${header.runId} in ${location}: the run continued differently there`,\n\t\t\t);\n\tif (events.length <= stored.events.length) return \"unchanged\";\n\tconst lease = stored.lease;\n\tif (lease !== undefined && lease.holder_id !== null && Number(lease.age_ms) < WORKFLOW_RUN_IMPORT_LIVE_LEASE_MS)\n\t\tfail(\n\t\t\t1,\n\t\t\t`run ${header.runId} is held by ${lease.holder_id} in ${location}, which may still be running it; stop it and import again`,\n\t\t);\n\treturn \"update\";\n}\n\n/**\n * Writes the part of `parsed` that `stored` lacks inside the caller's transaction: the run row when it is new, the\n * events after the stored ones, the latest status, and an unheld lease at an epoch above every epoch the run's events\n * and any earlier holder used, so no holder from another machine is imported and a stale one here is fenced.\n */\nasync function writeImport(\n\ttx: SqliteExecutor,\n\tt: Tables,\n\tparsed: ParsedWorkflowRun,\n\tstored: StoredRun | undefined,\n): Promise<void> {\n\tconst { header, events } = parsed;\n\tif (stored === undefined)\n\t\tawait tx.run(\n\t\t\t`INSERT INTO ${t.runs}(run_id, name, cwd, created_at, status, header_json) VALUES (?, ?, ?, ?, ?, ?)`,\n\t\t\theader.runId,\n\t\t\theader.name,\n\t\t\theader.cwd,\n\t\t\theader.createdAt,\n\t\t\theader.status,\n\t\t\tJSON.stringify(header.header),\n\t\t);\n\telse await tx.run(`UPDATE ${t.runs} SET status = ? WHERE run_id = ?`, header.status, header.runId);\n\tfor (const event of events.slice(stored?.events.length ?? 0))\n\t\tawait tx.run(\n\t\t\t`INSERT INTO ${t.events}(run_id, seq, epoch, key, type, payload, at) VALUES (?, ?, ?, ?, ?, ?, ?)`,\n\t\t\theader.runId,\n\t\t\tevent.seq,\n\t\t\tevent.epoch,\n\t\t\tevent.key,\n\t\t\tevent.type,\n\t\t\tJSON.stringify(event.payload),\n\t\t\tevent.at,\n\t\t);\n\tconst epoch = events.reduce((highest, event) => Math.max(highest, event.epoch), 0);\n\tawait tx.run(\n\t\t`INSERT INTO ${t.leases}(run_id, holder_id, epoch, renewed_at) VALUES (?, NULL, ?, ${STORE_NOW})\n\t\tON CONFLICT(run_id) DO UPDATE SET holder_id = NULL, renewed_at = excluded.renewed_at,\n\t\t\tepoch = MAX(excluded.epoch, ${t.leases}.epoch + (CASE WHEN ${t.leases}.holder_id IS NULL THEN 0 ELSE 1 END))`,\n\t\theader.runId,\n\t\tepoch,\n\t);\n}\n\n/** A journal file an import reads its runs from while it decides what to write: read-only, opened once. */\nclass ReadOnlyFiles {\n\tprivate readonly opened = new Map<string, Promise<SqliteDatabase>>();\n\n\tread(path: string): Promise<SqliteDatabase> {\n\t\tlet database = this.opened.get(path);\n\t\tif (database === undefined) {\n\t\t\tdatabase = openNodeSqliteDatabase(path, { readOnly: true });\n\t\t\tthis.opened.set(path, database);\n\t\t}\n\t\treturn database;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst settled = await Promise.allSettled(this.opened.values());\n\t\tawait closeEach(settled.flatMap((result) => (result.status === \"fulfilled\" ? [result.value] : [])));\n\t}\n}\n\nfunction unreadableShard(parsed: ParsedWorkflowRun, path: string, error: Error): StorageTransferError {\n\treturn new StorageTransferError({\n\t\tpath: parsed.file,\n\t\tline: 1,\n\t\tid: parsed.header.runId,\n\t\treason: `run ${parsed.header.runId} is in the journal file ${path}, which cannot be read: ${error.message}`,\n\t\tcause: error,\n\t});\n}\n\n/**\n * The shard of a store holding `runId`: the one the catalog names, else any shard that holds it although the catalog\n * does not list it, as an adopted journal another process wrote to or a shard an interrupted import wrote to before\n * it recorded the run in the catalog.\n */\nasync function storedShard(\n\tcatalog: JournalCatalog,\n\tfiles: ReadOnlyFiles,\n\tt: Tables,\n\trunId: string,\n): Promise<{ readonly shard: JournalShardRecord; readonly catalogued: boolean } | undefined> {\n\tconst found = await catalog.locate(runId);\n\tif (found !== undefined) return { shard: found.shard, catalogued: true };\n\tfor (const shard of await catalog.shards()) {\n\t\tif (!existsSync(shard.path)) continue;\n\t\ttry {\n\t\t\tconst database = await files.read(shard.path);\n\t\t\tif ((await hasTables(database, t)) && (await database.get(`SELECT 1 FROM ${t.runs} WHERE run_id = ?`, runId)))\n\t\t\t\treturn { shard, catalogued: false };\n\t\t} catch {}\n\t}\n\treturn undefined;\n}\n\n/** One run of an import plan: what the import does to it, and the storage's copy the decision was made on. */\ninterface PlannedRun {\n\treadonly run: ParsedWorkflowRun;\n\treadonly action: WorkflowRunImportAction;\n\treadonly stored: StoredRun | undefined;\n\t/** The shard holding the run; for a store only. */\n\treadonly shard?: JournalShardRecord;\n\t/** Whether the store's catalog lists the run. */\n\treadonly catalogued: boolean;\n}\n\n/** What importing a set of export files does to a local workflow journal, decided before anything is written. */\nexport interface WorkflowRunImportPlan {\n\treadonly storage: WorkflowRunTransferStorage;\n\treadonly runs: readonly PlannedRun[];\n}\n\n/** The runs of a plan an import writes. */\nexport function pendingWorkflowRuns(plan: WorkflowRunImportPlan): string[] {\n\treturn plan.runs.filter((run) => run.action !== \"unchanged\").map((run) => run.run.header.runId);\n}\n\n/**\n * Compares every run of `runs` with the storage's copy, writing nothing: a run that continued differently here, or that\n * a process here may still be running, fails with the file and line.\n */\nexport async function planWorkflowRunImport(\n\tstorage: WorkflowRunTransferStorage,\n\truns: readonly ParsedWorkflowRun[],\n): Promise<WorkflowRunImportPlan> {\n\tconst t = runJournalTables(storage.kind === \"sqlite\" ? storage.prefix : undefined);\n\tconst location = storageLocation(storage);\n\tconst files = new ReadOnlyFiles();\n\tconst planned: PlannedRun[] = [];\n\tif (runs.length === 0) return { storage, runs: planned };\n\tawait withCleanup(\n\t\tasync () => {\n\t\t\tconst catalogExists = storage.kind === \"store\" && (await adoptLegacyJournal(storage.directory));\n\t\t\tconst catalog = catalogExists ? await JournalCatalog.open(storage.directory) : undefined;\n\t\t\tawait withCleanup(\n\t\t\t\tasync () => {\n\t\t\t\t\tfor (const run of runs) {\n\t\t\t\t\t\tconst found =\n\t\t\t\t\t\t\tcatalog === undefined ? undefined : await storedShard(catalog, files, t, run.header.runId);\n\t\t\t\t\t\tlet path = found?.shard.path;\n\t\t\t\t\t\tif (storage.kind === \"sqlite\") path = existsSync(storage.path) ? storage.path : undefined;\n\t\t\t\t\t\tlet stored: StoredRun | undefined;\n\t\t\t\t\t\tif (path !== undefined && existsSync(path)) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tstored = await readStoredRun(await files.read(path), t, run.header.runId);\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tthrow unreadableShard(run, path, error as Error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tplanned.push({\n\t\t\t\t\t\t\trun,\n\t\t\t\t\t\t\taction: importAction(run, stored, path ?? location),\n\t\t\t\t\t\t\tstored,\n\t\t\t\t\t\t\tcatalogued: found?.catalogued ?? false,\n\t\t\t\t\t\t\t...(found === undefined ? {} : { shard: found.shard }),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tasync () => catalog?.close(),\n\t\t\t);\n\t\t},\n\t\t() => files.close(),\n\t);\n\treturn { storage, runs: planned };\n}\n\n/** The runs an import writes to one journal file, under that file's write lock. */\ninterface ImportGroup {\n\treadonly path: string;\n\treadonly shard?: JournalShardRecord;\n\treadonly runs: PlannedRun[];\n\tdatabase?: SqliteDatabase;\n\ttx?: SqliteExecutor;\n}\n\n/**\n * Writes what `plan` decided. Every journal file the import writes to is opened and its write lock taken, in path\n * order, before anything is written, and every run is compared again under those locks: a run another process changed\n * since the plan was made (a resume took its lease, events were added, a consolidation moved it) fails the import with\n * nothing written. The locks are held until the last run is written; each file then commits. Separate journal files\n * cannot commit together, so when one fails to commit after another did, `StorageImportIncompleteError` names the runs\n * written and the runs not written, and importing again writes only the rest. A store's catalog records added runs\n * after their files commit; a run an interrupted import wrote before recording it is found and recorded by the next.\n */\nexport async function applyWorkflowRunImport(plan: WorkflowRunImportPlan): Promise<WorkflowRunImportReport> {\n\tconst { storage } = plan;\n\tconst prefix = storage.kind === \"sqlite\" ? storage.prefix : undefined;\n\tconst t = runJournalTables(prefix);\n\tconst report = { added: [] as string[], updated: [] as string[], unchanged: [] as string[] };\n\tconst pending = plan.runs.filter((run) => {\n\t\tif (run.action === \"unchanged\") report.unchanged.push(run.run.header.runId);\n\t\treturn run.action !== \"unchanged\";\n\t});\n\tconst uncatalogued = plan.runs.filter((run) => run.action === \"unchanged\" && !run.catalogued && run.shard);\n\tif (pending.length === 0 && uncatalogued.length === 0) return report;\n\tconst catalog = storage.kind === \"store\" ? await JournalCatalog.open(storage.directory) : undefined;\n\tconst groups = new Map<string, ImportGroup>();\n\tconst committed: ImportGroup[] = [];\n\tconst written = () => committed.flatMap((group) => group.runs.map((run) => run.run.header.runId));\n\ttry {\n\t\tfor (const run of pending) {\n\t\t\tconst shard =\n\t\t\t\tcatalog === undefined ? undefined : (run.shard ?? (await catalog.homeShard(run.run.header.runId)));\n\t\t\tconst path = shard?.path ?? storageLocation(storage);\n\t\t\tlet group = groups.get(path);\n\t\t\tif (group === undefined) {\n\t\t\t\tgroup = { path, runs: [], ...(shard === undefined ? {} : { shard }) };\n\t\t\t\tgroups.set(path, group);\n\t\t\t}\n\t\t\tgroup.runs.push(run);\n\t\t}\n\t\tconst ordered = [...groups.values()].sort((left, right) => (left.path < right.path ? -1 : 1));\n\t\tfor (const group of ordered) {\n\t\t\ttry {\n\t\t\t\tgroup.database = await openNodeSqliteDatabase(group.path);\n\t\t\t} catch (error) {\n\t\t\t\tthrow unreadableShard(group.runs[0]!.run, group.path, error as Error);\n\t\t\t}\n\t\t}\n\t\tconst lockAll = async (index: number): Promise<void> => {\n\t\t\tif (index === ordered.length) {\n\t\t\t\tfor (const group of ordered)\n\t\t\t\t\tfor (const run of group.runs) {\n\t\t\t\t\t\tconst now = await readStoredRun(group.tx!, t, run.run.header.runId);\n\t\t\t\t\t\tif (fingerprint(now) !== fingerprint(run.stored))\n\t\t\t\t\t\t\tthrow new StorageTransferError({\n\t\t\t\t\t\t\t\tpath: run.run.file,\n\t\t\t\t\t\t\t\tline: 1,\n\t\t\t\t\t\t\t\tid: run.run.header.runId,\n\t\t\t\t\t\t\t\treason: `run ${run.run.header.runId} changed in ${group.path} after the import compared it (another process wrote to it, took its lease or moved it); nothing was imported, so import again`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\timportAction(run.run, now, group.path);\n\t\t\t\t\t}\n\t\t\t\tfor (const group of ordered) {\n\t\t\t\t\tawait ensureRunJournalSchema(group.tx!, prefix);\n\t\t\t\t\tfor (const run of group.runs) await writeImport(group.tx!, t, run.run, run.stored);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst group = ordered[index]!;\n\t\t\tawait group.database!.transaction(async (tx) => {\n\t\t\t\tgroup.tx = tx;\n\t\t\t\tawait lockAll(index + 1);\n\t\t\t}, TRANSFER_TRANSACTION);\n\t\t\tcommitted.push(group);\n\t\t};\n\t\tawait lockAll(0);\n\t\tif (catalog !== undefined) {\n\t\t\tfor (const group of ordered)\n\t\t\t\tfor (const run of group.runs) {\n\t\t\t\t\tconst { runId, name, cwd, status } = run.run.header;\n\t\t\t\t\tif (run.catalogued) await catalog.setStatus(runId, status);\n\t\t\t\t\telse await catalog.index(group.shard!.id, { runId, name, cwd, status });\n\t\t\t\t}\n\t\t\tfor (const run of uncatalogued) {\n\t\t\t\tconst { runId, name, cwd, status } = run.run.header;\n\t\t\t\tawait catalog.index(run.shard!.id, { runId, name, cwd, status });\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tconst done = written();\n\t\tif (done.length === 0) throw error;\n\t\tconst doneSet = new Set(done);\n\t\tthrow new StorageImportIncompleteError(error as Error, {\n\t\t\twritten: { sessions: [], workflows: done },\n\t\t\tnotWritten: {\n\t\t\t\tsessions: [],\n\t\t\t\tworkflows: pending.map((run) => run.run.header.runId).filter((runId) => !doneSet.has(runId)),\n\t\t\t},\n\t\t});\n\t} finally {\n\t\tawait closeEach(\n\t\t\t[...groups.values()].flatMap((group) => (group.database === undefined ? [] : [group.database])),\n\t\t).catch(() => undefined);\n\t\tawait catalog?.close();\n\t}\n\tfor (const run of pending) (run.action === \"add\" ? report.added : report.updated).push(run.run.header.runId);\n\treturn report;\n}\n\n/**\n * Imports every `<name>.jsonl` export file in `directory` into a local workflow journal: `readWorkflowRunExports`,\n * `planWorkflowRunImport` and `applyWorkflowRunImport` in turn. Every file is read and checked, and every run compared\n * with the storage's copy, before anything is written. A run the storage does not hold is added; one whose earlier\n * events it holds gets the file's later ones; one it holds every event of is left as it is, so importing again changes\n * nothing. String values inside the records are not compared, so a file whose strings a tool redacted imports as the\n * run it was exported from.\n */\nexport async function importWorkflowRuns(\n\tstorage: WorkflowRunTransferStorage,\n\tdirectory: string,\n): Promise<WorkflowRunImportReport> {\n\treturn applyWorkflowRunImport(await planWorkflowRunImport(storage, await readWorkflowRunExports(directory)));\n}\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files `atomic storage export` writes and `atomic storage import` reads (#4716, #4720): one JSONL file per session
|
|
3
|
+
* or workflow run, in its own subdirectory of the export directory. Each file is written whole through a temporary
|
|
4
|
+
* file, and one that already holds the same bytes is left untouched.
|
|
5
|
+
*/
|
|
6
|
+
import { StorageError, type StorageFailureCause } from "./errors.js";
|
|
7
|
+
/** The file name extension of an exported session or run; import reads every file with it and ignores the rest. */
|
|
8
|
+
export declare const TRANSFER_FILE_EXTENSION = ".jsonl";
|
|
9
|
+
/** The subdirectory of an export directory that holds sessions. */
|
|
10
|
+
export declare const SESSIONS_TRANSFER_DIRECTORY = "sessions";
|
|
11
|
+
/** The subdirectory of an export directory that holds workflow runs. */
|
|
12
|
+
export declare const WORKFLOWS_TRANSFER_DIRECTORY = "workflows";
|
|
13
|
+
export interface StorageTransferErrorInit {
|
|
14
|
+
/** The file or storage location the error is about. */
|
|
15
|
+
readonly path: string;
|
|
16
|
+
/** The 1-based line of `path`. */
|
|
17
|
+
readonly line?: number;
|
|
18
|
+
/** The session or run the error is about. */
|
|
19
|
+
readonly id?: string;
|
|
20
|
+
readonly reason: string;
|
|
21
|
+
readonly cause?: StorageFailureCause;
|
|
22
|
+
}
|
|
23
|
+
/** An export or import that could not be done; an import that fails this way wrote nothing. */
|
|
24
|
+
export declare class StorageTransferError extends StorageError {
|
|
25
|
+
readonly name: "StorageTransferError";
|
|
26
|
+
readonly path: string;
|
|
27
|
+
readonly line: number | undefined;
|
|
28
|
+
readonly id: string | undefined;
|
|
29
|
+
readonly reason: string;
|
|
30
|
+
constructor(init: StorageTransferErrorInit);
|
|
31
|
+
}
|
|
32
|
+
/** The sessions and workflow runs an import wrote, or did not write. */
|
|
33
|
+
export interface TransferredIds {
|
|
34
|
+
readonly sessions: readonly string[];
|
|
35
|
+
readonly workflows: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An import that failed after it wrote some sessions or runs: `written` names exactly what it wrote, and `notWritten`
|
|
39
|
+
* what it did not. Importing the same files again writes only what is missing.
|
|
40
|
+
*/
|
|
41
|
+
export declare class StorageImportIncompleteError extends StorageError {
|
|
42
|
+
readonly name: "StorageImportIncompleteError";
|
|
43
|
+
readonly written: TransferredIds;
|
|
44
|
+
readonly notWritten: TransferredIds;
|
|
45
|
+
constructor(cause: Error, outcome: {
|
|
46
|
+
readonly written: TransferredIds;
|
|
47
|
+
readonly notWritten: TransferredIds;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export declare function isStorageImportIncompleteError(value: unknown): value is StorageImportIncompleteError;
|
|
51
|
+
export declare function isStorageTransferError(value: unknown): value is StorageTransferError;
|
|
52
|
+
/** The file a session or run with `id` is exported to in `directory`. */
|
|
53
|
+
export declare function transferFile(directory: string, id: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Writes `lines`, each followed by a newline, to `file` through an owner-only temporary file in the same directory
|
|
56
|
+
* that is flushed and then renamed over it, so `file` holds either its earlier content or all of the new content. The
|
|
57
|
+
* lines are written as they come, so a large session is never held as one string. A file that already holds exactly
|
|
58
|
+
* these bytes is left alone.
|
|
59
|
+
*/
|
|
60
|
+
export declare function writeLinesAtomically(file: string, lines: Iterable<string> | AsyncIterable<string>): Promise<"written" | "unchanged">;
|
|
61
|
+
/** One export file as import reads it: its path and its lines, each with its 1-based line number. */
|
|
62
|
+
export interface TransferFileLines {
|
|
63
|
+
readonly file: string;
|
|
64
|
+
readonly lines: readonly {
|
|
65
|
+
readonly line: number;
|
|
66
|
+
readonly text: string;
|
|
67
|
+
}[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The `*.jsonl` files of `directory`, in name order, each decoded as UTF-8 and split into lines; a final newline does
|
|
71
|
+
* not start another line. A directory that does not exist holds no files. Throws `StorageTransferError` naming the
|
|
72
|
+
* file when one cannot be read or is not UTF-8.
|
|
73
|
+
*/
|
|
74
|
+
export declare function readTransferDirectory(directory: string): Promise<TransferFileLines[]>;
|
|
75
|
+
//# sourceMappingURL=transfer-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-files.d.ts","sourceRoot":"","sources":["../../../src/core/storage/transfer-files.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErE,mHAAmH;AACnH,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAChD,mEAAmE;AACnE,eAAO,MAAM,2BAA2B,aAAa,CAAC;AACtD,wEAAwE;AACxE,eAAO,MAAM,4BAA4B,cAAc,CAAC;AAExD,MAAM,WAAW,wBAAwB;IACxC,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kCAAkC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED,+FAA+F;AAC/F,qBAAa,oBAAqB,SAAQ,YAAY;IACrD,SAAkB,IAAI,EAAG,sBAAsB,CAAU;IACzD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,IAAI,EAAE,wBAAwB,EAMzC;CACD;AAED,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,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` writes and `atomic storage import` reads (#4716, #4720): one JSONL file per session
|
|
3
|
+
* or workflow run, in its own subdirectory of the export directory. Each file is written whole through a temporary
|
|
4
|
+
* file, and one that already holds the same bytes is left untouched.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { open, readdir, readFile, rename, rm } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { withCleanup } from "./cleanup.js";
|
|
10
|
+
import { StorageError } from "./errors.js";
|
|
11
|
+
/** The file name extension of an exported session or run; import reads every file with it and ignores the rest. */
|
|
12
|
+
export const TRANSFER_FILE_EXTENSION = ".jsonl";
|
|
13
|
+
/** The subdirectory of an export directory that holds sessions. */
|
|
14
|
+
export const SESSIONS_TRANSFER_DIRECTORY = "sessions";
|
|
15
|
+
/** The subdirectory of an export directory that holds workflow runs. */
|
|
16
|
+
export const WORKFLOWS_TRANSFER_DIRECTORY = "workflows";
|
|
17
|
+
/** An export or import that could not be done; an import that fails this way wrote nothing. */
|
|
18
|
+
export class StorageTransferError extends StorageError {
|
|
19
|
+
name = "StorageTransferError";
|
|
20
|
+
path;
|
|
21
|
+
line;
|
|
22
|
+
id;
|
|
23
|
+
reason;
|
|
24
|
+
constructor(init) {
|
|
25
|
+
super(`${init.path}${init.line === undefined ? "" : `:${init.line}`}: ${init.reason}`, { cause: init.cause });
|
|
26
|
+
this.path = init.path;
|
|
27
|
+
this.line = init.line;
|
|
28
|
+
this.id = init.id;
|
|
29
|
+
this.reason = init.reason;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* An import that failed after it wrote some sessions or runs: `written` names exactly what it wrote, and `notWritten`
|
|
34
|
+
* what it did not. Importing the same files again writes only what is missing.
|
|
35
|
+
*/
|
|
36
|
+
export class StorageImportIncompleteError extends StorageError {
|
|
37
|
+
name = "StorageImportIncompleteError";
|
|
38
|
+
written;
|
|
39
|
+
notWritten;
|
|
40
|
+
constructor(cause, outcome) {
|
|
41
|
+
super(cause.message, { cause });
|
|
42
|
+
this.written = outcome.written;
|
|
43
|
+
this.notWritten = outcome.notWritten;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function isStorageImportIncompleteError(value) {
|
|
47
|
+
if (value instanceof StorageImportIncompleteError)
|
|
48
|
+
return true;
|
|
49
|
+
return (typeof value === "object" &&
|
|
50
|
+
value !== null &&
|
|
51
|
+
value.name === "StorageImportIncompleteError");
|
|
52
|
+
}
|
|
53
|
+
export function isStorageTransferError(value) {
|
|
54
|
+
if (value instanceof StorageTransferError)
|
|
55
|
+
return true;
|
|
56
|
+
return typeof value === "object" && value !== null && value.name === "StorageTransferError";
|
|
57
|
+
}
|
|
58
|
+
/** The file a session or run with `id` is exported to in `directory`. */
|
|
59
|
+
export function transferFile(directory, id) {
|
|
60
|
+
return join(directory, `${encodeURIComponent(id)}${TRANSFER_FILE_EXTENSION}`);
|
|
61
|
+
}
|
|
62
|
+
async function sameBytes(left, right) {
|
|
63
|
+
const [a, b] = await Promise.all([open(left, "r"), open(right, "r").catch(() => undefined)]);
|
|
64
|
+
if (b === undefined) {
|
|
65
|
+
await a.close();
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return withCleanup(async () => {
|
|
69
|
+
const [sizeA, sizeB] = await Promise.all([a.stat(), b.stat()]);
|
|
70
|
+
if (sizeA.size !== sizeB.size)
|
|
71
|
+
return false;
|
|
72
|
+
const chunkA = Buffer.alloc(64 * 1024);
|
|
73
|
+
const chunkB = Buffer.alloc(64 * 1024);
|
|
74
|
+
for (let offset = 0; offset < sizeA.size;) {
|
|
75
|
+
const [readA, readB] = await Promise.all([
|
|
76
|
+
a.read(chunkA, 0, chunkA.length, offset),
|
|
77
|
+
b.read(chunkB, 0, chunkB.length, offset),
|
|
78
|
+
]);
|
|
79
|
+
if (readA.bytesRead === 0 || readA.bytesRead !== readB.bytesRead)
|
|
80
|
+
return false;
|
|
81
|
+
if (!chunkA.subarray(0, readA.bytesRead).equals(chunkB.subarray(0, readB.bytesRead)))
|
|
82
|
+
return false;
|
|
83
|
+
offset += readA.bytesRead;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}, async () => {
|
|
87
|
+
await Promise.allSettled([a.close(), b.close()]);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Writes `lines`, each followed by a newline, to `file` through an owner-only temporary file in the same directory
|
|
92
|
+
* that is flushed and then renamed over it, so `file` holds either its earlier content or all of the new content. The
|
|
93
|
+
* lines are written as they come, so a large session is never held as one string. A file that already holds exactly
|
|
94
|
+
* these bytes is left alone.
|
|
95
|
+
*/
|
|
96
|
+
export async function writeLinesAtomically(file, lines) {
|
|
97
|
+
const temporary = join(file, "..", `.${randomUUID()}.tmp`);
|
|
98
|
+
try {
|
|
99
|
+
const handle = await open(temporary, "wx", 0o600);
|
|
100
|
+
await withCleanup(async () => {
|
|
101
|
+
for await (const line of lines)
|
|
102
|
+
await handle.write(`${line}\n`, null, "utf8");
|
|
103
|
+
await handle.sync();
|
|
104
|
+
}, () => handle.close());
|
|
105
|
+
if (await sameBytes(temporary, file)) {
|
|
106
|
+
await rm(temporary, { force: true });
|
|
107
|
+
return "unchanged";
|
|
108
|
+
}
|
|
109
|
+
await rename(temporary, file);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
await rm(temporary, { force: true }).catch(() => undefined);
|
|
113
|
+
if (isStorageTransferError(error))
|
|
114
|
+
throw error;
|
|
115
|
+
throw new StorageTransferError({
|
|
116
|
+
path: file,
|
|
117
|
+
reason: `cannot write the export file: ${error.message}`,
|
|
118
|
+
cause: error,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return "written";
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The `*.jsonl` files of `directory`, in name order, each decoded as UTF-8 and split into lines; a final newline does
|
|
125
|
+
* not start another line. A directory that does not exist holds no files. Throws `StorageTransferError` naming the
|
|
126
|
+
* file when one cannot be read or is not UTF-8.
|
|
127
|
+
*/
|
|
128
|
+
export async function readTransferDirectory(directory) {
|
|
129
|
+
let names;
|
|
130
|
+
try {
|
|
131
|
+
names = await readdir(directory);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error.code === "ENOENT")
|
|
135
|
+
return [];
|
|
136
|
+
throw new StorageTransferError({
|
|
137
|
+
path: directory,
|
|
138
|
+
reason: `cannot read the directory: ${error.message}`,
|
|
139
|
+
cause: error,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const files = [];
|
|
143
|
+
for (const name of names.filter((entry) => entry.endsWith(TRANSFER_FILE_EXTENSION)).sort()) {
|
|
144
|
+
const file = join(directory, name);
|
|
145
|
+
let bytes;
|
|
146
|
+
try {
|
|
147
|
+
bytes = await readFile(file);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw new StorageTransferError({
|
|
151
|
+
path: file,
|
|
152
|
+
reason: `cannot read the file: ${error.message}`,
|
|
153
|
+
cause: error,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
let text;
|
|
157
|
+
try {
|
|
158
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
throw new StorageTransferError({ path: file, reason: "is not valid UTF-8 text" });
|
|
162
|
+
}
|
|
163
|
+
const lines = text.split("\n");
|
|
164
|
+
if (lines.at(-1) === "")
|
|
165
|
+
lines.pop();
|
|
166
|
+
files.push({ file, lines: lines.map((line, index) => ({ line: index + 1, text: line })) });
|
|
167
|
+
}
|
|
168
|
+
return files;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=transfer-files.js.map
|