@dudousxd/nestjs-durable-core 0.1.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.
Files changed (45) hide show
  1. package/dist/duration.d.ts +6 -0
  2. package/dist/duration.d.ts.map +1 -0
  3. package/dist/duration.js +42 -0
  4. package/dist/duration.js.map +1 -0
  5. package/dist/engine.d.ts +115 -0
  6. package/dist/engine.d.ts.map +1 -0
  7. package/dist/engine.js +588 -0
  8. package/dist/engine.js.map +1 -0
  9. package/dist/errors.d.ts +34 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +59 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/index.d.ts +11 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +30 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/interfaces.d.ts +249 -0
  18. package/dist/interfaces.d.ts.map +1 -0
  19. package/dist/interfaces.js +3 -0
  20. package/dist/interfaces.js.map +1 -0
  21. package/dist/protocol.d.ts +12 -0
  22. package/dist/protocol.d.ts.map +1 -0
  23. package/dist/protocol.js +35 -0
  24. package/dist/protocol.js.map +1 -0
  25. package/dist/remote-step-factory.d.ts +15 -0
  26. package/dist/remote-step-factory.d.ts.map +1 -0
  27. package/dist/remote-step-factory.js +15 -0
  28. package/dist/remote-step-factory.js.map +1 -0
  29. package/dist/scheduler.d.ts +19 -0
  30. package/dist/scheduler.d.ts.map +1 -0
  31. package/dist/scheduler.js +24 -0
  32. package/dist/scheduler.js.map +1 -0
  33. package/dist/testing/in-memory-state-store.d.ts +25 -0
  34. package/dist/testing/in-memory-state-store.d.ts.map +1 -0
  35. package/dist/testing/in-memory-state-store.js +88 -0
  36. package/dist/testing/in-memory-state-store.js.map +1 -0
  37. package/dist/testing/in-memory-transport.d.ts +16 -0
  38. package/dist/testing/in-memory-transport.d.ts.map +1 -0
  39. package/dist/testing/in-memory-transport.js +29 -0
  40. package/dist/testing/in-memory-transport.js.map +1 -0
  41. package/dist/tokens.d.ts +8 -0
  42. package/dist/tokens.d.ts.map +1 -0
  43. package/dist/tokens.js +11 -0
  44. package/dist/tokens.js.map +1 -0
  45. package/package.json +31 -0
package/dist/engine.js ADDED
@@ -0,0 +1,588 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoteStepError = exports.WorkflowEngine = void 0;
4
+ const duration_1 = require("./duration");
5
+ const errors_1 = require("./errors");
6
+ const protocol_1 = require("./protocol");
7
+ const versionKey = (name, version) => `${name}@${version}`;
8
+ /** True when version `a` is newer than `b` (numeric when both parse as numbers, else natural sort). */
9
+ function isNewerVersion(a, b) {
10
+ const na = Number(a);
11
+ const nb = Number(b);
12
+ if (!Number.isNaN(na) && !Number.isNaN(nb))
13
+ return na > nb;
14
+ return a.localeCompare(b, undefined, { numeric: true }) > 0;
15
+ }
16
+ /** Read a `Completion` from a signal payload: return the value, or throw a FatalError if it failed. */
17
+ function unwrapCompletion(payload, label) {
18
+ const c = payload;
19
+ if (c && typeof c === 'object' && 'ok' in c && c.ok === false) {
20
+ throw new errors_1.FatalError(`${label} failed: ${c.error}`);
21
+ }
22
+ return c?.value;
23
+ }
24
+ /**
25
+ * The orchestrator. Owns workflow state and replays runs deterministically: each step's
26
+ * result is checkpointed, so on resume a completed step returns its saved output instead of
27
+ * re-executing. Remote steps are dispatched over the Transport; their results checkpoint the
28
+ * same way local steps do.
29
+ */
30
+ class WorkflowEngine {
31
+ store;
32
+ transport;
33
+ clock;
34
+ instanceId;
35
+ leaseMs;
36
+ /** Every registered workflow, keyed by `name@version` — so old versions stay runnable. */
37
+ workflows = new Map();
38
+ /** The newest registered version per workflow name — used to `start` new runs. */
39
+ latest = new Map();
40
+ /** In-flight remote steps awaiting a worker result, keyed by stepId. */
41
+ pending = new Map();
42
+ /** Per-step "reset the liveness timer" callbacks, called when a heartbeat arrives. */
43
+ heartbeatResets = new Map();
44
+ listeners = new Set();
45
+ /** Executions currently in flight, so a graceful shutdown can wait for them to settle. */
46
+ inflight = new Set();
47
+ draining = false;
48
+ constructor(deps) {
49
+ this.store = deps.store;
50
+ this.transport = deps.transport;
51
+ this.clock = deps.clock ?? Date.now;
52
+ this.instanceId = deps.instanceId ?? globalThis.crypto.randomUUID();
53
+ this.leaseMs = deps.leaseMs ?? 30_000;
54
+ this.transport?.onResult(async (result) => {
55
+ const waiter = this.pending.get(result.stepId);
56
+ if (!waiter)
57
+ return;
58
+ this.pending.delete(result.stepId);
59
+ if (result.status === 'completed') {
60
+ waiter.resolve(result.output);
61
+ }
62
+ else {
63
+ waiter.reject(new RemoteStepError(result.error));
64
+ }
65
+ });
66
+ // A heartbeat for an in-flight long step resets its liveness window (see callRemote).
67
+ this.transport?.onHeartbeat(async (beat) => {
68
+ this.heartbeatResets.get(beat.stepId)?.();
69
+ });
70
+ }
71
+ /**
72
+ * Register a workflow version. Register multiple versions of the same name to keep in-flight
73
+ * runs working across a breaking change: old runs resume on the version they started on, new
74
+ * runs start on the newest registered version.
75
+ */
76
+ register(name, version, fn) {
77
+ const registered = { name, version, fn };
78
+ this.workflows.set(versionKey(name, version), registered);
79
+ const current = this.latest.get(name);
80
+ if (!current || isNewerVersion(version, current.version))
81
+ this.latest.set(name, registered);
82
+ }
83
+ /** Subscribe to lifecycle events. Returns an unsubscribe function. */
84
+ subscribe(listener) {
85
+ this.listeners.add(listener);
86
+ return () => this.listeners.delete(listener);
87
+ }
88
+ emit(event) {
89
+ const full = { ...event, at: new Date() };
90
+ for (const listener of this.listeners) {
91
+ try {
92
+ listener(full);
93
+ }
94
+ catch {
95
+ // a misbehaving subscriber must never break workflow execution
96
+ }
97
+ }
98
+ }
99
+ async start(workflow, input, runId) {
100
+ const registered = this.latest.get(workflow);
101
+ if (!registered)
102
+ throw new Error(`workflow ${workflow} is not registered`);
103
+ // Idempotent by run id: a redelivered trigger (at-least-once queues) or a scheduler re-tick for
104
+ // the same id is a no-op, returning the existing run's state instead of starting a duplicate.
105
+ const prior = await this.store.getRun(runId);
106
+ if (prior) {
107
+ return { runId, status: prior.status, output: prior.output, error: prior.error };
108
+ }
109
+ const now = new Date();
110
+ const run = {
111
+ id: runId,
112
+ workflow,
113
+ workflowVersion: registered.version,
114
+ status: 'running',
115
+ input,
116
+ createdAt: now,
117
+ updatedAt: now,
118
+ };
119
+ await this.store.createRun(run);
120
+ this.emit({ type: 'run.started', runId, workflow });
121
+ return this.track(this.execute(run, registered.fn));
122
+ }
123
+ async resume(runId) {
124
+ const run = await this.store.getRun(runId);
125
+ if (!run)
126
+ throw new Error(`run ${runId} not found`);
127
+ // Pin to the version the run STARTED on — replay is positional, so running a changed
128
+ // workflow body against old checkpoints would corrupt the run.
129
+ const registered = this.workflows.get(versionKey(run.workflow, run.workflowVersion));
130
+ if (!registered) {
131
+ throw new Error(`workflow ${run.workflow}@${run.workflowVersion} is not registered — keep the prior version deployed so in-flight runs can drain (skew protection)`);
132
+ }
133
+ return this.track(this.execute(run, registered.fn));
134
+ }
135
+ /** Track an in-flight execution so {@link drain} can wait for it. */
136
+ track(p) {
137
+ this.inflight.add(p);
138
+ void p.finally(() => this.inflight.delete(p));
139
+ return p;
140
+ }
141
+ /**
142
+ * Graceful shutdown: stop picking up new runs (recovery/timer become no-ops) and wait for
143
+ * in-flight executions to settle, up to `timeoutMs`. Call from your app's shutdown hook so a
144
+ * deploy hands off cleanly instead of leaving runs to the lease timeout.
145
+ */
146
+ async drain(timeoutMs = 10_000) {
147
+ this.draining = true;
148
+ if (this.inflight.size === 0)
149
+ return;
150
+ const timer = new Promise((resolve) => {
151
+ const t = setTimeout(resolve, timeoutMs);
152
+ t.unref?.();
153
+ });
154
+ await Promise.race([Promise.allSettled([...this.inflight]), timer]);
155
+ }
156
+ /**
157
+ * Resume every run left incomplete by a crash or deploy. Called on boot. Completed steps
158
+ * replay from their checkpoints, so only the work that had not finished runs again.
159
+ */
160
+ async recoverIncomplete() {
161
+ return this.resumeLeased(await this.store.listIncompleteRuns());
162
+ }
163
+ /**
164
+ * Resume every suspended run whose durable timer is due. Call periodically (a poller) and on
165
+ * boot. A run still not due re-suspends cheaply without running new work.
166
+ */
167
+ async resumeDueTimers(nowMs = this.clock()) {
168
+ return this.resumeLeased(await this.store.listDueTimers(nowMs), nowMs);
169
+ }
170
+ /**
171
+ * Resume each run only if this instance can acquire its recovery lease — so when several
172
+ * replicas recover or poll at once, each run is picked up by exactly one of them.
173
+ */
174
+ async resumeLeased(runs, nowMs = this.clock()) {
175
+ if (this.draining)
176
+ return []; // shutting down — don't pick up new runs
177
+ const results = [];
178
+ for (const run of runs) {
179
+ const acquired = await this.store.tryLockRun(run.id, this.instanceId, nowMs + this.leaseMs, nowMs);
180
+ if (acquired)
181
+ results.push(await this.resume(run.id));
182
+ }
183
+ return results;
184
+ }
185
+ /**
186
+ * Deliver an external signal to the run waiting on `token` and resume it with `payload`.
187
+ * Returns the run result, or null if no run is waiting for that token.
188
+ */
189
+ async signal(token, payload) {
190
+ const waiter = await this.store.takeSignalWaiter(token);
191
+ if (!waiter)
192
+ return null;
193
+ const at = new Date();
194
+ await this.store.saveCheckpoint({
195
+ runId: waiter.runId,
196
+ seq: waiter.seq,
197
+ name: `signal:${token}`,
198
+ kind: 'signal',
199
+ stepId: (0, protocol_1.stepId)(waiter.runId, waiter.seq),
200
+ status: 'completed',
201
+ output: payload,
202
+ attempts: 1,
203
+ startedAt: at,
204
+ finishedAt: at,
205
+ });
206
+ return this.resume(waiter.runId);
207
+ }
208
+ /**
209
+ * Report the result of a `ctx.task(name, …)` back to its run (async completion). The external
210
+ * worker that the task dispatched to calls this when done; the run resumes with `result`. Returns
211
+ * null if no run is waiting on the task (e.g. a duplicate/late delivery) — a safe no-op.
212
+ */
213
+ async completeTask(runId, name, result) {
214
+ return this.signal(`task:${runId}:${name}`, { ok: true, value: result });
215
+ }
216
+ /** Report that a `ctx.task` failed — the run resumes and throws a FatalError at the task. */
217
+ async failTask(runId, name, error) {
218
+ return this.signal(`task:${runId}:${name}`, { ok: false, error });
219
+ }
220
+ /**
221
+ * Notify a parent that's waiting on `runId` as a child of its terminal outcome (the `ctx.child`
222
+ * rendezvous). A no-op when no parent is waiting, so `execute()` can call it on every run without
223
+ * knowing about the child feature.
224
+ */
225
+ notifyParent(runId, completion) {
226
+ void this.signal(`child:${runId}`, completion).catch(() => undefined);
227
+ }
228
+ /** Cancel a run (e.g. from the dashboard). Returns null if the run does not exist. */
229
+ async cancel(runId) {
230
+ const run = await this.store.getRun(runId);
231
+ if (!run)
232
+ return null;
233
+ const error = { message: 'cancelled' };
234
+ await this.store.updateRun(runId, { status: 'cancelled', error, updatedAt: new Date() });
235
+ this.emit({ type: 'run.failed', runId, workflow: run.workflow, error });
236
+ return { runId, status: 'cancelled', error };
237
+ }
238
+ /** Checkpoint a finished step and announce it — the two things that must always happen together. */
239
+ async completeStep(step) {
240
+ await this.store.saveCheckpoint({
241
+ runId: step.runId,
242
+ seq: step.seq,
243
+ name: step.name,
244
+ kind: step.kind,
245
+ stepId: (0, protocol_1.stepId)(step.runId, step.seq),
246
+ status: 'completed',
247
+ output: step.output,
248
+ attempts: step.attempts,
249
+ workerGroup: step.workerGroup,
250
+ startedAt: step.startedAt,
251
+ finishedAt: new Date(),
252
+ });
253
+ this.emit({
254
+ type: 'step.completed',
255
+ runId: step.runId,
256
+ seq: step.seq,
257
+ name: step.name,
258
+ kind: step.kind,
259
+ output: step.output,
260
+ durationMs: Date.now() - step.startedAt.getTime(),
261
+ });
262
+ }
263
+ /** Checkpoint a step that failed terminally, so the failure point is visible (not just the run). */
264
+ async failStep(step) {
265
+ await this.store.saveCheckpoint({
266
+ runId: step.runId,
267
+ seq: step.seq,
268
+ name: step.name,
269
+ kind: step.kind,
270
+ stepId: (0, protocol_1.stepId)(step.runId, step.seq),
271
+ status: 'failed',
272
+ error: step.error,
273
+ attempts: step.attempts,
274
+ workerGroup: step.workerGroup,
275
+ startedAt: step.startedAt,
276
+ finishedAt: new Date(),
277
+ });
278
+ this.emit({
279
+ type: 'step.failed',
280
+ runId: step.runId,
281
+ seq: step.seq,
282
+ name: step.name,
283
+ kind: step.kind,
284
+ error: step.error,
285
+ durationMs: Date.now() - step.startedAt.getTime(),
286
+ });
287
+ }
288
+ async execute(run, fn) {
289
+ // Saga compensations registered by completed steps; run in reverse if the run later fails.
290
+ const compensations = [];
291
+ const ctx = this.makeCtx(run.id, compensations);
292
+ try {
293
+ const output = await fn(ctx, run.input);
294
+ // Clear any error from an earlier failed-then-retried attempt: a completed run is a success
295
+ // and must not carry a stale error (otherwise dashboards show a green run with a red error).
296
+ await this.store.updateRun(run.id, {
297
+ status: 'completed',
298
+ output,
299
+ error: undefined,
300
+ updatedAt: new Date(),
301
+ });
302
+ this.emit({ type: 'run.completed', runId: run.id, workflow: run.workflow, output });
303
+ // Wake a parent waiting on this run as a child (no-op when there's no parent).
304
+ void this.notifyParent(run.id, { ok: true, value: output });
305
+ return { runId: run.id, status: 'completed', output };
306
+ }
307
+ catch (err) {
308
+ if (err instanceof errors_1.WorkflowSuspended) {
309
+ await this.store.updateRun(run.id, {
310
+ status: 'suspended',
311
+ wakeAt: err.wakeAt,
312
+ updatedAt: new Date(),
313
+ });
314
+ this.emit({ type: 'run.suspended', runId: run.id, workflow: run.workflow });
315
+ return { runId: run.id, status: 'suspended' };
316
+ }
317
+ const error = {
318
+ message: err instanceof Error ? err.message : String(err),
319
+ stack: err instanceof Error ? err.stack : undefined,
320
+ };
321
+ // Saga: undo completed steps in reverse. A compensation that throws is logged-and-skipped so
322
+ // one bad undo can't strand the rest. (Compensations are best-effort and should be idempotent.)
323
+ for (let i = compensations.length - 1; i >= 0; i -= 1) {
324
+ try {
325
+ await compensations[i]?.();
326
+ }
327
+ catch {
328
+ // a failing compensation must not mask the original failure
329
+ }
330
+ }
331
+ await this.store.updateRun(run.id, { status: 'failed', error, updatedAt: new Date() });
332
+ this.emit({ type: 'run.failed', runId: run.id, workflow: run.workflow, error });
333
+ void this.notifyParent(run.id, { ok: false, error: error.message });
334
+ return { runId: run.id, status: 'failed', error };
335
+ }
336
+ finally {
337
+ // Release the recovery lease once the run reaches a terminal/suspended state, so the
338
+ // next instance (or the timer poller) can pick it up promptly.
339
+ await this.store.releaseRunLock(run.id);
340
+ }
341
+ }
342
+ makeCtx(runId, compensations) {
343
+ let seq = -1;
344
+ const nextSeq = () => {
345
+ seq += 1;
346
+ return seq;
347
+ };
348
+ const store = this.store;
349
+ // Each ctx primitive is a named closure over `nextSeq` (the per-run logical position counter)
350
+ // and `compensations` (the saga undo stack). They're defined up front so `task`/`child` can
351
+ // compose `step`/`waitForSignal` directly — no post-construction mutation, no cast.
352
+ const step = async (name, fn, options) => {
353
+ const current = nextSeq();
354
+ const existing = await store.getCheckpoint(runId, current);
355
+ if (existing && existing.status === 'completed') {
356
+ // Register the compensation on replay too, so a saga undoes ALL completed steps — even
357
+ // those done in an earlier (since-suspended) pass — not just the ones run this pass.
358
+ if (options?.compensate)
359
+ compensations.push(options.compensate);
360
+ return existing.output;
361
+ }
362
+ const maxAttempts = Math.max(1, options?.retries ?? 1);
363
+ const startedAt = new Date();
364
+ for (let attempt = 1;; attempt += 1) {
365
+ try {
366
+ const output = await fn();
367
+ await this.completeStep({ runId, seq: current, name, kind: 'local', output, attempts: attempt, startedAt });
368
+ if (options?.compensate)
369
+ compensations.push(options.compensate);
370
+ return output;
371
+ }
372
+ catch (err) {
373
+ if (err instanceof errors_1.FatalError || attempt >= maxAttempts) {
374
+ await this.failStep({
375
+ runId,
376
+ seq: current,
377
+ name,
378
+ kind: 'local',
379
+ error: {
380
+ message: err instanceof Error ? err.message : String(err),
381
+ stack: err instanceof Error ? err.stack : undefined,
382
+ },
383
+ attempts: attempt,
384
+ startedAt,
385
+ });
386
+ throw err;
387
+ }
388
+ }
389
+ }
390
+ };
391
+ const sleep = async (duration) => {
392
+ const current = nextSeq();
393
+ const now = this.clock();
394
+ const existing = await store.getCheckpoint(runId, current);
395
+ if (existing) {
396
+ // Timer already recorded: resume if due, otherwise re-suspend cheaply.
397
+ if (now >= (existing.wakeAt ?? 0))
398
+ return;
399
+ throw new errors_1.WorkflowSuspended(existing.wakeAt ?? now);
400
+ }
401
+ const wakeAt = now + (0, duration_1.parseDuration)(duration);
402
+ await this.recordTimer(runId, current, 'sleep', wakeAt);
403
+ throw new errors_1.WorkflowSuspended(wakeAt);
404
+ };
405
+ // NOTE (determinism): a bounded wait consumes TWO logical positions (deadline + wait), an
406
+ // unbounded one consumes ONE. So adding or removing `{ timeoutMs }` on an existing
407
+ // `waitForSignal` shifts the seq of every later step — treat it as a workflow-version change
408
+ // (register a new @Workflow version) for runs already in flight.
409
+ const waitForSignal = async (token, opts) => {
410
+ if (opts?.timeoutMs == null) {
411
+ const current = nextSeq();
412
+ const existing = await store.getCheckpoint(runId, current);
413
+ if (existing && existing.status === 'completed')
414
+ return existing.output;
415
+ await store.putSignalWaiter({ token, runId, seq: current });
416
+ throw new errors_1.WorkflowSuspended();
417
+ }
418
+ const timeoutMs = opts.timeoutMs;
419
+ const deadlineSeq = nextSeq();
420
+ const waitSeq = nextSeq();
421
+ // The deadline is recorded durably as a timer checkpoint so replay knows it; the run also gets
422
+ // a run-level wakeAt (via WorkflowSuspended) so the timer poller resumes it at the deadline.
423
+ const recorded = await store.getCheckpoint(runId, deadlineSeq);
424
+ const deadline = recorded?.wakeAt ?? this.clock() + timeoutMs;
425
+ if (!recorded)
426
+ await this.recordTimer(runId, deadlineSeq, `timeout:${token}`, deadline);
427
+ const waited = await store.getCheckpoint(runId, waitSeq);
428
+ if (waited && waited.status === 'completed')
429
+ return waited.output;
430
+ if (this.clock() >= deadline) {
431
+ await store.takeSignalWaiter(token).catch(() => undefined);
432
+ throw new errors_1.SignalTimeoutError(token, timeoutMs);
433
+ }
434
+ await store.putSignalWaiter({ token, runId, seq: waitSeq });
435
+ throw new errors_1.WorkflowSuspended(deadline);
436
+ };
437
+ // An external task = a checkpointed dispatch + a wait for its async-completion `Completion`
438
+ // (delivered by engine.completeTask/failTask). The whole "fire at a foreign system, suspend,
439
+ // resume when it reports back" pattern as one call.
440
+ const task = async (name, dispatch, options) => {
441
+ await step(`task:dispatch:${name}`, dispatch, options);
442
+ return unwrapCompletion(await waitForSignal(`task:${runId}:${name}`), `task "${name}"`);
443
+ };
444
+ // Child workflow: start it once, then suspend on a `child:<id>` waiter the child signals on its
445
+ // terminal state (see notifyParent). The start is deferred to a microtask so it runs AFTER this
446
+ // run suspends — a fast child can't reentrantly resume a parent that's still running.
447
+ const child = async (workflow, input, childId) => {
448
+ const current = nextSeq();
449
+ const id = childId ?? `${runId}.child.${current}`;
450
+ const existing = await store.getCheckpoint(runId, current);
451
+ if (existing && existing.status === 'completed') {
452
+ return unwrapCompletion(existing.output, `child "${id}"`);
453
+ }
454
+ await store.putSignalWaiter({ token: `child:${id}`, runId, seq: current });
455
+ if (!(await store.getRun(id))) {
456
+ queueMicrotask(() => {
457
+ void this.start(workflow, input, id).catch(() => undefined);
458
+ });
459
+ }
460
+ throw new errors_1.WorkflowSuspended();
461
+ };
462
+ return {
463
+ runId,
464
+ step,
465
+ sleep,
466
+ waitForSignal,
467
+ task,
468
+ child,
469
+ call: (remote, input) => this.callRemote(runId, nextSeq(), remote, input),
470
+ };
471
+ }
472
+ /** Persist a completed timer checkpoint (a durable sleep / signal deadline) at a logical position. */
473
+ async recordTimer(runId, seq, name, wakeAt) {
474
+ const at = new Date();
475
+ await this.store.saveCheckpoint({
476
+ runId,
477
+ seq,
478
+ name,
479
+ kind: 'sleep',
480
+ stepId: (0, protocol_1.stepId)(runId, seq),
481
+ status: 'completed',
482
+ wakeAt,
483
+ attempts: 1,
484
+ startedAt: at,
485
+ finishedAt: at,
486
+ });
487
+ }
488
+ async callRemote(runId, seq, step, input) {
489
+ const existing = await this.store.getCheckpoint(runId, seq);
490
+ if (existing && existing.status === 'completed') {
491
+ return existing.output;
492
+ }
493
+ if (!this.transport)
494
+ throw new Error('remote steps require a Transport');
495
+ const validInput = step.input.parse(input);
496
+ const id = (0, protocol_1.stepId)(runId, seq);
497
+ const startedAt = new Date();
498
+ // Retry policy differs from a LOCAL step on purpose: a local `ctx.step` retries any non-fatal
499
+ // throw (the work is in-process), but a remote step only re-dispatches on a liveness TIMEOUT
500
+ // (presumed-dead worker). A worker that *reported* an error returned a deterministic verdict, so
501
+ // we surface it to the workflow instead of hammering the worker. Timeout retries need a window
502
+ // to detect death, so they're gated on `timeoutMs` being set.
503
+ const maxAttempts = step.timeoutMs ? Math.max(1, step.retries ?? 1) : 1;
504
+ for (let attempt = 1;; attempt += 1) {
505
+ const resultPromise = new Promise((resolve, reject) => {
506
+ this.pending.set(id, { resolve, reject });
507
+ });
508
+ await this.transport.dispatch({
509
+ runId,
510
+ seq,
511
+ name: step.name,
512
+ stepId: id,
513
+ group: step.group,
514
+ input: validInput,
515
+ attempt,
516
+ });
517
+ try {
518
+ const rawOutput = step.timeoutMs
519
+ ? await this.awaitWithHeartbeat(id, resultPromise, step.timeoutMs)
520
+ : await resultPromise;
521
+ const output = step.output.parse(rawOutput);
522
+ await this.completeStep({
523
+ runId,
524
+ seq,
525
+ name: step.name,
526
+ kind: 'remote',
527
+ output,
528
+ attempts: attempt,
529
+ workerGroup: step.group,
530
+ startedAt,
531
+ });
532
+ return output;
533
+ }
534
+ catch (err) {
535
+ this.pending.delete(id);
536
+ if (err instanceof errors_1.RemoteStepTimeout && attempt < maxAttempts)
537
+ continue;
538
+ throw err;
539
+ }
540
+ }
541
+ }
542
+ /**
543
+ * Await a remote result, but reject with `RemoteStepTimeout` if neither the result nor a heartbeat
544
+ * arrives within `timeoutMs`. Each heartbeat (delivered via `transport.onHeartbeat`) rearms the
545
+ * window, so a worker that keeps beating stays alive past `timeoutMs`.
546
+ */
547
+ awaitWithHeartbeat(id, resultPromise, timeoutMs) {
548
+ return new Promise((resolve, reject) => {
549
+ let timer;
550
+ const cleanup = () => {
551
+ clearTimeout(timer);
552
+ this.heartbeatResets.delete(id);
553
+ };
554
+ const arm = () => {
555
+ timer = setTimeout(() => {
556
+ cleanup();
557
+ this.pending.delete(id);
558
+ reject(new errors_1.RemoteStepTimeout(id, timeoutMs));
559
+ }, timeoutMs);
560
+ timer.unref?.();
561
+ };
562
+ this.heartbeatResets.set(id, () => {
563
+ clearTimeout(timer);
564
+ arm();
565
+ });
566
+ arm();
567
+ resultPromise.then((value) => {
568
+ cleanup();
569
+ resolve(value);
570
+ }, (err) => {
571
+ cleanup();
572
+ reject(err);
573
+ });
574
+ });
575
+ }
576
+ }
577
+ exports.WorkflowEngine = WorkflowEngine;
578
+ /** Raised inside the workflow when a remote worker reports a step failure. */
579
+ class RemoteStepError extends Error {
580
+ stepError;
581
+ constructor(stepError) {
582
+ super(stepError?.message ?? 'remote step failed');
583
+ this.name = 'RemoteStepError';
584
+ this.stepError = stepError;
585
+ }
586
+ }
587
+ exports.RemoteStepError = RemoteStepError;
588
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAC3C,qCAAgG;AAchG,yCAAoC;AAUpC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,OAAe,EAAU,EAAE,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;AAEnF,uGAAuG;AACvG,SAAS,cAAc,CAAC,CAAS,EAAE,CAAS;IAC1C,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IAC3D,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;AAC9D,CAAC;AAcD,uGAAuG;AACvG,SAAS,gBAAgB,CAAI,OAAg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AED,8EAA8E;AAC9E,MAAa,eAAgB,SAAQ,KAAK;IAC/B,SAAS,CAAa;IAC/B,YAAY,SAAqB;QAC/B,KAAK,CAAC,SAAS,EAAE,OAAO,IAAI,oBAAoB,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAPD,0CAOC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Thrown inside a step to signal an unrecoverable failure: the engine will NOT retry it,
3
+ * regardless of the step's `retries` setting, and fails the run immediately. Use it for
4
+ * business errors that retrying cannot fix (e.g. a declined card, invalid input).
5
+ */
6
+ export declare class FatalError extends Error {
7
+ readonly code?: string;
8
+ constructor(message: string, code?: string);
9
+ }
10
+ /**
11
+ * Internal control signal thrown to suspend a run (e.g. on a durable sleep). Not an error the
12
+ * user should throw or catch; the engine uses it to stop execution and persist `wakeAt`.
13
+ */
14
+ export declare class SignalTimeoutError extends Error {
15
+ readonly token: string;
16
+ readonly timeoutMs: number;
17
+ constructor(token: string, timeoutMs: number);
18
+ }
19
+ /**
20
+ * Thrown when a remote step produces no result and no heartbeat within its `timeoutMs` window —
21
+ * i.e. the worker is presumed dead. Subject to the step's `retries` (it's retryable), so the engine
22
+ * re-dispatches before giving up.
23
+ */
24
+ export declare class RemoteStepTimeout extends Error {
25
+ readonly stepId: string;
26
+ readonly timeoutMs: number;
27
+ constructor(stepId: string, timeoutMs: number);
28
+ }
29
+ export declare class WorkflowSuspended extends Error {
30
+ /** Epoch ms to auto-resume (durable sleep), or undefined when waiting on an external signal. */
31
+ readonly wakeAt?: number;
32
+ constructor(wakeAt?: number);
33
+ }
34
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBACX,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAK3C;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBACf,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAM7C;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBACf,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAM9C;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,gGAAgG;IAChG,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,MAAM,CAAC,EAAE,MAAM;CAK5B"}