@bastani/atomic 0.9.62-alpha.1 → 0.9.63-alpha.1

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.
Files changed (29) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/package.json +1 -1
  5. package/dist/builtin/web-access/package.json +1 -1
  6. package/dist/builtin/workflows/builtin/{chunk-vzbec50q.js → chunk-95r61ve5.js} +1 -1
  7. package/dist/builtin/workflows/builtin/{chunk-a2j0x1a6.js → chunk-qbthhjjk.js} +1 -1
  8. package/dist/builtin/workflows/builtin/{chunk-zhyqnf5g.js → chunk-rv4xxwd6.js} +69 -26
  9. package/dist/builtin/workflows/builtin/goal.js +2 -2
  10. package/dist/builtin/workflows/builtin/index.js +3 -3
  11. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  12. package/dist/builtin/workflows/package.json +1 -1
  13. package/dist/builtin/workflows/src/durable/journal/internal.d.ts +11 -1
  14. package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +2 -0
  15. package/dist/builtin/workflows/src/extension/index.bundle.mjs +106 -50
  16. package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +106 -50
  17. package/dist/builtin/workflows/src/index.js +106 -50
  18. package/dist/builtin/workflows/src/local-worker-entry.mjs +106 -50
  19. package/dist/core/storage/database.d.ts +11 -1
  20. package/dist/core/storage/database.d.ts.map +1 -1
  21. package/dist/core/storage/database.js.map +1 -1
  22. package/dist/core/storage/index.d.ts +1 -1
  23. package/dist/core/storage/index.d.ts.map +1 -1
  24. package/dist/core/storage/index.js.map +1 -1
  25. package/dist/core/storage/node-sqlite.d.ts.map +1 -1
  26. package/dist/core/storage/node-sqlite.js +194 -23
  27. package/dist/core/storage/node-sqlite.js.map +1 -1
  28. package/npm-shrinkwrap.json +32 -32
  29. package/package.json +3 -3
@@ -1862,13 +1862,13 @@ class WorkflowObservationRuntime {
1862
1862
  return run.rootRunId;
1863
1863
  if (run.parentRunId === undefined)
1864
1864
  return run.id;
1865
- const parent = this.runs().find((candidate) => candidate.id === run.parentRunId);
1865
+ const parent = this.runs.find(run.parentRunId);
1866
1866
  return parent ? this.rootRunId(parent) : run.parentRunId;
1867
1867
  }
1868
1868
  lifecycle(target, attribution = "unknown") {
1869
1869
  if (this.recovering && !this.liveRunIds.has(target.runId))
1870
1870
  return;
1871
- const run = this.runs().find((candidate) => candidate.id === target.runId);
1871
+ const run = this.runs.find(target.runId);
1872
1872
  if (!run)
1873
1873
  return;
1874
1874
  const rootRunId = this.rootRunId(run);
@@ -1889,7 +1889,7 @@ class WorkflowObservationRuntime {
1889
1889
  });
1890
1890
  }
1891
1891
  control(runId, action, attribution = "unknown") {
1892
- const run = this.runs().find((candidate) => candidate.id === runId);
1892
+ const run = this.runs.find(runId);
1893
1893
  if (!run)
1894
1894
  return;
1895
1895
  if ((action === "quit" || action === "kill" || action === "pause") && this.liveRunIds.has(runId))
@@ -1900,7 +1900,7 @@ class WorkflowObservationRuntime {
1900
1900
  this.invalidate({ runId });
1901
1901
  }
1902
1902
  heartbeat(runId, scheduledAt, intervalMinutes) {
1903
- const run = this.runs().find((candidate) => candidate.id === runId);
1903
+ const run = this.runs.find(runId);
1904
1904
  if (run)
1905
1905
  this.emit({
1906
1906
  kind: "heartbeat",
@@ -1926,7 +1926,7 @@ class WorkflowObservationRuntime {
1926
1926
  if (changes === undefined) {
1927
1927
  const next = new Map;
1928
1928
  const nextOwners = new Map;
1929
- for (const run of this.runs()) {
1929
+ for (const run of this.runs.all()) {
1930
1930
  const owners = nextOwners.get(run.id) ?? new Map;
1931
1931
  nextOwners.set(run.id, owners);
1932
1932
  this.captureRun(run, this.previous.has(`run:${run.id}`), next, owners);
@@ -1953,10 +1953,15 @@ class WorkflowObservationRuntime {
1953
1953
  nodes.tools.add(change.toolNodeId);
1954
1954
  changed.set(change.runId, nodes);
1955
1955
  }
1956
- for (const run of this.runs()) {
1957
- const change = changed.get(run.id);
1958
- if (change === undefined)
1956
+ const ordered = [...changed.keys()].flatMap((runId) => {
1957
+ const position = this.runs.position(runId);
1958
+ return position === undefined ? [] : [{ runId, position }];
1959
+ }).sort((left, right) => left.position - right.position);
1960
+ for (const { runId } of ordered) {
1961
+ const run = this.runs.find(runId);
1962
+ if (run === undefined)
1959
1963
  continue;
1964
+ const change = changed.get(runId);
1960
1965
  const existing = this.previous.has(`run:${run.id}`);
1961
1966
  const nodes = change === "run" || !existing ? undefined : change;
1962
1967
  const next = new Map;
@@ -1994,7 +1999,7 @@ class WorkflowObservationRuntime {
1994
1999
  keys.push(key);
1995
2000
  const previous = this.previous.get(key);
1996
2001
  if (!historical && this.liveRunIds.has(target.runId) && previous?.status !== target.status) {
1997
- this.lifecycle(previous && previous.kind !== "prompt" && target.kind !== "prompt" ? { ...target, previousStatus: previous.status } : target, this.runs().find((candidate) => candidate.id === target.runId)?.origin);
2002
+ this.lifecycle(previous && previous.kind !== "prompt" && target.kind !== "prompt" ? { ...target, previousStatus: previous.status } : target, this.runs.find(target.runId)?.origin);
1998
2003
  }
1999
2004
  };
2000
2005
  visit("run", `run:${run.id}`, { kind: "run", runId: run.id, status: run.status });
@@ -2123,6 +2128,7 @@ function applyRunEndMetadata(run, metadata) {
2123
2128
  function createStoreState() {
2124
2129
  return {
2125
2130
  runs: [],
2131
+ runPositions: new Map,
2126
2132
  notices: [],
2127
2133
  listeners: new Set,
2128
2134
  invalidationListeners: new Set,
@@ -2132,11 +2138,27 @@ function createStoreState() {
2132
2138
  version: 0
2133
2139
  };
2134
2140
  }
2141
+ function reindexRuns(state) {
2142
+ state.runPositions.clear();
2143
+ state.runs.forEach((run, position) => {
2144
+ if (!state.runPositions.has(run.id))
2145
+ state.runPositions.set(run.id, position);
2146
+ });
2147
+ }
2148
+ function runPosition(state, runId) {
2149
+ const position = state.runPositions.get(runId);
2150
+ if (position !== undefined && state.runs[position]?.id === runId)
2151
+ return position;
2152
+ if (position === undefined && state.runPositions.size === state.runs.length)
2153
+ return;
2154
+ reindexRuns(state);
2155
+ return state.runPositions.get(runId);
2156
+ }
2135
2157
  function createStoreContext(state = createStoreState()) {
2136
2158
  let cachedGraphVersion = -1;
2137
2159
  let cachedGraphSnapshot;
2138
2160
  const graphBuilder = new GraphStoreSnapshotBuilder;
2139
- const observation = new WorkflowObservationRuntime(() => state.runs, bumpAndNotify);
2161
+ const observation = new WorkflowObservationRuntime({ all: () => state.runs, find: findRun, position: (runId) => runPosition(state, runId) }, bumpAndNotify);
2140
2162
  function snapshot() {
2141
2163
  return JSON.parse(JSON.stringify({ runs: state.runs, notices: state.notices, version: state.version }));
2142
2164
  }
@@ -2150,7 +2172,7 @@ function createStoreContext(state = createStoreState()) {
2150
2172
  function graphRun(runId) {
2151
2173
  if (cachedGraphSnapshot !== undefined && cachedGraphVersion === state.version)
2152
2174
  return findSnapshotRun(cachedGraphSnapshot.runs, runId);
2153
- const run = state.runs.find((candidate) => candidate.id === runId);
2175
+ const run = findRun(runId);
2154
2176
  return run === undefined ? undefined : graphBuilder.buildRun(run);
2155
2177
  }
2156
2178
  let batchDepth = 0;
@@ -2204,7 +2226,29 @@ function createStoreContext(state = createStoreState()) {
2204
2226
  }
2205
2227
  }
2206
2228
  function findRun(runId) {
2207
- return state.runs.find((r) => r.id === runId);
2229
+ const position = runPosition(state, runId);
2230
+ return position === undefined ? undefined : state.runs[position];
2231
+ }
2232
+ function placeRun(run) {
2233
+ const position = runPosition(state, run.id);
2234
+ if (position !== undefined) {
2235
+ state.runs[position] = run;
2236
+ return;
2237
+ }
2238
+ state.runPositions.set(run.id, state.runs.length);
2239
+ state.runs.push(run);
2240
+ }
2241
+ function removeRunAt(position) {
2242
+ const [removed] = state.runs.splice(position, 1);
2243
+ if (removed === undefined)
2244
+ return;
2245
+ state.runPositions.delete(removed.id);
2246
+ for (let index = position;index < state.runs.length; index++)
2247
+ state.runPositions.set(state.runs[index].id, index);
2248
+ }
2249
+ function clearRuns() {
2250
+ state.runs.length = 0;
2251
+ state.runPositions.clear();
2208
2252
  }
2209
2253
  function findStage(run, stageId) {
2210
2254
  return run.stages.find((s) => s.id === stageId);
@@ -2260,6 +2304,10 @@ function createStoreContext(state = createStoreState()) {
2260
2304
  batch,
2261
2305
  bumpAndNotify,
2262
2306
  findRun,
2307
+ runPosition: (runId) => runPosition(state, runId),
2308
+ placeRun,
2309
+ removeRunAt,
2310
+ clearRuns,
2263
2311
  findStage,
2264
2312
  rejectPrompt,
2265
2313
  rejectStagePrompt,
@@ -4229,6 +4277,9 @@ function createRunStoreMethods(context) {
4229
4277
  runs() {
4230
4278
  return state.runs;
4231
4279
  },
4280
+ run(runId) {
4281
+ return context.findRun(runId);
4282
+ },
4232
4283
  notices() {
4233
4284
  return state.notices;
4234
4285
  },
@@ -4248,11 +4299,7 @@ function createRunStoreMethods(context) {
4248
4299
  return null;
4249
4300
  },
4250
4301
  recordRunStart(run) {
4251
- const index = state.runs.findIndex((existing) => existing.id === run.id);
4252
- if (index === -1)
4253
- state.runs.push(run);
4254
- else
4255
- state.runs[index] = run;
4302
+ context.placeRun(run);
4256
4303
  context.bumpAndNotify({ runId: run.id });
4257
4304
  },
4258
4305
  recordRunSummary(runId, summary, summarizedThrough) {
@@ -4393,17 +4440,13 @@ function createRunStoreMethods(context) {
4393
4440
  restored.result = metadata.result;
4394
4441
  if (metadata.budgetState !== undefined)
4395
4442
  restored.budgetState = metadata.budgetState;
4396
- const index = state.runs.findIndex((candidate) => candidate.id === source.id);
4397
- if (index < 0)
4398
- state.runs.push(restored);
4399
- else
4400
- state.runs[index] = restored;
4443
+ context.placeRun(restored);
4401
4444
  context.bumpAndNotify();
4402
4445
  return true;
4403
4446
  },
4404
4447
  removeRun(runId) {
4405
- const index = state.runs.findIndex((r) => r.id === runId);
4406
- if (index < 0)
4448
+ const index = context.runPosition(runId);
4449
+ if (index === undefined)
4407
4450
  return false;
4408
4451
  const run = state.runs[index];
4409
4452
  const pending = run.pendingPrompt;
@@ -4415,7 +4458,7 @@ function createRunStoreMethods(context) {
4415
4458
  for (const stage of run.stages) {
4416
4459
  state.stagePromptAnswers.delete(context.stagePromptAnswerKey(runId, stage.id));
4417
4460
  }
4418
- state.runs.splice(index, 1);
4461
+ context.removeRunAt(index);
4419
4462
  for (let i = state.notices.length - 1;i >= 0; i--) {
4420
4463
  if (state.notices[i]?.runId === runId)
4421
4464
  state.notices.splice(i, 1);
@@ -4507,7 +4550,7 @@ function createRunStoreMethods(context) {
4507
4550
  clear() {
4508
4551
  if (state.runs.length === 0 && state.notices.length === 0 && state.resolvers.size === 0 && state.stagePromptAnswers.size === 0 && state.stagePromptDrafts.size === 0)
4509
4552
  return;
4510
- state.runs.length = 0;
4553
+ context.clearRuns();
4511
4554
  state.notices.length = 0;
4512
4555
  for (const entry of state.resolvers.values()) {
4513
4556
  entry.reject(new Error("atomic-workflows: store cleared"));
@@ -6601,9 +6644,10 @@ function registerSqlPoolStorage(journal, storage) {
6601
6644
  function sqlPoolStorage(journal) {
6602
6645
  return poolStorage.get(journal);
6603
6646
  }
6604
- var JOURNAL_READ_PAGE_SIZE = 256, NON_SNAPSHOT_EVENT_TYPES, poolStorage;
6647
+ var JOURNAL_READ_PAGE_SIZE = 256, JOURNAL_TRANSACTION, NON_SNAPSHOT_EVENT_TYPES, poolStorage;
6605
6648
  var init_internal = __esm(() => {
6606
6649
  init_types();
6650
+ JOURNAL_TRANSACTION = { lockWaitMs: 10 * 60000 };
6607
6651
  NON_SNAPSHOT_EVENT_TYPES = [
6608
6652
  RUN_EVENT_TYPES.checkpointRecorded,
6609
6653
  RUN_EVENT_TYPES.messageSettled,
@@ -7776,7 +7820,7 @@ class LegacyJournalRuns {
7776
7820
  return;
7777
7821
  await tx.exec(`CREATE TABLE IF NOT EXISTS ${CURRENT.legacyDeleted}(${JOURNAL_COLUMNS.runId} TEXT PRIMARY KEY, deleted_at INTEGER NOT NULL)`);
7778
7822
  return new LegacyJournalRuns;
7779
- });
7823
+ }, JOURNAL_TRANSACTION);
7780
7824
  } catch {
7781
7825
  return;
7782
7826
  }
@@ -7816,6 +7860,7 @@ class LegacyJournalRuns {
7816
7860
  }
7817
7861
  var CURRENT, COPIED_ALL_MARKER = "unprefixed-journal-tables", LEGACY_COLUMNS, PENDING_LEGACY_RUNS;
7818
7862
  var init_legacy_journal_tables = __esm(() => {
7863
+ init_internal();
7819
7864
  init_types();
7820
7865
  CURRENT = renderStorageIdentifiers("journal", {
7821
7866
  ...JOURNAL_TABLES,
@@ -7866,7 +7911,7 @@ class SqlRunJournal {
7866
7911
  this.tables = tables;
7867
7912
  this.legacy = legacy;
7868
7913
  registerSqlPoolStorage(this, {
7869
- transaction: (body) => this.operation(() => this.database.transaction(body)),
7914
+ transaction: (body) => this.operation(() => this.transaction(body)),
7870
7915
  read: (body) => this.operation(() => body(this.database)),
7871
7916
  withAppendGuard: (guard, action) => this.appendGuard.run(guard, action),
7872
7917
  tables: this.tables
@@ -7906,7 +7951,7 @@ class SqlRunJournal {
7906
7951
  ${JOURNAL_COLUMNS.holderId} TEXT, ${JOURNAL_COLUMNS.epoch} INTEGER NOT NULL, ${JOURNAL_COLUMNS.renewedAt} INTEGER NOT NULL
7907
7952
  );
7908
7953
  `);
7909
- });
7954
+ }, JOURNAL_TRANSACTION);
7910
7955
  const legacy = options.prefix ? undefined : await LegacyJournalRuns.open(database);
7911
7956
  return new SqlRunJournal(database, t, legacy);
7912
7957
  }
@@ -7920,6 +7965,9 @@ class SqlRunJournal {
7920
7965
  if (this.closed)
7921
7966
  throw new StorageUnavailableError2(this.descriptor, new JournalClosedError);
7922
7967
  }
7968
+ transaction(body) {
7969
+ return this.database.transaction(body, JOURNAL_TRANSACTION);
7970
+ }
7923
7971
  operation(action) {
7924
7972
  this.assertOpen();
7925
7973
  const result = action();
@@ -7946,7 +7994,7 @@ class SqlRunJournal {
7946
7994
  return this.operation(async () => {
7947
7995
  if (await this.legacy?.find(this.database, header.runId))
7948
7996
  return "exists";
7949
- const result = await this.database.run(`INSERT INTO ${runs} VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT(${JOURNAL_COLUMNS.runId}) DO NOTHING`, header.runId, header.name, header.cwd, header.createdAt, header.status, json);
7997
+ 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));
7950
7998
  return result.changes === 1 ? "created" : "exists";
7951
7999
  });
7952
8000
  }
@@ -8038,7 +8086,7 @@ class SqlRunJournal {
8038
8086
  this.assertOpen();
8039
8087
  validateText("runId", runId);
8040
8088
  validateText("holderId", holderId);
8041
- return this.operation(() => this.database.transaction(async (tx) => {
8089
+ return this.operation(() => this.transaction(async (tx) => {
8042
8090
  await this.requireRun(tx, runId);
8043
8091
  const current = await this.leaseRow(tx, runId);
8044
8092
  if (current?.[JOURNAL_COLUMNS.holderId] === holderId)
@@ -8053,7 +8101,7 @@ class SqlRunJournal {
8053
8101
  validateText("runId", runId);
8054
8102
  validateText("holderId", holderId);
8055
8103
  validateText("expectedHolder", expectedHolder);
8056
- return this.operation(() => this.database.transaction(async (tx) => {
8104
+ return this.operation(() => this.transaction(async (tx) => {
8057
8105
  await this.requireRun(tx, runId);
8058
8106
  const current = await this.leaseRow(tx, runId);
8059
8107
  if (current?.[JOURNAL_COLUMNS.holderId] !== expectedHolder)
@@ -8083,7 +8131,7 @@ class SqlRunJournal {
8083
8131
  this.assertOpen();
8084
8132
  validateText("runId", runId);
8085
8133
  validateText("holderId", holderId);
8086
- return this.operation(() => this.database.transaction(async (tx) => {
8134
+ return this.operation(() => this.transaction(async (tx) => {
8087
8135
  await this.requireRun(tx, runId);
8088
8136
  const current = await this.leaseRow(tx, runId);
8089
8137
  if (current?.[JOURNAL_COLUMNS.holderId] === holderId)
@@ -8107,7 +8155,7 @@ class SqlRunJournal {
8107
8155
  validateText("runId", lease.runId);
8108
8156
  validateText("holderId", lease.holderId);
8109
8157
  const owned = { ...lease };
8110
- return this.operation(() => this.database.transaction(async (tx) => {
8158
+ return this.operation(() => this.transaction(async (tx) => {
8111
8159
  await this.checkLease(tx, owned);
8112
8160
  await tx.run(`UPDATE ${this.tables.leases} SET ${JOURNAL_COLUMNS.renewedAt} = ${STORE_NOW} WHERE ${JOURNAL_COLUMNS.runId} = ?`, owned.runId);
8113
8161
  }));
@@ -8117,7 +8165,7 @@ class SqlRunJournal {
8117
8165
  validateText("runId", lease.runId);
8118
8166
  validateText("holderId", lease.holderId);
8119
8167
  const owned = { ...lease };
8120
- return this.operation(() => this.database.transaction(async (tx) => {
8168
+ return this.operation(() => this.transaction(async (tx) => {
8121
8169
  await this.checkLease(tx, owned);
8122
8170
  await tx.run(`UPDATE ${this.tables.leases} SET ${JOURNAL_COLUMNS.holderId} = ? WHERE ${JOURNAL_COLUMNS.runId} = ?`, JOURNAL_LEASE.unheld, owned.runId);
8123
8171
  }));
@@ -8133,7 +8181,7 @@ class SqlRunJournal {
8133
8181
  const owned = { ...lease };
8134
8182
  const prepared = this.prepare(event, options?.key, this.appendGuard.getStore());
8135
8183
  const expected = options?.expectSeq;
8136
- return this.operation(() => this.database.transaction(async (tx) => {
8184
+ return this.operation(() => this.transaction(async (tx) => {
8137
8185
  await this.checkLease(tx, owned);
8138
8186
  return this.insert(tx, owned, prepared, expected);
8139
8187
  }));
@@ -8153,7 +8201,7 @@ class SqlRunJournal {
8153
8201
  const batch = this.database.batch?.bind(this.database);
8154
8202
  if (batch && prepared.every((append) => append instanceof Error || append.guard === undefined && typeof append.payload === "string"))
8155
8203
  return this.operation(() => this.appendInOneRequest(batch, owned, prepared));
8156
- return this.operation(() => this.database.transaction(async (tx) => {
8204
+ return this.operation(() => this.transaction(async (tx) => {
8157
8205
  await this.checkLease(tx, owned);
8158
8206
  const results = [];
8159
8207
  for (const append of prepared) {
@@ -8304,14 +8352,14 @@ class SqlRunJournal {
8304
8352
  async deleteRun(runId) {
8305
8353
  this.assertOpen();
8306
8354
  validateText("runId", runId);
8307
- return this.operation(() => this.database.transaction((tx) => this.deleteRunData(tx, runId)));
8355
+ return this.operation(() => this.transaction((tx) => this.deleteRunData(tx, runId)));
8308
8356
  }
8309
8357
  async deleteOwnedRun(lease, expectSeq) {
8310
8358
  this.assertOpen();
8311
8359
  validateText("runId", lease.runId);
8312
8360
  validateText("holderId", lease.holderId);
8313
8361
  const owned = { ...lease };
8314
- return this.operation(() => this.database.transaction(async (tx) => {
8362
+ return this.operation(() => this.transaction(async (tx) => {
8315
8363
  await this.checkLease(tx, owned);
8316
8364
  if (expectSeq !== undefined) {
8317
8365
  const actual = await this.sequence(tx, owned.runId);
@@ -70702,16 +70750,25 @@ class PoolStageHandoff {
70702
70750
  throw outside2(run.id);
70703
70751
  }
70704
70752
  };
70705
- const before = new Map(this.store.runs().map((run) => [run.id, run]));
70753
+ const before = this.known(subtree);
70706
70754
  owned(before);
70707
70755
  if (subtree.some((run) => before.get(run.id) === undefined))
70708
70756
  await this.backend.catchUpWorkflow(root);
70709
70757
  await this.queue.assertCurrent(this.lease, work);
70710
70758
  return () => this.commit(work, subtree, owned);
70711
70759
  }
70760
+ known(subtree) {
70761
+ const known = new Map;
70762
+ for (const run of subtree) {
70763
+ const existing = this.store.run(run.id);
70764
+ if (existing !== undefined)
70765
+ known.set(run.id, existing);
70766
+ }
70767
+ return known;
70768
+ }
70712
70769
  commit(work, subtree, owned) {
70713
70770
  const root = this.lease.runId;
70714
- const known = new Map(this.store.runs().map((run) => [run.id, run]));
70771
+ const known = this.known(subtree);
70715
70772
  owned(known);
70716
70773
  const attempt = this.enter(work);
70717
70774
  const execution = {
@@ -70745,7 +70802,7 @@ class PoolStageHandoff {
70745
70802
  else
70746
70803
  attempt.sessions.set(key, stage.sessionId);
70747
70804
  }
70748
- const previous = this.store.runs().find((candidate) => candidate.id === run.id);
70805
+ const previous = this.store.run(run.id);
70749
70806
  for (const stage of run.stages)
70750
70807
  if (previous?.stages.find((candidate) => candidate.id === stage.id)?.attached === true)
70751
70808
  stage.attached = true;
@@ -70764,7 +70821,7 @@ class PoolStageHandoff {
70764
70821
  }
70765
70822
  if (runs.length === 0)
70766
70823
  return [];
70767
- const rootRun = this.store.runs().find((run) => run.id === root);
70824
+ const rootRun = this.store.run(root);
70768
70825
  const boundary = rootRun?.stages.find((stage) => stage.id === work.boundaryId);
70769
70826
  if (authoritativeWorkflowChildRunId(boundary) !== work.childRunId)
70770
70827
  throw new Error(`Pool work boundary ${work.boundaryId} is not linked to ${work.childRunId} in the root run`);
@@ -70829,7 +70886,7 @@ class PoolStageHandoff {
70829
70886
  for (const id of attempt.runs)
70830
70887
  rotateWorkflowPendingStageRouteCapability(this.store, id);
70831
70888
  for (const id of attempt.runs) {
70832
- const run = this.store.runs().find((candidate) => candidate.id === id);
70889
+ const run = this.store.run(id);
70833
70890
  if (run?.stages.some((stage) => isLive(stage)) !== true)
70834
70891
  continue;
70835
70892
  this.store.recordRunStart({
@@ -72477,7 +72534,7 @@ class LocalWorkerPool {
72477
72534
  return false;
72478
72535
  }
72479
72536
  applyHeldAnswer(runId, stageId, heldGeneration) {
72480
- const stage = this.store?.runs().find((run) => run.id === runId)?.stages.find((candidate) => candidate.id === stageId);
72537
+ const stage = this.store?.run(runId)?.stages.find((candidate) => candidate.id === stageId);
72481
72538
  if (stage === undefined || this.closed)
72482
72539
  return;
72483
72540
  const generation = stage.workerExecution?.generation ?? 0;
@@ -72533,7 +72590,7 @@ class LocalWorkerPool {
72533
72590
  const key = JSON.stringify([runId, stageId]);
72534
72591
  let view = this.stageViews.get(key);
72535
72592
  if (view === undefined) {
72536
- const stageName = this.store?.runs().find((run) => run.id === runId)?.stages.find((stage) => stage.id === stageId)?.name ?? stageId;
72593
+ const stageName = this.store?.run(runId)?.stages.find((stage) => stage.id === stageId)?.name ?? stageId;
72537
72594
  const created = { key, holders: 0, opening: Promise.resolve(undefined) };
72538
72595
  const transport = this.stageTransport((reason) => {
72539
72596
  tracePooledWatch("root.view.watch-ended", { key, reason, current: this.stageViews.get(key) === created });
@@ -72599,10 +72656,9 @@ class LocalWorkerPool {
72599
72656
  };
72600
72657
  }
72601
72658
  reconnectStageViews() {
72602
- const runs = this.store?.runs() ?? [];
72603
72659
  const stageOf = (key) => {
72604
72660
  const [runId, stageId] = JSON.parse(key);
72605
- const run = runs.find((candidate) => candidate.id === runId);
72661
+ const run = this.store?.run(runId);
72606
72662
  return { runId, stageId, run, stage: run?.stages.find((candidate) => candidate.id === stageId) };
72607
72663
  };
72608
72664
  const ended = (key) => {
@@ -72683,7 +72739,7 @@ class LocalWorkerPool {
72683
72739
  };
72684
72740
  }
72685
72741
  rootProjection() {
72686
- const run = this.store?.runs().find((candidate) => candidate.id === this.root);
72742
+ const run = this.root === undefined ? undefined : this.store?.run(this.root);
72687
72743
  return run === undefined ? undefined : projectRootRun(run);
72688
72744
  }
72689
72745
  rootRun() {