@bastani/atomic 0.9.65 → 0.9.66
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 +28 -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/builtin/workflows/src/extension/index.bundle.mjs +154 -36
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +125 -16
- package/dist/builtin/workflows/src/index.js +125 -16
- package/dist/builtin/workflows/src/local-worker-entry.mjs +125 -16
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +8 -0
- package/dist/core/agent-session-auto-compaction.js +2 -2
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +9 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +5 -2
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.js +2 -2
- package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
- package/dist/core/compaction/compaction-runner.d.ts +18 -2
- package/dist/core/compaction/compaction-runner.d.ts.map +1 -1
- package/dist/core/compaction/compaction-runner.js +129 -15
- package/dist/core/compaction/compaction-runner.js.map +1 -1
- package/dist/core/compaction/compaction-types.d.ts +4 -0
- package/dist/core/compaction/compaction-types.d.ts.map +1 -1
- package/dist/core/compaction/compaction-types.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +2 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +2 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +2 -0
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +7 -0
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-schema.d.ts +2 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +4 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/docs/compaction.md +5 -1
- package/docs/session-format.md +1 -1
- package/docs/settings.md +2 -1
- package/docs/workflows/api-reference.md +3 -1
- package/docs/workflows/operations.md +5 -2
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/schemas/settings.schema.json +14 -0
|
@@ -17424,12 +17424,19 @@ class SqlResourceAdmission {
|
|
|
17424
17424
|
if (!(await tx.all(`PRAGMA table_info(${admission.owners})`)).some((entry) => entry.name === "boot"))
|
|
17425
17425
|
await tx.exec(`ALTER TABLE ${admission.owners} ADD COLUMN boot TEXT`);
|
|
17426
17426
|
await tx.run(`INSERT INTO ${admission.owners}(id, host, pid, expires_at, boot) VALUES (?, ?, ?, CAST(unixepoch('subsec') * 1000 AS INTEGER) + ?, ?)`, admission.owner, admissionHost, process.pid, OWNER_LEASE_MS, boot);
|
|
17427
|
+
const rootLimits = options.rootLimits ?? "check";
|
|
17427
17428
|
for (const [scope, limits] of [
|
|
17428
17429
|
[`root:${options.root}`, options.limits],
|
|
17429
17430
|
["user", options.userLimits]
|
|
17430
17431
|
]) {
|
|
17431
|
-
|
|
17432
|
+
const ofRoot = scope !== "user";
|
|
17433
|
+
if (ofRoot && rootLimits === "unchanged")
|
|
17432
17434
|
continue;
|
|
17435
|
+
if (!limits && (scope === "user" || !options.host)) {
|
|
17436
|
+
if (ofRoot && rootLimits === "replace")
|
|
17437
|
+
await tx.run(`DELETE FROM ${admission.configuration} WHERE scope = ?`, scope);
|
|
17438
|
+
continue;
|
|
17439
|
+
}
|
|
17433
17440
|
const config = JSON.stringify({
|
|
17434
17441
|
session: limits?.session ?? null,
|
|
17435
17442
|
process: limits?.process ?? null,
|
|
@@ -17440,6 +17447,10 @@ class SqlResourceAdmission {
|
|
|
17440
17447
|
}
|
|
17441
17448
|
}
|
|
17442
17449
|
});
|
|
17450
|
+
if (ofRoot && rootLimits === "replace") {
|
|
17451
|
+
await tx.run(`INSERT OR REPLACE INTO ${admission.configuration} VALUES (?, ?)`, scope, config);
|
|
17452
|
+
continue;
|
|
17453
|
+
}
|
|
17443
17454
|
await tx.run(`INSERT OR IGNORE INTO ${admission.configuration} VALUES (?, ?)`, scope, config);
|
|
17444
17455
|
if ((await tx.get(`SELECT config FROM ${admission.configuration} WHERE scope = ?`, scope))?.config !== config)
|
|
17445
17456
|
throw new Error("Conflicting resource admission configuration");
|
|
@@ -17879,7 +17890,8 @@ async function admitWorkflowSessions(backend, opts, callback) {
|
|
|
17879
17890
|
const admission = await SqlResourceAdmission.open(poolJournalFor(rootBackend.journal), {
|
|
17880
17891
|
...config,
|
|
17881
17892
|
root: opts.parentRun?.rootRunId ?? opts.runId,
|
|
17882
|
-
holder: randomUUID7()
|
|
17893
|
+
holder: randomUUID7(),
|
|
17894
|
+
...opts.parentRun === undefined ? { rootLimits: "replace" } : {}
|
|
17883
17895
|
});
|
|
17884
17896
|
return withResourceAdmission(admission, () => callback({
|
|
17885
17897
|
...opts,
|
|
@@ -60277,6 +60289,12 @@ function expiry(now, duration) {
|
|
|
60277
60289
|
positive(expiresAt);
|
|
60278
60290
|
return expiresAt;
|
|
60279
60291
|
}
|
|
60292
|
+
function short(digest) {
|
|
60293
|
+
return digest.slice(0, 12);
|
|
60294
|
+
}
|
|
60295
|
+
function shownMode(mode) {
|
|
60296
|
+
return mode === undefined ? "unset" : JSON.stringify(mode);
|
|
60297
|
+
}
|
|
60280
60298
|
|
|
60281
60299
|
class SqlPoolQueue {
|
|
60282
60300
|
storage;
|
|
@@ -60457,7 +60475,7 @@ class SqlPoolQueue {
|
|
|
60457
60475
|
throw new Error(STALE_WORK_LEASE);
|
|
60458
60476
|
});
|
|
60459
60477
|
}
|
|
60460
|
-
async enqueue(lease, descriptor, boundary) {
|
|
60478
|
+
async enqueue(lease, descriptor, boundary, options = {}) {
|
|
60461
60479
|
lease = snapshotLease(lease);
|
|
60462
60480
|
const { boundaryId, childRunId, scope } = descriptor;
|
|
60463
60481
|
const topology = boundary.topology;
|
|
@@ -60486,12 +60504,11 @@ class SqlPoolQueue {
|
|
|
60486
60504
|
const { now } = await this.authority(tx, lease);
|
|
60487
60505
|
const previous = await tx.get(`SELECT * FROM ${this.work} WHERE root = ? AND (boundary = ? OR json_extract(descriptor, '$.scope') = ? OR json_extract(descriptor, '$.childRunId') = ?)`, lease.runId, boundaryId, scope, childRunId);
|
|
60488
60506
|
if (previous) {
|
|
60489
|
-
|
|
60490
|
-
|
|
60491
|
-
|
|
60492
|
-
|
|
60493
|
-
|
|
60494
|
-
return fromRow({ ...previous, state: "ready", epoch: lease.epoch });
|
|
60507
|
+
const row = previous.fingerprint === fingerprint ? previous : await this.rebind(tx, lease, previous, json, JSON.parse(payload), fingerprint, options);
|
|
60508
|
+
if (row.state !== "ready" && row.state !== "failed" || row.epoch >= lease.epoch)
|
|
60509
|
+
return fromRow(row);
|
|
60510
|
+
await tx.run(`UPDATE ${this.work} SET state = 'ready', epoch = ? WHERE id = ?`, lease.epoch, row.id);
|
|
60511
|
+
return fromRow({ ...row, state: "ready", epoch: lease.epoch });
|
|
60495
60512
|
}
|
|
60496
60513
|
const siblings = await tx.all(`SELECT json_extract(descriptor, '$.scope') AS scope FROM ${this.work} WHERE root = ?`, lease.runId);
|
|
60497
60514
|
if (siblings.some((item) => scope.startsWith(`${item.scope}:`) || item.scope.startsWith(`${scope}:`)))
|
|
@@ -60522,6 +60539,32 @@ class SqlPoolQueue {
|
|
|
60522
60539
|
if (outcome.status === "exists" && !isSameCheckpointValue(outcome.entry.event.payload, boundary))
|
|
60523
60540
|
throw new Error("Pool boundary identity conflict");
|
|
60524
60541
|
}
|
|
60542
|
+
async rebind(tx, lease, previous, json, boundary, fingerprint, options) {
|
|
60543
|
+
const queued = JSON.parse(previous.descriptor);
|
|
60544
|
+
const requested = JSON.parse(json);
|
|
60545
|
+
const queuedMode = queued.execution.executionMode;
|
|
60546
|
+
const requestedMode = requested.execution.executionMode;
|
|
60547
|
+
const { executionMode: _mode, ...execution } = requested.execution;
|
|
60548
|
+
const asQueued = {
|
|
60549
|
+
...requested,
|
|
60550
|
+
digest: queued.digest,
|
|
60551
|
+
execution: queuedMode === undefined ? execution : { ...execution, executionMode: queuedMode }
|
|
60552
|
+
};
|
|
60553
|
+
if (durableHash({ descriptor: asQueued, boundary }) !== previous.fingerprint)
|
|
60554
|
+
throw new Error("Pool boundary identity conflict");
|
|
60555
|
+
const entryEdited = queued.digest !== requested.digest;
|
|
60556
|
+
if (previous.epoch >= lease.epoch) {
|
|
60557
|
+
const changes = [
|
|
60558
|
+
...entryEdited ? [`entry module (sha256 ${short(queued.digest)} to ${short(requested.digest)})`] : [],
|
|
60559
|
+
...queuedMode !== requestedMode ? [`execution mode (${shownMode(queuedMode)} to ${shownMode(requestedMode)})`] : []
|
|
60560
|
+
];
|
|
60561
|
+
throw new Error(`Pool boundary identity conflict: child ${requested.childRunId} is already queued by this incarnation of root ${lease.runId}, and its worker may be running it, so its ${changes.join(" and ")} cannot change`);
|
|
60562
|
+
}
|
|
60563
|
+
if (entryEdited && options.acceptEntryChanges !== true)
|
|
60564
|
+
throw new Error(`Pool boundary identity conflict: child ${requested.childRunId} was queued by an earlier run of root ${lease.runId} with the entry module of worker definition ${requested.definition} at sha256 ${short(queued.digest)}, and the root now runs that module at sha256 ${short(requested.digest)}. Resume the root with /workflow resume ${lease.runId} --accept-entry-changes, or acceptEntryChanges: true in the SDK, to run the child with the edited module, or restore the module.`);
|
|
60565
|
+
await tx.run(`UPDATE ${this.work} SET descriptor = ?, fingerprint = ? WHERE id = ?`, json, fingerprint, previous.id);
|
|
60566
|
+
return { ...previous, descriptor: json, fingerprint };
|
|
60567
|
+
}
|
|
60525
60568
|
async claim(lease, worker, definitions, durationMs) {
|
|
60526
60569
|
positive(durationMs);
|
|
60527
60570
|
lease = snapshotLease(lease);
|
|
@@ -66203,7 +66246,9 @@ class PoolCoordinator {
|
|
|
66203
66246
|
const queue = this.queue;
|
|
66204
66247
|
const lease = this.lease;
|
|
66205
66248
|
const work = await this.retainedTransition(async () => {
|
|
66206
|
-
let enqueued = await this.whileRootLate(queue, () => queue.enqueue(lease, command.descriptor, command.boundary
|
|
66249
|
+
let enqueued = await this.whileRootLate(queue, () => queue.enqueue(lease, command.descriptor, command.boundary, {
|
|
66250
|
+
acceptEntryChanges: command.acceptEntryChanges === true
|
|
66251
|
+
}));
|
|
66207
66252
|
if (enqueued.state === "completed" && enqueued.epoch < lease.epoch)
|
|
66208
66253
|
enqueued = await this.whileRootLate(queue, () => queue.reopenCompleted(lease, enqueued.id, failedOnInfrastructureFault)) ?? enqueued;
|
|
66209
66254
|
const retained = this.retained.get(enqueued.id);
|
|
@@ -69843,7 +69888,8 @@ class LocalWorkerPool {
|
|
|
69843
69888
|
inputs,
|
|
69844
69889
|
execution
|
|
69845
69890
|
},
|
|
69846
|
-
boundary
|
|
69891
|
+
boundary,
|
|
69892
|
+
...this.options.acceptEntryChanges === true ? { acceptEntryChanges: true } : {}
|
|
69847
69893
|
});
|
|
69848
69894
|
const work = enqueued.work;
|
|
69849
69895
|
this.works.set(work.id, work);
|
|
@@ -70279,14 +70325,66 @@ var DEFAULT_POOLED_STAGE_START_MAX_LOAD_PER_CPU = 3;
|
|
|
70279
70325
|
// dist/builtin/workflows/src/workers/public-pool.ts
|
|
70280
70326
|
import { resolve as resolve15 } from "node:path";
|
|
70281
70327
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
70328
|
+
function shown(value2) {
|
|
70329
|
+
return value2 === undefined ? "unset" : JSON.stringify(value2);
|
|
70330
|
+
}
|
|
70331
|
+
function isPlainRecord(value2) {
|
|
70332
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
70333
|
+
}
|
|
70334
|
+
function settingChanges(path, saved, current, changes) {
|
|
70335
|
+
if (isDeepStrictEqual2(saved, current))
|
|
70336
|
+
return;
|
|
70337
|
+
if ((saved === undefined || isPlainRecord(saved)) && (current === undefined || isPlainRecord(current))) {
|
|
70338
|
+
for (const key of new Set([...Object.keys(saved ?? {}), ...Object.keys(current ?? {})]))
|
|
70339
|
+
settingChanges(`${path}.${key}`, saved?.[key], current?.[key], changes);
|
|
70340
|
+
return;
|
|
70341
|
+
}
|
|
70342
|
+
changes.push({
|
|
70343
|
+
description: `${path} changed from ${shown(saved)} to ${shown(current)}`,
|
|
70344
|
+
resumable: RESUMABLE_SETTINGS.has(path)
|
|
70345
|
+
});
|
|
70346
|
+
}
|
|
70347
|
+
function resourceChanges(saved, current) {
|
|
70348
|
+
const changes = [];
|
|
70349
|
+
if (saved.localWorkers === undefined !== (current.localWorkers === undefined))
|
|
70350
|
+
changes.push({
|
|
70351
|
+
description: `local workers were turned ${current.localWorkers === undefined ? "off" : "on"}`,
|
|
70352
|
+
resumable: false
|
|
70353
|
+
});
|
|
70354
|
+
else {
|
|
70355
|
+
settingChanges("localWorkers", saved.localWorkers && { ...saved.localWorkers, definitions: undefined }, current.localWorkers && { ...current.localWorkers, definitions: undefined }, changes);
|
|
70356
|
+
}
|
|
70357
|
+
const named = (list) => new Map((list ?? []).map((source) => [`${source.path}#${source.exportName}`, source.digest]));
|
|
70358
|
+
const before = named(saved.definitions);
|
|
70359
|
+
const after = named(current.definitions);
|
|
70360
|
+
for (const [name, digest] of before) {
|
|
70361
|
+
const now = after.get(name);
|
|
70362
|
+
if (now === undefined)
|
|
70363
|
+
changes.push({ description: `worker definition ${name} is no longer listed`, resumable: false });
|
|
70364
|
+
else if (now !== digest)
|
|
70365
|
+
changes.push({
|
|
70366
|
+
description: `the entry module of worker definition ${name} was edited (sha256 ${digest.slice(0, 12)} to ${now.slice(0, 12)})`,
|
|
70367
|
+
resumable: false,
|
|
70368
|
+
entry: true
|
|
70369
|
+
});
|
|
70370
|
+
}
|
|
70371
|
+
for (const name of after.keys())
|
|
70372
|
+
if (!before.has(name))
|
|
70373
|
+
changes.push({ description: `worker definition ${name} was added`, resumable: false });
|
|
70374
|
+
settingChanges("admission", saved.admission, current.admission, changes);
|
|
70375
|
+
settingChanges("coordinator", saved.coordinator, current.coordinator, changes);
|
|
70376
|
+
return changes;
|
|
70377
|
+
}
|
|
70282
70378
|
async function restoreWorkerOptions(backend, options) {
|
|
70283
70379
|
const source = options.continuation?.source.id ?? options.runId;
|
|
70284
70380
|
if (source !== undefined)
|
|
70285
70381
|
await backend.hydrateWorkflow(source);
|
|
70286
70382
|
const original = source === undefined ? undefined : backend.getWorkflow(source);
|
|
70287
70383
|
const saved = original?.resources;
|
|
70288
|
-
if (original && !saved && (options.localWorkers || options.admission))
|
|
70289
|
-
|
|
70384
|
+
if (original && !saved && (options.localWorkers || options.admission)) {
|
|
70385
|
+
const set = [options.localWorkers && "localWorkers", options.admission && "admission"].filter(Boolean).join(" and ");
|
|
70386
|
+
throw new Error(`Root ${source} started without local workers or resource admission, and this resume sets ${set}: immutable resource configuration cannot change on an existing root. Resume it without them, or start a new run.`);
|
|
70387
|
+
}
|
|
70290
70388
|
return {
|
|
70291
70389
|
...options,
|
|
70292
70390
|
localWorkers: options.localWorkers ?? saved?.localWorkers,
|
|
@@ -70349,14 +70447,16 @@ async function activatePublicPool(backend, options) {
|
|
|
70349
70447
|
throw new Error(`This root's local workers ran on another machine (${saved.host}). Their work queue and leases are in that machine's pool database, which this machine cannot see, and its workers may still be running children. Resume the root on that machine.`);
|
|
70350
70448
|
if (saved !== undefined && resources.coordinator !== undefined && saved.host === resources.coordinator.host && saved.database !== resources.coordinator.database)
|
|
70351
70449
|
throw new Error(`This root's local workers keep their work queue and leases in the pool database ${saved.database} on this machine, but the journal is now selected in a way that uses ${resources.coordinator.database}: its adapter, options, prefix or the agent directory changed. Resume the root with the journal selected as it was when the root started.`);
|
|
70352
|
-
|
|
70353
|
-
|
|
70450
|
+
const refused = options.effectiveResources === undefined ? [] : resourceChanges(options.effectiveResources, resources).filter((change) => !change.resumable && !(change.entry && options.acceptEntryChanges === true));
|
|
70451
|
+
if (refused.length > 0)
|
|
70452
|
+
throw new Error(`Since root ${options.runId} started, ${refused.map((change) => change.description).join("; ")}. Its recorded steps and queued children depend on these, so restore them to resume it, or start a new run. The pool size (localWorkers.count) and the root's own limits (admission.limits and admission.host) can change between resumes.${refused.some((change) => change.entry) ? ` An edited entry module can also be accepted: resume with /workflow resume ${options.runId} --accept-entry-changes, or acceptEntryChanges: true in the SDK, to replay the recorded steps and run the rest of each unfinished child with the edited module.` : ""}`);
|
|
70354
70453
|
options.effectiveResources = resources;
|
|
70355
70454
|
if (resources.admission)
|
|
70356
70455
|
await SqlResourceAdmission.open(poolJournal, {
|
|
70357
70456
|
...resources.admission,
|
|
70358
70457
|
root: options.runId,
|
|
70359
|
-
holder: "preflight"
|
|
70458
|
+
holder: "preflight",
|
|
70459
|
+
rootLimits: "unchanged"
|
|
70360
70460
|
});
|
|
70361
70461
|
if (!localWorkers)
|
|
70362
70462
|
return;
|
|
@@ -70371,6 +70471,7 @@ async function activatePublicPool(backend, options) {
|
|
|
70371
70471
|
startupTimeoutMs: options.localWorkers?.startupTimeoutMs,
|
|
70372
70472
|
leaseMs: options.localWorkers?.leaseMs,
|
|
70373
70473
|
maxLoadPerCpu: options.localWorkers?.maxLoadPerCpu ?? DEFAULT_POOLED_STAGE_START_MAX_LOAD_PER_CPU,
|
|
70474
|
+
...options.acceptEntryChanges === true ? { acceptEntryChanges: true } : {},
|
|
70374
70475
|
...options.stageControlRegistry === undefined || options[hostWorkerBindings] ? {} : { stageControlRegistry: options.stageControlRegistry }
|
|
70375
70476
|
});
|
|
70376
70477
|
try {
|
|
@@ -70381,6 +70482,7 @@ async function activatePublicPool(backend, options) {
|
|
|
70381
70482
|
throw error;
|
|
70382
70483
|
}
|
|
70383
70484
|
}
|
|
70485
|
+
var RESUMABLE_SETTINGS;
|
|
70384
70486
|
var init_public_pool = __esm(() => {
|
|
70385
70487
|
init_journal_backend();
|
|
70386
70488
|
init_admission_host();
|
|
@@ -70389,6 +70491,13 @@ var init_public_pool = __esm(() => {
|
|
|
70389
70491
|
init_local_pool();
|
|
70390
70492
|
init_pool_journal();
|
|
70391
70493
|
init_resource_admission();
|
|
70494
|
+
RESUMABLE_SETTINGS = new Set([
|
|
70495
|
+
"localWorkers.count",
|
|
70496
|
+
"admission.limits.session",
|
|
70497
|
+
"admission.limits.process",
|
|
70498
|
+
"admission.host.maxLoadPerCpu",
|
|
70499
|
+
"admission.host.minFreeMemoryBytes"
|
|
70500
|
+
]);
|
|
70392
70501
|
});
|
|
70393
70502
|
|
|
70394
70503
|
// dist/builtin/workflows/src/engine/primitives/chain.ts
|
|
@@ -17535,12 +17535,19 @@ class SqlResourceAdmission {
|
|
|
17535
17535
|
if (!(await tx.all(`PRAGMA table_info(${admission.owners})`)).some((entry) => entry.name === "boot"))
|
|
17536
17536
|
await tx.exec(`ALTER TABLE ${admission.owners} ADD COLUMN boot TEXT`);
|
|
17537
17537
|
await tx.run(`INSERT INTO ${admission.owners}(id, host, pid, expires_at, boot) VALUES (?, ?, ?, CAST(unixepoch('subsec') * 1000 AS INTEGER) + ?, ?)`, admission.owner, admissionHost, process.pid, OWNER_LEASE_MS, boot);
|
|
17538
|
+
const rootLimits = options.rootLimits ?? "check";
|
|
17538
17539
|
for (const [scope, limits] of [
|
|
17539
17540
|
[`root:${options.root}`, options.limits],
|
|
17540
17541
|
["user", options.userLimits]
|
|
17541
17542
|
]) {
|
|
17542
|
-
|
|
17543
|
+
const ofRoot = scope !== "user";
|
|
17544
|
+
if (ofRoot && rootLimits === "unchanged")
|
|
17543
17545
|
continue;
|
|
17546
|
+
if (!limits && (scope === "user" || !options.host)) {
|
|
17547
|
+
if (ofRoot && rootLimits === "replace")
|
|
17548
|
+
await tx.run(`DELETE FROM ${admission.configuration} WHERE scope = ?`, scope);
|
|
17549
|
+
continue;
|
|
17550
|
+
}
|
|
17544
17551
|
const config = JSON.stringify({
|
|
17545
17552
|
session: limits?.session ?? null,
|
|
17546
17553
|
process: limits?.process ?? null,
|
|
@@ -17551,6 +17558,10 @@ class SqlResourceAdmission {
|
|
|
17551
17558
|
}
|
|
17552
17559
|
}
|
|
17553
17560
|
});
|
|
17561
|
+
if (ofRoot && rootLimits === "replace") {
|
|
17562
|
+
await tx.run(`INSERT OR REPLACE INTO ${admission.configuration} VALUES (?, ?)`, scope, config);
|
|
17563
|
+
continue;
|
|
17564
|
+
}
|
|
17554
17565
|
await tx.run(`INSERT OR IGNORE INTO ${admission.configuration} VALUES (?, ?)`, scope, config);
|
|
17555
17566
|
if ((await tx.get(`SELECT config FROM ${admission.configuration} WHERE scope = ?`, scope))?.config !== config)
|
|
17556
17567
|
throw new Error("Conflicting resource admission configuration");
|
|
@@ -17990,7 +18001,8 @@ async function admitWorkflowSessions(backend, opts, callback) {
|
|
|
17990
18001
|
const admission = await SqlResourceAdmission.open(poolJournalFor(rootBackend.journal), {
|
|
17991
18002
|
...config,
|
|
17992
18003
|
root: opts.parentRun?.rootRunId ?? opts.runId,
|
|
17993
|
-
holder: randomUUID8()
|
|
18004
|
+
holder: randomUUID8(),
|
|
18005
|
+
...opts.parentRun === undefined ? { rootLimits: "replace" } : {}
|
|
17994
18006
|
});
|
|
17995
18007
|
return withResourceAdmission(admission, () => callback({
|
|
17996
18008
|
...opts,
|
|
@@ -60388,6 +60400,12 @@ function expiry(now, duration) {
|
|
|
60388
60400
|
positive(expiresAt);
|
|
60389
60401
|
return expiresAt;
|
|
60390
60402
|
}
|
|
60403
|
+
function short(digest) {
|
|
60404
|
+
return digest.slice(0, 12);
|
|
60405
|
+
}
|
|
60406
|
+
function shownMode(mode) {
|
|
60407
|
+
return mode === undefined ? "unset" : JSON.stringify(mode);
|
|
60408
|
+
}
|
|
60391
60409
|
|
|
60392
60410
|
class SqlPoolQueue {
|
|
60393
60411
|
storage;
|
|
@@ -60568,7 +60586,7 @@ class SqlPoolQueue {
|
|
|
60568
60586
|
throw new Error(STALE_WORK_LEASE);
|
|
60569
60587
|
});
|
|
60570
60588
|
}
|
|
60571
|
-
async enqueue(lease, descriptor, boundary) {
|
|
60589
|
+
async enqueue(lease, descriptor, boundary, options = {}) {
|
|
60572
60590
|
lease = snapshotLease(lease);
|
|
60573
60591
|
const { boundaryId, childRunId, scope } = descriptor;
|
|
60574
60592
|
const topology = boundary.topology;
|
|
@@ -60597,12 +60615,11 @@ class SqlPoolQueue {
|
|
|
60597
60615
|
const { now } = await this.authority(tx, lease);
|
|
60598
60616
|
const previous = await tx.get(`SELECT * FROM ${this.work} WHERE root = ? AND (boundary = ? OR json_extract(descriptor, '$.scope') = ? OR json_extract(descriptor, '$.childRunId') = ?)`, lease.runId, boundaryId, scope, childRunId);
|
|
60599
60617
|
if (previous) {
|
|
60600
|
-
|
|
60601
|
-
|
|
60602
|
-
|
|
60603
|
-
|
|
60604
|
-
|
|
60605
|
-
return fromRow({ ...previous, state: "ready", epoch: lease.epoch });
|
|
60618
|
+
const row = previous.fingerprint === fingerprint ? previous : await this.rebind(tx, lease, previous, json, JSON.parse(payload), fingerprint, options);
|
|
60619
|
+
if (row.state !== "ready" && row.state !== "failed" || row.epoch >= lease.epoch)
|
|
60620
|
+
return fromRow(row);
|
|
60621
|
+
await tx.run(`UPDATE ${this.work} SET state = 'ready', epoch = ? WHERE id = ?`, lease.epoch, row.id);
|
|
60622
|
+
return fromRow({ ...row, state: "ready", epoch: lease.epoch });
|
|
60606
60623
|
}
|
|
60607
60624
|
const siblings = await tx.all(`SELECT json_extract(descriptor, '$.scope') AS scope FROM ${this.work} WHERE root = ?`, lease.runId);
|
|
60608
60625
|
if (siblings.some((item) => scope.startsWith(`${item.scope}:`) || item.scope.startsWith(`${scope}:`)))
|
|
@@ -60633,6 +60650,32 @@ class SqlPoolQueue {
|
|
|
60633
60650
|
if (outcome.status === "exists" && !isSameCheckpointValue(outcome.entry.event.payload, boundary))
|
|
60634
60651
|
throw new Error("Pool boundary identity conflict");
|
|
60635
60652
|
}
|
|
60653
|
+
async rebind(tx, lease, previous, json, boundary, fingerprint, options) {
|
|
60654
|
+
const queued = JSON.parse(previous.descriptor);
|
|
60655
|
+
const requested = JSON.parse(json);
|
|
60656
|
+
const queuedMode = queued.execution.executionMode;
|
|
60657
|
+
const requestedMode = requested.execution.executionMode;
|
|
60658
|
+
const { executionMode: _mode, ...execution } = requested.execution;
|
|
60659
|
+
const asQueued = {
|
|
60660
|
+
...requested,
|
|
60661
|
+
digest: queued.digest,
|
|
60662
|
+
execution: queuedMode === undefined ? execution : { ...execution, executionMode: queuedMode }
|
|
60663
|
+
};
|
|
60664
|
+
if (durableHash({ descriptor: asQueued, boundary }) !== previous.fingerprint)
|
|
60665
|
+
throw new Error("Pool boundary identity conflict");
|
|
60666
|
+
const entryEdited = queued.digest !== requested.digest;
|
|
60667
|
+
if (previous.epoch >= lease.epoch) {
|
|
60668
|
+
const changes = [
|
|
60669
|
+
...entryEdited ? [`entry module (sha256 ${short(queued.digest)} to ${short(requested.digest)})`] : [],
|
|
60670
|
+
...queuedMode !== requestedMode ? [`execution mode (${shownMode(queuedMode)} to ${shownMode(requestedMode)})`] : []
|
|
60671
|
+
];
|
|
60672
|
+
throw new Error(`Pool boundary identity conflict: child ${requested.childRunId} is already queued by this incarnation of root ${lease.runId}, and its worker may be running it, so its ${changes.join(" and ")} cannot change`);
|
|
60673
|
+
}
|
|
60674
|
+
if (entryEdited && options.acceptEntryChanges !== true)
|
|
60675
|
+
throw new Error(`Pool boundary identity conflict: child ${requested.childRunId} was queued by an earlier run of root ${lease.runId} with the entry module of worker definition ${requested.definition} at sha256 ${short(queued.digest)}, and the root now runs that module at sha256 ${short(requested.digest)}. Resume the root with /workflow resume ${lease.runId} --accept-entry-changes, or acceptEntryChanges: true in the SDK, to run the child with the edited module, or restore the module.`);
|
|
60676
|
+
await tx.run(`UPDATE ${this.work} SET descriptor = ?, fingerprint = ? WHERE id = ?`, json, fingerprint, previous.id);
|
|
60677
|
+
return { ...previous, descriptor: json, fingerprint };
|
|
60678
|
+
}
|
|
60636
60679
|
async claim(lease, worker, definitions, durationMs) {
|
|
60637
60680
|
positive(durationMs);
|
|
60638
60681
|
lease = snapshotLease(lease);
|
|
@@ -66314,7 +66357,9 @@ class PoolCoordinator {
|
|
|
66314
66357
|
const queue = this.queue;
|
|
66315
66358
|
const lease = this.lease;
|
|
66316
66359
|
const work = await this.retainedTransition(async () => {
|
|
66317
|
-
let enqueued = await this.whileRootLate(queue, () => queue.enqueue(lease, command.descriptor, command.boundary
|
|
66360
|
+
let enqueued = await this.whileRootLate(queue, () => queue.enqueue(lease, command.descriptor, command.boundary, {
|
|
66361
|
+
acceptEntryChanges: command.acceptEntryChanges === true
|
|
66362
|
+
}));
|
|
66318
66363
|
if (enqueued.state === "completed" && enqueued.epoch < lease.epoch)
|
|
66319
66364
|
enqueued = await this.whileRootLate(queue, () => queue.reopenCompleted(lease, enqueued.id, failedOnInfrastructureFault)) ?? enqueued;
|
|
66320
66365
|
const retained = this.retained.get(enqueued.id);
|
|
@@ -69928,7 +69973,8 @@ class LocalWorkerPool {
|
|
|
69928
69973
|
inputs,
|
|
69929
69974
|
execution
|
|
69930
69975
|
},
|
|
69931
|
-
boundary
|
|
69976
|
+
boundary,
|
|
69977
|
+
...this.options.acceptEntryChanges === true ? { acceptEntryChanges: true } : {}
|
|
69932
69978
|
});
|
|
69933
69979
|
const work = enqueued.work;
|
|
69934
69980
|
this.works.set(work.id, work);
|
|
@@ -70364,14 +70410,66 @@ var DEFAULT_POOLED_STAGE_START_MAX_LOAD_PER_CPU = 3;
|
|
|
70364
70410
|
// dist/builtin/workflows/src/workers/public-pool.ts
|
|
70365
70411
|
import { resolve as resolve16 } from "node:path";
|
|
70366
70412
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
70413
|
+
function shown(value2) {
|
|
70414
|
+
return value2 === undefined ? "unset" : JSON.stringify(value2);
|
|
70415
|
+
}
|
|
70416
|
+
function isPlainRecord(value2) {
|
|
70417
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
70418
|
+
}
|
|
70419
|
+
function settingChanges(path, saved, current, changes) {
|
|
70420
|
+
if (isDeepStrictEqual2(saved, current))
|
|
70421
|
+
return;
|
|
70422
|
+
if ((saved === undefined || isPlainRecord(saved)) && (current === undefined || isPlainRecord(current))) {
|
|
70423
|
+
for (const key of new Set([...Object.keys(saved ?? {}), ...Object.keys(current ?? {})]))
|
|
70424
|
+
settingChanges(`${path}.${key}`, saved?.[key], current?.[key], changes);
|
|
70425
|
+
return;
|
|
70426
|
+
}
|
|
70427
|
+
changes.push({
|
|
70428
|
+
description: `${path} changed from ${shown(saved)} to ${shown(current)}`,
|
|
70429
|
+
resumable: RESUMABLE_SETTINGS.has(path)
|
|
70430
|
+
});
|
|
70431
|
+
}
|
|
70432
|
+
function resourceChanges(saved, current) {
|
|
70433
|
+
const changes = [];
|
|
70434
|
+
if (saved.localWorkers === undefined !== (current.localWorkers === undefined))
|
|
70435
|
+
changes.push({
|
|
70436
|
+
description: `local workers were turned ${current.localWorkers === undefined ? "off" : "on"}`,
|
|
70437
|
+
resumable: false
|
|
70438
|
+
});
|
|
70439
|
+
else {
|
|
70440
|
+
settingChanges("localWorkers", saved.localWorkers && { ...saved.localWorkers, definitions: undefined }, current.localWorkers && { ...current.localWorkers, definitions: undefined }, changes);
|
|
70441
|
+
}
|
|
70442
|
+
const named = (list) => new Map((list ?? []).map((source) => [`${source.path}#${source.exportName}`, source.digest]));
|
|
70443
|
+
const before = named(saved.definitions);
|
|
70444
|
+
const after = named(current.definitions);
|
|
70445
|
+
for (const [name, digest] of before) {
|
|
70446
|
+
const now = after.get(name);
|
|
70447
|
+
if (now === undefined)
|
|
70448
|
+
changes.push({ description: `worker definition ${name} is no longer listed`, resumable: false });
|
|
70449
|
+
else if (now !== digest)
|
|
70450
|
+
changes.push({
|
|
70451
|
+
description: `the entry module of worker definition ${name} was edited (sha256 ${digest.slice(0, 12)} to ${now.slice(0, 12)})`,
|
|
70452
|
+
resumable: false,
|
|
70453
|
+
entry: true
|
|
70454
|
+
});
|
|
70455
|
+
}
|
|
70456
|
+
for (const name of after.keys())
|
|
70457
|
+
if (!before.has(name))
|
|
70458
|
+
changes.push({ description: `worker definition ${name} was added`, resumable: false });
|
|
70459
|
+
settingChanges("admission", saved.admission, current.admission, changes);
|
|
70460
|
+
settingChanges("coordinator", saved.coordinator, current.coordinator, changes);
|
|
70461
|
+
return changes;
|
|
70462
|
+
}
|
|
70367
70463
|
async function restoreWorkerOptions(backend, options) {
|
|
70368
70464
|
const source = options.continuation?.source.id ?? options.runId;
|
|
70369
70465
|
if (source !== undefined)
|
|
70370
70466
|
await backend.hydrateWorkflow(source);
|
|
70371
70467
|
const original = source === undefined ? undefined : backend.getWorkflow(source);
|
|
70372
70468
|
const saved = original?.resources;
|
|
70373
|
-
if (original && !saved && (options.localWorkers || options.admission))
|
|
70374
|
-
|
|
70469
|
+
if (original && !saved && (options.localWorkers || options.admission)) {
|
|
70470
|
+
const set = [options.localWorkers && "localWorkers", options.admission && "admission"].filter(Boolean).join(" and ");
|
|
70471
|
+
throw new Error(`Root ${source} started without local workers or resource admission, and this resume sets ${set}: immutable resource configuration cannot change on an existing root. Resume it without them, or start a new run.`);
|
|
70472
|
+
}
|
|
70375
70473
|
return {
|
|
70376
70474
|
...options,
|
|
70377
70475
|
localWorkers: options.localWorkers ?? saved?.localWorkers,
|
|
@@ -70434,14 +70532,16 @@ async function activatePublicPool(backend, options) {
|
|
|
70434
70532
|
throw new Error(`This root's local workers ran on another machine (${saved.host}). Their work queue and leases are in that machine's pool database, which this machine cannot see, and its workers may still be running children. Resume the root on that machine.`);
|
|
70435
70533
|
if (saved !== undefined && resources.coordinator !== undefined && saved.host === resources.coordinator.host && saved.database !== resources.coordinator.database)
|
|
70436
70534
|
throw new Error(`This root's local workers keep their work queue and leases in the pool database ${saved.database} on this machine, but the journal is now selected in a way that uses ${resources.coordinator.database}: its adapter, options, prefix or the agent directory changed. Resume the root with the journal selected as it was when the root started.`);
|
|
70437
|
-
|
|
70438
|
-
|
|
70535
|
+
const refused = options.effectiveResources === undefined ? [] : resourceChanges(options.effectiveResources, resources).filter((change) => !change.resumable && !(change.entry && options.acceptEntryChanges === true));
|
|
70536
|
+
if (refused.length > 0)
|
|
70537
|
+
throw new Error(`Since root ${options.runId} started, ${refused.map((change) => change.description).join("; ")}. Its recorded steps and queued children depend on these, so restore them to resume it, or start a new run. The pool size (localWorkers.count) and the root's own limits (admission.limits and admission.host) can change between resumes.${refused.some((change) => change.entry) ? ` An edited entry module can also be accepted: resume with /workflow resume ${options.runId} --accept-entry-changes, or acceptEntryChanges: true in the SDK, to replay the recorded steps and run the rest of each unfinished child with the edited module.` : ""}`);
|
|
70439
70538
|
options.effectiveResources = resources;
|
|
70440
70539
|
if (resources.admission)
|
|
70441
70540
|
await SqlResourceAdmission.open(poolJournal, {
|
|
70442
70541
|
...resources.admission,
|
|
70443
70542
|
root: options.runId,
|
|
70444
|
-
holder: "preflight"
|
|
70543
|
+
holder: "preflight",
|
|
70544
|
+
rootLimits: "unchanged"
|
|
70445
70545
|
});
|
|
70446
70546
|
if (!localWorkers)
|
|
70447
70547
|
return;
|
|
@@ -70456,6 +70556,7 @@ async function activatePublicPool(backend, options) {
|
|
|
70456
70556
|
startupTimeoutMs: options.localWorkers?.startupTimeoutMs,
|
|
70457
70557
|
leaseMs: options.localWorkers?.leaseMs,
|
|
70458
70558
|
maxLoadPerCpu: options.localWorkers?.maxLoadPerCpu ?? DEFAULT_POOLED_STAGE_START_MAX_LOAD_PER_CPU,
|
|
70559
|
+
...options.acceptEntryChanges === true ? { acceptEntryChanges: true } : {},
|
|
70459
70560
|
...options.stageControlRegistry === undefined || options[hostWorkerBindings] ? {} : { stageControlRegistry: options.stageControlRegistry }
|
|
70460
70561
|
});
|
|
70461
70562
|
try {
|
|
@@ -70466,6 +70567,7 @@ async function activatePublicPool(backend, options) {
|
|
|
70466
70567
|
throw error;
|
|
70467
70568
|
}
|
|
70468
70569
|
}
|
|
70570
|
+
var RESUMABLE_SETTINGS;
|
|
70469
70571
|
var init_public_pool = __esm(() => {
|
|
70470
70572
|
init_journal_backend();
|
|
70471
70573
|
init_admission_host();
|
|
@@ -70474,6 +70576,13 @@ var init_public_pool = __esm(() => {
|
|
|
70474
70576
|
init_local_pool();
|
|
70475
70577
|
init_pool_journal();
|
|
70476
70578
|
init_resource_admission();
|
|
70579
|
+
RESUMABLE_SETTINGS = new Set([
|
|
70580
|
+
"localWorkers.count",
|
|
70581
|
+
"admission.limits.session",
|
|
70582
|
+
"admission.limits.process",
|
|
70583
|
+
"admission.host.maxLoadPerCpu",
|
|
70584
|
+
"admission.host.minFreeMemoryBytes"
|
|
70585
|
+
]);
|
|
70477
70586
|
});
|
|
70478
70587
|
|
|
70479
70588
|
// dist/builtin/workflows/src/engine/primitives/chain.ts
|