@bastani/atomic 0.9.62 → 0.9.63
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 +24 -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/builtin/{chunk-vzbec50q.js → chunk-95r61ve5.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-a2j0x1a6.js → chunk-qbthhjjk.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-zhyqnf5g.js → chunk-rv4xxwd6.js} +69 -26
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/durable/journal/internal.d.ts +11 -1
- package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +2 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +106 -50
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +106 -50
- package/dist/builtin/workflows/src/index.js +106 -50
- package/dist/builtin/workflows/src/local-worker-entry.mjs +106 -50
- package/dist/core/storage/database.d.ts +11 -1
- package/dist/core/storage/database.d.ts.map +1 -1
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/index.d.ts +1 -1
- package/dist/core/storage/index.d.ts.map +1 -1
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/node-sqlite.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite.js +194 -23
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -1071,9 +1071,10 @@ function registerSqlPoolStorage(journal, storage) {
|
|
|
1071
1071
|
function sqlPoolStorage(journal) {
|
|
1072
1072
|
return poolStorage.get(journal);
|
|
1073
1073
|
}
|
|
1074
|
-
var JOURNAL_READ_PAGE_SIZE = 256, NON_SNAPSHOT_EVENT_TYPES, poolStorage;
|
|
1074
|
+
var JOURNAL_READ_PAGE_SIZE = 256, JOURNAL_TRANSACTION, NON_SNAPSHOT_EVENT_TYPES, poolStorage;
|
|
1075
1075
|
var init_internal = __esm(() => {
|
|
1076
1076
|
init_types();
|
|
1077
|
+
JOURNAL_TRANSACTION = { lockWaitMs: 10 * 60000 };
|
|
1077
1078
|
NON_SNAPSHOT_EVENT_TYPES = [
|
|
1078
1079
|
RUN_EVENT_TYPES.checkpointRecorded,
|
|
1079
1080
|
RUN_EVENT_TYPES.messageSettled,
|
|
@@ -1368,7 +1369,7 @@ class LegacyJournalRuns {
|
|
|
1368
1369
|
return;
|
|
1369
1370
|
await tx.exec(`CREATE TABLE IF NOT EXISTS ${CURRENT.legacyDeleted}(${JOURNAL_COLUMNS.runId} TEXT PRIMARY KEY, deleted_at INTEGER NOT NULL)`);
|
|
1370
1371
|
return new LegacyJournalRuns;
|
|
1371
|
-
});
|
|
1372
|
+
}, JOURNAL_TRANSACTION);
|
|
1372
1373
|
} catch {
|
|
1373
1374
|
return;
|
|
1374
1375
|
}
|
|
@@ -1408,6 +1409,7 @@ class LegacyJournalRuns {
|
|
|
1408
1409
|
}
|
|
1409
1410
|
var CURRENT, COPIED_ALL_MARKER = "unprefixed-journal-tables", LEGACY_COLUMNS, PENDING_LEGACY_RUNS;
|
|
1410
1411
|
var init_legacy_journal_tables = __esm(() => {
|
|
1412
|
+
init_internal();
|
|
1411
1413
|
init_types();
|
|
1412
1414
|
CURRENT = renderStorageIdentifiers("journal", {
|
|
1413
1415
|
...JOURNAL_TABLES,
|
|
@@ -1458,7 +1460,7 @@ class SqlRunJournal {
|
|
|
1458
1460
|
this.tables = tables;
|
|
1459
1461
|
this.legacy = legacy;
|
|
1460
1462
|
registerSqlPoolStorage(this, {
|
|
1461
|
-
transaction: (body) => this.operation(() => this.
|
|
1463
|
+
transaction: (body) => this.operation(() => this.transaction(body)),
|
|
1462
1464
|
read: (body) => this.operation(() => body(this.database)),
|
|
1463
1465
|
withAppendGuard: (guard, action) => this.appendGuard.run(guard, action),
|
|
1464
1466
|
tables: this.tables
|
|
@@ -1498,7 +1500,7 @@ class SqlRunJournal {
|
|
|
1498
1500
|
${JOURNAL_COLUMNS.holderId} TEXT, ${JOURNAL_COLUMNS.epoch} INTEGER NOT NULL, ${JOURNAL_COLUMNS.renewedAt} INTEGER NOT NULL
|
|
1499
1501
|
);
|
|
1500
1502
|
`);
|
|
1501
|
-
});
|
|
1503
|
+
}, JOURNAL_TRANSACTION);
|
|
1502
1504
|
const legacy = options.prefix ? undefined : await LegacyJournalRuns.open(database);
|
|
1503
1505
|
return new SqlRunJournal(database, t, legacy);
|
|
1504
1506
|
}
|
|
@@ -1512,6 +1514,9 @@ class SqlRunJournal {
|
|
|
1512
1514
|
if (this.closed)
|
|
1513
1515
|
throw new StorageUnavailableError2(this.descriptor, new JournalClosedError);
|
|
1514
1516
|
}
|
|
1517
|
+
transaction(body) {
|
|
1518
|
+
return this.database.transaction(body, JOURNAL_TRANSACTION);
|
|
1519
|
+
}
|
|
1515
1520
|
operation(action) {
|
|
1516
1521
|
this.assertOpen();
|
|
1517
1522
|
const result = action();
|
|
@@ -1538,7 +1543,7 @@ class SqlRunJournal {
|
|
|
1538
1543
|
return this.operation(async () => {
|
|
1539
1544
|
if (await this.legacy?.find(this.database, header.runId))
|
|
1540
1545
|
return "exists";
|
|
1541
|
-
const result = await this.
|
|
1546
|
+
const result = await this.transaction((tx) => tx.run(`INSERT INTO ${runs} VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT(${JOURNAL_COLUMNS.runId}) DO NOTHING`, header.runId, header.name, header.cwd, header.createdAt, header.status, json));
|
|
1542
1547
|
return result.changes === 1 ? "created" : "exists";
|
|
1543
1548
|
});
|
|
1544
1549
|
}
|
|
@@ -1630,7 +1635,7 @@ class SqlRunJournal {
|
|
|
1630
1635
|
this.assertOpen();
|
|
1631
1636
|
validateText("runId", runId);
|
|
1632
1637
|
validateText("holderId", holderId);
|
|
1633
|
-
return this.operation(() => this.
|
|
1638
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1634
1639
|
await this.requireRun(tx, runId);
|
|
1635
1640
|
const current = await this.leaseRow(tx, runId);
|
|
1636
1641
|
if (current?.[JOURNAL_COLUMNS.holderId] === holderId)
|
|
@@ -1645,7 +1650,7 @@ class SqlRunJournal {
|
|
|
1645
1650
|
validateText("runId", runId);
|
|
1646
1651
|
validateText("holderId", holderId);
|
|
1647
1652
|
validateText("expectedHolder", expectedHolder);
|
|
1648
|
-
return this.operation(() => this.
|
|
1653
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1649
1654
|
await this.requireRun(tx, runId);
|
|
1650
1655
|
const current = await this.leaseRow(tx, runId);
|
|
1651
1656
|
if (current?.[JOURNAL_COLUMNS.holderId] !== expectedHolder)
|
|
@@ -1675,7 +1680,7 @@ class SqlRunJournal {
|
|
|
1675
1680
|
this.assertOpen();
|
|
1676
1681
|
validateText("runId", runId);
|
|
1677
1682
|
validateText("holderId", holderId);
|
|
1678
|
-
return this.operation(() => this.
|
|
1683
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1679
1684
|
await this.requireRun(tx, runId);
|
|
1680
1685
|
const current = await this.leaseRow(tx, runId);
|
|
1681
1686
|
if (current?.[JOURNAL_COLUMNS.holderId] === holderId)
|
|
@@ -1699,7 +1704,7 @@ class SqlRunJournal {
|
|
|
1699
1704
|
validateText("runId", lease.runId);
|
|
1700
1705
|
validateText("holderId", lease.holderId);
|
|
1701
1706
|
const owned = { ...lease };
|
|
1702
|
-
return this.operation(() => this.
|
|
1707
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1703
1708
|
await this.checkLease(tx, owned);
|
|
1704
1709
|
await tx.run(`UPDATE ${this.tables.leases} SET ${JOURNAL_COLUMNS.renewedAt} = ${STORE_NOW} WHERE ${JOURNAL_COLUMNS.runId} = ?`, owned.runId);
|
|
1705
1710
|
}));
|
|
@@ -1709,7 +1714,7 @@ class SqlRunJournal {
|
|
|
1709
1714
|
validateText("runId", lease.runId);
|
|
1710
1715
|
validateText("holderId", lease.holderId);
|
|
1711
1716
|
const owned = { ...lease };
|
|
1712
|
-
return this.operation(() => this.
|
|
1717
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1713
1718
|
await this.checkLease(tx, owned);
|
|
1714
1719
|
await tx.run(`UPDATE ${this.tables.leases} SET ${JOURNAL_COLUMNS.holderId} = ? WHERE ${JOURNAL_COLUMNS.runId} = ?`, JOURNAL_LEASE.unheld, owned.runId);
|
|
1715
1720
|
}));
|
|
@@ -1725,7 +1730,7 @@ class SqlRunJournal {
|
|
|
1725
1730
|
const owned = { ...lease };
|
|
1726
1731
|
const prepared = this.prepare(event, options?.key, this.appendGuard.getStore());
|
|
1727
1732
|
const expected = options?.expectSeq;
|
|
1728
|
-
return this.operation(() => this.
|
|
1733
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1729
1734
|
await this.checkLease(tx, owned);
|
|
1730
1735
|
return this.insert(tx, owned, prepared, expected);
|
|
1731
1736
|
}));
|
|
@@ -1745,7 +1750,7 @@ class SqlRunJournal {
|
|
|
1745
1750
|
const batch = this.database.batch?.bind(this.database);
|
|
1746
1751
|
if (batch && prepared.every((append) => append instanceof Error || append.guard === undefined && typeof append.payload === "string"))
|
|
1747
1752
|
return this.operation(() => this.appendInOneRequest(batch, owned, prepared));
|
|
1748
|
-
return this.operation(() => this.
|
|
1753
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1749
1754
|
await this.checkLease(tx, owned);
|
|
1750
1755
|
const results = [];
|
|
1751
1756
|
for (const append of prepared) {
|
|
@@ -1896,14 +1901,14 @@ class SqlRunJournal {
|
|
|
1896
1901
|
async deleteRun(runId) {
|
|
1897
1902
|
this.assertOpen();
|
|
1898
1903
|
validateText("runId", runId);
|
|
1899
|
-
return this.operation(() => this.
|
|
1904
|
+
return this.operation(() => this.transaction((tx) => this.deleteRunData(tx, runId)));
|
|
1900
1905
|
}
|
|
1901
1906
|
async deleteOwnedRun(lease, expectSeq) {
|
|
1902
1907
|
this.assertOpen();
|
|
1903
1908
|
validateText("runId", lease.runId);
|
|
1904
1909
|
validateText("holderId", lease.holderId);
|
|
1905
1910
|
const owned = { ...lease };
|
|
1906
|
-
return this.operation(() => this.
|
|
1911
|
+
return this.operation(() => this.transaction(async (tx) => {
|
|
1907
1912
|
await this.checkLease(tx, owned);
|
|
1908
1913
|
if (expectSeq !== undefined) {
|
|
1909
1914
|
const actual = await this.sequence(tx, owned.runId);
|
|
@@ -4389,13 +4394,13 @@ class WorkflowObservationRuntime {
|
|
|
4389
4394
|
return run.rootRunId;
|
|
4390
4395
|
if (run.parentRunId === undefined)
|
|
4391
4396
|
return run.id;
|
|
4392
|
-
const parent = this.runs
|
|
4397
|
+
const parent = this.runs.find(run.parentRunId);
|
|
4393
4398
|
return parent ? this.rootRunId(parent) : run.parentRunId;
|
|
4394
4399
|
}
|
|
4395
4400
|
lifecycle(target, attribution = "unknown") {
|
|
4396
4401
|
if (this.recovering && !this.liveRunIds.has(target.runId))
|
|
4397
4402
|
return;
|
|
4398
|
-
const run = this.runs
|
|
4403
|
+
const run = this.runs.find(target.runId);
|
|
4399
4404
|
if (!run)
|
|
4400
4405
|
return;
|
|
4401
4406
|
const rootRunId = this.rootRunId(run);
|
|
@@ -4416,7 +4421,7 @@ class WorkflowObservationRuntime {
|
|
|
4416
4421
|
});
|
|
4417
4422
|
}
|
|
4418
4423
|
control(runId, action, attribution = "unknown") {
|
|
4419
|
-
const run = this.runs
|
|
4424
|
+
const run = this.runs.find(runId);
|
|
4420
4425
|
if (!run)
|
|
4421
4426
|
return;
|
|
4422
4427
|
if ((action === "quit" || action === "kill" || action === "pause") && this.liveRunIds.has(runId))
|
|
@@ -4427,7 +4432,7 @@ class WorkflowObservationRuntime {
|
|
|
4427
4432
|
this.invalidate({ runId });
|
|
4428
4433
|
}
|
|
4429
4434
|
heartbeat(runId, scheduledAt, intervalMinutes) {
|
|
4430
|
-
const run = this.runs
|
|
4435
|
+
const run = this.runs.find(runId);
|
|
4431
4436
|
if (run)
|
|
4432
4437
|
this.emit({
|
|
4433
4438
|
kind: "heartbeat",
|
|
@@ -4453,7 +4458,7 @@ class WorkflowObservationRuntime {
|
|
|
4453
4458
|
if (changes === undefined) {
|
|
4454
4459
|
const next = new Map;
|
|
4455
4460
|
const nextOwners = new Map;
|
|
4456
|
-
for (const run of this.runs()) {
|
|
4461
|
+
for (const run of this.runs.all()) {
|
|
4457
4462
|
const owners = nextOwners.get(run.id) ?? new Map;
|
|
4458
4463
|
nextOwners.set(run.id, owners);
|
|
4459
4464
|
this.captureRun(run, this.previous.has(`run:${run.id}`), next, owners);
|
|
@@ -4480,10 +4485,15 @@ class WorkflowObservationRuntime {
|
|
|
4480
4485
|
nodes.tools.add(change.toolNodeId);
|
|
4481
4486
|
changed.set(change.runId, nodes);
|
|
4482
4487
|
}
|
|
4483
|
-
|
|
4484
|
-
const
|
|
4485
|
-
|
|
4488
|
+
const ordered = [...changed.keys()].flatMap((runId) => {
|
|
4489
|
+
const position = this.runs.position(runId);
|
|
4490
|
+
return position === undefined ? [] : [{ runId, position }];
|
|
4491
|
+
}).sort((left, right) => left.position - right.position);
|
|
4492
|
+
for (const { runId } of ordered) {
|
|
4493
|
+
const run = this.runs.find(runId);
|
|
4494
|
+
if (run === undefined)
|
|
4486
4495
|
continue;
|
|
4496
|
+
const change = changed.get(runId);
|
|
4487
4497
|
const existing = this.previous.has(`run:${run.id}`);
|
|
4488
4498
|
const nodes = change === "run" || !existing ? undefined : change;
|
|
4489
4499
|
const next = new Map;
|
|
@@ -4521,7 +4531,7 @@ class WorkflowObservationRuntime {
|
|
|
4521
4531
|
keys.push(key);
|
|
4522
4532
|
const previous = this.previous.get(key);
|
|
4523
4533
|
if (!historical && this.liveRunIds.has(target.runId) && previous?.status !== target.status) {
|
|
4524
|
-
this.lifecycle(previous && previous.kind !== "prompt" && target.kind !== "prompt" ? { ...target, previousStatus: previous.status } : target, this.runs
|
|
4534
|
+
this.lifecycle(previous && previous.kind !== "prompt" && target.kind !== "prompt" ? { ...target, previousStatus: previous.status } : target, this.runs.find(target.runId)?.origin);
|
|
4525
4535
|
}
|
|
4526
4536
|
};
|
|
4527
4537
|
visit("run", `run:${run.id}`, { kind: "run", runId: run.id, status: run.status });
|
|
@@ -4650,6 +4660,7 @@ function applyRunEndMetadata(run, metadata) {
|
|
|
4650
4660
|
function createStoreState() {
|
|
4651
4661
|
return {
|
|
4652
4662
|
runs: [],
|
|
4663
|
+
runPositions: new Map,
|
|
4653
4664
|
notices: [],
|
|
4654
4665
|
listeners: new Set,
|
|
4655
4666
|
invalidationListeners: new Set,
|
|
@@ -4659,11 +4670,27 @@ function createStoreState() {
|
|
|
4659
4670
|
version: 0
|
|
4660
4671
|
};
|
|
4661
4672
|
}
|
|
4673
|
+
function reindexRuns(state) {
|
|
4674
|
+
state.runPositions.clear();
|
|
4675
|
+
state.runs.forEach((run, position) => {
|
|
4676
|
+
if (!state.runPositions.has(run.id))
|
|
4677
|
+
state.runPositions.set(run.id, position);
|
|
4678
|
+
});
|
|
4679
|
+
}
|
|
4680
|
+
function runPosition(state, runId) {
|
|
4681
|
+
const position = state.runPositions.get(runId);
|
|
4682
|
+
if (position !== undefined && state.runs[position]?.id === runId)
|
|
4683
|
+
return position;
|
|
4684
|
+
if (position === undefined && state.runPositions.size === state.runs.length)
|
|
4685
|
+
return;
|
|
4686
|
+
reindexRuns(state);
|
|
4687
|
+
return state.runPositions.get(runId);
|
|
4688
|
+
}
|
|
4662
4689
|
function createStoreContext(state = createStoreState()) {
|
|
4663
4690
|
let cachedGraphVersion = -1;
|
|
4664
4691
|
let cachedGraphSnapshot;
|
|
4665
4692
|
const graphBuilder = new GraphStoreSnapshotBuilder;
|
|
4666
|
-
const observation = new WorkflowObservationRuntime(() => state.runs, bumpAndNotify);
|
|
4693
|
+
const observation = new WorkflowObservationRuntime({ all: () => state.runs, find: findRun, position: (runId) => runPosition(state, runId) }, bumpAndNotify);
|
|
4667
4694
|
function snapshot() {
|
|
4668
4695
|
return JSON.parse(JSON.stringify({ runs: state.runs, notices: state.notices, version: state.version }));
|
|
4669
4696
|
}
|
|
@@ -4677,7 +4704,7 @@ function createStoreContext(state = createStoreState()) {
|
|
|
4677
4704
|
function graphRun(runId) {
|
|
4678
4705
|
if (cachedGraphSnapshot !== undefined && cachedGraphVersion === state.version)
|
|
4679
4706
|
return findSnapshotRun(cachedGraphSnapshot.runs, runId);
|
|
4680
|
-
const run =
|
|
4707
|
+
const run = findRun(runId);
|
|
4681
4708
|
return run === undefined ? undefined : graphBuilder.buildRun(run);
|
|
4682
4709
|
}
|
|
4683
4710
|
let batchDepth = 0;
|
|
@@ -4731,7 +4758,29 @@ function createStoreContext(state = createStoreState()) {
|
|
|
4731
4758
|
}
|
|
4732
4759
|
}
|
|
4733
4760
|
function findRun(runId) {
|
|
4734
|
-
|
|
4761
|
+
const position = runPosition(state, runId);
|
|
4762
|
+
return position === undefined ? undefined : state.runs[position];
|
|
4763
|
+
}
|
|
4764
|
+
function placeRun(run) {
|
|
4765
|
+
const position = runPosition(state, run.id);
|
|
4766
|
+
if (position !== undefined) {
|
|
4767
|
+
state.runs[position] = run;
|
|
4768
|
+
return;
|
|
4769
|
+
}
|
|
4770
|
+
state.runPositions.set(run.id, state.runs.length);
|
|
4771
|
+
state.runs.push(run);
|
|
4772
|
+
}
|
|
4773
|
+
function removeRunAt(position) {
|
|
4774
|
+
const [removed] = state.runs.splice(position, 1);
|
|
4775
|
+
if (removed === undefined)
|
|
4776
|
+
return;
|
|
4777
|
+
state.runPositions.delete(removed.id);
|
|
4778
|
+
for (let index = position;index < state.runs.length; index++)
|
|
4779
|
+
state.runPositions.set(state.runs[index].id, index);
|
|
4780
|
+
}
|
|
4781
|
+
function clearRuns() {
|
|
4782
|
+
state.runs.length = 0;
|
|
4783
|
+
state.runPositions.clear();
|
|
4735
4784
|
}
|
|
4736
4785
|
function findStage(run, stageId) {
|
|
4737
4786
|
return run.stages.find((s) => s.id === stageId);
|
|
@@ -4787,6 +4836,10 @@ function createStoreContext(state = createStoreState()) {
|
|
|
4787
4836
|
batch,
|
|
4788
4837
|
bumpAndNotify,
|
|
4789
4838
|
findRun,
|
|
4839
|
+
runPosition: (runId) => runPosition(state, runId),
|
|
4840
|
+
placeRun,
|
|
4841
|
+
removeRunAt,
|
|
4842
|
+
clearRuns,
|
|
4790
4843
|
findStage,
|
|
4791
4844
|
rejectPrompt,
|
|
4792
4845
|
rejectStagePrompt,
|
|
@@ -5868,6 +5921,9 @@ function createRunStoreMethods(context) {
|
|
|
5868
5921
|
runs() {
|
|
5869
5922
|
return state.runs;
|
|
5870
5923
|
},
|
|
5924
|
+
run(runId) {
|
|
5925
|
+
return context.findRun(runId);
|
|
5926
|
+
},
|
|
5871
5927
|
notices() {
|
|
5872
5928
|
return state.notices;
|
|
5873
5929
|
},
|
|
@@ -5887,11 +5943,7 @@ function createRunStoreMethods(context) {
|
|
|
5887
5943
|
return null;
|
|
5888
5944
|
},
|
|
5889
5945
|
recordRunStart(run) {
|
|
5890
|
-
|
|
5891
|
-
if (index === -1)
|
|
5892
|
-
state.runs.push(run);
|
|
5893
|
-
else
|
|
5894
|
-
state.runs[index] = run;
|
|
5946
|
+
context.placeRun(run);
|
|
5895
5947
|
context.bumpAndNotify({ runId: run.id });
|
|
5896
5948
|
},
|
|
5897
5949
|
recordRunSummary(runId, summary, summarizedThrough) {
|
|
@@ -6032,17 +6084,13 @@ function createRunStoreMethods(context) {
|
|
|
6032
6084
|
restored.result = metadata.result;
|
|
6033
6085
|
if (metadata.budgetState !== undefined)
|
|
6034
6086
|
restored.budgetState = metadata.budgetState;
|
|
6035
|
-
|
|
6036
|
-
if (index < 0)
|
|
6037
|
-
state.runs.push(restored);
|
|
6038
|
-
else
|
|
6039
|
-
state.runs[index] = restored;
|
|
6087
|
+
context.placeRun(restored);
|
|
6040
6088
|
context.bumpAndNotify();
|
|
6041
6089
|
return true;
|
|
6042
6090
|
},
|
|
6043
6091
|
removeRun(runId) {
|
|
6044
|
-
const index =
|
|
6045
|
-
if (index
|
|
6092
|
+
const index = context.runPosition(runId);
|
|
6093
|
+
if (index === undefined)
|
|
6046
6094
|
return false;
|
|
6047
6095
|
const run = state.runs[index];
|
|
6048
6096
|
const pending = run.pendingPrompt;
|
|
@@ -6054,7 +6102,7 @@ function createRunStoreMethods(context) {
|
|
|
6054
6102
|
for (const stage of run.stages) {
|
|
6055
6103
|
state.stagePromptAnswers.delete(context.stagePromptAnswerKey(runId, stage.id));
|
|
6056
6104
|
}
|
|
6057
|
-
|
|
6105
|
+
context.removeRunAt(index);
|
|
6058
6106
|
for (let i = state.notices.length - 1;i >= 0; i--) {
|
|
6059
6107
|
if (state.notices[i]?.runId === runId)
|
|
6060
6108
|
state.notices.splice(i, 1);
|
|
@@ -6146,7 +6194,7 @@ function createRunStoreMethods(context) {
|
|
|
6146
6194
|
clear() {
|
|
6147
6195
|
if (state.runs.length === 0 && state.notices.length === 0 && state.resolvers.size === 0 && state.stagePromptAnswers.size === 0 && state.stagePromptDrafts.size === 0)
|
|
6148
6196
|
return;
|
|
6149
|
-
|
|
6197
|
+
context.clearRuns();
|
|
6150
6198
|
state.notices.length = 0;
|
|
6151
6199
|
for (const entry of state.resolvers.values()) {
|
|
6152
6200
|
entry.reject(new Error("atomic-workflows: store cleared"));
|
|
@@ -67750,16 +67798,25 @@ class PoolStageHandoff {
|
|
|
67750
67798
|
throw outside2(run.id);
|
|
67751
67799
|
}
|
|
67752
67800
|
};
|
|
67753
|
-
const before =
|
|
67801
|
+
const before = this.known(subtree);
|
|
67754
67802
|
owned(before);
|
|
67755
67803
|
if (subtree.some((run) => before.get(run.id) === undefined))
|
|
67756
67804
|
await this.backend.catchUpWorkflow(root);
|
|
67757
67805
|
await this.queue.assertCurrent(this.lease, work);
|
|
67758
67806
|
return () => this.commit(work, subtree, owned);
|
|
67759
67807
|
}
|
|
67808
|
+
known(subtree) {
|
|
67809
|
+
const known = new Map;
|
|
67810
|
+
for (const run of subtree) {
|
|
67811
|
+
const existing = this.store.run(run.id);
|
|
67812
|
+
if (existing !== undefined)
|
|
67813
|
+
known.set(run.id, existing);
|
|
67814
|
+
}
|
|
67815
|
+
return known;
|
|
67816
|
+
}
|
|
67760
67817
|
commit(work, subtree, owned) {
|
|
67761
67818
|
const root = this.lease.runId;
|
|
67762
|
-
const known =
|
|
67819
|
+
const known = this.known(subtree);
|
|
67763
67820
|
owned(known);
|
|
67764
67821
|
const attempt = this.enter(work);
|
|
67765
67822
|
const execution = {
|
|
@@ -67793,7 +67850,7 @@ class PoolStageHandoff {
|
|
|
67793
67850
|
else
|
|
67794
67851
|
attempt.sessions.set(key, stage.sessionId);
|
|
67795
67852
|
}
|
|
67796
|
-
const previous = this.store.
|
|
67853
|
+
const previous = this.store.run(run.id);
|
|
67797
67854
|
for (const stage of run.stages)
|
|
67798
67855
|
if (previous?.stages.find((candidate) => candidate.id === stage.id)?.attached === true)
|
|
67799
67856
|
stage.attached = true;
|
|
@@ -67812,7 +67869,7 @@ class PoolStageHandoff {
|
|
|
67812
67869
|
}
|
|
67813
67870
|
if (runs.length === 0)
|
|
67814
67871
|
return [];
|
|
67815
|
-
const rootRun = this.store.
|
|
67872
|
+
const rootRun = this.store.run(root);
|
|
67816
67873
|
const boundary = rootRun?.stages.find((stage) => stage.id === work.boundaryId);
|
|
67817
67874
|
if (authoritativeWorkflowChildRunId(boundary) !== work.childRunId)
|
|
67818
67875
|
throw new Error(`Pool work boundary ${work.boundaryId} is not linked to ${work.childRunId} in the root run`);
|
|
@@ -67877,7 +67934,7 @@ class PoolStageHandoff {
|
|
|
67877
67934
|
for (const id of attempt.runs)
|
|
67878
67935
|
rotateWorkflowPendingStageRouteCapability(this.store, id);
|
|
67879
67936
|
for (const id of attempt.runs) {
|
|
67880
|
-
const run = this.store.
|
|
67937
|
+
const run = this.store.run(id);
|
|
67881
67938
|
if (run?.stages.some((stage) => isLive(stage)) !== true)
|
|
67882
67939
|
continue;
|
|
67883
67940
|
this.store.recordRunStart({
|
|
@@ -69573,7 +69630,7 @@ class LocalWorkerPool {
|
|
|
69573
69630
|
return false;
|
|
69574
69631
|
}
|
|
69575
69632
|
applyHeldAnswer(runId, stageId, heldGeneration) {
|
|
69576
|
-
const stage = this.store?.
|
|
69633
|
+
const stage = this.store?.run(runId)?.stages.find((candidate) => candidate.id === stageId);
|
|
69577
69634
|
if (stage === undefined || this.closed)
|
|
69578
69635
|
return;
|
|
69579
69636
|
const generation = stage.workerExecution?.generation ?? 0;
|
|
@@ -69629,7 +69686,7 @@ class LocalWorkerPool {
|
|
|
69629
69686
|
const key = JSON.stringify([runId, stageId]);
|
|
69630
69687
|
let view = this.stageViews.get(key);
|
|
69631
69688
|
if (view === undefined) {
|
|
69632
|
-
const stageName = this.store?.
|
|
69689
|
+
const stageName = this.store?.run(runId)?.stages.find((stage) => stage.id === stageId)?.name ?? stageId;
|
|
69633
69690
|
const created = { key, holders: 0, opening: Promise.resolve(undefined) };
|
|
69634
69691
|
const transport = this.stageTransport((reason) => {
|
|
69635
69692
|
tracePooledWatch("root.view.watch-ended", { key, reason, current: this.stageViews.get(key) === created });
|
|
@@ -69695,10 +69752,9 @@ class LocalWorkerPool {
|
|
|
69695
69752
|
};
|
|
69696
69753
|
}
|
|
69697
69754
|
reconnectStageViews() {
|
|
69698
|
-
const runs = this.store?.runs() ?? [];
|
|
69699
69755
|
const stageOf = (key) => {
|
|
69700
69756
|
const [runId, stageId] = JSON.parse(key);
|
|
69701
|
-
const run =
|
|
69757
|
+
const run = this.store?.run(runId);
|
|
69702
69758
|
return { runId, stageId, run, stage: run?.stages.find((candidate) => candidate.id === stageId) };
|
|
69703
69759
|
};
|
|
69704
69760
|
const ended = (key) => {
|
|
@@ -69779,7 +69835,7 @@ class LocalWorkerPool {
|
|
|
69779
69835
|
};
|
|
69780
69836
|
}
|
|
69781
69837
|
rootProjection() {
|
|
69782
|
-
const run = this.
|
|
69838
|
+
const run = this.root === undefined ? undefined : this.store?.run(this.root);
|
|
69783
69839
|
return run === undefined ? undefined : projectRootRun(run);
|
|
69784
69840
|
}
|
|
69785
69841
|
rootRun() {
|