@swirls/looms 0.13.1 → 0.14.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-Dqg2e5oY.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-CtGiJU8b.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>
@@ -1,15 +1,17 @@
1
1
  import { Clock, Deferred, Effect, Exit, Fiber, Option, Queue, } from 'effect';
2
- import { createEvent, deferredUntil, EventStoreTag, foldRun, isRunTerminal, } from '@swirls/looms/core';
2
+ import { createEvent, deferredUntil, EventStoreTag, foldRun, isPrimitiveEffect, isRunTerminal, } from '@swirls/looms/core';
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
6
  import { DuplicateEffectDispatchError, MaxWakeIterationsError, RuntimeExecutionError, } from './errors.js';
7
- import { cascadedCancellations, groupOutstanding, stripSeq, synthesizedThreadFailed, waitSatisfiedEvents, } from './helpers.js';
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';
10
10
  import { requestWakeAgain, } from './run-execution-context.js';
11
11
  import { dispatchWorkerEffect, isWorkerEffect, planWorkerEffects } from './worker-effect-dispatch.js';
12
12
  const DEFAULT_LIVENESS_LEASE_MS = 30_000;
13
+ /** Attempts allowed for an effect with no retry policy when its attempts keep being lost. */
14
+ const DEFAULT_LOST_ATTEMPT_LIMIT = 3;
13
15
  function currentTimeMillis() {
14
16
  return Math.floor(performance.timeOrigin + performance.now());
15
17
  }
@@ -77,6 +79,9 @@ export function createWakeEngine(options) {
77
79
  executionContext.resolveWakeCompletion = resolveCompletion;
78
80
  executionContext.waking = true;
79
81
  let released = false;
82
+ // `effectId:attempt` of every attempt this wake started, across its passes. An attempt
83
+ // found running that is not here was started by a wake that never finished it.
84
+ const startedByThisWake = new Set();
80
85
  // When the liveness deadline is next due for renewal; `null` while this wake holds none.
81
86
  let livenessRenewAt = null;
82
87
  // In-process effects have no deadline of their own, so nothing would wake the run if this
@@ -319,11 +324,35 @@ export function createWakeEngine(options) {
319
324
  }
320
325
  return yield* new DuplicateEffectDispatchError(runId, item.effectId, item.threadId);
321
326
  }
327
+ // An attempt left running by a wake that is gone (its process was lost, or the wake
328
+ // failed) is re-attempted below. That counts against the effect's attempts, so an
329
+ // effect that takes its process down every time fails instead of repeating forever.
330
+ const exhausted = outstanding.flatMap((item) => {
331
+ const execution = state.effectExecutions[item.effectId];
332
+ if (execution?.status !== 'running' ||
333
+ isPrimitiveEffect(item.effect) ||
334
+ startedByThisWake.has(`${item.effectId}:${execution.attempt}`)) {
335
+ return [];
336
+ }
337
+ const limit = registry.effects.get(item.effect.type)?.retry?.maxAttempts ??
338
+ DEFAULT_LOST_ATTEMPT_LIMIT;
339
+ return execution.attempt >= limit
340
+ ? [
341
+ createEffectFailedEvent(runId, item, `attempt ${execution.attempt} was lost before it finished, and no attempts remain`),
342
+ ]
343
+ : [];
344
+ });
345
+ if (exhausted.length > 0) {
346
+ yield* foldProduced(exhausted);
347
+ continue;
348
+ }
322
349
  const due = outstanding.filter((item) => !dispatchedEffectIds.has(dispatchKeyFor(item)));
323
350
  if (due.length > 0) {
324
351
  const attempts = new Map(due.map((item) => [item.effectId, attemptFor(item)]));
325
352
  for (const item of due) {
326
- dispatchedEffectIds.add(`${item.effectId}:${attempts.get(item.effectId) ?? 1}`);
353
+ const key = `${item.effectId}:${attempts.get(item.effectId) ?? 1}`;
354
+ dispatchedEffectIds.add(key);
355
+ startedByThisWake.add(key);
327
356
  }
328
357
  const attemptEvents = due.map((item) => createEvent(runId, {
329
358
  type: 'runtime.effect.attempt.started',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirls/looms",
3
- "version": "0.13.1",
3
+ "version": "0.14.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": {