@swirls/looms 0.18.0 → 0.19.0

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.
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Looms debugger</title>
7
- <script type="module" crossorigin src="./assets/index-BjZn1DuJ.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-Et8_0gnF.js"></script>
8
8
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-CbXtAM7H.js">
9
9
  <link rel="stylesheet" crossorigin href="./assets/index-CO5gIvV8.css">
10
10
  </head>
@@ -41,6 +41,11 @@ function settled(transaction) {
41
41
  function eventsOf(key) {
42
42
  return IDBKeyRange.bound([key, 0], [key, Number.MAX_SAFE_INTEGER]);
43
43
  }
44
+ function touch(transaction, key) {
45
+ transaction
46
+ .objectStore(RUNS)
47
+ .put({ key, touchedAt: DateTime.toEpochMillis(DateTime.nowUnsafe()) });
48
+ }
44
49
  /**
45
50
  * An `EventCache` in the browser's IndexedDB. Every failure is swallowed: a cache that cannot be
46
51
  * read is an empty cache, and one that cannot be written is simply not written, so the store
@@ -86,11 +91,6 @@ export function indexedDbEventCache(options = {}) {
86
91
  return settled(transaction);
87
92
  });
88
93
  };
89
- const touch = (transaction, key) => {
90
- transaction
91
- .objectStore(RUNS)
92
- .put({ key, touchedAt: DateTime.toEpochMillis(DateTime.nowUnsafe()) });
93
- };
94
94
  return {
95
95
  load: (key) => {
96
96
  if (!factory) {
@@ -85,6 +85,10 @@ export declare class DuplicateEffectDispatchError extends DuplicateEffectDispatc
85
85
  declare const MaxWakeIterationsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
86
86
  readonly _tag: "MaxWakeIterationsError";
87
87
  } & Readonly<A>;
88
+ /**
89
+ * @deprecated The runtime no longer raises this. A wake that reaches `maxWakeIterations` parks
90
+ * and hands the rest of its work to a new wake.
91
+ */
88
92
  export declare class MaxWakeIterationsError extends MaxWakeIterationsError_base<{
89
93
  readonly runId: string;
90
94
  readonly maxIterations: number;
@@ -64,6 +64,10 @@ export class DuplicateEffectDispatchError extends Data.TaggedError('DuplicateEff
64
64
  this.name = 'DuplicateEffectDispatchError';
65
65
  }
66
66
  }
67
+ /**
68
+ * @deprecated The runtime no longer raises this. A wake that reaches `maxWakeIterations` parks
69
+ * and hands the rest of its work to a new wake.
70
+ */
67
71
  export class MaxWakeIterationsError extends Data.TaggedError('MaxWakeIterationsError') {
68
72
  constructor(runId, maxIterations) {
69
73
  super({
@@ -21,6 +21,12 @@ export interface CreateRuntimeOptions<TModules extends readonly AnyRuntimeModule
21
21
  * after a crash inside one long wake.
22
22
  */
23
23
  readonly snapshotEvery?: number;
24
+ /**
25
+ * How many times one wake may plan before it hands the run to a new wake. Default 100. A wake
26
+ * that reaches it starts nothing new, waits for the effects it already started, parks, and
27
+ * asks its scheduler to wake the run again at once. It bounds the work one wake does in a
28
+ * single host invocation; it does not stop a run.
29
+ */
24
30
  readonly maxWakeIterations?: number;
25
31
  /**
26
32
  * How far ahead a wake with in-process effects in flight keeps its `WakeScheduler.keepAlive`
@@ -3,7 +3,7 @@ import { createEvent, deferredUntil, EventStoreTag, foldRun, isPrimitiveEffect,
3
3
  import { childCloseCancellations, notifyLaunchingParent } from './child-run.js';
4
4
  import { nextRuntimeDeadline, planDeadlineTransitions, planTerminalCancellationTransitions, } from './deadline-transition-planner.js';
5
5
  import { admitOrFailAttempt } from './effect-admission.js';
6
- import { DuplicateEffectDispatchError, MaxWakeIterationsError, RuntimeExecutionError, } from './errors.js';
6
+ import { DuplicateEffectDispatchError, RuntimeExecutionError } from './errors.js';
7
7
  import { cascadedCancellations, createEffectFailedEvent, groupOutstanding, stripSeq, synthesizedThreadFailed, waitSatisfiedEvents, } from './helpers.js';
8
8
  import { executeLocalEffects } from './local-effect-executor.js';
9
9
  import { notifyObserver } from './observer.js';
@@ -175,6 +175,8 @@ export function createWakeEngine(options) {
175
175
  const inFlight = new Map();
176
176
  const settled = yield* Queue.unbounded();
177
177
  let guard = 0;
178
+ // Set once this pass has used its iterations: the rest of the work goes to a new wake.
179
+ let yieldToNextWake = false;
178
180
  // Deadlines at or before this instant were handled by the last loop iteration.
179
181
  let plannedAt = Number.NEGATIVE_INFINITY;
180
182
  const foldProduced = (produced) => Effect.gen(function* () {
@@ -211,10 +213,19 @@ export function createWakeEngine(options) {
211
213
  };
212
214
  const dispatchKeyFor = (item) => `${item.effectId}:${attemptFor(item)}`;
213
215
  while (!isRunTerminal(cursor.state)) {
214
- if (guard >= maxWakeIterations) {
215
- return yield* new MaxWakeIterationsError(runId, maxWakeIterations);
216
+ // A pass that has used its iterations starts nothing new. It waits for the effects
217
+ // it already started, then parks and hands the rest to a new wake (see below). A
218
+ // long-lived run (an agent that keeps calling tools while siblings wait) does far
219
+ // more than one pass's worth of work, and failing here would leave it with nothing
220
+ // driving it until some request happened to wake it again.
221
+ const draining = guard >= maxWakeIterations;
222
+ if (draining && inFlight.size === 0) {
223
+ yieldToNextWake = true;
224
+ break;
225
+ }
226
+ if (!draining) {
227
+ guard += 1;
216
228
  }
217
- guard += 1;
218
229
  // A signal (or coalesced join) may have appended events while local effects ran.
219
230
  if (executionContext.wakeAgain) {
220
231
  executionContext.wakeAgain = false;
@@ -224,7 +235,7 @@ export function createWakeEngine(options) {
224
235
  const now = yield* Clock.currentTimeMillis;
225
236
  plannedAt = now;
226
237
  const deadlinePlan = planDeadlineTransitions({ runId, state, registry, now });
227
- if (deadlinePlan.events.length > 0) {
238
+ if (!draining && deadlinePlan.events.length > 0) {
228
239
  for (const notice of deadlinePlan.timerNotices) {
229
240
  observe({
230
241
  type: 'timer.late',
@@ -265,7 +276,7 @@ export function createWakeEngine(options) {
265
276
  now,
266
277
  maxInFlightWorkerEffects: options.maxInFlightWorkerEffects,
267
278
  });
268
- if (workerPlans.length > 0) {
279
+ if (!draining && workerPlans.length > 0) {
269
280
  for (const workerPlan of workerPlans) {
270
281
  const admission = yield* admitOrFailAttempt({
271
282
  registry,
@@ -351,12 +362,12 @@ export function createWakeEngine(options) {
351
362
  ]
352
363
  : [];
353
364
  });
354
- if (exhausted.length > 0) {
365
+ if (!draining && exhausted.length > 0) {
355
366
  yield* foldProduced(exhausted);
356
367
  continue;
357
368
  }
358
369
  const due = outstanding.filter((item) => !dispatchedEffectIds.has(dispatchKeyFor(item)));
359
- if (due.length > 0) {
370
+ if (!draining && due.length > 0) {
360
371
  const attempts = new Map(due.map((item) => [item.effectId, attemptFor(item)]));
361
372
  for (const item of due) {
362
373
  const key = `${item.effectId}:${attempts.get(item.effectId) ?? 1}`;
@@ -501,7 +512,11 @@ export function createWakeEngine(options) {
501
512
  }
502
513
  // Snapshot on park: the next wake (on any instance) starts from here.
503
514
  cursor = yield* persistSnapshot(store, runId, cursor);
504
- const nextDeadline = nextRuntimeDeadline(cursor.state, plannedAt);
515
+ const runtimeDeadline = nextRuntimeDeadline(cursor.state, plannedAt);
516
+ // Work this pass left for the next wake is due now.
517
+ const nextDeadline = yieldToNextWake
518
+ ? Math.min(runtimeDeadline ?? Number.POSITIVE_INFINITY, yield* Clock.currentTimeMillis)
519
+ : runtimeDeadline;
505
520
  if (nextDeadline !== undefined) {
506
521
  yield* options.scheduler().schedule(runId, nextDeadline);
507
522
  }
@@ -342,15 +342,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
342
342
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
343
343
  readonly type: "schedule.paused";
344
344
  readonly payload: {};
345
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
346
- readonly type: "schedule.resumed";
347
- readonly payload: {};
348
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
- readonly type: "schedule.retired";
350
- readonly payload: {};
351
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
352
- readonly type: "schedule.triggered";
353
- readonly payload: {};
354
345
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
355
346
  readonly type: "schedule.planned";
356
347
  readonly payload: {
@@ -374,6 +365,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
374
365
  readonly payload: {
375
366
  readonly reason: string;
376
367
  };
368
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
369
+ readonly type: "schedule.resumed";
370
+ readonly payload: {};
371
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
372
+ readonly type: "schedule.retired";
373
+ readonly payload: {};
377
374
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
378
375
  readonly type: "schedule.skipped";
379
376
  readonly payload: {
@@ -384,6 +381,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
384
381
  readonly manual: boolean;
385
382
  readonly triggerId?: string | undefined;
386
383
  };
384
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
385
+ readonly type: "schedule.triggered";
386
+ readonly payload: {};
387
387
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
388
388
  readonly type: "schedule.updated";
389
389
  readonly payload: {
@@ -693,15 +693,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
693
693
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
694
694
  readonly type: "schedule.paused";
695
695
  readonly payload: {};
696
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
697
- readonly type: "schedule.resumed";
698
- readonly payload: {};
699
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
700
- readonly type: "schedule.retired";
701
- readonly payload: {};
702
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
703
- readonly type: "schedule.triggered";
704
- readonly payload: {};
705
696
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
706
697
  readonly type: "schedule.planned";
707
698
  readonly payload: {
@@ -725,6 +716,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
725
716
  readonly payload: {
726
717
  readonly reason: string;
727
718
  };
719
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
720
+ readonly type: "schedule.resumed";
721
+ readonly payload: {};
722
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
723
+ readonly type: "schedule.retired";
724
+ readonly payload: {};
728
725
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
729
726
  readonly type: "schedule.skipped";
730
727
  readonly payload: {
@@ -735,6 +732,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
735
732
  readonly manual: boolean;
736
733
  readonly triggerId?: string | undefined;
737
734
  };
735
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
736
+ readonly type: "schedule.triggered";
737
+ readonly payload: {};
738
738
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
739
739
  readonly type: "schedule.updated";
740
740
  readonly payload: {
@@ -1120,15 +1120,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1120
1120
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1121
1121
  readonly type: "schedule.paused";
1122
1122
  readonly payload: {};
1123
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1124
- readonly type: "schedule.resumed";
1125
- readonly payload: {};
1126
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1127
- readonly type: "schedule.retired";
1128
- readonly payload: {};
1129
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1130
- readonly type: "schedule.triggered";
1131
- readonly payload: {};
1132
1123
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1133
1124
  readonly type: "schedule.planned";
1134
1125
  readonly payload: {
@@ -1152,6 +1143,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1152
1143
  readonly payload: {
1153
1144
  readonly reason: string;
1154
1145
  };
1146
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1147
+ readonly type: "schedule.resumed";
1148
+ readonly payload: {};
1149
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1150
+ readonly type: "schedule.retired";
1151
+ readonly payload: {};
1155
1152
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1156
1153
  readonly type: "schedule.skipped";
1157
1154
  readonly payload: {
@@ -1162,6 +1159,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1162
1159
  readonly manual: boolean;
1163
1160
  readonly triggerId?: string | undefined;
1164
1161
  };
1162
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1163
+ readonly type: "schedule.triggered";
1164
+ readonly payload: {};
1165
1165
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1166
1166
  readonly type: "schedule.updated";
1167
1167
  readonly payload: {
@@ -1471,15 +1471,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1471
1471
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1472
1472
  readonly type: "schedule.paused";
1473
1473
  readonly payload: {};
1474
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1475
- readonly type: "schedule.resumed";
1476
- readonly payload: {};
1477
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1478
- readonly type: "schedule.retired";
1479
- readonly payload: {};
1480
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1481
- readonly type: "schedule.triggered";
1482
- readonly payload: {};
1483
1474
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1484
1475
  readonly type: "schedule.planned";
1485
1476
  readonly payload: {
@@ -1503,6 +1494,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1503
1494
  readonly payload: {
1504
1495
  readonly reason: string;
1505
1496
  };
1497
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1498
+ readonly type: "schedule.resumed";
1499
+ readonly payload: {};
1500
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1501
+ readonly type: "schedule.retired";
1502
+ readonly payload: {};
1506
1503
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1507
1504
  readonly type: "schedule.skipped";
1508
1505
  readonly payload: {
@@ -1513,6 +1510,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1513
1510
  readonly manual: boolean;
1514
1511
  readonly triggerId?: string | undefined;
1515
1512
  };
1513
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1514
+ readonly type: "schedule.triggered";
1515
+ readonly payload: {};
1516
1516
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1517
1517
  readonly type: "schedule.updated";
1518
1518
  readonly payload: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirls/looms",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Pluggable event-sourced runtime for durable agents and workflows",
5
5
  "homepage": "https://github.com/ByteSliceHQ/looms#readme",
6
6
  "bugs": {
@@ -193,15 +193,13 @@
193
193
  "test": "bun -e \"void 0\""
194
194
  },
195
195
  "dependencies": {
196
- "@effect/platform-bun": "4.0.0-rc.112",
197
- "@effect/platform-node-shared": "4.0.0-rc.112",
196
+ "@effect/platform-bun": "^4.1.4",
198
197
  "@noble/hashes": "^2.0.1",
199
198
  "@s2-dev/streamstore": "^0.23.0",
200
199
  "@standard-schema/spec": "^1.1.0",
201
200
  "@tanstack/react-virtual": "^3.14.11",
202
201
  "clsx": "^2.1.1",
203
202
  "cmdk": "^1.1.1",
204
- "effect": "4.0.0-rc.112",
205
203
  "lucide-react": "^1.43.0",
206
204
  "radix-ui": "^1.6.7",
207
205
  "react-resizable-panels": "^4.13.3",
@@ -229,6 +227,7 @@
229
227
  "@looms/workflow": "workspace:*",
230
228
  "@types/bun": "^1.3.9",
231
229
  "ai": "^7.0.105",
230
+ "effect": "4.1.4",
232
231
  "postgres": "^3.4.0",
233
232
  "react": "19",
234
233
  "react-dom": "19",
@@ -238,6 +237,7 @@
238
237
  "@cloudflare/workers-types": "^5.20260914.1",
239
238
  "ai": "^7.0.0",
240
239
  "drizzle-orm": "^0.44.0",
240
+ "effect": "^4.1.4",
241
241
  "postgres": "^3.4.0",
242
242
  "react": "^19.0.0",
243
243
  "react-dom": "^19.0.0"