@voltro/workflow 0.71.0 → 0.72.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.
@@ -1,178 +1,178 @@
1
- import { E as e, F as t, I as n, L as r, M as i, N as a, P as o, T as s, w as c } from "./primitives-DsMsMr5S.js";
2
- import { d as l, f as u, h as d, i as f, m as p, p as m, s as h, u as g } from "./clusterDiagnostics-jpkNVay6.js";
3
- import { Activity as _, DurableClock as v, DurableDeferred as y, Workflow as ee, WorkflowEngine as b } from "@effect/workflow";
4
- import { Cause as x, Effect as S, Either as C, Exit as te, Fiber as ne, FiberRef as re, Layer as ie, Schema as w } from "effect";
5
- import { WorkflowQueuedCancellationResultSchema as ae, WorkflowStartTerminalOutcomeSchema as oe, publishServerError as se } from "@voltro/protocol";
6
- import { and as T, boolean as E, derivedRowId as D, eq as O, generateId as ce, gt as k, gte as le, id as A, inSet as ue, integer as j, isNotNull as de, isNull as M, json as N, lt as fe, or as pe, queryFor as me, reference as he, registerRetention as ge, retentionTtlMsFromEnv as _e, table as P, text as F, timestamp as I } from "@voltro/database";
7
- import { createHash as ve, randomUUID as L } from "node:crypto";
8
- import { WorkflowInstance as ye } from "@effect/workflow/WorkflowEngine";
1
+ import { E as e, F as t, I as n, L as r, M as i, N as a, P as o, T as s, w as c } from "./primitives-bv2JHUfk.js";
2
+ import { _ as l, c as u, d, f, g as p, h as m, i as h, m as g, p as _, s as v, v as ee } from "./clusterDiagnostics-Cwt-WFec.js";
3
+ import { Activity as y, DurableClock as b, DurableDeferred as te, Workflow as ne, WorkflowEngine as re } from "@effect/workflow";
4
+ import { Cause as x, Effect as S, Either as C, Exit as ie, Fiber as ae, FiberRef as oe, Layer as se, Schema as w } from "effect";
5
+ import { WorkflowQueuedCancellationResultSchema as T, WorkflowStartTerminalOutcomeSchema as E, publishServerError as ce } from "@voltro/protocol";
6
+ import { and as D, boolean as le, derivedRowId as ue, eq as O, generateId as k, gt as A, gte as de, id as j, inSet as fe, integer as M, isNotNull as pe, isNull as N, json as P, lt as me, or as he, queryFor as ge, reference as _e, registerRetention as ve, retentionTtlMsFromEnv as ye, table as F, text as I, timestamp as L } from "@voltro/database";
7
+ import { createHash as be, randomUUID as R } from "node:crypto";
8
+ import { WorkflowInstance as xe } from "@effect/workflow/WorkflowEngine";
9
9
  //#region src/inMemoryLayer.ts
10
- var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
11
- id: A({ prefix: "wfrun" }),
12
- tag: F(),
13
- executionId: F().unique(),
14
- status: F().oneOf([
10
+ var Se = re.layerMemory, Ce = F("_voltro_workflow_runs", {
11
+ id: j({ prefix: "wfrun" }),
12
+ tag: I(),
13
+ executionId: I().unique(),
14
+ status: I().oneOf([
15
15
  "running",
16
16
  "succeeded",
17
17
  "failed",
18
18
  "cancelled",
19
19
  "suspended"
20
20
  ]).default("running"),
21
- payload: N(),
22
- workflowVersion: F().nullable(),
23
- workflowPatches: N().nullable(),
24
- runnerEnteredAt: I().nullable(),
25
- runnerGeneration: F().nullable(),
26
- engineDelivery: N().nullable(),
27
- reclaimCount: j().default(0),
28
- output: N().nullable(),
29
- subject: N().nullable(),
30
- source: F().nullable(),
31
- errorTag: F().nullable(),
32
- errorMessage: F().nullable(),
33
- cancelled: E().default(!1),
34
- discardedAt: I().nullable(),
35
- discardedBy: F().nullable(),
36
- startedAt: I().default("now"),
37
- completedAt: I().nullable(),
38
- durationMs: j().nullable(),
39
- traceId: F().nullable(),
40
- parentExecutionId: F().nullable(),
41
- parentGeneration: F().nullable(),
42
- parentClosePolicy: F().oneOf([
21
+ payload: P(),
22
+ workflowVersion: I().nullable(),
23
+ workflowPatches: P().nullable(),
24
+ runnerEnteredAt: L().nullable(),
25
+ runnerGeneration: I().nullable(),
26
+ engineDelivery: P().nullable(),
27
+ reclaimCount: M().default(0),
28
+ output: P().nullable(),
29
+ subject: P().nullable(),
30
+ source: I().nullable(),
31
+ errorTag: I().nullable(),
32
+ errorMessage: I().nullable(),
33
+ cancelled: le().default(!1),
34
+ discardedAt: L().nullable(),
35
+ discardedBy: I().nullable(),
36
+ startedAt: L().default("now"),
37
+ completedAt: L().nullable(),
38
+ durationMs: M().nullable(),
39
+ traceId: I().nullable(),
40
+ parentExecutionId: I().nullable(),
41
+ parentGeneration: I().nullable(),
42
+ parentClosePolicy: I().oneOf([
43
43
  "cancel",
44
44
  "terminate",
45
45
  "abandon"
46
46
  ]).nullable()
47
- }).index(["tag"]).index(["status"]).index(["source"]).index(["startedAt"]).index(["parentExecutionId"]).index(["parentClosePolicy"]), Se = P("_voltro_workflow_run_steps", {
48
- id: A({ prefix: "wfstep" }),
49
- runId: he(() => xe, {
47
+ }).index(["tag"]).index(["status"]).index(["source"]).index(["startedAt"]).index(["parentExecutionId"]).index(["parentClosePolicy"]), we = F("_voltro_workflow_run_steps", {
48
+ id: j({ prefix: "wfstep" }),
49
+ runId: _e(() => Ce, {
50
50
  index: !1,
51
51
  onDelete: "cascade"
52
52
  }),
53
- stepName: F(),
54
- attempt: j().default(1),
55
- status: F().oneOf([
53
+ stepName: I(),
54
+ attempt: M().default(1),
55
+ status: I().oneOf([
56
56
  "running",
57
57
  "succeeded",
58
58
  "failed"
59
59
  ]).default("running"),
60
- input: N().nullable(),
61
- retryPolicy: N().nullable(),
62
- output: N().nullable(),
63
- errorTag: F().nullable(),
64
- errorMessage: F().nullable(),
65
- errorCause: N().nullable(),
66
- startedAt: I().default("now"),
67
- completedAt: I().nullable(),
68
- durationMs: j().nullable()
69
- }).index(["runId", "stepName"]).index(["startedAt"]), Ce = P("_voltro_workflow_run_events", {
70
- id: A({ prefix: "wfev" }),
71
- runId: he(() => xe, {
60
+ input: P().nullable(),
61
+ retryPolicy: P().nullable(),
62
+ output: P().nullable(),
63
+ errorTag: I().nullable(),
64
+ errorMessage: I().nullable(),
65
+ errorCause: P().nullable(),
66
+ startedAt: L().default("now"),
67
+ completedAt: L().nullable(),
68
+ durationMs: M().nullable()
69
+ }).index(["runId", "stepName"]).index(["startedAt"]), Te = F("_voltro_workflow_run_events", {
70
+ id: j({ prefix: "wfev" }),
71
+ runId: _e(() => Ce, {
72
72
  index: !1,
73
73
  onDelete: "cascade"
74
74
  }),
75
- eventType: F(),
76
- payload: N().nullable(),
77
- occurredAt: I().default("now"),
78
- stepName: F().nullable(),
79
- attempt: j().nullable()
80
- }).index(["runId", "occurredAt"]).index(["eventType"]), we = P("_voltro_workflow_start_contexts", {
81
- id: A({ prefix: "wfctx" }),
82
- workflowName: F(),
83
- executionId: F().unique(),
84
- subject: N().nullable(),
85
- traceId: F().nullable(),
86
- source: F().nullable(),
87
- parentExecutionId: F().nullable(),
88
- parentGeneration: F().nullable(),
89
- parentClosePolicy: F().oneOf([
75
+ eventType: I(),
76
+ payload: P().nullable(),
77
+ occurredAt: L().default("now"),
78
+ stepName: I().nullable(),
79
+ attempt: M().nullable()
80
+ }).index(["runId", "occurredAt"]).index(["eventType"]), Ee = F("_voltro_workflow_start_contexts", {
81
+ id: j({ prefix: "wfctx" }),
82
+ workflowName: I(),
83
+ executionId: I().unique(),
84
+ subject: P().nullable(),
85
+ traceId: I().nullable(),
86
+ source: I().nullable(),
87
+ parentExecutionId: I().nullable(),
88
+ parentGeneration: I().nullable(),
89
+ parentClosePolicy: I().oneOf([
90
90
  "cancel",
91
91
  "terminate",
92
92
  "abandon"
93
93
  ]).nullable(),
94
- createdAt: I().default("now")
95
- }).index(["workflowName"]).index(["executionId"]).index(["parentExecutionId"]), Te = P("_voltro_workflow_admission_locks", {
96
- id: A({ prefix: "wfalk" }),
97
- nonce: F()
98
- }).nonReactive(), Ee = P("_voltro_workflow_parent_closures", {
99
- id: A({ prefix: "wfpc" }),
100
- runId: F(),
101
- workflowName: F(),
102
- executionId: F(),
103
- generation: F(),
104
- parentStatus: F().oneOf([
94
+ createdAt: L().default("now")
95
+ }).index(["workflowName"]).index(["executionId"]).index(["parentExecutionId"]), De = F("_voltro_workflow_admission_locks", {
96
+ id: j({ prefix: "wfalk" }),
97
+ nonce: I()
98
+ }).nonReactive(), Oe = F("_voltro_workflow_parent_closures", {
99
+ id: j({ prefix: "wfpc" }),
100
+ runId: I(),
101
+ workflowName: I(),
102
+ executionId: I(),
103
+ generation: I(),
104
+ parentStatus: I().oneOf([
105
105
  "succeeded",
106
106
  "failed",
107
107
  "cancelled"
108
108
  ]),
109
- closedAt: I(),
110
- afterChildId: F().nullable(),
111
- scanHasOpenChildren: E().default(!1),
112
- completedAt: I().nullable()
113
- }).index(["executionId"]).index(["completedAt", "id"]).nonReactive(), De = P("_voltro_workflow_control_requests", {
114
- id: A({ prefix: "wfctl" }),
115
- runId: F(),
116
- workflowName: F(),
117
- executionId: F(),
118
- generation: F(),
119
- operation: F().oneOf([
109
+ closedAt: L(),
110
+ afterChildId: I().nullable(),
111
+ scanHasOpenChildren: le().default(!1),
112
+ completedAt: L().nullable()
113
+ }).index(["executionId"]).index(["completedAt", "id"]).nonReactive(), ke = F("_voltro_workflow_control_requests", {
114
+ id: j({ prefix: "wfctl" }),
115
+ runId: I(),
116
+ workflowName: I(),
117
+ executionId: I(),
118
+ generation: I(),
119
+ operation: I().oneOf([
120
120
  "cancel",
121
121
  "terminate",
122
122
  "resume"
123
123
  ]),
124
- requestedAt: I(),
125
- owner: N().nullable(),
126
- cause: N().nullable(),
127
- parentClosureId: F().nullable(),
128
- resumeJournal: N().nullable(),
129
- dispatchAttempts: j().default(0),
130
- result: N().nullable()
131
- }).index(["runId"]).index(["parentClosureId", "id"]).nonReactive(), Oe = P("_voltro_workflow_failure_reports", {
132
- id: A({ prefix: "wffr" }),
133
- workflowName: F(),
134
- tenantId: F().nullable(),
135
- sourceId: F(),
136
- sourceKind: F().oneOf([
124
+ requestedAt: L(),
125
+ owner: P().nullable(),
126
+ cause: P().nullable(),
127
+ parentClosureId: I().nullable(),
128
+ resumeJournal: P().nullable(),
129
+ dispatchAttempts: M().default(0),
130
+ result: P().nullable()
131
+ }).index(["runId"]).index(["parentClosureId", "id"]).nonReactive(), Ae = F("_voltro_workflow_failure_reports", {
132
+ id: j({ prefix: "wffr" }),
133
+ workflowName: I(),
134
+ tenantId: I().nullable(),
135
+ sourceId: I(),
136
+ sourceKind: I().oneOf([
137
137
  "submission",
138
138
  "intent",
139
139
  "run"
140
140
  ]),
141
- handler: F().nullable(),
142
- callerContext: N().nullable(),
143
- report: N(),
144
- handoffReceiptId: F().nullable(),
145
- handoffAttempt: j().default(0),
146
- acceptedExecutionId: F().nullable()
147
- }).index(["sourceKind", "sourceId"]).nonReactive(), ke = P("_voltro_workflow_submissions", {
148
- id: A({ prefix: "wfsub" }),
149
- workflowName: F(),
150
- tenantId: F().nullable(),
151
- ledgerId: F(),
152
- executionId: F().nullable(),
153
- runId: F().nullable(),
154
- receiptsBound: E().default(!1),
155
- preparedExecutionId: F().nullable(),
156
- dispatchAttempts: j().default(0),
157
- failureId: F().nullable(),
158
- retry: N(),
159
- payload: N(),
160
- callerContext: N().nullable(),
161
- intentIds: N(),
162
- eviction: N().nullable()
163
- }).nonReactive(), Ae = P("_voltro_workflow_start_receipts", {
164
- id: A({ prefix: "wfrc" }),
165
- workflowName: F(),
166
- tenantId: F().nullable(),
167
- pendingId: F().maxLength(64),
168
- submissionId: F().maxLength(64).nullable(),
169
- terminal: N().nullable()
170
- }).index(["pendingId"]).nonReactive(), je = P("_voltro_workflow_pending", {
171
- id: A({ prefix: "wfp" }),
172
- tenantId: F().nullable(),
173
- workflowName: F(),
174
- controlKey: F(),
175
- mode: F().oneOf([
141
+ handler: I().nullable(),
142
+ callerContext: P().nullable(),
143
+ report: P(),
144
+ handoffReceiptId: I().nullable(),
145
+ handoffAttempt: M().default(0),
146
+ acceptedExecutionId: I().nullable()
147
+ }).index(["sourceKind", "sourceId"]).nonReactive(), je = F("_voltro_workflow_submissions", {
148
+ id: j({ prefix: "wfsub" }),
149
+ workflowName: I(),
150
+ tenantId: I().nullable(),
151
+ ledgerId: I(),
152
+ executionId: I().nullable(),
153
+ runId: I().nullable(),
154
+ receiptsBound: le().default(!1),
155
+ preparedExecutionId: I().nullable(),
156
+ dispatchAttempts: M().default(0),
157
+ failureId: I().nullable(),
158
+ retry: P(),
159
+ payload: P(),
160
+ callerContext: P().nullable(),
161
+ intentIds: P(),
162
+ eviction: P().nullable()
163
+ }).nonReactive(), Me = F("_voltro_workflow_start_receipts", {
164
+ id: j({ prefix: "wfrc" }),
165
+ workflowName: I(),
166
+ tenantId: I().nullable(),
167
+ pendingId: I().maxLength(64),
168
+ submissionId: I().maxLength(64).nullable(),
169
+ terminal: P().nullable()
170
+ }).index(["pendingId"]).nonReactive(), Ne = F("_voltro_workflow_pending", {
171
+ id: j({ prefix: "wfp" }),
172
+ tenantId: I().nullable(),
173
+ workflowName: I(),
174
+ controlKey: I(),
175
+ mode: I().oneOf([
176
176
  "debounce",
177
177
  "batch",
178
178
  "throttle",
@@ -180,24 +180,24 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
180
180
  "paused",
181
181
  "delayed"
182
182
  ]),
183
- payload: N(),
184
- callerContext: N().nullable(),
185
- queuedAppVersion: F().nullable(),
186
- queuedSchemaFingerprint: F().nullable(),
187
- priority: j().default(0),
188
- dueAt: I(),
189
- deadlineAt: I().nullable(),
190
- collapsed: j().default(1),
191
- firstSeenAt: I().default("now"),
192
- updatedAt: I().default("now"),
193
- attempts: j().default(0),
194
- lastError: F().nullable(),
195
- deadLetteredAt: I().nullable()
196
- }).index(["workflowName", "controlKey"]).index(["dueAt"]).index(["workflowName", "mode"]).index(["tenantId"]), Me = P("_voltro_workflow_admissions", {
197
- id: A({ prefix: "wfadm" }),
198
- tenantId: F().nullable(),
199
- workflowName: F(),
200
- outcome: F().oneOf([
183
+ payload: P(),
184
+ callerContext: P().nullable(),
185
+ queuedAppVersion: I().nullable(),
186
+ queuedSchemaFingerprint: I().nullable(),
187
+ priority: M().default(0),
188
+ dueAt: L(),
189
+ deadlineAt: L().nullable(),
190
+ collapsed: M().default(1),
191
+ firstSeenAt: L().default("now"),
192
+ updatedAt: L().default("now"),
193
+ attempts: M().default(0),
194
+ lastError: I().nullable(),
195
+ deadLetteredAt: L().nullable()
196
+ }).index(["workflowName", "controlKey"]).index(["dueAt"]).index(["workflowName", "mode"]).index(["tenantId"]), Pe = F("_voltro_workflow_admissions", {
197
+ id: j({ prefix: "wfadm" }),
198
+ tenantId: I().nullable(),
199
+ workflowName: I(),
200
+ outcome: I().oneOf([
201
201
  "admitted",
202
202
  "dropped",
203
203
  "skipped",
@@ -205,77 +205,77 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
205
205
  "expired",
206
206
  "discarded"
207
207
  ]),
208
- mode: F().nullable(),
209
- reason: F().nullable(),
210
- collapsed: j().default(1),
211
- waitedMs: j().nullable(),
212
- executionId: F().nullable(),
213
- runId: F().nullable(),
214
- singletonKey: F().nullable(),
215
- concurrencyKey: F().nullable(),
216
- concurrencyReservation: N().nullable(),
217
- rateKey: F().nullable(),
218
- admittedAt: I().default("now"),
219
- expiresAt: I().nullable(),
220
- releasedAt: I().nullable()
221
- }).index(["workflowName", "admittedAt"]).index(["concurrencyKey", "releasedAt"]).index(["singletonKey", "releasedAt"]).index(["rateKey", "admittedAt"]).index(["executionId"]).index(["tenantId"]), Ne = P("_voltro_workflow_pauses", {
222
- id: A({ prefix: "wfpause" }),
223
- pausedAt: I().default("now"),
224
- pausedBy: F().nullable(),
225
- reason: F().nullable()
226
- }), Pe = "_voltro_workflow_admission_locks", Fe = "deployment", Ie = async (e, t) => (await e.insertIgnoreWithOutcome(Pe, {
227
- id: Fe,
228
- nonce: L()
208
+ mode: I().nullable(),
209
+ reason: I().nullable(),
210
+ collapsed: M().default(1),
211
+ waitedMs: M().nullable(),
212
+ executionId: I().nullable(),
213
+ runId: I().nullable(),
214
+ singletonKey: I().nullable(),
215
+ concurrencyKey: I().nullable(),
216
+ concurrencyReservation: P().nullable(),
217
+ rateKey: I().nullable(),
218
+ admittedAt: L().default("now"),
219
+ expiresAt: L().nullable(),
220
+ releasedAt: L().nullable()
221
+ }).index(["workflowName", "admittedAt"]).index(["concurrencyKey", "releasedAt"]).index(["singletonKey", "releasedAt"]).index(["rateKey", "admittedAt"]).index(["executionId"]).index(["tenantId"]), Fe = F("_voltro_workflow_pauses", {
222
+ id: j({ prefix: "wfpause" }),
223
+ pausedAt: L().default("now"),
224
+ pausedBy: I().nullable(),
225
+ reason: I().nullable()
226
+ }), Ie = "_voltro_workflow_admission_locks", Le = "deployment", Re = async (e, t) => (await e.insertIgnoreWithOutcome(Ie, {
227
+ id: Le,
228
+ nonce: R()
229
229
  }, { conflictColumns: ["id"] }), e.transactional(async (e) => {
230
230
  if ((await e.query({
231
231
  table: "_voltro_workflow_admission_locks",
232
- predicate: O("id", Fe),
232
+ predicate: O("id", Le),
233
233
  lock: "update",
234
234
  order: [],
235
235
  take: 1,
236
236
  skip: void 0,
237
237
  projection: void 0
238
238
  })).length !== 1) throw Error("Admission coordinator row is missing; refusing an unlocked decision");
239
- if (await e.update("_voltro_workflow_admission_locks", Fe, { nonce: L() }) === null) throw Error("Admission coordinator row disappeared; refusing an unlocked decision");
239
+ if (await e.update("_voltro_workflow_admission_locks", Le, { nonce: R() }) === null) throw Error("Admission coordinator row disappeared; refusing an unlocked decision");
240
240
  return t(e);
241
- })), Le = class extends Error {
241
+ })), ze = class extends Error {
242
242
  workflowName;
243
243
  field;
244
244
  constructor(e, t, n) {
245
245
  super(`workflow '${e}': ${t}(payload) threw — a flow-control key function must be total over every payload the workflow accepts, because it runs before the run exists and there is nowhere to report a partial failure to. Cause: ${n instanceof Error ? n.message : String(n)}`), this.name = "FlowControlKeyError", this.workflowName = e, this.field = t, this.cause = n;
246
246
  }
247
- }, Re = (e, t, n, r) => {
247
+ }, Be = (e, t, n, r) => {
248
248
  try {
249
249
  let e = n(r);
250
250
  if (typeof e != "string" || e.length === 0) throw Error(`returned ${e === "" ? "an empty string" : String(e)}; expected a non-empty string`);
251
251
  return e;
252
252
  } catch (n) {
253
- throw new Le(e, t, n);
253
+ throw new ze(e, t, n);
254
254
  }
255
- }, ze = (e, t) => JSON.stringify([e ?? null, t]), R = (e, t) => {
255
+ }, Ve = (e, t) => JSON.stringify([e ?? null, t]), He = (e, t) => {
256
256
  let n = e.workflowName, r = 0;
257
257
  if (e.priority !== void 0) try {
258
258
  let n = e.priority(t);
259
259
  if (!Number.isFinite(n)) throw Error(`returned ${String(n)}; expected a finite number`);
260
260
  r = Math.trunc(n);
261
261
  } catch (e) {
262
- throw new Le(n, "priority", e);
262
+ throw new ze(n, "priority", e);
263
263
  }
264
264
  return {
265
- ...e.debounce === void 0 ? {} : { debounceKey: Re(n, "debounce.key", e.debounce.key, t) },
266
- ...e.singleton === void 0 ? {} : { singletonKey: Re(n, "singleton.key", e.singleton.key, t) },
267
- ...e.concurrency === void 0 ? {} : { concurrencyKey: ze(e.concurrency.pool, e.concurrency.key === void 0 ? "" : Re(n, "concurrency.key", e.concurrency.key, t)) },
268
- ...e.throttle?.key === void 0 ? e.throttle === void 0 ? {} : { throttleKey: "" } : { throttleKey: Re(n, "throttle.key", e.throttle.key, t) },
269
- ...e.rateLimit?.key === void 0 ? e.rateLimit === void 0 ? {} : { rateLimitKey: "" } : { rateLimitKey: Re(n, "rateLimit.key", e.rateLimit.key, t) },
270
- ...e.batch?.key === void 0 ? e.batch === void 0 ? {} : { batchKey: "" } : { batchKey: Re(n, "batch.key", e.batch.key, t) },
265
+ ...e.debounce === void 0 ? {} : { debounceKey: Be(n, "debounce.key", e.debounce.key, t) },
266
+ ...e.singleton === void 0 ? {} : { singletonKey: Be(n, "singleton.key", e.singleton.key, t) },
267
+ ...e.concurrency === void 0 ? {} : { concurrencyKey: Ve(e.concurrency.pool, e.concurrency.key === void 0 ? "" : Be(n, "concurrency.key", e.concurrency.key, t)) },
268
+ ...e.throttle?.key === void 0 ? e.throttle === void 0 ? {} : { throttleKey: "" } : { throttleKey: Be(n, "throttle.key", e.throttle.key, t) },
269
+ ...e.rateLimit?.key === void 0 ? e.rateLimit === void 0 ? {} : { rateLimitKey: "" } : { rateLimitKey: Be(n, "rateLimit.key", e.rateLimit.key, t) },
270
+ ...e.batch?.key === void 0 ? e.batch === void 0 ? {} : { batchKey: "" } : { batchKey: Be(n, "batch.key", e.batch.key, t) },
271
271
  priority: r
272
272
  };
273
- }, Be = (e, t, n, r) => {
273
+ }, Ue = (e, t, n, r) => {
274
274
  let i = e.filter((e) => e > r - n);
275
275
  if (i.length < t) return;
276
276
  let a = [...i].sort((e, t) => t - e)[t - 1];
277
277
  if (a !== void 0) return a + n;
278
- }, Ve = (e) => {
278
+ }, We = (e) => {
279
279
  let { control: t, keys: n, state: r, now: i, reconsidering: a } = e;
280
280
  if (r.paused === !0) return {
281
281
  kind: "defer",
@@ -285,7 +285,7 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
285
285
  keys: n
286
286
  };
287
287
  if (t.rateLimit !== void 0) {
288
- let e = Be(r.recentAdmissions ?? [], t.rateLimit.limit, t.rateLimit.periodMs, i);
288
+ let e = Ue(r.recentAdmissions ?? [], t.rateLimit.limit, t.rateLimit.periodMs, i);
289
289
  if (e !== void 0) return {
290
290
  kind: "drop",
291
291
  reason: "rate-limit",
@@ -311,12 +311,12 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
311
311
  kind: "admit",
312
312
  reason: "debounce-deadline",
313
313
  keys: n,
314
- ...Ue(t, r)
314
+ ...Ke(t, r)
315
315
  } : {
316
316
  kind: "admit",
317
317
  reason: "debounce-elapsed",
318
318
  keys: n,
319
- ...Ue(t, r)
319
+ ...Ke(t, r)
320
320
  } : {
321
321
  kind: "defer",
322
322
  mode: "debounce",
@@ -332,12 +332,12 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
332
332
  kind: "admit",
333
333
  reason: "batch-full",
334
334
  keys: n,
335
- ...Ue(t, r)
335
+ ...Ke(t, r)
336
336
  } : a && i >= s ? {
337
337
  kind: "admit",
338
338
  reason: "batch-timeout",
339
339
  keys: n,
340
- ...Ue(t, r)
340
+ ...Ke(t, r)
341
341
  } : {
342
342
  kind: "defer",
343
343
  mode: "batch",
@@ -347,7 +347,7 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
347
347
  };
348
348
  }
349
349
  if (t.throttle !== void 0) {
350
- let e = Be(r.recentAdmissions ?? [], t.throttle.limit, t.throttle.periodMs, i);
350
+ let e = Ue(r.recentAdmissions ?? [], t.throttle.limit, t.throttle.periodMs, i);
351
351
  if (e !== void 0) return {
352
352
  kind: "defer",
353
353
  mode: "throttle",
@@ -364,17 +364,17 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
364
364
  keys: n
365
365
  } : {
366
366
  kind: "admit",
367
- reason: He(t) ? "under-limits" : "no-controls",
367
+ reason: Ge(t) ? "under-limits" : "no-controls",
368
368
  keys: n,
369
- ...Ue(t, r)
369
+ ...Ke(t, r)
370
370
  };
371
- }, He = (e) => e.debounce !== void 0 || e.singleton !== void 0 || e.concurrency !== void 0 || e.throttle !== void 0 || e.rateLimit !== void 0 || e.batch !== void 0, Ue = (e, t) => e.singleton?.mode === "cancel" && t.singletonHolder !== void 0 ? { evict: t.singletonHolder } : {}, We = (e, t, n) => {
371
+ }, Ge = (e) => e.debounce !== void 0 || e.singleton !== void 0 || e.concurrency !== void 0 || e.throttle !== void 0 || e.rateLimit !== void 0 || e.batch !== void 0, Ke = (e, t) => e.singleton?.mode === "cancel" && t.singletonHolder !== void 0 ? { evict: t.singletonHolder } : {}, qe = (e, t, n) => {
372
372
  let r = e.timeouts?.startMs;
373
373
  return r !== void 0 && n - t.firstSeenAt >= r;
374
- }, Ge = (e, t, n) => {
374
+ }, Je = (e, t, n) => {
375
375
  let r = e.timeouts?.finishMs;
376
376
  return r === void 0 || t.terminal ? !1 : n - t.startedAt >= r;
377
- }, Ke = (e, t) => e.priority === t.priority ? e.firstSeenAt === t.firstSeenAt ? e.id < t.id ? -1 : +(e.id > t.id) : e.firstSeenAt - t.firstSeenAt : t.priority - e.priority, qe = "_voltro_workflow_failure_reports", Je = w.Struct({
377
+ }, Ye = (e, t) => e.priority === t.priority ? e.firstSeenAt === t.firstSeenAt ? e.id < t.id ? -1 : +(e.id > t.id) : e.firstSeenAt - t.firstSeenAt : t.priority - e.priority, Xe = "_voltro_workflow_failure_reports", Ze = w.Struct({
378
378
  id: w.String,
379
379
  workflowName: w.String,
380
380
  tenantId: w.NullOr(w.String),
@@ -394,35 +394,35 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
394
394
  })
395
395
  }), z = async (e, t) => {
396
396
  let n = await e.query({
397
- table: qe,
397
+ table: Xe,
398
398
  predicate: O("id", t),
399
399
  order: [],
400
400
  take: 1,
401
401
  skip: void 0,
402
402
  projection: void 0
403
403
  });
404
- return n[0] === void 0 ? void 0 : w.decodeUnknownSync(Je)(n[0]);
405
- }, Ye = async (e, t) => {
404
+ return n[0] === void 0 ? void 0 : w.decodeUnknownSync(Ze)(n[0]);
405
+ }, Qe = async (e, t) => {
406
406
  if (t.id.length === 0 || t.sourceId.length === 0) throw Error("Workflow failure requires a stable report and source identity");
407
407
  let n = await z(e, t.id);
408
408
  if (n !== void 0) {
409
409
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.sourceId !== t.sourceId || n.sourceKind !== t.sourceKind) throw Error("Workflow failure identity belongs to a different source, workflow or tenant");
410
410
  return n;
411
411
  }
412
- let r = w.decodeUnknownSync(Je)(t);
412
+ let r = w.decodeUnknownSync(Ze)(t);
413
413
  if (r.report.workflow !== r.workflowName) throw Error("Workflow failure report does not describe its owning workflow");
414
- return await e.insert(qe, {
414
+ return await e.insert(Xe, {
415
415
  ...r,
416
416
  handoffReceiptId: null,
417
417
  handoffAttempt: 0,
418
418
  acceptedExecutionId: null
419
419
  }), r;
420
- }, Xe = async (e, t, n) => {
421
- let r, i = t === "submissionId" ? O(t, n) : T(O(t, n), M("submissionId"), M("terminal"));
420
+ }, $e = async (e, t, n) => {
421
+ let r, i = t === "submissionId" ? O(t, n) : D(O(t, n), N("submissionId"), N("terminal"));
422
422
  for (;;) {
423
423
  let t = await e.query({
424
- table: Tt,
425
- predicate: r === void 0 ? i : T(i, k("id", r)),
424
+ table: Dt,
425
+ predicate: r === void 0 ? i : D(i, A("id", r)),
426
426
  order: [{
427
427
  column: "id",
428
428
  direction: "asc"
@@ -433,8 +433,8 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
433
433
  });
434
434
  if (t.length === 0) return !1;
435
435
  for (let n of t) {
436
- let t = V(n), i = await e.query({
437
- table: qe,
436
+ let t = kt(n), i = await e.query({
437
+ table: Xe,
438
438
  predicate: O("handoffReceiptId", t.id),
439
439
  order: [],
440
440
  take: 1,
@@ -448,36 +448,36 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
448
448
  r = t.id;
449
449
  }
450
450
  }
451
- }, Ze = (e, t) => Xe(e, "submissionId", t), Qe = (e, t) => Xe(e, "pendingId", t), $e = async (e, t, n, r) => {
452
- for await (let i of ft(e, t, n)) {
451
+ }, et = (e, t) => $e(e, "submissionId", t), tt = (e, t) => $e(e, "pendingId", t), nt = async (e, t, n, r) => {
452
+ for await (let i of mt(e, t, n)) {
453
453
  if (i.tenantId !== r) throw Error("Failure delivery belongs to a different resident tenant");
454
- if (await Ze(e, i.id)) return !0;
454
+ if (await et(e, i.id)) return !0;
455
455
  }
456
456
  return !1;
457
- }, et = w.Struct({
457
+ }, rt = w.Struct({
458
458
  handoffReceiptId: w.NullOr(w.String),
459
459
  handoffAttempt: w.NonNegativeInt,
460
460
  acceptedExecutionId: w.NullOr(w.NonEmptyString)
461
- }), tt = (e, t) => `wfrc_${ve("sha256").update(JSON.stringify([
461
+ }), it = (e, t) => `wfrc_${be("sha256").update(JSON.stringify([
462
462
  "failure",
463
463
  e,
464
464
  t
465
- ])).digest("hex").slice(0, 40)}`, nt = async (e, t) => {
465
+ ])).digest("hex").slice(0, 40)}`, at = async (e, t) => {
466
466
  let n = await e.query({
467
- table: qe,
467
+ table: Xe,
468
468
  predicate: O("id", t),
469
469
  order: [],
470
470
  take: 1,
471
471
  skip: void 0,
472
472
  projection: void 0
473
- }), r = w.decodeUnknownSync(et)(n[0]);
473
+ }), r = w.decodeUnknownSync(rt)(n[0]);
474
474
  if (r.handoffReceiptId === null && (r.handoffAttempt !== 0 || r.acceptedExecutionId !== null)) throw Error("Failure report has contradictory unstarted handoff metadata");
475
475
  return r;
476
- }, rt = async (e, t, n, r, i) => {
476
+ }, ot = async (e, t, n, r, i) => {
477
477
  if (t.handler === null || t.handler.length === 0) throw Error("Cannot queue an unconfigured failure handler");
478
478
  if (!Number.isSafeInteger(n) || n < 0) throw Error("Failure handoff attempt exhausted");
479
479
  if (!Number.isFinite(r)) throw Error("Failure handoff retry deadline is invalid");
480
- let a = await Ht({
480
+ let a = await Gt({
481
481
  store: e,
482
482
  workflowName: t.handler,
483
483
  payload: t.report,
@@ -485,8 +485,8 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
485
485
  tenantId: t.tenantId,
486
486
  at: r,
487
487
  now: i
488
- }), o = await kt(e, {
489
- id: tt(t.id, n),
488
+ }), o = await Mt(e, {
489
+ id: it(t.id, n),
490
490
  workflowName: t.handler,
491
491
  tenantId: t.tenantId,
492
492
  pendingId: a.intentId
@@ -500,20 +500,20 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
500
500
  receiptId: o.id,
501
501
  intentId: o.pendingId
502
502
  };
503
- }, it = async (e, t, n) => {
503
+ }, B = async (e, t, n) => {
504
504
  if (!Number.isFinite(n)) throw Error("Failure handoff requires a finite timestamp");
505
505
  let r = await z(e, t);
506
506
  if (r === void 0) throw Error("Cannot hand off an unknown workflow failure");
507
- let { handoffReceiptId: i, handoffAttempt: a, acceptedExecutionId: o } = await nt(e, t);
507
+ let { handoffReceiptId: i, handoffAttempt: a, acceptedExecutionId: o } = await at(e, t);
508
508
  if (r.handler === null) {
509
509
  if (i !== null || o !== null) throw Error("Unconfigured failure report has a contradictory handoff");
510
510
  return { kind: "unconfigured" };
511
511
  }
512
512
  if (r.handler.length === 0) throw Error("Failure report has an empty handler");
513
- let s = tt(t, a);
513
+ let s = it(t, a);
514
514
  if (i !== null) {
515
515
  if (i !== s) throw Error("Failure handoff receipt belongs to a different report");
516
- let t = await Dt(e, i);
516
+ let t = await At(e, i);
517
517
  if (t === void 0 || t.workflowName !== r.handler || t.tenantId !== r.tenantId) throw Error("Failure report has no matching durable start receipt");
518
518
  return {
519
519
  kind: "queued",
@@ -521,16 +521,16 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
521
521
  intentId: t.pendingId
522
522
  };
523
523
  }
524
- return rt(e, r, 0, n, n);
525
- }, at = class extends Error {
524
+ return ot(e, r, 0, n, n);
525
+ }, st = class extends Error {
526
526
  reason;
527
527
  constructor(e) {
528
528
  super(`Workflow failure delivery requires reconciliation: ${e}`), this.reason = e;
529
529
  }
530
- }, ot = async (e, t, n) => {
531
- let r = await it(e, t, n);
530
+ }, ct = async (e, t, n) => {
531
+ let r = await B(e, t, n);
532
532
  if (r.kind === "unconfigured") return r;
533
- let i = await nt(e, t), a = await Dt(e, r.receiptId);
533
+ let i = await at(e, t), a = await At(e, r.receiptId);
534
534
  if (a === void 0) throw Error("Failure handoff receipt disappeared during reconciliation");
535
535
  if (i.acceptedExecutionId !== null) {
536
536
  if (a.terminal !== null || a.submissionId === null) throw Error("Accepted failure report has no submitted receipt");
@@ -546,8 +546,8 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
546
546
  };
547
547
  let r = await z(e, t);
548
548
  if (r === void 0) throw Error("Failure report disappeared during retry");
549
- let o = i.handoffAttempt + 1, s = Math.max(Zt(o, () => 1), a.terminal.kind === "dropped" ? a.terminal.retryAfterMs : 0);
550
- return rt(e, r, o, Math.max(n, a.terminal.at + s), n);
549
+ let o = i.handoffAttempt + 1, s = Math.max(en(o, () => 1), a.terminal.kind === "dropped" ? a.terminal.retryAfterMs : 0);
550
+ return ot(e, r, o, Math.max(n, a.terminal.at + s), n);
551
551
  }
552
552
  if (a.submissionId === null) {
553
553
  let t = (await e.query({
@@ -558,20 +558,20 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
558
558
  skip: void 0,
559
559
  projection: void 0
560
560
  }))[0];
561
- if (t === void 0) throw new at("arrival-missing");
562
- if (t.workflowName !== a.workflowName || t.tenantId !== a.tenantId) throw new at("arrival-owner-mismatch");
563
- if (t.deadLetteredAt !== null) throw new at("arrival-dead-lettered");
561
+ if (t === void 0) throw new st("arrival-missing");
562
+ if (t.workflowName !== a.workflowName || t.tenantId !== a.tenantId) throw new st("arrival-owner-mismatch");
563
+ if (t.deadLetteredAt !== null) throw new st("arrival-dead-lettered");
564
564
  return r;
565
565
  }
566
- let o = await B(e, a.submissionId);
566
+ let o = await V(e, a.submissionId);
567
567
  if (o === void 0 || !o.receiptsBound || o.workflowName !== a.workflowName || o.tenantId !== a.tenantId || !o.intentIds.includes(a.pendingId)) throw Error("Failure handoff receipt has no matching admission submission");
568
568
  if (o.failureId !== null) {
569
569
  let r = await z(e, o.failureId);
570
- if (o.executionId !== null || o.dispatchAttempts > 1 || r === void 0 || r.sourceKind !== "submission" || r.sourceId !== o.id || r.workflowName !== o.workflowName || r.tenantId !== o.tenantId || r.report.executionId !== null || r.report.runId !== null) throw new at("rejection-proof-invalid");
570
+ if (o.executionId !== null || o.dispatchAttempts > 1 || r === void 0 || r.sourceKind !== "submission" || r.sourceId !== o.id || r.workflowName !== o.workflowName || r.tenantId !== o.tenantId || r.report.executionId !== null || r.report.runId !== null) throw new st("rejection-proof-invalid");
571
571
  let a = await z(e, t);
572
572
  if (a === void 0) throw Error("Failure report disappeared during rejected handler retry");
573
573
  let s = i.handoffAttempt + 1;
574
- return rt(e, a, s, Math.max(n, r.report.failedAt + Zt(s, () => 1)), n);
574
+ return ot(e, a, s, Math.max(n, r.report.failedAt + en(s, () => 1)), n);
575
575
  }
576
576
  if (o.executionId === null) return r;
577
577
  if (o.failureId !== null || o.executionId.length === 0 || o.preparedExecutionId !== o.executionId) throw Error("Failure handler acknowledgement contradicts its prepared submission");
@@ -580,14 +580,14 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
580
580
  kind: "accepted",
581
581
  executionId: o.executionId
582
582
  };
583
- }, st = w.Struct({
583
+ }, lt = w.Struct({
584
584
  runId: w.NonEmptyString,
585
585
  workflowName: w.NonEmptyString,
586
586
  executionId: w.NonEmptyString,
587
587
  generation: w.NonEmptyString,
588
588
  parentStatus: w.Literal("succeeded", "failed", "cancelled"),
589
589
  closedAt: w.DateFromSelf
590
- }), ct = async (e, t, n) => {
590
+ }), ut = async (e, t, n) => {
591
591
  let [r] = await e.query({
592
592
  table: "_voltro_workflow_runs",
593
593
  predicate: O("executionId", n),
@@ -627,14 +627,14 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
627
627
  projection: void 0
628
628
  });
629
629
  if (i === void 0) return;
630
- let a = w.decodeUnknownSync(st)(i);
630
+ let a = w.decodeUnknownSync(lt)(i);
631
631
  if (a.workflowName !== t || a.executionId !== n) throw Error("Admission acknowledgement belongs to a different resident workflow");
632
632
  if (!Number.isFinite(a.closedAt.getTime())) throw Error("Workflow closure has no valid completion timestamp");
633
633
  return {
634
634
  runId: a.runId,
635
635
  completedAt: a.closedAt
636
636
  };
637
- }, lt = "_voltro_workflow_submissions", ut = w.Struct({
637
+ }, dt = "_voltro_workflow_submissions", ft = w.Struct({
638
638
  id: w.String,
639
639
  workflowName: w.String,
640
640
  tenantId: w.NullOr(w.String),
@@ -658,13 +658,13 @@ var be = b.layerMemory, xe = P("_voltro_workflow_runs", {
658
658
  executionId: w.String,
659
659
  runId: w.String
660
660
  }))
661
- }), dt = w.decodeUnknownSync(ut);
662
- async function* ft(e, t, n) {
661
+ }), pt = w.decodeUnknownSync(ft);
662
+ async function* mt(e, t, n) {
663
663
  let r;
664
664
  for (;;) {
665
- let i = T(O("preparedExecutionId", t), k("dispatchAttempts", 0)), a = await e.query({
666
- table: lt,
667
- predicate: r === void 0 ? i : T(i, k("id", r)),
665
+ let i = D(O("preparedExecutionId", t), A("dispatchAttempts", 0)), a = await e.query({
666
+ table: dt,
667
+ predicate: r === void 0 ? i : D(i, A("id", r)),
668
668
  order: [{
669
669
  column: "id",
670
670
  direction: "asc"
@@ -675,17 +675,17 @@ async function* ft(e, t, n) {
675
675
  });
676
676
  if (a.length === 0) return;
677
677
  for (let e of a) {
678
- let i = dt(e);
678
+ let i = pt(e);
679
679
  if (i.workflowName !== n || !i.receiptsBound || i.failureId !== null || i.executionId !== null && i.executionId !== t) throw Error("Workflow completion has an inconsistent resident submission owner");
680
680
  yield i, r = i.id;
681
681
  }
682
682
  }
683
683
  }
684
- var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e, t, n) => {
684
+ var ht = async (e, t, n) => (await gt(e, t, n)).map((e) => pt(e)), gt = async (e, t, n) => {
685
685
  if (!Number.isSafeInteger(t) || t < 1) throw Error("Submission recovery requires a positive page size");
686
686
  return e.query({
687
- table: lt,
688
- predicate: n === void 0 ? T(O("receiptsBound", !0), M("executionId"), M("failureId")) : T(O("receiptsBound", !0), M("executionId"), M("failureId"), k("id", n)),
687
+ table: dt,
688
+ predicate: n === void 0 ? D(O("receiptsBound", !0), N("executionId"), N("failureId")) : D(O("receiptsBound", !0), N("executionId"), N("failureId"), A("id", n)),
689
689
  order: [{
690
690
  column: "id",
691
691
  direction: "asc"
@@ -694,20 +694,20 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
694
694
  skip: void 0,
695
695
  projection: void 0
696
696
  });
697
- }, B = async (e, t) => {
697
+ }, V = async (e, t) => {
698
698
  let n = await e.query({
699
- table: lt,
699
+ table: dt,
700
700
  predicate: O("id", t),
701
701
  order: [],
702
702
  take: 1,
703
703
  skip: void 0,
704
704
  projection: void 0
705
705
  });
706
- return n[0] === void 0 ? void 0 : w.decodeUnknownSync(ut)(n[0]);
707
- }, ht = async (e, t) => Ie(e, (e) => gt(e, t)), gt = async (e, t) => {
706
+ return n[0] === void 0 ? void 0 : w.decodeUnknownSync(ft)(n[0]);
707
+ }, _t = async (e, t) => Re(e, (e) => vt(e, t)), vt = async (e, t) => {
708
708
  if (t.id.length === 0) throw Error("Admission submission requires a stable non-empty identity");
709
709
  let n = await e.query({
710
- table: lt,
710
+ table: dt,
711
711
  predicate: O("id", t.id),
712
712
  order: [],
713
713
  take: 1,
@@ -715,7 +715,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
715
715
  projection: void 0
716
716
  });
717
717
  if (n[0] !== void 0) {
718
- let e = w.decodeUnknownSync(ut)(n[0]);
718
+ let e = w.decodeUnknownSync(ft)(n[0]);
719
719
  if (e.workflowName !== t.control.workflowName || e.tenantId !== t.tenantId) throw Error("Admission submission identity belongs to a different workflow or tenant");
720
720
  return {
721
721
  kind: "reserved",
@@ -723,7 +723,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
723
723
  reused: !0
724
724
  };
725
725
  }
726
- let r = R(t.control, t.keyPayload), i = await tn({
726
+ let r = He(t.control, t.keyPayload), i = await an({
727
727
  store: e,
728
728
  control: t.control,
729
729
  keys: r,
@@ -752,7 +752,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
752
752
  if (a === void 0) throw Error("Admission reservation has no ledger identity");
753
753
  return {
754
754
  kind: "reserved",
755
- submission: await _t(e, {
755
+ submission: await yt(e, {
756
756
  id: t.id,
757
757
  workflowName: t.control.workflowName,
758
758
  tenantId: t.tenantId,
@@ -764,7 +764,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
764
764
  }),
765
765
  reused: !1
766
766
  };
767
- }, _t = async (e, t) => {
767
+ }, yt = async (e, t) => {
768
768
  if (t.id.length === 0 || t.ledgerId.length === 0) throw Error("Submission requires its reserved admission identity");
769
769
  let n = {
770
770
  ...t,
@@ -783,11 +783,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
783
783
  stoppedAt: null
784
784
  }
785
785
  };
786
- return await e.insert(lt, n), n;
787
- }, vt = async (e, t, n) => Ie(e, (e) => yt(e, t, n)), yt = async (e, t, n) => {
786
+ return await e.insert(dt, n), n;
787
+ }, bt = async (e, t, n) => Re(e, (e) => xt(e, t, n)), xt = async (e, t, n) => {
788
788
  if (n.executionId.length === 0) throw Error("Engine acknowledgement requires an execution identity");
789
789
  let r = await e.query({
790
- table: lt,
790
+ table: dt,
791
791
  predicate: O("id", t),
792
792
  order: [],
793
793
  take: 1,
@@ -795,11 +795,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
795
795
  projection: void 0
796
796
  });
797
797
  if (r[0] === void 0) throw Error("Cannot acknowledge an unknown admission submission");
798
- let i = w.decodeUnknownSync(ut)(r[0]);
798
+ let i = w.decodeUnknownSync(ft)(r[0]);
799
799
  if (i.failureId !== null) throw Error("Cannot acknowledge a permanently rejected admission submission");
800
800
  if (i.preparedExecutionId !== null && i.preparedExecutionId !== n.executionId) throw Error("Engine acknowledgement contradicts the prepared execution identity");
801
801
  if (i.executionId !== null && i.executionId !== n.executionId || i.runId !== null && n.runId !== null && i.runId !== n.runId) throw Error("Admission submission already belongs to a different execution or run");
802
- let a = await ct(e, i.workflowName, n.executionId), o = i.runId ?? n.runId;
802
+ let a = await ut(e, i.workflowName, n.executionId), o = i.runId ?? n.runId;
803
803
  if (a !== void 0 && o !== null && a.runId !== o) throw Error("Admission acknowledgement belongs to a different resident run");
804
804
  let s = {
805
805
  executionId: n.executionId,
@@ -814,9 +814,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
814
814
  ...i,
815
815
  ...s
816
816
  };
817
- }, bt = async (e, t, n) => {
817
+ }, St = async (e, t, n) => {
818
818
  if (n.length === 0) throw Error("Prepared submission requires a non-empty execution identity");
819
- let r = await B(e, t);
819
+ let r = await V(e, t);
820
820
  if (r === void 0) throw Error("Cannot prepare an unknown admission submission");
821
821
  if (!r.receiptsBound || r.failureId !== null) throw Error("Cannot prepare an incomplete or terminal admission submission");
822
822
  if (r.preparedExecutionId !== null) {
@@ -831,15 +831,15 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
831
831
  ...r,
832
832
  preparedExecutionId: n
833
833
  };
834
- }, xt = async (e, t, n, r, i = !1) => {
834
+ }, Ct = async (e, t, n, r, i = !1) => {
835
835
  if (i !== !1 && (!Number.isSafeInteger(i) || i < 1)) throw Error("Submission retry limit must be a positive integer or false");
836
- let a = await B(e, t);
836
+ let a = await V(e, t);
837
837
  if (a === void 0) throw Error("Cannot record failure for an unknown submission");
838
838
  if (a.executionId !== null || a.failureId !== null || a.retry.stoppedAt !== null) return a;
839
839
  let o = a.retry.attempts + 1, s = {
840
840
  attempts: o,
841
841
  lastError: n,
842
- after: r + Zt(o),
842
+ after: r + en(o),
843
843
  stoppedAt: i !== !1 && o >= i ? r : null
844
844
  };
845
845
  if (await e.update("_voltro_workflow_submissions", t, { retry: s }) === null) throw Error("Admission submission disappeared while recording failure");
@@ -847,8 +847,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
847
847
  ...a,
848
848
  retry: s
849
849
  };
850
- }, St = async (e, t, n) => {
851
- let r = await B(e, t);
850
+ }, wt = async (e, t, n) => {
851
+ let r = await V(e, t);
852
852
  if (r === void 0) throw Error("Cannot dispatch an unknown admission submission");
853
853
  if (!r.receiptsBound || r.executionId !== null || r.failureId !== null || r.retry.stoppedAt !== null || r.retry.after > n) return null;
854
854
  let i = r.dispatchAttempts + 1;
@@ -858,23 +858,23 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
858
858
  ...r,
859
859
  dispatchAttempts: i
860
860
  };
861
- }, Ct = async (e, t, n, r) => {
861
+ }, Tt = async (e, t, n, r) => {
862
862
  if (!Number.isSafeInteger(n) || n < 0) throw Error("Invalid submission dispatch attempt");
863
- let i = await B(e, t);
863
+ let i = await V(e, t);
864
864
  if (i === void 0) throw Error("Cannot reject an unknown admission submission");
865
865
  if (i.failureId !== null) {
866
866
  let n = await z(e, i.failureId);
867
867
  if (n === void 0 || n.sourceKind !== "submission" || n.sourceId !== t || n.workflowName !== i.workflowName || n.tenantId !== i.tenantId) throw Error("Rejected submission has no matching durable failure report");
868
- return await it(e, n.id, r.now), n;
868
+ return await B(e, n.id, r.now), n;
869
869
  }
870
870
  if (!i.receiptsBound || i.executionId !== null || i.dispatchAttempts !== n || n > 1) return;
871
- let a = `wffr_${ve("sha256").update(JSON.stringify(["submission", t])).digest("hex").slice(0, 40)}`, o = await Ye(e, {
871
+ let a = `wffr_${be("sha256").update(JSON.stringify(["submission", t])).digest("hex").slice(0, 40)}`, o = await Qe(e, {
872
872
  id: a,
873
873
  sourceKind: "submission",
874
874
  sourceId: t,
875
875
  workflowName: i.workflowName,
876
876
  tenantId: i.tenantId,
877
- handler: await Ze(e, t) ? null : r.handler,
877
+ handler: await et(e, t) ? null : r.handler,
878
878
  callerContext: i.callerContext,
879
879
  report: {
880
880
  workflow: i.workflowName,
@@ -889,31 +889,31 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
889
889
  });
890
890
  if (await e.update("_voltro_workflow_admissions", i.ledgerId, { releasedAt: new Date(r.now) }) === null) throw Error("Rejected admission submission has no lease");
891
891
  if (await e.update("_voltro_workflow_submissions", t, { failureId: a }) === null) throw Error("Admission submission disappeared during rejection");
892
- return await it(e, o.id, r.now), o;
893
- }, wt = async (e, t) => {
892
+ return await B(e, o.id, r.now), o;
893
+ }, Et = async (e, t) => {
894
894
  if (t.failureId === null) throw Error("Workflow submission has no rejection marker");
895
895
  let n = await z(e, t.failureId);
896
896
  if (t.executionId !== null || t.dispatchAttempts > 1 || n === void 0 || n.sourceKind !== "submission" || n.sourceId !== t.id || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.report.executionId !== null || n.report.runId !== null) throw Error("Workflow start rejection has contradictory ownership or execution evidence");
897
897
  return n.id;
898
- }, Tt = "_voltro_workflow_start_receipts", Et = w.Struct({
898
+ }, Dt = "_voltro_workflow_start_receipts", Ot = w.Struct({
899
899
  id: w.String,
900
900
  workflowName: w.String,
901
901
  tenantId: w.NullOr(w.String),
902
902
  pendingId: w.String,
903
903
  submissionId: w.NullOr(w.String),
904
- terminal: w.NullOr(oe)
905
- }).pipe(w.filter((e) => e.submissionId === null || e.terminal === null, { message: () => "A start receipt cannot be both submitted and terminal before admission" })), V = w.decodeUnknownSync(Et), Dt = async (e, t) => {
904
+ terminal: w.NullOr(E)
905
+ }).pipe(w.filter((e) => e.submissionId === null || e.terminal === null, { message: () => "A start receipt cannot be both submitted and terminal before admission" })), kt = w.decodeUnknownSync(Ot), At = async (e, t) => {
906
906
  let n = await e.query({
907
- table: Tt,
907
+ table: Dt,
908
908
  predicate: O("id", t),
909
909
  order: [],
910
910
  take: 1,
911
911
  skip: void 0,
912
912
  projection: void 0
913
913
  });
914
- return n[0] === void 0 ? void 0 : V(n[0]);
915
- }, Ot = async (e, t) => {
916
- let n = await Dt(e, t.receiptId);
914
+ return n[0] === void 0 ? void 0 : kt(n[0]);
915
+ }, jt = async (e, t) => {
916
+ let n = await At(e, t.receiptId);
917
917
  if (n === void 0 || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Workflow start receipt is missing or belongs to another workflow or tenant");
918
918
  if (n.terminal !== null) {
919
919
  if (n.terminal.kind === "abandoned") {
@@ -940,11 +940,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
940
940
  if (r.deadLetteredAt !== void 0) throw Error("Workflow receipt input is dead-lettered; reconciliation required");
941
941
  return { kind: "pending" };
942
942
  }
943
- let r = await B(e, n.submissionId);
943
+ let r = await V(e, n.submissionId);
944
944
  if (r === void 0 || !r.receiptsBound || r.workflowName !== n.workflowName || r.tenantId !== n.tenantId || !r.intentIds.includes(n.pendingId)) throw Error("Workflow receipt has no matching admission submission");
945
945
  if (r.failureId !== null) return {
946
946
  kind: "rejected",
947
- failureId: await wt(e, r)
947
+ failureId: await Et(e, r)
948
948
  };
949
949
  if (r.executionId === null) {
950
950
  if (r.retry.stoppedAt !== null) throw Error("Workflow start acceptance is unresolved; reconciliation required");
@@ -955,24 +955,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
955
955
  kind: "accepted",
956
956
  executionId: r.executionId
957
957
  };
958
- }, kt = async (e, t) => {
958
+ }, Mt = async (e, t) => {
959
959
  if (t.id.length === 0 || t.id === t.pendingId) throw Error("Workflow start receipt requires an identity distinct from its queue slot");
960
- let n = V((await e.insertIgnoreWithOutcome(Tt, {
960
+ let n = kt((await e.insertIgnoreWithOutcome(Dt, {
961
961
  ...t,
962
962
  submissionId: null,
963
963
  terminal: null
964
964
  }, { conflictColumns: ["id"] })).row);
965
965
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.pendingId !== t.pendingId) throw Error("Workflow start receipt identity belongs to a different start");
966
966
  return n;
967
- }, At = async (e, t) => {
968
- let n = await B(e, t);
967
+ }, Nt = async (e, t) => {
968
+ let n = await V(e, t);
969
969
  if (n === void 0) throw Error("Cannot bind receipts to an unknown admission submission");
970
970
  if (n.receiptsBound) return 0;
971
971
  let r = 0;
972
972
  for (let t of new Set(n.intentIds)) for (;;) {
973
973
  let i = await e.query({
974
- table: Tt,
975
- predicate: T(O("pendingId", t), M("submissionId"), M("terminal")),
974
+ table: Dt,
975
+ predicate: D(O("pendingId", t), N("submissionId"), N("terminal")),
976
976
  order: [{
977
977
  column: "id",
978
978
  direction: "asc"
@@ -983,7 +983,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
983
983
  });
984
984
  if (i.length === 0) break;
985
985
  for (let t of i) {
986
- let i = V(t);
986
+ let i = kt(t);
987
987
  if (i.workflowName !== n.workflowName || i.tenantId !== n.tenantId) throw Error("Pending receipt belongs to a different workflow or tenant");
988
988
  if (await e.update("_voltro_workflow_start_receipts", i.id, { submissionId: n.id }) === null) throw Error("Workflow start receipt disappeared during queue transfer");
989
989
  r++;
@@ -992,11 +992,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
992
992
  if (await e.update("_voltro_workflow_submissions", t, { receiptsBound: !0 }) === null) throw Error("Admission submission disappeared during receipt binding");
993
993
  return r;
994
994
  }, H = async (e, t) => {
995
- let n = w.decodeUnknownSync(oe)(t.terminal);
995
+ let n = w.decodeUnknownSync(E)(t.terminal);
996
996
  for (;;) {
997
997
  let r = await e.query({
998
- table: Tt,
999
- predicate: T(O("pendingId", t.pendingId), M("submissionId"), M("terminal")),
998
+ table: Dt,
999
+ predicate: D(O("pendingId", t.pendingId), N("submissionId"), N("terminal")),
1000
1000
  order: [{
1001
1001
  column: "id",
1002
1002
  direction: "asc"
@@ -1007,17 +1007,17 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1007
1007
  });
1008
1008
  if (r.length === 0) return;
1009
1009
  for (let i of r) {
1010
- let r = V(i);
1010
+ let r = kt(i);
1011
1011
  if (r.workflowName !== t.workflowName || r.tenantId !== t.tenantId) throw Error("Terminal receipt belongs to a different workflow or tenant");
1012
1012
  if (await e.update("_voltro_workflow_start_receipts", r.id, { terminal: n }) === null) throw Error("Start receipt disappeared while recording its terminal outcome");
1013
1013
  }
1014
1014
  }
1015
- }, U = "_voltro_workflow_pending", W = "_voltro_workflow_admissions", jt = "_voltro_workflow_pauses", Mt = (e, t, n) => e.encodeWorkflowPayload === void 0 ? n : e.encodeWorkflowPayload(t, n), G = (e, t, n) => e.decodeWorkflowPayload === void 0 ? n : e.decodeWorkflowPayload(t, n), Nt = 864e5, Pt = (e, t, n) => `wfp_${ve("sha256").update(`${e}\u0000${t}\u0000${n}`).digest("hex").slice(0, 40)}`, K = (e) => {
1015
+ }, U = "_voltro_workflow_pending", W = "_voltro_workflow_admissions", Pt = "_voltro_workflow_pauses", Ft = (e, t, n) => e.encodeWorkflowPayload === void 0 ? n : e.encodeWorkflowPayload(t, n), G = (e, t, n) => e.decodeWorkflowPayload === void 0 ? n : e.decodeWorkflowPayload(t, n), It = 864e5, Lt = (e, t, n) => `wfp_${be("sha256").update(`${e}\u0000${t}\u0000${n}`).digest("hex").slice(0, 40)}`, K = (e) => {
1016
1016
  if (e instanceof Date) return e.getTime();
1017
1017
  if (typeof e == "number") return e;
1018
1018
  let t = Date.parse(String(e));
1019
1019
  return Number.isNaN(t) ? 0 : t;
1020
- }, Ft = (e, t) => {
1020
+ }, Rt = (e, t) => {
1021
1021
  let n = typeof e == "number" ? e : Number(e);
1022
1022
  return Number.isFinite(n) ? Math.trunc(n) : t;
1023
1023
  }, q = (e) => ({
@@ -1030,12 +1030,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1030
1030
  callerContext: e.callerContext ?? null,
1031
1031
  queuedAppVersion: e.queuedAppVersion === null || e.queuedAppVersion === void 0 ? null : String(e.queuedAppVersion),
1032
1032
  queuedSchemaFingerprint: e.queuedSchemaFingerprint === null || e.queuedSchemaFingerprint === void 0 ? null : String(e.queuedSchemaFingerprint),
1033
- priority: Ft(e.priority, 0),
1033
+ priority: Rt(e.priority, 0),
1034
1034
  dueAt: K(e.dueAt),
1035
1035
  deadlineAt: e.deadlineAt === null || e.deadlineAt === void 0 ? void 0 : K(e.deadlineAt),
1036
- collapsed: Ft(e.collapsed, 1),
1036
+ collapsed: Rt(e.collapsed, 1),
1037
1037
  firstSeenAt: K(e.firstSeenAt),
1038
- attempts: Ft(e.attempts, 0),
1038
+ attempts: Rt(e.attempts, 0),
1039
1039
  lastError: e.lastError === null || e.lastError === void 0 ? null : String(e.lastError),
1040
1040
  deadLetteredAt: e.deadLetteredAt === null || e.deadLetteredAt === void 0 ? void 0 : K(e.deadLetteredAt)
1041
1041
  }), J = (e, t, n, r) => ({
@@ -1045,11 +1045,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1045
1045
  take: r,
1046
1046
  skip: void 0,
1047
1047
  projection: void 0
1048
- }), It = async (e) => {
1049
- let t = await e.query(J(jt, void 0, [], 1e3));
1048
+ }), zt = async (e) => {
1049
+ let t = await e.query(J(Pt, void 0, [], 1e3));
1050
1050
  return new Set(t.map((e) => String(e.id)));
1051
- }, Lt = async (e, t, n, r) => {
1052
- await e.upsert(jt, {
1051
+ }, Bt = async (e, t, n, r) => {
1052
+ await e.upsert(Pt, {
1053
1053
  id: t,
1054
1054
  pausedAt: /* @__PURE__ */ new Date(),
1055
1055
  pausedBy: n,
@@ -1062,19 +1062,19 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1062
1062
  "reason"
1063
1063
  ]
1064
1064
  });
1065
- }, Rt = async (e, t) => e.delete(jt, t), zt = async (e) => {
1065
+ }, Vt = async (e, t) => e.delete(Pt, t), Ht = async (e) => {
1066
1066
  let { store: t, control: n, keys: r, now: i } = e, a = { paused: e.paused }, o = [];
1067
1067
  n.debounce !== void 0 && r.debounceKey !== void 0 && o.push((async () => {
1068
- let e = (await t.query(J(U, T(O("workflowName", n.workflowName), O("controlKey", r.debounceKey), O("mode", "debounce")), [], 1)))[0];
1068
+ let e = (await t.query(J(U, D(O("workflowName", n.workflowName), O("controlKey", r.debounceKey), O("mode", "debounce")), [], 1)))[0];
1069
1069
  if (e === void 0) return;
1070
1070
  let i = e.deadlineAt === null || e.deadlineAt === void 0 ? void 0 : K(e.deadlineAt);
1071
1071
  a.debouncePending = {
1072
1072
  firstSeenAt: K(e.firstSeenAt),
1073
- collapsed: Ft(e.collapsed, 1),
1073
+ collapsed: Rt(e.collapsed, 1),
1074
1074
  ...i === void 0 ? {} : { deadlineAt: i }
1075
1075
  };
1076
1076
  })()), n.batch !== void 0 && r.batchKey !== void 0 && o.push((async () => {
1077
- let e = await t.query(J(U, T(O("workflowName", n.workflowName), O("controlKey", r.batchKey), O("mode", "batch")), [{
1077
+ let e = await t.query(J(U, D(O("workflowName", n.workflowName), O("controlKey", r.batchKey), O("mode", "batch")), [{
1078
1078
  column: "firstSeenAt",
1079
1079
  direction: "asc"
1080
1080
  }], n.batch.maxSize + 1));
@@ -1083,23 +1083,23 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1083
1083
  firstSeenAt: K(e[0].firstSeenAt)
1084
1084
  });
1085
1085
  })()), n.singleton !== void 0 && r.singletonKey !== void 0 && o.push((async () => {
1086
- let e = await Bt(t, n.workflowName, r.singletonKey, i);
1086
+ let e = await Ut(t, n.workflowName, r.singletonKey, i);
1087
1087
  e === "unacknowledged" ? a.singletonUnacknowledged = !0 : e !== void 0 && (a.singletonHolder = e);
1088
1088
  })()), n.concurrency !== void 0 && r.concurrencyKey !== void 0 && o.push((async () => {
1089
- let e = n.concurrency.pool === void 0 ? [O("workflowName", n.workflowName)] : [], o = await t.query(J(W, T(...e, O("concurrencyKey", r.concurrencyKey), M("releasedAt"), pe(M("executionId"), k("expiresAt", new Date(i)))), [], n.concurrency.limit));
1089
+ let e = n.concurrency.pool === void 0 ? [O("workflowName", n.workflowName)] : [], o = await t.query(J(W, D(...e, O("concurrencyKey", r.concurrencyKey), N("releasedAt"), he(N("executionId"), A("expiresAt", new Date(i)))), [], n.concurrency.limit));
1090
1090
  a.inFlight = o.length;
1091
1091
  })());
1092
1092
  let s = n.rateLimit ?? n.throttle, c = r.rateLimitKey ?? r.throttleKey;
1093
1093
  return s !== void 0 && c !== void 0 && o.push((async () => {
1094
- let e = await t.query(J(W, T(O("workflowName", n.workflowName), O("rateKey", c), O("outcome", "admitted"), k("admittedAt", new Date(i - s.periodMs))), [{
1094
+ let e = await t.query(J(W, D(O("workflowName", n.workflowName), O("rateKey", c), O("outcome", "admitted"), A("admittedAt", new Date(i - s.periodMs))), [{
1095
1095
  column: "admittedAt",
1096
1096
  direction: "desc"
1097
1097
  }], s.limit));
1098
1098
  a.recentAdmissions = e.map((e) => K(e.admittedAt));
1099
1099
  })()), await Promise.all(o), a;
1100
- }, Bt = async (e, t, n, r) => {
1101
- if ((await e.query(J("_voltro_workflow_admissions", T(O("workflowName", t), O("singletonKey", n), M("releasedAt"), M("executionId")), [], 1))).length > 0) return "unacknowledged";
1102
- let i = (await e.query(J(W, T(O("workflowName", t), O("singletonKey", n), M("releasedAt"), k("expiresAt", new Date(r))), [{
1100
+ }, Ut = async (e, t, n, r) => {
1101
+ if ((await e.query(J("_voltro_workflow_admissions", D(O("workflowName", t), O("singletonKey", n), N("releasedAt"), N("executionId")), [], 1))).length > 0) return "unacknowledged";
1102
+ let i = (await e.query(J(W, D(O("workflowName", t), O("singletonKey", n), N("releasedAt"), A("expiresAt", new Date(r))), [{
1103
1103
  column: "admittedAt",
1104
1104
  direction: "desc"
1105
1105
  }], 1)))[0];
@@ -1110,17 +1110,17 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1110
1110
  runId: i.runId === null || i.runId === void 0 ? "" : String(i.runId),
1111
1111
  admittedAt: K(i.admittedAt)
1112
1112
  };
1113
- }, Vt = async (e) => {
1114
- let { store: t, control: n, decision: r, now: i } = e, a = Ut(r.mode, r.keys);
1113
+ }, Wt = async (e) => {
1114
+ let { store: t, control: n, decision: r, now: i } = e, a = Kt(r.mode, r.keys);
1115
1115
  if (r.collapse === "hold") {
1116
- let o = e.existingId ?? Pt(n.workflowName, r.mode, a);
1116
+ let o = e.existingId ?? Lt(n.workflowName, r.mode, a);
1117
1117
  return await t.update(U, o, {
1118
1118
  dueAt: new Date(r.dueAt),
1119
1119
  updatedAt: new Date(i)
1120
1120
  }), o;
1121
1121
  }
1122
1122
  if (r.collapse === "replace") {
1123
- let o = Pt(n.workflowName, r.mode, a);
1123
+ let o = Lt(n.workflowName, r.mode, a);
1124
1124
  return await H(t, {
1125
1125
  pendingId: o,
1126
1126
  workflowName: n.workflowName,
@@ -1135,7 +1135,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1135
1135
  workflowName: n.workflowName,
1136
1136
  controlKey: a,
1137
1137
  mode: r.mode,
1138
- payload: Mt(t, n.workflowName, e.payload),
1138
+ payload: Ft(t, n.workflowName, e.payload),
1139
1139
  callerContext: e.callerContext ?? null,
1140
1140
  queuedAppVersion: e.queuedAppVersion ?? null,
1141
1141
  queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
@@ -1151,14 +1151,14 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1151
1151
  }, {
1152
1152
  conflictColumns: ["id"],
1153
1153
  update: (a) => ({
1154
- payload: Mt(t, n.workflowName, e.payload),
1154
+ payload: Ft(t, n.workflowName, e.payload),
1155
1155
  callerContext: e.callerContext ?? null,
1156
1156
  queuedAppVersion: e.queuedAppVersion ?? null,
1157
1157
  queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
1158
1158
  priority: r.keys.priority,
1159
1159
  dueAt: new Date(r.dueAt),
1160
1160
  deadlineAt: r.deadlineAt === void 0 ? a.deadlineAt ?? null : new Date(r.deadlineAt),
1161
- collapsed: Ft(a.collapsed, 1) + 1,
1161
+ collapsed: Rt(a.collapsed, 1) + 1,
1162
1162
  updatedAt: new Date(i),
1163
1163
  attempts: 0,
1164
1164
  lastError: null,
@@ -1167,12 +1167,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1167
1167
  }), o;
1168
1168
  }
1169
1169
  let o = await t.insert(U, {
1170
- id: `wfpi_${L()}`,
1170
+ id: `wfpi_${R()}`,
1171
1171
  tenantId: e.tenantId,
1172
1172
  workflowName: n.workflowName,
1173
1173
  controlKey: a,
1174
1174
  mode: r.mode,
1175
- payload: Mt(t, n.workflowName, e.payload),
1175
+ payload: Ft(t, n.workflowName, e.payload),
1176
1176
  callerContext: e.callerContext ?? null,
1177
1177
  queuedAppVersion: e.queuedAppVersion ?? null,
1178
1178
  queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
@@ -1187,14 +1187,14 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1187
1187
  deadLetteredAt: null
1188
1188
  });
1189
1189
  return String(o.id);
1190
- }, Ht = async (e) => {
1190
+ }, Gt = async (e) => {
1191
1191
  let t = await e.store.insert(U, {
1192
- id: `wfpi_${L()}`,
1192
+ id: `wfpi_${R()}`,
1193
1193
  tenantId: e.tenantId,
1194
1194
  workflowName: e.workflowName,
1195
1195
  controlKey: "",
1196
1196
  mode: "delayed",
1197
- payload: Mt(e.store, e.workflowName, e.payload),
1197
+ payload: Ft(e.store, e.workflowName, e.payload),
1198
1198
  callerContext: e.callerContext ?? null,
1199
1199
  queuedAppVersion: e.queuedAppVersion ?? null,
1200
1200
  queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
@@ -1212,7 +1212,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1212
1212
  intentId: String(t.id),
1213
1213
  dueAt: e.at
1214
1214
  };
1215
- }, Ut = (e, t) => {
1215
+ }, Kt = (e, t) => {
1216
1216
  switch (e) {
1217
1217
  case "debounce": return t.debounceKey ?? "";
1218
1218
  case "batch": return t.batchKey ?? "";
@@ -1223,7 +1223,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1223
1223
  }
1224
1224
  }, Y = async (e) => {
1225
1225
  let { control: t, keys: n, now: r } = e, i = t.timeouts?.finishMs ?? 864e5, a = await e.store.insert(W, {
1226
- id: `wfad_${L()}`,
1226
+ id: `wfad_${R()}`,
1227
1227
  tenantId: e.tenantId,
1228
1228
  workflowName: t.workflowName,
1229
1229
  outcome: e.outcome,
@@ -1246,16 +1246,16 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1246
1246
  releasedAt: e.outcome === "admitted" ? null : new Date(r)
1247
1247
  });
1248
1248
  return String(a.id);
1249
- }, Wt = async (e, t, n) => {
1249
+ }, qt = async (e, t, n) => {
1250
1250
  let r = !1;
1251
1251
  for (;;) {
1252
- let i = await e.query(J(W, T(O("executionId", t), O("outcome", "admitted"), M("releasedAt")), [], 10));
1252
+ let i = await e.query(J(W, D(O("executionId", t), O("outcome", "admitted"), N("releasedAt")), [], 10));
1253
1253
  if (i.length === 0) return r;
1254
1254
  for (let t of i) if (await e.update("_voltro_workflow_admissions", String(t.id), { releasedAt: new Date(n) }) === null) throw Error("Admission lease disappeared during release");
1255
1255
  r = !0;
1256
1256
  }
1257
- }, Gt = async (e, t, n) => (await Kt(e, t, n)).due, Kt = async (e, t, n) => {
1258
- let r = (await e.query(J(U, M("deadLetteredAt"), [{
1257
+ }, Jt = async (e, t, n) => (await Yt(e, t, n)).due, Yt = async (e, t, n) => {
1258
+ let r = (await e.query(J(U, N("deadLetteredAt"), [{
1259
1259
  column: "priority",
1260
1260
  direction: "desc"
1261
1261
  }, {
@@ -1264,18 +1264,18 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1264
1264
  }], n))).map(q), i;
1265
1265
  for (let e of r) e.dueAt <= t || (i === void 0 || e.dueAt < i) && (i = e.dueAt);
1266
1266
  return {
1267
- due: r.filter((e) => e.dueAt <= t).sort(Ke),
1267
+ due: r.filter((e) => e.dueAt <= t).sort(Ye),
1268
1268
  nextDueAt: i
1269
1269
  };
1270
- }, qt = async (e, t) => (await e.query(J(U, void 0, [{
1270
+ }, Xt = async (e, t) => (await e.query(J(U, void 0, [{
1271
1271
  column: "firstSeenAt",
1272
1272
  direction: "asc"
1273
- }], t))).map(q), Jt = async (e, t) => e.delete(U, t), Yt = async (e, t, n, r) => Ie(e, (e) => Xt(e, t, n, r)), Xt = async (e, t, n, r) => {
1273
+ }], t))).map(q), Zt = async (e, t) => e.delete(U, t), Qt = async (e, t, n, r) => Re(e, (e) => $t(e, t, n, r)), $t = async (e, t, n, r) => {
1274
1274
  let i = (await e.query(J(U, O("id", t), [], 1)))[0];
1275
1275
  if (i === void 0) return !1;
1276
1276
  let a = q(i);
1277
1277
  if (await e.insert(W, {
1278
- id: `wfa_${L()}`,
1278
+ id: `wfa_${R()}`,
1279
1279
  tenantId: a.tenantId,
1280
1280
  workflowName: a.workflowName,
1281
1281
  outcome: "discarded",
@@ -1301,23 +1301,23 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1301
1301
  }
1302
1302
  }), !await e.delete("_voltro_workflow_pending", t)) throw Error("Pending intent disappeared during discard");
1303
1303
  return !0;
1304
- }, Zt = (e, t = Math.random) => {
1304
+ }, en = (e, t = Math.random) => {
1305
1305
  let n = Math.min(1e3 * 2 ** Math.max(0, e - 1), 3e5);
1306
1306
  return Math.round(n / 2 + t() * (n / 2));
1307
- }, Qt = async (e, t, n, r) => {
1307
+ }, tn = async (e, t, n, r) => {
1308
1308
  let i = t.attempts + 1;
1309
1309
  await e.update(U, t.id, {
1310
1310
  attempts: i,
1311
1311
  lastError: n.slice(0, 500),
1312
- dueAt: new Date(r + Zt(i)),
1312
+ dueAt: new Date(r + en(i)),
1313
1313
  updatedAt: new Date(r)
1314
1314
  });
1315
- }, $t = async (e, t, n, r) => await e.update(U, t.id, {
1315
+ }, nn = async (e, t, n, r) => await e.update(U, t.id, {
1316
1316
  attempts: t.attempts + 1,
1317
1317
  lastError: n.slice(0, 500),
1318
1318
  deadLetteredAt: new Date(r),
1319
1319
  updatedAt: new Date(r)
1320
- }) !== null, en = async (e, t, n) => {
1320
+ }) !== null, rn = async (e, t, n) => {
1321
1321
  let r = (await e.query(J(U, O("id", t), [], 1)))[0];
1322
1322
  return r === void 0 || r.deadLetteredAt === null || r.deadLetteredAt === void 0 ? !1 : await e.update(U, t, {
1323
1323
  attempts: 0,
@@ -1326,37 +1326,37 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1326
1326
  dueAt: new Date(n),
1327
1327
  updatedAt: new Date(n)
1328
1328
  }) !== null;
1329
- }, tn = async (e) => {
1330
- let t = await zt({
1329
+ }, an = async (e) => {
1330
+ let t = await Ht({
1331
1331
  store: e.store,
1332
1332
  control: e.control,
1333
1333
  keys: e.keys,
1334
1334
  now: e.now,
1335
1335
  paused: e.paused
1336
1336
  });
1337
- return Ve({
1337
+ return We({
1338
1338
  control: e.control,
1339
1339
  keys: e.keys,
1340
1340
  state: t,
1341
1341
  now: e.now,
1342
1342
  reconsidering: e.reconsidering
1343
1343
  });
1344
- }, nn = async (e, t, n = 1e3) => {
1344
+ }, on = async (e, t, n = 1e3) => {
1345
1345
  let r = await e.query(J(W, void 0, [{
1346
1346
  column: "admittedAt",
1347
1347
  direction: "asc"
1348
1348
  }], n)), i = t.getTime(), a = r.filter((e) => e.releasedAt != null && K(e.admittedAt) < i);
1349
1349
  return await Promise.all(a.map((t) => e.delete(W, String(t.id)))), a.length;
1350
- }, rn = async (e, t) => {
1350
+ }, sn = async (e, t) => {
1351
1351
  if (!Number.isFinite(t.now) || !Number.isFinite(new Date(t.now).getTime())) throw Error("Queued cancellation requires a valid timestamp");
1352
- let n = await Dt(e, t.receiptId);
1352
+ let n = await At(e, t.receiptId);
1353
1353
  if (n === void 0 || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Queued cancellation receipt is missing or belongs to another workflow or tenant");
1354
1354
  if (n.terminal !== null) return {
1355
1355
  kind: "terminal",
1356
1356
  outcome: n.terminal
1357
1357
  };
1358
1358
  if (n.submissionId !== null) {
1359
- let t = await B(e, n.submissionId);
1359
+ let t = await V(e, n.submissionId);
1360
1360
  if (t === void 0 || !t.receiptsBound || t.workflowName !== n.workflowName || t.tenantId !== n.tenantId || !t.intentIds.includes(n.pendingId)) throw Error("Queued cancellation receipt has no matching submission");
1361
1361
  return {
1362
1362
  kind: "submitted",
@@ -1389,7 +1389,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1389
1389
  kind: "terminal",
1390
1390
  outcome: a
1391
1391
  };
1392
- }, an = "_voltro_workflow_parent_closures", X = w.NonEmptyString, on = w.Struct({
1392
+ }, cn = "_voltro_workflow_parent_closures", X = w.NonEmptyString, ln = w.Struct({
1393
1393
  id: X,
1394
1394
  runId: X,
1395
1395
  workflowName: X,
@@ -1400,7 +1400,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1400
1400
  afterChildId: w.NullOr(X),
1401
1401
  scanHasOpenChildren: w.Boolean,
1402
1402
  completedAt: w.NullOr(w.DateFromSelf)
1403
- }), sn = w.Struct({
1403
+ }), un = w.Struct({
1404
1404
  id: X,
1405
1405
  tag: X,
1406
1406
  executionId: X,
@@ -1408,12 +1408,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1408
1408
  runnerGeneration: w.optional(w.NullOr(X)),
1409
1409
  parentGeneration: w.optional(w.NullOr(X)),
1410
1410
  parentClosePolicy: w.NullOr(w.Literal("cancel", "terminate", "abandon"))
1411
- }), cn = async (e, t, n) => {
1411
+ }), dn = async (e, t, n) => {
1412
1412
  if (t.parentClosePolicy !== "cancel" && t.parentClosePolicy !== "terminate") return !1;
1413
1413
  if (typeof t.parentExecutionId != "string" || t.parentExecutionId.length === 0 || typeof t.parentGeneration != "string" || t.parentGeneration.length === 0) throw Error("Child entry requires its original parent execution and generation");
1414
1414
  let r = n ?? (await e.query({
1415
- table: an,
1416
- predicate: T(O("executionId", t.parentExecutionId), O("generation", t.parentGeneration)),
1415
+ table: cn,
1416
+ predicate: D(O("executionId", t.parentExecutionId), O("generation", t.parentGeneration)),
1417
1417
  lock: "update",
1418
1418
  order: [],
1419
1419
  take: 1,
@@ -1421,19 +1421,19 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1421
1421
  projection: void 0
1422
1422
  }))[0];
1423
1423
  if (r === void 0) return !1;
1424
- let i = w.decodeUnknownSync(on)(r);
1424
+ let i = w.decodeUnknownSync(ln)(r);
1425
1425
  if (i.executionId !== t.parentExecutionId || i.generation !== t.parentGeneration) return !1;
1426
- let a = w.decodeUnknownSync(sn)(t), o = D("wfctl", JSON.stringify([
1426
+ let a = w.decodeUnknownSync(un)(t), o = ue("wfctl", JSON.stringify([
1427
1427
  "parent-close",
1428
1428
  i.id,
1429
1429
  a.id
1430
- ])), s = await m(e, o);
1430
+ ])), s = await p(e, o);
1431
1431
  if (s !== void 0) {
1432
1432
  if (s.runId !== a.id || s.workflowName !== a.tag || s.executionId !== a.executionId || s.operation === "resume" || s.cause?.reason !== "parent-close" || s.cause.detail?.closureId !== i.id) throw Error("Parent closure receipt belongs to another child");
1433
1433
  } else {
1434
1434
  if (a.status !== "running" && a.status !== "suspended") return !1;
1435
1435
  if (a.runnerGeneration === void 0 || a.runnerGeneration === null) throw Error("Child entry requires its own generation");
1436
- await h(e, {
1436
+ await u(e, {
1437
1437
  id: o,
1438
1438
  runId: a.id,
1439
1439
  workflowName: a.tag,
@@ -1455,9 +1455,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1455
1455
  });
1456
1456
  }
1457
1457
  return !0;
1458
- }, ln = async (e, t, n = Date.now()) => {
1458
+ }, fn = async (e, t, n = Date.now()) => {
1459
1459
  let [r] = await e.query({
1460
- table: an,
1460
+ table: cn,
1461
1461
  predicate: O("id", t),
1462
1462
  lock: "update",
1463
1463
  order: [],
@@ -1466,7 +1466,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1466
1466
  projection: void 0
1467
1467
  });
1468
1468
  if (r === void 0) throw Error("Parent closure is missing");
1469
- let i = w.decodeUnknownSync(on)(r);
1469
+ let i = w.decodeUnknownSync(ln)(r);
1470
1470
  if (i.completedAt !== null) return {
1471
1471
  scanned: 0,
1472
1472
  controls: 0,
@@ -1475,7 +1475,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1475
1475
  if (!Number.isFinite(n)) throw Error("Parent closure requires a finite completion timestamp");
1476
1476
  let a = await e.query({
1477
1477
  table: "_voltro_workflow_runs",
1478
- predicate: T(O("parentExecutionId", i.executionId), ...i.afterChildId === null ? [] : [k("id", i.afterChildId)]),
1478
+ predicate: D(O("parentExecutionId", i.executionId), ...i.afterChildId === null ? [] : [A("id", i.afterChildId)]),
1479
1479
  lock: "update",
1480
1480
  order: [{
1481
1481
  column: "id",
@@ -1486,10 +1486,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1486
1486
  projection: void 0
1487
1487
  }), o = 0, s = i.scanHasOpenChildren, c = null;
1488
1488
  for (let t of a) {
1489
- let r = w.decodeUnknownSync(sn)(t);
1489
+ let r = w.decodeUnknownSync(un)(t);
1490
1490
  if (c = r.id, r.parentClosePolicy !== null && r.parentClosePolicy !== "abandon") {
1491
1491
  if (r.parentGeneration === void 0 || r.parentGeneration === null) throw Error("Parent closure cannot attribute a child without its parent generation");
1492
- r.parentGeneration === i.generation && ((r.status === "running" || r.status === "suspended") && (s = !0), await cn(e, t, i) && (o++, r.status === "suspended" && typeof r.runnerGeneration == "string" && await hn(e, {
1492
+ r.parentGeneration === i.generation && ((r.status === "running" || r.status === "suspended") && (s = !0), await dn(e, t, i) && (o++, r.status === "suspended" && typeof r.runnerGeneration == "string" && await xn(e, {
1493
1493
  runId: r.id,
1494
1494
  workflowName: r.tag,
1495
1495
  executionId: r.executionId,
@@ -1497,30 +1497,73 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1497
1497
  }, n)));
1498
1498
  }
1499
1499
  }
1500
- let u = a.length < 100, d = u && !s && !await l(e, i.id);
1501
- if (await e.update(an, i.id, {
1502
- afterChildId: u ? null : c,
1503
- scanHasOpenChildren: !u && s,
1504
- completedAt: d ? new Date(n) : null
1500
+ let l = a.length < 100, u = l && !s && !await _(e, i.id);
1501
+ if (await e.update(cn, i.id, {
1502
+ afterChildId: l ? null : c,
1503
+ scanHasOpenChildren: !l && s,
1504
+ completedAt: u ? new Date(n) : null
1505
1505
  }) === null) throw Error("Parent closure disappeared before saving its cursor");
1506
1506
  return {
1507
1507
  scanned: a.length,
1508
1508
  controls: o,
1509
- wrapped: u
1509
+ wrapped: l
1510
1510
  };
1511
- }, un = "_voltro_workflow_runs", dn = w.NullOr(w.Struct({
1511
+ }, pn = F("_voltro_workflow_restart_requests", {
1512
+ id: j({ prefix: "wfrs" }),
1513
+ runId: I(),
1514
+ workflowName: I(),
1515
+ executionId: I(),
1516
+ generation: I(),
1517
+ token: I(),
1518
+ ledgerId: I(),
1519
+ tenantId: I().nullable(),
1520
+ delivery: P(),
1521
+ replies: P(),
1522
+ eviction: P().nullable(),
1523
+ requestedAt: L(),
1524
+ dispatchAttempts: M().default(0),
1525
+ enteredGeneration: I().nullable()
1526
+ }).unique(["runId", "generation"]).unique(["runId", "token"]).nonReactive(), Z = w.NonEmptyString, mn = w.Struct({
1527
+ requestId: Z,
1528
+ restartToken: w.NullOr(Z)
1529
+ }), hn = w.Struct({
1530
+ requestId: Z,
1531
+ replyId: Z
1532
+ });
1533
+ w.Struct({
1534
+ id: Z,
1535
+ runId: Z,
1536
+ workflowName: Z,
1537
+ executionId: Z,
1538
+ generation: Z,
1539
+ token: Z,
1540
+ ledgerId: Z,
1541
+ tenantId: w.NullOr(Z),
1542
+ delivery: mn,
1543
+ replies: w.Array(hn),
1544
+ eviction: w.NullOr(w.Struct({
1545
+ executionId: Z,
1546
+ runId: w.String
1547
+ })),
1548
+ requestedAt: w.DateFromSelf,
1549
+ dispatchAttempts: w.NonNegativeInt,
1550
+ enteredGeneration: w.NullOr(Z)
1551
+ });
1552
+ //#endregion
1553
+ //#region src/runGeneration.ts
1554
+ var gn = "_voltro_workflow_runs", _n = w.NullOr(w.Struct({
1512
1555
  requestId: w.NonEmptyString,
1513
1556
  restartToken: w.NullOr(w.NonEmptyString)
1514
- })), fn = async (e, t, n, r) => {
1557
+ })), vn = async (e, t, n, r) => {
1515
1558
  if (typeof t.id != "string") throw Error("Child entry has no allocated run identity");
1516
1559
  let i = {
1517
1560
  runId: t.id,
1518
1561
  workflowName: n.workflowName,
1519
1562
  executionId: n.executionId,
1520
1563
  generation: n.generation
1521
- }, a = await An(e, i), o = await cn(e, t);
1564
+ }, a = await In(e, i), o = await dn(e, t);
1522
1565
  if (!a && !o) return;
1523
- let s = await _n(e, {
1566
+ let s = await Cn(e, {
1524
1567
  owner: i,
1525
1568
  now: n.now,
1526
1569
  durationMs: 0,
@@ -1533,21 +1576,21 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1533
1576
  previous: r,
1534
1577
  terminalEvent: s.terminalEvent
1535
1578
  };
1536
- }, pn = async (e, t) => {
1579
+ }, yn = async (e, t) => {
1537
1580
  if ([
1538
1581
  t.workflowName,
1539
1582
  t.executionId,
1540
1583
  t.generation
1541
1584
  ].some((e) => e.length === 0) || typeof t.initialRow.id != "string" || t.initialRow.id.length === 0 || !Number.isFinite(t.now)) throw Error("Workflow entry requires allocated identities and a finite timestamp");
1542
1585
  let n = (await e.query({
1543
- table: un,
1586
+ table: gn,
1544
1587
  predicate: O("executionId", t.executionId),
1545
1588
  lock: "update",
1546
1589
  order: [],
1547
1590
  take: 1,
1548
1591
  skip: void 0,
1549
1592
  projection: void 0
1550
- }))[0], r = w.decodeUnknownSync(dn)(t.delivery ?? null), i = (r) => fn(e, r, t, n);
1593
+ }))[0], r = w.decodeUnknownSync(_n)(t.delivery ?? null), i = (r) => vn(e, r, t, n);
1551
1594
  if (n === void 0) {
1552
1595
  if (r !== null && r.restartToken !== null) throw Error("Workflow restart delivery has no resident authorization");
1553
1596
  if ((await e.query({
@@ -1559,7 +1602,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1559
1602
  skip: void 0,
1560
1603
  projection: ["id"]
1561
1604
  })).length !== 0) throw Error("Workflow execution is already terminal; restore its engine journal instead of re-entering the body");
1562
- let n = await e.insert(un, {
1605
+ let n = await e.insert(gn, {
1563
1606
  ...t.initialRow,
1564
1607
  tag: t.workflowName,
1565
1608
  executionId: t.executionId,
@@ -1576,7 +1619,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1576
1619
  };
1577
1620
  }
1578
1621
  if (n.tag !== t.workflowName || typeof n.id != "string") throw Error("Workflow entry execution belongs to a different resident run");
1579
- let a = w.decodeUnknownSync(dn)(n.engineDelivery ?? null);
1622
+ let a = w.decodeUnknownSync(_n)(n.engineDelivery ?? null);
1580
1623
  if (a?.requestId !== r?.requestId || a?.restartToken !== r?.restartToken) throw Error("Workflow delivery does not match its resident owner");
1581
1624
  if (n.status === "cancelled") return {
1582
1625
  kind: "already-cancelled",
@@ -1591,8 +1634,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1591
1634
  executionId: t.executionId,
1592
1635
  generation: n.runnerGeneration
1593
1636
  };
1594
- if (await g(e, r)) {
1595
- let i = await _n(e, {
1637
+ if (await f(e, r)) {
1638
+ let i = await Cn(e, {
1596
1639
  owner: r,
1597
1640
  now: t.now,
1598
1641
  durationMs: 0,
@@ -1616,7 +1659,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1616
1659
  if (typeof s != "number" || !Number.isSafeInteger(s) || s < 0) throw Error("Workflow entry has an invalid resident reclaim counter");
1617
1660
  let c = o ? s + 1 : 0;
1618
1661
  if (!Number.isSafeInteger(c)) throw Error("Workflow reclaim counter exhausted");
1619
- let l = await e.update(un, n.id, {
1662
+ let l = await e.update(gn, n.id, {
1620
1663
  runnerGeneration: t.generation,
1621
1664
  runnerEnteredAt: new Date(t.now),
1622
1665
  reclaimCount: c,
@@ -1628,7 +1671,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1628
1671
  });
1629
1672
  if (l === null) throw Error("Workflow run disappeared while entering its new generation");
1630
1673
  let u = await i(l);
1631
- return u === void 0 ? (n.status === "suspended" && n.runnerEnteredAt === null && typeof n.runnerGeneration == "string" && await d(e, {
1674
+ return u === void 0 ? (n.status === "suspended" && n.runnerEnteredAt === null && typeof n.runnerGeneration == "string" && await ee(e, {
1632
1675
  runId: n.id,
1633
1676
  workflowName: t.workflowName,
1634
1677
  executionId: t.executionId,
@@ -1638,7 +1681,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1638
1681
  row: l,
1639
1682
  previous: n
1640
1683
  }) : u;
1641
- }, mn = async (e, t) => {
1684
+ }, bn = async (e, t) => {
1642
1685
  if ([
1643
1686
  t.runId,
1644
1687
  t.workflowName,
@@ -1646,7 +1689,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1646
1689
  t.generation
1647
1690
  ].some((e) => e.length === 0)) throw Error("Workflow runner ownership requires non-empty identities");
1648
1691
  let n = (await e.query({
1649
- table: un,
1692
+ table: gn,
1650
1693
  predicate: O("id", t.runId),
1651
1694
  lock: "update",
1652
1695
  order: [],
@@ -1656,21 +1699,21 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1656
1699
  }))[0];
1657
1700
  if (n === void 0 || n.tag !== t.workflowName || n.executionId !== t.executionId) throw Error("Workflow runner ownership does not match its resident run");
1658
1701
  return n;
1659
- }, hn = async (e, t, n) => {
1660
- let r = await mn(e, t);
1661
- if (r.runnerGeneration !== t.generation || r.status !== "suspended" || r.runnerEnteredAt !== null || !await g(e, t)) return !1;
1662
- if ((await _n(e, {
1702
+ }, xn = async (e, t, n) => {
1703
+ let r = await bn(e, t);
1704
+ if (r.runnerGeneration !== t.generation || r.status !== "suspended" || r.runnerEnteredAt !== null || !await f(e, t)) return !1;
1705
+ if ((await Cn(e, {
1663
1706
  owner: t,
1664
1707
  now: n,
1665
1708
  durationMs: 0,
1666
1709
  outcome: { status: "cancelled" }
1667
1710
  }, "suspended")).kind !== "committed") throw Error("Suspended cancellation lost its resident owner");
1668
1711
  return !0;
1669
- }, gn = async (e, t, n) => {
1670
- let r = await mn(e, t);
1712
+ }, Sn = async (e, t, n) => {
1713
+ let r = await bn(e, t);
1671
1714
  if (r.runnerGeneration !== t.generation) return { kind: "superseded" };
1672
1715
  if (r.status !== "running") return { kind: "not-running" };
1673
- let i = await e.update(un, t.runId, {
1716
+ let i = await e.update(gn, t.runId, {
1674
1717
  status: "suspended",
1675
1718
  runnerEnteredAt: null,
1676
1719
  errorTag: n.errorTag,
@@ -1681,24 +1724,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1681
1724
  kind: "committed",
1682
1725
  row: i
1683
1726
  };
1684
- }, _n = async (e, t, n) => {
1685
- let r = await mn(e, t.owner);
1727
+ }, Cn = async (e, t, n) => {
1728
+ let r = await bn(e, t.owner);
1686
1729
  if (r.runnerGeneration !== t.owner.generation) return { kind: "superseded" };
1687
1730
  if (r.status !== n) return { kind: "not-running" };
1688
1731
  if (!Number.isFinite(t.now) || !Number.isFinite(t.durationMs) || t.durationMs < 0) throw Error("Workflow completion requires finite time and non-negative duration");
1689
1732
  let i = t.outcome, a = null;
1690
- i.status === "failed" && (a = `wffr_${ve("sha256").update(JSON.stringify([
1733
+ if (i.status === "failed" && (a = `wffr_${be("sha256").update(JSON.stringify([
1691
1734
  "run",
1692
1735
  t.owner.workflowName,
1693
1736
  t.owner.runId,
1694
1737
  t.owner.generation
1695
- ])).digest("hex").slice(0, 40)}`, await Ye(e, {
1738
+ ])).digest("hex").slice(0, 40)}`, await Qe(e, {
1696
1739
  id: a,
1697
1740
  sourceKind: "run",
1698
1741
  sourceId: t.owner.runId,
1699
1742
  workflowName: t.owner.workflowName,
1700
1743
  tenantId: i.tenantId,
1701
- handler: await $e(e, t.owner.executionId, t.owner.workflowName, i.tenantId) ? null : i.handler,
1744
+ handler: await nt(e, t.owner.executionId, t.owner.workflowName, i.tenantId) ? null : i.handler,
1702
1745
  callerContext: i.callerContext,
1703
1746
  report: {
1704
1747
  workflow: t.owner.workflowName,
@@ -1710,8 +1753,50 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1710
1753
  reason: "the run failed",
1711
1754
  failedAt: t.now
1712
1755
  }
1713
- }), await it(e, a, t.now));
1714
- let o = await e.update(un, t.owner.runId, {
1756
+ }), await B(e, a, t.now)), i.status === "cancelled") {
1757
+ let n = (await m((t) => e.query({
1758
+ ...t,
1759
+ lock: "update"
1760
+ }), t.owner)).map((e) => ({
1761
+ request: e,
1762
+ cause: d(e)
1763
+ })).find((e) => e.cause !== void 0);
1764
+ if (n !== void 0 && n.cause !== void 0) {
1765
+ let i = w.decodeUnknownOption(w.Struct({ tenantId: w.NullOr(w.String) }))(r.subject), o = n.request.owner?.tenantId ?? (i._tag === "Some" ? i.value.tenantId : null);
1766
+ a = `wffr_${be("sha256").update(JSON.stringify([
1767
+ "finish-timeout",
1768
+ t.owner.workflowName,
1769
+ t.owner.runId,
1770
+ t.owner.generation
1771
+ ])).digest("hex").slice(0, 40)}`, await Qe(e, {
1772
+ id: a,
1773
+ sourceKind: "run",
1774
+ sourceId: t.owner.runId,
1775
+ workflowName: t.owner.workflowName,
1776
+ tenantId: o,
1777
+ handler: await nt(e, t.owner.executionId, t.owner.workflowName, o) ? null : n.cause.detail.onFailure,
1778
+ callerContext: {
1779
+ subject: r.subject ?? null,
1780
+ traceId: r.traceId ?? null,
1781
+ source: r.source ?? null,
1782
+ parentExecutionId: r.parentExecutionId ?? null,
1783
+ parentGeneration: r.parentGeneration ?? null,
1784
+ parentClosePolicy: r.parentClosePolicy ?? null
1785
+ },
1786
+ report: {
1787
+ workflow: t.owner.workflowName,
1788
+ payload: r.payload,
1789
+ errorTag: null,
1790
+ errorMessage: null,
1791
+ runId: t.owner.runId,
1792
+ executionId: t.owner.executionId,
1793
+ reason: n.cause.reason,
1794
+ failedAt: t.now
1795
+ }
1796
+ }), await B(e, a, t.now);
1797
+ }
1798
+ }
1799
+ let o = await e.update(gn, t.owner.runId, {
1715
1800
  status: i.status,
1716
1801
  completedAt: new Date(t.now),
1717
1802
  durationMs: t.durationMs,
@@ -1723,7 +1808,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1723
1808
  });
1724
1809
  if (o === null) throw Error("Workflow run disappeared during terminal recording");
1725
1810
  await e.insert("_voltro_workflow_parent_closures", {
1726
- id: D("wfpc", JSON.stringify([t.owner.runId, t.owner.generation])),
1811
+ id: ue("wfpc", JSON.stringify([t.owner.runId, t.owner.generation])),
1727
1812
  runId: t.owner.runId,
1728
1813
  workflowName: t.owner.workflowName,
1729
1814
  executionId: t.owner.executionId,
@@ -1735,7 +1820,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1735
1820
  completedAt: null
1736
1821
  });
1737
1822
  let s = await e.insert("_voltro_workflow_run_events", {
1738
- id: D("wfev", JSON.stringify([
1823
+ id: ue("wfev", JSON.stringify([
1739
1824
  "terminal",
1740
1825
  t.owner.runId,
1741
1826
  t.owner.generation
@@ -1755,8 +1840,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1755
1840
  } : {}
1756
1841
  }
1757
1842
  });
1758
- await p(e, t), await Wt(e, t.owner.executionId, t.now);
1759
- for await (let n of ft(e, t.owner.executionId, t.owner.workflowName)) {
1843
+ await l(e, t), await qt(e, t.owner.executionId, t.now);
1844
+ for await (let n of mt(e, t.owner.executionId, t.owner.workflowName)) {
1760
1845
  let [r] = await e.query({
1761
1846
  table: W,
1762
1847
  predicate: O("id", n.ledgerId),
@@ -1775,28 +1860,28 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1775
1860
  failureId: a,
1776
1861
  terminalEvent: s
1777
1862
  };
1778
- }, vn = (e, t) => _n(e, t, "running"), yn = P("_voltro_workflow_queued_cancellations", {
1779
- id: A({ prefix: "wfqc" }),
1780
- receiptId: F(),
1781
- workflowName: F(),
1782
- tenantId: F().nullable(),
1783
- requestedAt: I(),
1784
- cause: N().nullable(),
1785
- target: N(),
1786
- controlBinding: N().nullable()
1787
- }).index(["receiptId"]).index(["workflowName", "id"]).nonReactive(), bn = w.NullOr(w.Struct({
1863
+ }, wn = (e, t) => Cn(e, t, "running"), Tn = F("_voltro_workflow_queued_cancellations", {
1864
+ id: j({ prefix: "wfqc" }),
1865
+ receiptId: I(),
1866
+ workflowName: I(),
1867
+ tenantId: I().nullable(),
1868
+ requestedAt: L(),
1869
+ cause: P().nullable(),
1870
+ target: P(),
1871
+ controlBinding: P().nullable()
1872
+ }).index(["receiptId"]).index(["workflowName", "id"]).nonReactive(), En = w.NullOr(w.Struct({
1788
1873
  reason: w.NonEmptyString,
1789
1874
  detail: w.optional(w.Record({
1790
1875
  key: w.String,
1791
1876
  value: w.Unknown
1792
1877
  }))
1793
- })), xn = w.Struct({
1878
+ })), Dn = w.Struct({
1794
1879
  id: w.NonEmptyString,
1795
1880
  receiptId: w.NonEmptyString,
1796
1881
  workflowName: w.NonEmptyString,
1797
1882
  tenantId: w.NullOr(w.String),
1798
1883
  requestedAt: w.DateFromSelf,
1799
- cause: bn,
1884
+ cause: En,
1800
1885
  controlBinding: w.NullOr(w.Struct({
1801
1886
  controlId: w.NonEmptyString,
1802
1887
  runId: w.NonEmptyString,
@@ -1810,14 +1895,14 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1810
1895
  kind: w.Literal("terminal"),
1811
1896
  receipt: w.Unknown
1812
1897
  }))
1813
- }), Sn = (e) => {
1814
- let t = w.decodeUnknownSync(xn)(e);
1898
+ }), On = (e) => {
1899
+ let t = w.decodeUnknownSync(Dn)(e);
1815
1900
  if (!Number.isFinite(t.requestedAt.getTime())) throw Error("Queued cancellation request has an invalid timestamp");
1816
1901
  if (t.target.kind === "submission") return {
1817
1902
  ...t,
1818
1903
  target: t.target
1819
1904
  };
1820
- let n = V(t.target.receipt);
1905
+ let n = kt(t.target.receipt);
1821
1906
  if (t.controlBinding !== null) throw Error("A non-executed start cannot have a run control binding");
1822
1907
  if (n.id !== t.receiptId || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.terminal === null) throw Error("Queued cancellation terminal evidence belongs to another start or is not terminal");
1823
1908
  return {
@@ -1827,9 +1912,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1827
1912
  receipt: n
1828
1913
  }
1829
1914
  };
1830
- }, Cn = async (e, t) => {
1915
+ }, kn = async (e, t) => {
1831
1916
  let [n] = await e.query({
1832
- table: yn.tableName,
1917
+ table: Tn.tableName,
1833
1918
  predicate: O("id", t),
1834
1919
  lock: "update",
1835
1920
  order: [],
@@ -1837,16 +1922,16 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1837
1922
  skip: void 0,
1838
1923
  projection: void 0
1839
1924
  });
1840
- return n === void 0 ? void 0 : Sn(n);
1841
- }, wn = async (e, t) => {
1925
+ return n === void 0 ? void 0 : On(n);
1926
+ }, An = async (e, t) => {
1842
1927
  let n = t.controlBinding;
1843
1928
  if (n === null) throw Error("Queued cancellation has no control binding");
1844
- let r = await m(e, n.controlId);
1929
+ let r = await p(e, n.controlId);
1845
1930
  if (r === void 0 || r.operation !== "cancel" || r.workflowName !== t.workflowName || r.runId !== n.runId || r.executionId !== n.executionId || r.generation !== n.generation || r.owner?.tenantId !== t.tenantId || r.result?.status === "running") throw Error("Queued cancellation lost its original resident control owner");
1846
1931
  return r;
1847
- }, Tn = async (e, t, n) => {
1932
+ }, jn = async (e, t, n) => {
1848
1933
  if (t.controlBinding === null) return;
1849
- let r = await wn(e, t);
1934
+ let r = await An(e, t);
1850
1935
  if (r.result !== null) return;
1851
1936
  let [i] = await e.query({
1852
1937
  table: "_voltro_workflow_runs",
@@ -1857,14 +1942,14 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1857
1942
  skip: void 0,
1858
1943
  projection: void 0
1859
1944
  });
1860
- i !== void 0 && await hn(e, {
1945
+ i !== void 0 && await xn(e, {
1861
1946
  runId: r.runId,
1862
1947
  workflowName: r.workflowName,
1863
1948
  executionId: r.executionId,
1864
1949
  generation: r.generation
1865
1950
  }, n);
1866
- }, En = async (e, t) => {
1867
- let n = await Cn(e, t.requestId);
1951
+ }, Mn = async (e, t) => {
1952
+ let n = await kn(e, t.requestId);
1868
1953
  if (n === void 0) return {
1869
1954
  kind: "unknown",
1870
1955
  reason: "missing-request"
@@ -1880,7 +1965,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1880
1965
  };
1881
1966
  }
1882
1967
  if (n.controlBinding !== null) {
1883
- let t = await wn(e, n);
1968
+ let t = await An(e, n);
1884
1969
  if (t.result !== null) return {
1885
1970
  kind: t.result.kind,
1886
1971
  request: n,
@@ -1914,7 +1999,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1914
1999
  run: r
1915
2000
  };
1916
2001
  }
1917
- let r = await B(e, n.target.submissionId);
2002
+ let r = await V(e, n.target.submissionId);
1918
2003
  if (r === void 0 || !r.receiptsBound || r.workflowName !== n.workflowName || r.tenantId !== n.tenantId) throw Error("Queued cancellation has no matching submission evidence");
1919
2004
  return r.failureId === null ? r.retry.stoppedAt !== null || r.runId !== null ? {
1920
2005
  kind: "unknown",
@@ -1928,10 +2013,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1928
2013
  request: n,
1929
2014
  outcome: {
1930
2015
  kind: "rejected",
1931
- failureId: await wt(e, r)
2016
+ failureId: await Et(e, r)
1932
2017
  }
1933
2018
  };
1934
- }, Dn = (e, t) => {
2019
+ }, Nn = (e, t) => {
1935
2020
  let n = "request" in t ? t.request : void 0;
1936
2021
  if (n !== void 0 && (n.id !== e.requestId || n.receiptId !== e.receiptId || n.workflowName !== e.workflowName)) throw Error("Queued control result belongs to another request or receipt");
1937
2022
  let r = {
@@ -1940,7 +2025,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1940
2025
  receiptId: e.receiptId,
1941
2026
  requestId: n?.id ?? null,
1942
2027
  kind: t.kind
1943
- }, i = w.decodeUnknownSync(ae);
2028
+ }, i = w.decodeUnknownSync(T);
1944
2029
  if (t.kind === "unknown") return i({
1945
2030
  ...r,
1946
2031
  observation: {
@@ -1979,14 +2064,14 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1979
2064
  ...r,
1980
2065
  observation: { kind: "pending" }
1981
2066
  });
1982
- }, On = async (e, t) => {
2067
+ }, Pn = async (e, t) => {
1983
2068
  let n = w.decodeUnknownSync(w.Struct({
1984
2069
  id: w.NonEmptyString,
1985
2070
  receiptId: w.NonEmptyString,
1986
2071
  workflowName: w.NonEmptyString,
1987
2072
  tenantId: w.NullOr(w.String),
1988
2073
  requestedAt: w.DateFromSelf,
1989
- cause: bn
2074
+ cause: En
1990
2075
  }))({
1991
2076
  id: t.requestId,
1992
2077
  receiptId: t.receiptId,
@@ -1996,31 +2081,31 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
1996
2081
  cause: t.cause ?? null
1997
2082
  });
1998
2083
  if (!Number.isFinite(n.requestedAt.getTime())) throw Error("Queued cancellation request requires a valid timestamp");
1999
- let r = await Cn(e, n.id);
2084
+ let r = await kn(e, n.id);
2000
2085
  if (r !== void 0) {
2001
2086
  if (r.receiptId !== n.receiptId || r.workflowName !== n.workflowName || r.tenantId !== n.tenantId) throw Error("Queued cancellation identity belongs to a different start or owner");
2002
- return await Tn(e, r, t.now), r;
2087
+ return await jn(e, r, t.now), r;
2003
2088
  }
2004
- let i = await rn(e, t), a;
2089
+ let i = await sn(e, t), a;
2005
2090
  if (i.kind === "submitted") a = {
2006
2091
  kind: "submission",
2007
2092
  submissionId: i.submissionId
2008
2093
  };
2009
2094
  else {
2010
- let n = await Dt(e, t.receiptId);
2095
+ let n = await At(e, t.receiptId);
2011
2096
  if (n === void 0) throw Error("Cancelled start receipt disappeared during request acceptance");
2012
2097
  a = {
2013
2098
  kind: "terminal",
2014
2099
  receipt: n
2015
2100
  };
2016
2101
  }
2017
- let o = Sn({
2102
+ let o = On({
2018
2103
  ...n,
2019
2104
  target: a,
2020
2105
  controlBinding: null
2021
2106
  });
2022
- if (await e.insert(yn.tableName, o), a.kind === "submission") {
2023
- let n = await B(e, a.submissionId);
2107
+ if (await e.insert(Tn.tableName, o), a.kind === "submission") {
2108
+ let n = await V(e, a.submissionId);
2024
2109
  if (n === void 0) throw Error("Queued cancellation submission disappeared during acceptance");
2025
2110
  if (n.preparedExecutionId !== null && n.dispatchAttempts > 0) {
2026
2111
  let [r] = await e.query({
@@ -2043,14 +2128,14 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2043
2128
  workflowName: n.tag,
2044
2129
  executionId: n.executionId,
2045
2130
  generation: n.runnerGeneration
2046
- }, a = await kn(e, o.id, i);
2047
- return await Tn(e, a.request, t.now), a.request;
2131
+ }, a = await Fn(e, o.id, i);
2132
+ return await jn(e, a.request, t.now), a.request;
2048
2133
  }
2049
2134
  }
2050
2135
  }
2051
2136
  return o;
2052
- }, kn = async (e, t, n) => {
2053
- let r = await Cn(e, t);
2137
+ }, Fn = async (e, t, n) => {
2138
+ let r = await kn(e, t);
2054
2139
  if (r === void 0) throw Error("Queued cancellation request is missing");
2055
2140
  if (r.target.kind === "terminal") return {
2056
2141
  kind: "terminal",
@@ -2059,9 +2144,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2059
2144
  if (r.controlBinding !== null) return {
2060
2145
  kind: "bound",
2061
2146
  request: r,
2062
- control: await wn(e, r)
2147
+ control: await An(e, r)
2063
2148
  };
2064
- let i = await B(e, r.target.submissionId);
2149
+ let i = await V(e, r.target.submissionId);
2065
2150
  if (i === void 0 || i.workflowName !== r.workflowName || i.tenantId !== r.tenantId || !i.receiptsBound || i.failureId !== null || i.dispatchAttempts === 0 || i.preparedExecutionId !== n.executionId || i.executionId !== null && i.executionId !== n.executionId || i.runId !== null && i.runId !== n.runId || n.workflowName !== r.workflowName) throw Error("Queued cancellation has no dispatched submission for this resident execution");
2066
2151
  let [a] = await e.query({
2067
2152
  table: "_voltro_workflow_runs",
@@ -2080,18 +2165,18 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2080
2165
  "cancelled"
2081
2166
  ].includes(String(a.status))) throw Error("Queued cancellation generation or tenant does not match the resident run");
2082
2167
  let s = {
2083
- controlId: D("wfctl", JSON.stringify(["queued-cancel", r.id])),
2168
+ controlId: ue("wfctl", JSON.stringify(["queued-cancel", r.id])),
2084
2169
  runId: n.runId,
2085
2170
  executionId: n.executionId,
2086
2171
  generation: n.generation
2087
- }, c = await h(e, {
2172
+ }, c = await u(e, {
2088
2173
  id: s.controlId,
2089
2174
  ...n,
2090
2175
  operation: "cancel",
2091
2176
  requestedAt: r.requestedAt.getTime(),
2092
2177
  cause: r.cause
2093
2178
  });
2094
- if (await e.update(yn.tableName, r.id, { controlBinding: s }) === null) throw Error("Queued cancellation request disappeared during run binding");
2179
+ if (await e.update(Tn.tableName, r.id, { controlBinding: s }) === null) throw Error("Queued cancellation request disappeared during run binding");
2095
2180
  return {
2096
2181
  kind: "bound",
2097
2182
  request: {
@@ -2100,15 +2185,15 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2100
2185
  },
2101
2186
  control: c
2102
2187
  };
2103
- }, An = async (e, t) => {
2188
+ }, In = async (e, t) => {
2104
2189
  let n = /* @__PURE__ */ new Set();
2105
- for await (let r of ft(e, t.executionId, t.workflowName)) n.add(r.id);
2190
+ for await (let r of mt(e, t.executionId, t.workflowName)) n.add(r.id);
2106
2191
  if (n.size === 0) return !1;
2107
2192
  let r, i = !1;
2108
2193
  for (;;) {
2109
2194
  let a = await e.query({
2110
- table: yn.tableName,
2111
- predicate: T(O("workflowName", t.workflowName), ...r === void 0 ? [] : [k("id", r)]),
2195
+ table: Tn.tableName,
2196
+ predicate: D(O("workflowName", t.workflowName), ...r === void 0 ? [] : [A("id", r)]),
2112
2197
  lock: "update",
2113
2198
  order: [{
2114
2199
  column: "id",
@@ -2119,9 +2204,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2119
2204
  projection: void 0
2120
2205
  });
2121
2206
  for (let o of a) {
2122
- let a = Sn(o);
2207
+ let a = On(o);
2123
2208
  if (r = a.id, a.target.kind !== "submission" || !n.has(a.target.submissionId)) continue;
2124
- let s = await kn(e, a.id, t);
2209
+ let s = await Fn(e, a.id, t);
2125
2210
  if (s.kind === "bound") {
2126
2211
  if (s.control.runId !== t.runId || s.control.executionId !== t.executionId || s.control.workflowName !== t.workflowName) throw Error("Queued cancellation entry does not match its original resident execution");
2127
2212
  s.control.result === null && (i = !0);
@@ -2129,24 +2214,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2129
2214
  }
2130
2215
  if (a.length < 100) return i;
2131
2216
  }
2132
- }, jn = w.Struct({
2217
+ }, Ln = w.Struct({
2133
2218
  requestId: w.NonEmptyString,
2134
2219
  receiptId: w.NonEmptyString,
2135
2220
  workflowName: w.NonEmptyString,
2136
2221
  tenantId: w.NullOr(w.String)
2137
- }), Mn = async (e, t) => {
2138
- let n = w.decodeUnknownSync(jn)(t);
2139
- return await On(e, {
2222
+ }), Rn = async (e, t) => {
2223
+ let n = w.decodeUnknownSync(Ln)(t);
2224
+ return await Pn(e, {
2140
2225
  ...n,
2141
2226
  now: t.now,
2142
2227
  ...t.cause === void 0 ? {} : { cause: t.cause }
2143
- }), Nn(e, n);
2144
- }, Nn = async (e, t) => {
2145
- let n = w.decodeUnknownSync(jn)(t);
2146
- return Dn(n, await En(e, n));
2147
- }, Pn = async (e, t) => {
2228
+ }), zn(e, n);
2229
+ }, zn = async (e, t) => {
2230
+ let n = w.decodeUnknownSync(Ln)(t);
2231
+ return Nn(n, await Mn(e, n));
2232
+ }, Bn = async (e, t) => {
2148
2233
  if (new Set(t.intentIds).size !== t.intentIds.length) throw Error("Admitted transfer requires distinct pending identities");
2149
- let n = await B(e, t.id);
2234
+ let n = await V(e, t.id);
2150
2235
  if (n !== void 0) {
2151
2236
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.ledgerId !== t.ledgerId || !n.receiptsBound) throw Error("Admitted transfer contradicts its existing submission");
2152
2237
  return n;
@@ -2165,16 +2250,16 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2165
2250
  let i = q(r[0]);
2166
2251
  if (i.workflowName !== t.workflowName || i.tenantId !== t.tenantId || i.deadLetteredAt !== void 0) throw Error("Admitted transfer selected a foreign or dead-lettered input");
2167
2252
  }
2168
- let r = await _t(e, t);
2169
- await At(e, r.id);
2253
+ let r = await yt(e, t);
2254
+ await Nt(e, r.id);
2170
2255
  for (let t of r.intentIds) if (!await e.delete("_voltro_workflow_pending", t)) throw Error("Admitted input disappeared during submission transfer");
2171
2256
  return {
2172
2257
  ...r,
2173
2258
  receiptsBound: !0
2174
2259
  };
2175
- }, Fn = async (e, t) => Ie(e, (e) => In(e, t)), In = async (e, t) => {
2260
+ }, Vn = async (e, t) => Re(e, (e) => Hn(e, t)), Hn = async (e, t) => {
2176
2261
  if (t.id.length === 0 || t.intentIds.length === 0 || new Set(t.intentIds).size !== t.intentIds.length) throw Error("Queue transfer requires a submission identity and distinct pending identities");
2177
- let n = await B(e, t.id);
2262
+ let n = await V(e, t.id);
2178
2263
  if (n !== void 0) {
2179
2264
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Admission submission identity belongs to a different workflow or tenant");
2180
2265
  if (!n.receiptsBound) throw Error("Submission exists without completed queue transfer");
@@ -2203,7 +2288,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2203
2288
  }
2204
2289
  let i = t.prepare(r);
2205
2290
  if (i.control.workflowName !== t.workflowName) throw Error("Prepared submission belongs to a different workflow");
2206
- let a = await gt(e, {
2291
+ let a = await vt(e, {
2207
2292
  ...i,
2208
2293
  id: t.id,
2209
2294
  tenantId: t.tenantId,
@@ -2211,7 +2296,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2211
2296
  now: t.now
2212
2297
  });
2213
2298
  if (a.kind !== "reserved") return a;
2214
- await At(e, t.id);
2299
+ await Nt(e, t.id);
2215
2300
  for (let t of r) if (!await e.delete("_voltro_workflow_pending", t.id)) throw Error("Pending start disappeared during queue transfer");
2216
2301
  return {
2217
2302
  ...a,
@@ -2220,8 +2305,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2220
2305
  receiptsBound: !0
2221
2306
  }
2222
2307
  };
2223
- }, Ln = async (e) => {
2224
- let { store: t, control: n, now: r } = e, i = R(n, e.payload), a = await tn({
2308
+ }, Un = async (e) => {
2309
+ let { store: t, control: n, now: r } = e, i = He(n, e.payload), a = await an({
2225
2310
  store: t,
2226
2311
  control: n,
2227
2312
  keys: i,
@@ -2266,7 +2351,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2266
2351
  };
2267
2352
  if (a.kind === "defer") return {
2268
2353
  kind: "queued",
2269
- intentId: await Vt({
2354
+ intentId: await Wt({
2270
2355
  store: t,
2271
2356
  control: n,
2272
2357
  decision: a,
@@ -2282,7 +2367,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2282
2367
  };
2283
2368
  let o = e.payload, s = [], c = 1;
2284
2369
  if (n.batch !== void 0 && i.batchKey !== void 0) {
2285
- let r = await Rn(t, n.workflowName, i.batchKey, n.batch.maxSize);
2370
+ let r = await Wn(t, n.workflowName, i.batchKey, n.batch.maxSize);
2286
2371
  o = { items: [...r.map((e) => e.payload), e.payload] }, s = r.map((e) => e.id), c = r.length + 1;
2287
2372
  }
2288
2373
  return {
@@ -2310,9 +2395,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2310
2395
  runId: a.evict.runId
2311
2396
  } }
2312
2397
  };
2313
- }, Rn = async (e, t, n, r) => (await e.query({
2398
+ }, Wn = async (e, t, n, r) => (await e.query({
2314
2399
  table: "_voltro_workflow_pending",
2315
- predicate: T(O("workflowName", t), O("controlKey", n), O("mode", "batch")),
2400
+ predicate: D(O("workflowName", t), O("controlKey", n), O("mode", "batch")),
2316
2401
  order: [{
2317
2402
  column: "firstSeenAt",
2318
2403
  direction: "asc"
@@ -2323,22 +2408,22 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2323
2408
  })).map((n) => ({
2324
2409
  id: String(n.id),
2325
2410
  payload: G(e, t, n.payload)
2326
- })), zn = async (e, t, n, r) => {
2411
+ })), Gn = async (e, t, n, r) => {
2327
2412
  await e.update("_voltro_workflow_admissions", t, {
2328
2413
  executionId: n,
2329
2414
  runId: r
2330
2415
  });
2331
- }, Bn = P("_voltro_workflow_watermarks", {
2332
- id: A({ prefix: "wfwm" }),
2333
- positionAt: I(),
2334
- updatedAt: I().default("now")
2335
- }), Vn = (e) => {
2416
+ }, Kn = F("_voltro_workflow_watermarks", {
2417
+ id: j({ prefix: "wfwm" }),
2418
+ positionAt: L(),
2419
+ updatedAt: L().default("now")
2420
+ }), qn = (e) => {
2336
2421
  let t = e instanceof Error ? e.message : String(e);
2337
2422
  return t.length > 400 ? `${t.slice(0, 400)}…` : t;
2338
- }, Hn = (e) => {
2423
+ }, Jn = (e) => {
2339
2424
  let t = [], n = [], r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = e.payloadSchema === void 0 ? (e) => C.right(e) : (t) => {
2340
2425
  let n = w.decodeUnknownEither(e.payloadSchema)(t);
2341
- return C.isRight(n) ? C.right(n.right) : C.left(Vn(n.left));
2426
+ return C.isRight(n) ? C.right(n.right) : C.left(qn(n.left));
2342
2427
  }, s = e.runs.map((e) => ({
2343
2428
  run: e,
2344
2429
  decoded: o(e.payload)
@@ -2355,7 +2440,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2355
2440
  workflowName: e.workflowName,
2356
2441
  event: o.event,
2357
2442
  subject: l.id,
2358
- detail: Vn(u.left)
2443
+ detail: qn(u.left)
2359
2444
  });
2360
2445
  continue;
2361
2446
  }
@@ -2375,7 +2460,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2375
2460
  workflowName: e.workflowName,
2376
2461
  event: o.event,
2377
2462
  subject: n,
2378
- detail: Vn(t)
2463
+ detail: qn(t)
2379
2464
  }), !1;
2380
2465
  }
2381
2466
  };
@@ -2398,33 +2483,33 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2398
2483
  discards: n,
2399
2484
  problems: r
2400
2485
  };
2401
- }, Un = (e) => {
2486
+ }, Yn = (e) => {
2402
2487
  let t;
2403
2488
  for (let n of e) (t === void 0 || n.occurredAt.getTime() > t.getTime()) && (t = n.occurredAt);
2404
2489
  return t;
2405
- }, Wn = "_voltro_workflow_watermarks", Gn = "_voltro_workflow_events", Kn = "cancelOn", qn = 36e5, Jn = 500, Yn = (e) => {
2490
+ }, Xn = "_voltro_workflow_watermarks", Zn = "_voltro_workflow_events", Qn = "cancelOn", $n = 36e5, er = 500, tr = (e) => {
2406
2491
  if (e instanceof Date) return e;
2407
2492
  if (typeof e == "number") return new Date(e);
2408
2493
  if (typeof e == "string") {
2409
2494
  let t = new Date(e);
2410
2495
  if (!Number.isNaN(t.getTime())) return t;
2411
2496
  }
2412
- }, Xn = (e) => e instanceof Error ? e.message : String(e), Zn = async (e, t) => Yn((await e.query({
2413
- table: Wn,
2497
+ }, nr = (e) => e instanceof Error ? e.message : String(e), rr = async (e, t) => tr((await e.query({
2498
+ table: Xn,
2414
2499
  predicate: O("id", t),
2415
2500
  order: [],
2416
2501
  take: 1,
2417
2502
  skip: void 0,
2418
2503
  projection: void 0
2419
- }))[0]?.positionAt), Qn = async (e, t, n) => {
2420
- await e.upsert(Wn, {
2504
+ }))[0]?.positionAt), ir = async (e, t, n) => {
2505
+ await e.upsert(Xn, {
2421
2506
  id: t,
2422
2507
  positionAt: n,
2423
2508
  updatedAt: /* @__PURE__ */ new Date()
2424
2509
  }, {
2425
2510
  conflictColumns: ["id"],
2426
2511
  update: (e) => {
2427
- let t = Yn(e.positionAt);
2512
+ let t = tr(e.positionAt);
2428
2513
  return t !== void 0 && t.getTime() >= n.getTime() ? {
2429
2514
  positionAt: t,
2430
2515
  updatedAt: /* @__PURE__ */ new Date()
@@ -2434,10 +2519,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2434
2519
  };
2435
2520
  }
2436
2521
  });
2437
- }, $n = async (e, t, n) => {
2522
+ }, ar = async (e, t, n) => {
2438
2523
  let r = async (r) => e.query({
2439
2524
  table: "_voltro_workflow_runs",
2440
- predicate: T(O("tag", t), O("status", r)),
2525
+ predicate: D(O("tag", t), O("status", r)),
2441
2526
  order: [{
2442
2527
  column: "startedAt",
2443
2528
  direction: "asc"
@@ -2447,7 +2532,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2447
2532
  projection: void 0
2448
2533
  });
2449
2534
  return [...await r("running"), ...await r("suspended")].flatMap((e) => {
2450
- let t = e, n = Yn(t.startedAt);
2535
+ let t = e, n = tr(t.startedAt);
2451
2536
  return typeof t.id != "string" || typeof t.executionId != "string" || n === void 0 ? [] : [{
2452
2537
  runId: t.id,
2453
2538
  executionId: t.executionId,
@@ -2455,7 +2540,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2455
2540
  startedAt: n
2456
2541
  }];
2457
2542
  });
2458
- }, er = async (e, t, n) => (await e.query({
2543
+ }, or = async (e, t, n) => (await e.query({
2459
2544
  table: "_voltro_workflow_pending",
2460
2545
  predicate: O("workflowName", t),
2461
2546
  order: [{
@@ -2466,13 +2551,13 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2466
2551
  skip: void 0,
2467
2552
  projection: void 0
2468
2553
  })).flatMap((e) => {
2469
- let t = e, n = Yn(t.firstSeenAt);
2554
+ let t = e, n = tr(t.firstSeenAt);
2470
2555
  return typeof t.id != "string" || n === void 0 ? [] : [{
2471
2556
  intentId: t.id,
2472
2557
  payload: t.payload,
2473
2558
  firstSeenAt: n
2474
2559
  }];
2475
- }), tr = async (e, t) => {
2560
+ }), sr = async (e, t) => {
2476
2561
  let n = t.workflows.filter((e) => e.entries.length > 0);
2477
2562
  if (n.length === 0) return {
2478
2563
  examined: !1,
@@ -2487,11 +2572,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2487
2572
  };
2488
2573
  let r = e.now?.() ?? Date.now(), i = t.batch ?? 500, a = t.coldLookbackMs ?? 36e5, o = /* @__PURE__ */ new Set();
2489
2574
  for (let e of n) for (let t of e.entries) o.add(t.event);
2490
- let s = await Zn(e.store, Kn), c = s ?? new Date(r - a);
2491
- s === void 0 && (await Qn(e.store, Kn, c), s = c);
2575
+ let s = await rr(e.store, Qn), c = s ?? new Date(r - a);
2576
+ s === void 0 && (await ir(e.store, Qn, c), s = c);
2492
2577
  let l = await e.store.query({
2493
- table: Gn,
2494
- predicate: le("occurredAt", c),
2578
+ table: Zn,
2579
+ predicate: de("occurredAt", c),
2495
2580
  order: [{
2496
2581
  column: "occurredAt",
2497
2582
  direction: "asc"
@@ -2501,7 +2586,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2501
2586
  projection: void 0
2502
2587
  }), u = [];
2503
2588
  for (let e of l) {
2504
- let t = e, n = Yn(t.occurredAt);
2589
+ let t = e, n = tr(t.occurredAt);
2505
2590
  typeof t.id == "string" && typeof t.name == "string" && n !== void 0 && o.has(t.name) && u.push({
2506
2591
  id: t.id,
2507
2592
  name: t.name,
@@ -2515,15 +2600,15 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2515
2600
  if (n.length === 0) continue;
2516
2601
  let r = [], i = [];
2517
2602
  try {
2518
- r = await $n(e.store, t.workflowName, _), i = await er(e.store, t.workflowName, _), (r.length >= _ || i.length >= _) && (h = !0);
2603
+ r = await ar(e.store, t.workflowName, _), i = await or(e.store, t.workflowName, _), (r.length >= _ || i.length >= _) && (h = !0);
2519
2604
  } catch (e) {
2520
2605
  f.push({
2521
2606
  subject: t.workflowName,
2522
- detail: Xn(e)
2607
+ detail: nr(e)
2523
2608
  }), g = !0;
2524
2609
  continue;
2525
2610
  }
2526
- let a = Hn({
2611
+ let a = Jn({
2527
2612
  workflowName: t.workflowName,
2528
2613
  entries: t.entries,
2529
2614
  payloadSchema: t.payloadSchema,
@@ -2545,7 +2630,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2545
2630
  } catch (e) {
2546
2631
  f.push({
2547
2632
  subject: n.runId,
2548
- detail: Xn(e)
2633
+ detail: nr(e)
2549
2634
  }), g = !0;
2550
2635
  }
2551
2636
  for (let n of a.discards) try {
@@ -2556,18 +2641,18 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2556
2641
  } catch (e) {
2557
2642
  f.push({
2558
2643
  subject: n.intentId,
2559
- detail: Xn(e)
2644
+ detail: nr(e)
2560
2645
  }), g = !0;
2561
2646
  }
2562
2647
  }
2563
- let v = Un(u), y = s;
2648
+ let v = Yn(u), ee = s;
2564
2649
  if (g) e.log?.warn("workflow.cancelOn: holding the watermark — evaluation or delivery remains incomplete", { failures: f.length });
2565
2650
  else if (v !== void 0) try {
2566
- await Qn(e.store, Kn, v), y = v;
2651
+ await ir(e.store, Qn, v), ee = v;
2567
2652
  } catch (e) {
2568
2653
  f.push({
2569
- subject: Kn,
2570
- detail: Xn(e)
2654
+ subject: Qn,
2655
+ detail: nr(e)
2571
2656
  });
2572
2657
  }
2573
2658
  return d.length > 0 && e.log?.warn("workflow.cancelOn: some events could not be evaluated", {
@@ -2582,16 +2667,16 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2582
2667
  sawFullRunPage: h,
2583
2668
  problems: d,
2584
2669
  failures: f,
2585
- watermark: y
2670
+ watermark: ee
2586
2671
  };
2587
- }, nr = 18e5, rr = 200, ir = 20, ar = (e) => {
2672
+ }, cr = 18e5, lr = 200, ur = 20, dr = (e) => {
2588
2673
  if (e instanceof Date) return e;
2589
2674
  if (typeof e == "number") return new Date(e);
2590
2675
  if (typeof e == "string") {
2591
2676
  let t = new Date(e);
2592
2677
  if (!Number.isNaN(t.getTime())) return t;
2593
2678
  }
2594
- }, or = (e) => e instanceof Error ? e.message : String(e), sr = async (e, t, n) => (await e.query({
2679
+ }, fr = (e) => e instanceof Error ? e.message : String(e), pr = async (e, t, n) => (await e.query({
2595
2680
  table: "_voltro_workflow_run_events",
2596
2681
  predicate: O("runId", t),
2597
2682
  order: [{
@@ -2602,13 +2687,13 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2602
2687
  skip: void 0,
2603
2688
  projection: void 0
2604
2689
  })).flatMap((e) => {
2605
- let t = e, n = ar(t.occurredAt);
2690
+ let t = e, n = dr(t.occurredAt);
2606
2691
  return typeof t.eventType != "string" || n === void 0 ? [] : [{
2607
2692
  eventType: t.eventType,
2608
2693
  occurredAt: n,
2609
2694
  payload: t.payload
2610
2695
  }];
2611
- }), cr = async (e, t) => {
2696
+ }), mr = async (e, t) => {
2612
2697
  let n = (await e.query({
2613
2698
  table: "_voltro_workflow_run_steps",
2614
2699
  predicate: O("runId", t),
@@ -2621,24 +2706,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2621
2706
  projection: void 0
2622
2707
  }))[0];
2623
2708
  if (n === void 0) return;
2624
- let r = ar(n.startedAt), i = ar(n.completedAt);
2709
+ let r = dr(n.startedAt), i = dr(n.completedAt);
2625
2710
  return r === void 0 ? i : i === void 0 ? r : i.getTime() > r.getTime() ? i : r;
2626
- }, lr = (e, t) => {
2711
+ }, hr = (e, t) => {
2627
2712
  for (let n of e) {
2628
2713
  if (n.eventType === "timer-fired") return !1;
2629
2714
  if (n.eventType !== "timer-set") continue;
2630
- let e = ar(n.payload?.scheduledWakeAt);
2715
+ let e = dr(n.payload?.scheduledWakeAt);
2631
2716
  return e !== void 0 && e.getTime() > t;
2632
2717
  }
2633
2718
  return !1;
2634
- }, ur = (e, t) => {
2719
+ }, gr = (e, t) => {
2635
2720
  if (e !== "suspended") return "no-progress";
2636
2721
  for (let e of t) {
2637
2722
  if (e.eventType === "signal-received" || e.eventType === "signal-sent") return "suspended";
2638
2723
  if (e.eventType === "signal-awaited") return "awaiting-signal";
2639
2724
  }
2640
2725
  return "suspended";
2641
- }, dr = async (e, t = {}) => {
2726
+ }, _r = async (e, t = {}) => {
2642
2727
  let n = e.now?.() ?? Date.now(), r = t.stallAfterMs ?? 18e5, i = t.runPage ?? 200, a = t.eventLookback ?? 20, o = new Date(n - r), s = [], c = [], l = 0, u = 0, d, f;
2643
2728
  try {
2644
2729
  if (!Number.isSafeInteger(i) || i < 1) throw Error("Staleness run page must be a positive integer");
@@ -2646,7 +2731,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2646
2731
  if (n !== void 0 && (!(n.startedAt instanceof Date) || !Number.isFinite(n.startedAt.getTime()) || typeof n.runId != "string" || n.runId.length === 0)) throw Error("Invalid staleness run cursor");
2647
2732
  d = await e.store.query({
2648
2733
  table: "_voltro_workflow_runs",
2649
- predicate: T(ue("status", ["running", "suspended"]), fe("startedAt", o), ...n === void 0 ? [] : [pe(k("startedAt", n.startedAt), T(O("startedAt", n.startedAt), k("id", n.runId)))]),
2734
+ predicate: D(fe("status", ["running", "suspended"]), me("startedAt", o), ...n === void 0 ? [] : [he(A("startedAt", n.startedAt), D(O("startedAt", n.startedAt), A("id", n.runId)))]),
2650
2735
  order: [{
2651
2736
  column: "startedAt",
2652
2737
  direction: "asc"
@@ -2660,7 +2745,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2660
2745
  });
2661
2746
  let r = n;
2662
2747
  for (let e of d) {
2663
- let t = ar(e.startedAt);
2748
+ let t = dr(e.startedAt);
2664
2749
  if (t === void 0 || !Number.isFinite(t.getTime()) || typeof e.id != "string" || e.id.length === 0) throw Error("Staleness candidate has no valid pagination identity");
2665
2750
  if (r !== void 0 && (t.getTime() < r.startedAt.getTime() || t.getTime() === r.startedAt.getTime() && e.id <= r.runId)) throw Error("Staleness candidate page did not advance");
2666
2751
  r = {
@@ -2678,24 +2763,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2678
2763
  sawFullRunPage: !1,
2679
2764
  failures: [{
2680
2765
  subject: "_voltro_workflow_runs",
2681
- detail: or(e)
2766
+ detail: fr(e)
2682
2767
  }]
2683
2768
  };
2684
2769
  }
2685
2770
  for (let t of d) {
2686
- let i = t, o = ar(i.startedAt);
2771
+ let i = t, o = dr(i.startedAt);
2687
2772
  if (typeof i.id != "string" || typeof i.tag != "string" || typeof i.executionId != "string" || typeof i.status != "string" || o === void 0) continue;
2688
2773
  let d, f;
2689
2774
  try {
2690
- d = await sr(e.store, i.id, a), f = await cr(e.store, i.id);
2775
+ d = await pr(e.store, i.id, a), f = await mr(e.store, i.id);
2691
2776
  } catch (e) {
2692
2777
  s.push({
2693
2778
  subject: i.id,
2694
- detail: or(e)
2779
+ detail: fr(e)
2695
2780
  });
2696
2781
  continue;
2697
2782
  }
2698
- if (lr(d, n)) {
2783
+ if (hr(d, n)) {
2699
2784
  u += 1;
2700
2785
  continue;
2701
2786
  }
@@ -2714,7 +2799,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2714
2799
  status: i.status,
2715
2800
  lastProgressAt: m,
2716
2801
  idleMs: h,
2717
- reason: ur(i.status, d)
2802
+ reason: gr(i.status, d)
2718
2803
  };
2719
2804
  c.push(g);
2720
2805
  let _ = {};
@@ -2723,7 +2808,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2723
2808
  } catch (e) {
2724
2809
  s.push({
2725
2810
  subject: `${g.runId}:describeRun`,
2726
- detail: or(e)
2811
+ detail: fr(e)
2727
2812
  });
2728
2813
  }
2729
2814
  if (e.log?.warn("workflow.staleness: run has made no progress", {
@@ -2749,7 +2834,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2749
2834
  } catch (e) {
2750
2835
  s.push({
2751
2836
  subject: g.runId,
2752
- detail: or(e)
2837
+ detail: fr(e)
2753
2838
  });
2754
2839
  }
2755
2840
  if (e.onStalled !== void 0) try {
@@ -2757,7 +2842,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2757
2842
  } catch (e) {
2758
2843
  s.push({
2759
2844
  subject: `${g.runId}:onStalled`,
2760
- detail: or(e)
2845
+ detail: fr(e)
2761
2846
  });
2762
2847
  }
2763
2848
  }
@@ -2770,8 +2855,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2770
2855
  failures: s,
2771
2856
  ...f === void 0 ? {} : { nextRun: f }
2772
2857
  };
2773
- }, fr = async (e, t, n) => {
2774
- let r = await e.transaction((e) => B(e, t.id));
2858
+ }, vr = async (e, t, n) => {
2859
+ let r = await e.transaction((e) => V(e, t.id));
2775
2860
  if (r === void 0 || r.workflowName !== t.workflowName || r.tenantId !== t.tenantId || r.ledgerId !== t.ledgerId) throw Error("Submission dispatch lost its resident owner");
2776
2861
  if (!r.receiptsBound || r.failureId !== null) throw Error("Cannot dispatch an incomplete or rejected submission");
2777
2862
  if (r.preparedExecutionId !== null) {
@@ -2779,26 +2864,26 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2779
2864
  return r.preparedExecutionId;
2780
2865
  }
2781
2866
  if (r.dispatchAttempts !== 0 || r.executionId !== null) throw Error("Submission has an unbound prior dispatch; reconciliation required");
2782
- let i = await e.resolveExecutionId(t.workflowName, n), a = await e.transaction((e) => bt(e, t.id, i));
2867
+ let i = await e.resolveExecutionId(t.workflowName, n), a = await e.transaction((e) => St(e, t.id, i));
2783
2868
  if (a.preparedExecutionId === null) throw Error("Submission preparation returned no execution identity");
2784
2869
  return a.preparedExecutionId;
2785
- }, pr = /* @__PURE__ */ new WeakMap(), mr = async (e, t, n, r) => {
2786
- let i = pr.get(e), a = await mt(e.store, n, i?.afterId), o = 0, s = 0, c = 0, l = 0, u = i?.nextDueAt, d = (e) => {
2870
+ }, yr = /* @__PURE__ */ new WeakMap(), br = async (e, t, n, r) => {
2871
+ let i = yr.get(e), a = await gt(e.store, n, i?.afterId), o = 0, s = 0, c = 0, l = 0, u = i?.nextDueAt, d = (e) => {
2787
2872
  u = Math.min(u ?? e, e);
2788
2873
  };
2789
2874
  for (let n of a) {
2790
2875
  let i;
2791
2876
  try {
2792
- i = dt(n);
2877
+ i = pt(n);
2793
2878
  } catch {
2794
- o++, c++, d(t + Zt(1)), e.log?.warn?.("workflow submission metadata is invalid", { submissionId: typeof n.id == "string" ? n.id : null });
2879
+ o++, c++, d(t + en(1)), e.log?.warn?.("workflow submission metadata is invalid", { submissionId: typeof n.id == "string" ? n.id : null });
2795
2880
  continue;
2796
2881
  }
2797
2882
  o++;
2798
2883
  let a = i.dispatchAttempts === 0 ? 0 : void 0;
2799
2884
  try {
2800
2885
  let n = i.preparedExecutionId, r = n === null || i.dispatchAttempts === 0 ? void 0 : await e.transaction(async (e) => {
2801
- let t = await ct(e, i.workflowName, n);
2886
+ let t = await ut(e, i.workflowName, n);
2802
2887
  return t === void 0 ? void 0 : {
2803
2888
  executionId: n,
2804
2889
  runId: t.runId
@@ -2817,7 +2902,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2817
2902
  continue;
2818
2903
  }
2819
2904
  let c = r ?? await (async () => {
2820
- let n = e.controls.get(i.workflowName)?.batch === void 0 ? G(e.store, i.workflowName, i.payload) : { items: w.decodeUnknownSync(w.Struct({ items: w.Array(w.Unknown) }))(i.payload).items.map((t) => G(e.store, i.workflowName, t)) }, r = await fr(e, i, n), o = await e.transaction((e) => St(e, i.id, t));
2905
+ let n = e.controls.get(i.workflowName)?.batch === void 0 ? G(e.store, i.workflowName, i.payload) : { items: w.decodeUnknownSync(w.Struct({ items: w.Array(w.Unknown) }))(i.payload).items.map((t) => G(e.store, i.workflowName, t)) }, r = await vr(e, i, n), o = await e.transaction((e) => wt(e, i.id, t));
2821
2906
  if (o === null) return;
2822
2907
  a = o.dispatchAttempts === 1 ? 1 : void 0;
2823
2908
  let s = await e.startAdmitted(i.workflowName, n, i.callerContext, r);
@@ -2833,7 +2918,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2833
2918
  source: "flow-control",
2834
2919
  mode: "singleton"
2835
2920
  }
2836
- }), await Wt(e.store, i.eviction.executionId, t)), await e.transaction((e) => yt(e, i.id, {
2921
+ }), await qt(e.store, i.eviction.executionId, t)), await e.transaction((e) => xt(e, i.id, {
2837
2922
  executionId: c.executionId,
2838
2923
  runId: c.runId ?? null
2839
2924
  })), s++;
@@ -2842,7 +2927,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2842
2927
  let o;
2843
2928
  try {
2844
2929
  if (a !== void 0 && e.isPermanentStartError?.(n) === !0) {
2845
- let r = a, o = await e.transaction((a) => Ct(a, i.id, r, {
2930
+ let r = a, o = await e.transaction((a) => Tt(a, i.id, r, {
2846
2931
  handler: e.controls.get(i.workflowName)?.onFailure ?? null,
2847
2932
  errorMessage: String(n),
2848
2933
  now: t
@@ -2856,7 +2941,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2856
2941
  continue;
2857
2942
  }
2858
2943
  }
2859
- o = await e.transaction((e) => xt(e, i.id, String(n), t, r));
2944
+ o = await e.transaction((e) => Ct(e, i.id, String(n), t, r));
2860
2945
  } catch (r) {
2861
2946
  d(t), e.log?.warn?.("workflow submission retry state could not be recorded", {
2862
2947
  workflow: i.workflowName,
@@ -2876,7 +2961,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2876
2961
  }
2877
2962
  }
2878
2963
  let f = a.at(-1);
2879
- return a.length === n && f !== void 0 && typeof f.id == "string" ? (pr.set(e, {
2964
+ return a.length === n && f !== void 0 && typeof f.id == "string" ? (yr.set(e, {
2880
2965
  afterId: f.id,
2881
2966
  nextDueAt: u
2882
2967
  }), {
@@ -2886,7 +2971,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2886
2971
  rejected: l,
2887
2972
  nextDueAt: t,
2888
2973
  examined: !0
2889
- }) : (pr.delete(e), {
2974
+ }) : (yr.delete(e), {
2890
2975
  scanned: o,
2891
2976
  admitted: s,
2892
2977
  failed: c,
@@ -2894,10 +2979,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2894
2979
  nextDueAt: u,
2895
2980
  examined: a.length > 0
2896
2981
  });
2897
- }, hr = /* @__PURE__ */ new WeakMap(), gr = async (e, t, n) => {
2898
- let r = hr.get(e), i = await e.store.query({
2899
- table: qe,
2900
- predicate: T(de("handler"), M("acceptedExecutionId"), ...r === void 0 ? [] : [k("id", r.afterId)]),
2982
+ }, xr = /* @__PURE__ */ new WeakMap(), Sr = async (e, t, n) => {
2983
+ let r = xr.get(e), i = await e.store.query({
2984
+ table: Xe,
2985
+ predicate: D(pe("handler"), N("acceptedExecutionId"), ...r === void 0 ? [] : [A("id", r.afterId)]),
2901
2986
  order: [{
2902
2987
  column: "id",
2903
2988
  direction: "asc"
@@ -2906,21 +2991,21 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2906
2991
  skip: void 0,
2907
2992
  projection: void 0
2908
2993
  }), a = 0, o = !1, s = r?.nextDueAt, c = () => {
2909
- let e = t + Zt(1, () => 1);
2994
+ let e = t + en(1, () => 1);
2910
2995
  s = Math.min(s ?? e, e);
2911
2996
  };
2912
2997
  for (let n of i) try {
2913
2998
  if (typeof n.id != "string" || n.id.length === 0) throw Error("Failure report has no identity");
2914
2999
  let r = n.id;
2915
- (await e.transaction((e) => ot(e, r, t))).kind === "queued" && (o = !0, c());
3000
+ (await e.transaction((e) => ct(e, r, t))).kind === "queued" && (o = !0, c());
2916
3001
  } catch (t) {
2917
3002
  a++, c(), e.log?.warn?.("workflow failure delivery could not be reconciled", {
2918
3003
  failureId: typeof n.id == "string" ? n.id : null,
2919
- ...t instanceof at ? { reason: t.reason } : {}
3004
+ ...t instanceof st ? { reason: t.reason } : {}
2920
3005
  });
2921
3006
  }
2922
3007
  let l = i.at(-1);
2923
- return i.length === n && l !== void 0 && typeof l.id == "string" ? (hr.set(e, {
3008
+ return i.length === n && l !== void 0 && typeof l.id == "string" ? (xr.set(e, {
2924
3009
  afterId: l.id,
2925
3010
  nextDueAt: s
2926
3011
  }), {
@@ -2929,17 +3014,17 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2929
3014
  hasPending: o,
2930
3015
  nextDueAt: t,
2931
3016
  examined: !0
2932
- }) : (hr.delete(e), {
3017
+ }) : (xr.delete(e), {
2933
3018
  scanned: i.length,
2934
3019
  failed: a,
2935
3020
  hasPending: o,
2936
3021
  nextDueAt: s,
2937
3022
  examined: i.length > 0
2938
3023
  });
2939
- }, _r = "_voltro_workflow_parent_closures", vr = /* @__PURE__ */ new WeakMap(), yr = async (e, t, n) => {
2940
- let r = vr.get(e), i = await e.store.query({
2941
- table: _r,
2942
- predicate: T(M("completedAt"), ...r === void 0 ? [] : [k("id", r.afterId)]),
3024
+ }, Cr = "_voltro_workflow_parent_closures", wr = /* @__PURE__ */ new WeakMap(), Tr = async (e, t, n) => {
3025
+ let r = wr.get(e), i = await e.store.query({
3026
+ table: Cr,
3027
+ predicate: D(N("completedAt"), ...r === void 0 ? [] : [A("id", r.afterId)]),
2943
3028
  order: [{
2944
3029
  column: "id",
2945
3030
  direction: "asc"
@@ -2954,9 +3039,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2954
3039
  if (typeof n.id != "string" || n.id.length === 0) throw Error("Parent closure has no identity");
2955
3040
  let r = n.id;
2956
3041
  await e.transaction(async (e) => {
2957
- await ln(e, r, t);
3042
+ await fn(e, r, t);
2958
3043
  let [n] = await e.query({
2959
- table: _r,
3044
+ table: Cr,
2960
3045
  predicate: O("id", r),
2961
3046
  order: [],
2962
3047
  take: 1,
@@ -2970,7 +3055,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2970
3055
  a++, s(), e.log?.warn?.("workflow parent closure could not be reconciled", { closureId: typeof n.id == "string" ? n.id : null });
2971
3056
  }
2972
3057
  let c = i.at(-1);
2973
- return i.length === n && typeof c?.id == "string" ? (vr.set(e, {
3058
+ return i.length === n && typeof c?.id == "string" ? (wr.set(e, {
2974
3059
  afterId: c.id,
2975
3060
  nextDueAt: o
2976
3061
  }), {
@@ -2978,13 +3063,13 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
2978
3063
  failed: a,
2979
3064
  nextDueAt: t,
2980
3065
  examined: !0
2981
- }) : (vr.delete(e), {
3066
+ }) : (wr.delete(e), {
2982
3067
  scanned: i.length,
2983
3068
  failed: a,
2984
3069
  nextDueAt: o,
2985
3070
  examined: i.length > 0
2986
3071
  });
2987
- }, br = async (e, t) => {
3072
+ }, Er = async (e, t) => {
2988
3073
  if (t.from === t.to) throw Error("Queue transfer requires distinct source and target");
2989
3074
  let n = await e.query({
2990
3075
  table: U,
@@ -3000,8 +3085,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3000
3085
  if (r.workflowName !== t.workflowName || r.tenantId !== t.tenantId) throw Error("Receipt target belongs to a different workflow or tenant");
3001
3086
  for (;;) {
3002
3087
  let n = await e.query({
3003
- table: Tt,
3004
- predicate: T(O("pendingId", t.from), M("submissionId"), M("terminal")),
3088
+ table: Dt,
3089
+ predicate: D(O("pendingId", t.from), N("submissionId"), N("terminal")),
3005
3090
  order: [{
3006
3091
  column: "id",
3007
3092
  direction: "asc"
@@ -3012,12 +3097,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3012
3097
  });
3013
3098
  if (n.length === 0) return;
3014
3099
  for (let r of n) {
3015
- let n = V(r);
3100
+ let n = kt(r);
3016
3101
  if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Forwarded receipt belongs to a different workflow or tenant");
3017
3102
  if (await e.update("_voltro_workflow_start_receipts", n.id, { pendingId: t.to }) === null) throw Error("Start receipt disappeared during queue transfer");
3018
3103
  }
3019
3104
  }
3020
- }, xr = {
3105
+ }, Dr = {
3021
3106
  scanned: 0,
3022
3107
  admitted: 0,
3023
3108
  deferred: 0,
@@ -3029,24 +3114,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3029
3114
  deadLettered: 0,
3030
3115
  timedOut: 0,
3031
3116
  examined: !1
3032
- }, Sr = 200, Cr = class extends Error {
3117
+ }, Or = 200, kr = class extends Error {
3033
3118
  submissionId;
3034
3119
  rejected;
3035
3120
  constructor(e, t, n = !1) {
3036
3121
  super(n ? `Submission ${e} rejected; failure report retained` : `Submission ${e} remains unacknowledged`, { cause: t }), this.submissionId = e, this.rejected = n;
3037
3122
  }
3038
- }, wr = async (e, t = {}) => {
3123
+ }, Ar = async (e, t = {}) => {
3039
3124
  let n = e.now ?? (() => Date.now()), r = e.log, i = t.batchSize ?? 200, a, o, s, c, l, u;
3040
3125
  try {
3041
- c = await mr(e, n(), i, e.deadLetterAfterAttempts ?? 50), l = await gr(e, n(), i), u = await yr(e, n(), i), a = await (e.readPauses?.() ?? It(e.store));
3126
+ c = await br(e, n(), i, e.deadLetterAfterAttempts ?? 50), l = await Sr(e, n(), i), u = await Tr(e, n(), i), a = await (e.readPauses?.() ?? zt(e.store));
3042
3127
  let r = t.skipPending === !0 && !l.hasPending ? {
3043
3128
  due: [],
3044
3129
  nextDueAt: void 0
3045
- } : await Kt(e.store, n(), i);
3130
+ } : await Yt(e.store, n(), i);
3046
3131
  o = r.due, s = c.nextDueAt === void 0 ? r.nextDueAt : Math.min(r.nextDueAt ?? c.nextDueAt, c.nextDueAt), l.nextDueAt !== void 0 && (s = Math.min(s ?? l.nextDueAt, l.nextDueAt)), u.nextDueAt !== void 0 && (s = Math.min(s ?? u.nextDueAt, u.nextDueAt));
3047
3132
  } catch (e) {
3048
3133
  return r?.warn?.("workflow flow control: could not read the admission queue", { cause: String(e) }), {
3049
- ...xr,
3134
+ ...Dr,
3050
3135
  scanned: (c?.scanned ?? 0) + (l?.scanned ?? 0) + (u?.scanned ?? 0),
3051
3136
  admitted: c?.admitted ?? 0,
3052
3137
  deadLettered: c?.rejected ?? 0,
@@ -3079,9 +3164,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3079
3164
  if (m !== !1 && t.attempts + 1 >= m) return `pending ${r} was dead-lettered after ${t.attempts + 1} failed attempts: ${String(n)}`;
3080
3165
  };
3081
3166
  for (let t of p) try {
3082
- await Dr(e, t, a, d, n());
3167
+ await Pr(e, t, a, d, n());
3083
3168
  } catch (i) {
3084
- if (d.failed++, i instanceof Cr) {
3169
+ if (d.failed++, i instanceof kr) {
3085
3170
  i.rejected && d.deadLettered++, r?.warn?.(i.message, {
3086
3171
  submissionId: i.submissionId,
3087
3172
  cause: String(i.cause)
@@ -3091,22 +3176,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3091
3176
  let a = h(t, i, "intent");
3092
3177
  if (a !== void 0) {
3093
3178
  let o = n(), s = String(i);
3094
- if (!await e.onAbandoned({
3095
- workflowName: t.workflowName,
3096
- payload: t.payload,
3097
- callerContext: t.callerContext,
3098
- reason: a,
3099
- runId: null,
3100
- executionId: null
3101
- }).then(() => !0, (e) => (r?.warn?.("workflow flow control: permanent failure could not signal onFailure", {
3179
+ if (await Mr(e, [t], a, s, o, !1).catch((e) => (r?.warn?.("workflow flow control: intent could not be dead-lettered with its report", {
3102
3180
  workflow: t.workflowName,
3103
3181
  intent: t.id,
3104
3182
  cause: String(e)
3105
- }), !1))) {
3106
- await Qt(e.store, t, s, o).catch(() => {});
3107
- continue;
3108
- }
3109
- if (await $t(e.store, t, s, o).catch(() => !1)) {
3183
+ }), 0)) > 0) {
3110
3184
  d.deadLettered++, r?.warn?.("workflow flow control: intent dead-lettered", {
3111
3185
  workflow: t.workflowName,
3112
3186
  intent: t.id,
@@ -3119,12 +3193,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3119
3193
  workflow: t.workflowName,
3120
3194
  intent: t.id,
3121
3195
  cause: String(i)
3122
- }), await Qt(e.store, t, String(i), n()).catch(() => {});
3196
+ }), await tn(e.store, t, String(i), n()).catch(() => {});
3123
3197
  }
3124
3198
  for (let t of f.values()) try {
3125
- await kr(e, t, a, d, n());
3199
+ await Ir(e, t, a, d, n());
3126
3200
  } catch (i) {
3127
- if (d.failed++, i instanceof Cr) {
3201
+ if (d.failed++, i instanceof kr) {
3128
3202
  i.rejected && d.deadLettered++, r?.warn?.(i.message, {
3129
3203
  submissionId: i.submissionId,
3130
3204
  cause: String(i.cause)
@@ -3134,23 +3208,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3134
3208
  let a = t[0], o = a === void 0 ? void 0 : h(a, i, "batch");
3135
3209
  if (a !== void 0 && o !== void 0) {
3136
3210
  let s = n(), c = String(i);
3137
- if (!await e.onAbandoned({
3138
- workflowName: a.workflowName,
3139
- payload: { items: t.map((e) => e.payload) },
3140
- callerContext: a.callerContext,
3141
- reason: o,
3142
- runId: null,
3143
- executionId: null
3144
- }).then(() => !0, (e) => (r?.warn?.("workflow flow control: permanent batch failure could not signal onFailure", {
3211
+ if (await Mr(e, t, o, c, s, !0).catch((e) => (r?.warn?.("workflow flow control: batch could not be dead-lettered with its report", {
3145
3212
  workflow: a.workflowName,
3146
3213
  intents: t.map((e) => e.id),
3147
3214
  size: t.length,
3148
3215
  cause: String(e)
3149
- }), !1))) {
3150
- await Promise.all(t.map((t) => Qt(e.store, t, c, s).catch(() => {})));
3151
- continue;
3152
- }
3153
- if ((await Promise.all(t.map((t) => $t(e.store, t, c, s).catch(() => !1)))).every(Boolean)) {
3216
+ }), 0)) === t.length) {
3154
3217
  d.deadLettered += t.length, r?.warn?.("workflow flow control: batch dead-lettered", {
3155
3218
  workflow: a.workflowName,
3156
3219
  intents: t.map((e) => e.id),
@@ -3183,7 +3246,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3183
3246
  if (i.workflowName !== r.workflowName || i.tenantId !== r.tenantId || i.mode !== r.mode || i.firstSeenAt !== r.firstSeenAt || i.dueAt !== r.dueAt || i.deadLetteredAt !== void 0) return;
3184
3247
  n.push(i);
3185
3248
  }
3186
- let r = new Date(s + Zt(Math.max(...n.map((e) => e.attempts + 1)), () => c));
3249
+ let r = new Date(s + en(Math.max(...n.map((e) => e.attempts + 1)), () => c));
3187
3250
  for (let t of n) if (await e.update("_voltro_workflow_pending", t.id, {
3188
3251
  attempts: t.attempts + 1,
3189
3252
  lastError: String(i).slice(0, 500),
@@ -3196,16 +3259,16 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3196
3259
  cause: String(e)
3197
3260
  }));
3198
3261
  }
3199
- let g = await Nr(e, n()).catch(() => ({ cancelled: 0 }));
3262
+ let g = await Br(e, n()).catch(() => ({ cancelled: 0 }));
3200
3263
  return d.timedOut = g.cancelled, g.nextDeadlineAt !== void 0 && (s === void 0 || g.nextDeadlineAt < s) && (s = g.nextDeadlineAt), {
3201
3264
  ...d,
3202
3265
  examined: t.skipPending !== !0 || c.examined || l.examined || u.examined,
3203
3266
  ...s === void 0 ? {} : { nextDueAt: s }
3204
3267
  };
3205
- }, Tr = async (e, t, n) => {
3268
+ }, jr = async (e, t, n) => {
3206
3269
  let r = t.map((e) => ({
3207
3270
  intent: e,
3208
- failureId: `wff_${L()}`
3271
+ failureId: `wff_${R()}`
3209
3272
  }));
3210
3273
  return e.transaction(async (e) => {
3211
3274
  let t = 0;
@@ -3224,7 +3287,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3224
3287
  if (o.workflowName !== i.workflowName || o.tenantId !== i.tenantId) throw Error("Abandoned queue selection belongs to another workflow or tenant");
3225
3288
  if (o.dueAt > n || o.deadLetteredAt !== void 0) continue;
3226
3289
  let s = `workflow '${o.workflowName}' no longer has its queued declaration`;
3227
- if (await Ye(e, {
3290
+ if (await Qe(e, {
3228
3291
  id: a,
3229
3292
  sourceKind: "intent",
3230
3293
  sourceId: o.id,
@@ -3256,8 +3319,64 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3256
3319
  }
3257
3320
  return t;
3258
3321
  });
3259
- }, Er = async (e, t, n, r, i) => {
3260
- let a = `wff_${L()}`;
3322
+ }, Mr = async (e, t, n, r, i, a) => {
3323
+ let o = `wff_${R()}`;
3324
+ return e.transaction(async (s) => {
3325
+ let c = [];
3326
+ for (let e of t) {
3327
+ let t = await s.query({
3328
+ table: U,
3329
+ predicate: O("id", e.id),
3330
+ order: [],
3331
+ take: 1,
3332
+ skip: void 0,
3333
+ projection: void 0,
3334
+ lock: "update"
3335
+ });
3336
+ if (t[0] === void 0) return 0;
3337
+ let n = q(t[0]);
3338
+ if (n.workflowName !== e.workflowName || n.tenantId !== e.tenantId) throw Error("Dead-letter selection belongs to another workflow or tenant");
3339
+ if (n.deadLetteredAt !== void 0) return 0;
3340
+ c.push(n);
3341
+ }
3342
+ let l = c[0];
3343
+ if (l === void 0) return 0;
3344
+ let u = await Promise.all(c.map((e) => tt(s, e.id)));
3345
+ if (u.some(Boolean) && !u.every(Boolean)) throw Error("Dead-lettered batch mixes failure delivery and ordinary callers; reconciliation required");
3346
+ let d = e.controls.get(l.workflowName);
3347
+ await Qe(s, {
3348
+ id: o,
3349
+ sourceKind: "intent",
3350
+ sourceId: l.id,
3351
+ workflowName: l.workflowName,
3352
+ tenantId: l.tenantId,
3353
+ handler: u.every(Boolean) ? null : d?.onFailure ?? null,
3354
+ callerContext: l.callerContext,
3355
+ report: {
3356
+ workflow: l.workflowName,
3357
+ payload: a ? { items: c.map((e) => e.payload) } : l.payload,
3358
+ reason: n,
3359
+ failedAt: i,
3360
+ errorTag: null,
3361
+ errorMessage: r.slice(0, 500),
3362
+ runId: null,
3363
+ executionId: null
3364
+ }
3365
+ });
3366
+ for (let e of c) if (await H(s, {
3367
+ pendingId: e.id,
3368
+ workflowName: e.workflowName,
3369
+ tenantId: e.tenantId,
3370
+ terminal: {
3371
+ kind: "abandoned",
3372
+ at: i,
3373
+ failureId: o
3374
+ }
3375
+ }), !await nn(s, e, r, i)) throw Error("Dead-lettered queue row disappeared before marking");
3376
+ return await B(s, o, i), c.length;
3377
+ });
3378
+ }, Nr = async (e, t, n, r, i) => {
3379
+ let a = `wff_${R()}`;
3261
3380
  return e.transaction(async (e) => {
3262
3381
  let o = [];
3263
3382
  for (let i of t) {
@@ -3278,11 +3397,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3278
3397
  }
3279
3398
  o.sort((e, t) => e.firstSeenAt - t.firstSeenAt || e.id.localeCompare(t.id));
3280
3399
  let s = o[0];
3281
- if (s === void 0 || !We(n, s, r)) return 0;
3282
- let c = await Promise.all(o.map((t) => Qe(e, t.id)));
3400
+ if (s === void 0 || !qe(n, s, r)) return 0;
3401
+ let c = await Promise.all(o.map((t) => tt(e, t.id)));
3283
3402
  if (c.some(Boolean) && !c.every(Boolean)) throw Error("Expired batch mixes failure delivery and ordinary callers; reconciliation required");
3284
3403
  let l = `timeouts.start (${n.timeouts?.startMs}ms) elapsed while ${o.length} queued input(s) waited`;
3285
- await Ye(e, {
3404
+ await Qe(e, {
3286
3405
  id: a,
3287
3406
  sourceKind: "intent",
3288
3407
  sourceId: s.id,
@@ -3303,7 +3422,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3303
3422
  }), await Y({
3304
3423
  store: e,
3305
3424
  control: n,
3306
- keys: R(n, G(e, s.workflowName, s.payload)),
3425
+ keys: He(n, G(e, s.workflowName, s.payload)),
3307
3426
  outcome: "expired",
3308
3427
  mode: s.mode,
3309
3428
  reason: l,
@@ -3324,23 +3443,23 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3324
3443
  failureId: a
3325
3444
  }
3326
3445
  }), !await e.delete("_voltro_workflow_pending", t.id)) throw Error("Expired queue row disappeared before deletion");
3327
- return await it(e, a, r), o.length;
3446
+ return await B(e, a, r), o.length;
3328
3447
  });
3329
- }, Dr = async (e, t, n, r, i) => {
3448
+ }, Pr = async (e, t, n, r, i) => {
3330
3449
  if (t = {
3331
3450
  ...t,
3332
3451
  payload: G(e.store, t.workflowName, t.payload)
3333
- }, t.mode === "delayed") return Or(e, t, n, r, i);
3452
+ }, t.mode === "delayed") return Fr(e, t, n, r, i);
3334
3453
  let a = e.controls.get(t.workflowName);
3335
3454
  if (a === void 0) {
3336
- r.expired += await Tr(e, [t], i);
3455
+ r.expired += await jr(e, [t], i);
3337
3456
  return;
3338
3457
  }
3339
- if (We(a, t, i)) {
3340
- r.expired += await Er(e, [t], a, i, !1);
3458
+ if (qe(a, t, i)) {
3459
+ r.expired += await Nr(e, [t], a, i, !1);
3341
3460
  return;
3342
3461
  }
3343
- let o = R(a, t.payload), s = await tn({
3462
+ let o = He(a, t.payload), s = await an({
3344
3463
  store: e.store,
3345
3464
  control: a,
3346
3465
  keys: o,
@@ -3348,7 +3467,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3348
3467
  now: i,
3349
3468
  reconsidering: !0
3350
3469
  });
3351
- await Ar(e, {
3470
+ await Lr(e, {
3352
3471
  control: a,
3353
3472
  intent: t,
3354
3473
  decision: s,
@@ -3358,12 +3477,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3358
3477
  paused: n,
3359
3478
  items: void 0
3360
3479
  });
3361
- }, Or = async (e, t, n, r, i) => {
3480
+ }, Fr = async (e, t, n, r, i) => {
3362
3481
  if (e.registeredWorkflows !== void 0 && !e.registeredWorkflows.has(t.workflowName)) {
3363
- r.expired += await Tr(e, [t], i);
3482
+ r.expired += await jr(e, [t], i);
3364
3483
  return;
3365
3484
  }
3366
- let a = e.controls.get(t.workflowName) ?? { workflowName: t.workflowName }, o = `wfsub_${L()}`, s = await e.transaction(async (e) => {
3485
+ let a = e.controls.get(t.workflowName) ?? { workflowName: t.workflowName }, o = `wfsub_${R()}`, s = await e.transaction(async (e) => {
3367
3486
  let r = await e.query({
3368
3487
  table: U,
3369
3488
  predicate: O("id", t.id),
@@ -3377,7 +3496,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3377
3496
  let s = q(r[0]);
3378
3497
  if (s.workflowName !== t.workflowName || s.tenantId !== t.tenantId) throw Error("Delayed arrival belongs to a different workflow or tenant");
3379
3498
  if (s.mode !== "delayed" || s.deadLetteredAt !== void 0 || s.dueAt > i) return;
3380
- let c = await Ln({
3499
+ let c = await Un({
3381
3500
  store: e,
3382
3501
  control: a,
3383
3502
  payload: G(e, s.workflowName, s.payload),
@@ -3387,18 +3506,18 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3387
3506
  now: i,
3388
3507
  waiting: !1
3389
3508
  });
3390
- if (c.kind === "queued" && (await br(e, {
3509
+ if (c.kind === "queued" && (await Er(e, {
3391
3510
  from: s.id,
3392
3511
  to: c.intentId,
3393
3512
  workflowName: s.workflowName,
3394
3513
  tenantId: s.tenantId
3395
- }), !await Jt(e, s.id))) throw Error("Delayed arrival disappeared during queue transfer");
3514
+ }), !await Zt(e, s.id))) throw Error("Delayed arrival disappeared during queue transfer");
3396
3515
  if (c.kind === "start") {
3397
3516
  if (c.ledgerId === void 0) throw Error("Delayed arrival has no admission reservation");
3398
- let t = a.batch === void 0 ? Mt(e, s.workflowName, c.payload) : { items: w.decodeUnknownSync(w.Struct({ items: w.Array(w.Unknown) }))(c.payload).items.map((t) => Mt(e, s.workflowName, t)) };
3517
+ let t = a.batch === void 0 ? Ft(e, s.workflowName, c.payload) : { items: w.decodeUnknownSync(w.Struct({ items: w.Array(w.Unknown) }))(c.payload).items.map((t) => Ft(e, s.workflowName, t)) };
3399
3518
  return {
3400
3519
  kind: "submission",
3401
- submission: await Pn(e, {
3520
+ submission: await Bn(e, {
3402
3521
  id: o,
3403
3522
  workflowName: s.workflowName,
3404
3523
  tenantId: s.tenantId,
@@ -3419,7 +3538,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3419
3538
  ...c,
3420
3539
  at: i
3421
3540
  }
3422
- }), !await Jt(e, s.id))) throw Error("Delayed arrival disappeared while recording its outcome");
3541
+ }), !await Zt(e, s.id))) throw Error("Delayed arrival disappeared while recording its outcome");
3423
3542
  return c;
3424
3543
  });
3425
3544
  if (s !== void 0) {
@@ -3435,9 +3554,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3435
3554
  r.skipped++;
3436
3555
  return;
3437
3556
  }
3438
- await Mr(e, s.submission, a, r, i, a.batch !== void 0, s.keys);
3557
+ await zr(e, s.submission, a, r, i, a.batch !== void 0, s.keys);
3439
3558
  }
3440
- }, kr = async (e, t, n, r, i) => {
3559
+ }, Ir = async (e, t, n, r, i) => {
3441
3560
  t = t.map((t) => ({
3442
3561
  ...t,
3443
3562
  payload: G(e.store, t.workflowName, t.payload)
@@ -3446,19 +3565,19 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3446
3565
  if (a === void 0) return;
3447
3566
  let o = e.controls.get(a.workflowName);
3448
3567
  if (o === void 0 || o.batch === void 0) {
3449
- r.expired += await Tr(e, t, i);
3568
+ r.expired += await jr(e, t, i);
3450
3569
  return;
3451
3570
  }
3452
3571
  let s = [...t].sort((e, t) => e.firstSeenAt - t.firstSeenAt), c = s[0];
3453
- if (We(o, c, i)) {
3454
- r.expired += await Er(e, s, o, i, !0);
3572
+ if (qe(o, c, i)) {
3573
+ r.expired += await Nr(e, s, o, i, !0);
3455
3574
  return;
3456
3575
  }
3457
- let l = R(o, c.payload);
3458
- await Ar(e, {
3576
+ let l = He(o, c.payload);
3577
+ await Lr(e, {
3459
3578
  control: o,
3460
3579
  intent: c,
3461
- decision: await tn({
3580
+ decision: await an({
3462
3581
  store: e.store,
3463
3582
  control: o,
3464
3583
  keys: l,
@@ -3472,10 +3591,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3472
3591
  paused: n,
3473
3592
  items: s
3474
3593
  });
3475
- }, Ar = async (e, t) => {
3594
+ }, Lr = async (e, t) => {
3476
3595
  let { control: n, intent: r, decision: i, keys: a, counters: o, now: s, items: c, paused: l } = t;
3477
3596
  if (i.kind === "defer") {
3478
- await Vt({
3597
+ await Wt({
3479
3598
  store: e.store,
3480
3599
  control: n,
3481
3600
  decision: i,
@@ -3507,11 +3626,11 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3507
3626
  t.push(o);
3508
3627
  }
3509
3628
  t.sort((e, t) => e.firstSeenAt - t.firstSeenAt);
3510
- let i = t[0], a = R(n, G(e, n.workflowName, i.payload)), o = await tn({
3629
+ let i = t[0], a = He(n, G(e, n.workflowName, i.payload)), o = await an({
3511
3630
  store: e,
3512
3631
  control: n,
3513
3632
  keys: a,
3514
- paused: l.has(n.workflowName) || (await It(e)).has(n.workflowName),
3633
+ paused: l.has(n.workflowName) || (await zt(e)).has(n.workflowName),
3515
3634
  now: s,
3516
3635
  reconsidering: !0
3517
3636
  });
@@ -3545,13 +3664,13 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3545
3664
  workflowName: n.workflowName,
3546
3665
  tenantId: n.tenantId,
3547
3666
  terminal: u
3548
- }), !await Jt(e, n.id)) throw Error("Queued input disappeared while recording its terminal outcome");
3667
+ }), !await Zt(e, n.id)) throw Error("Queued input disappeared while recording its terminal outcome");
3549
3668
  return u.kind;
3550
3669
  });
3551
3670
  t !== void 0 && o[t]++;
3552
3671
  return;
3553
3672
  }
3554
- let u = `wfsub_${L()}`, d = await e.transaction((t) => In(t, {
3673
+ let u = `wfsub_${R()}`, d = await e.transaction((t) => Hn(t, {
3555
3674
  id: u,
3556
3675
  workflowName: n.workflowName,
3557
3676
  tenantId: r.tenantId,
@@ -3576,16 +3695,16 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3576
3695
  o.deferred++;
3577
3696
  return;
3578
3697
  }
3579
- await Mr(e, d.submission, n, o, s, c !== void 0, a);
3698
+ await zr(e, d.submission, n, o, s, c !== void 0, a);
3580
3699
  }
3581
- }, jr = async (e, t, n, r, i) => {
3582
- let a = await e.transaction((e) => B(e, t.id));
3700
+ }, Rr = async (e, t, n, r, i) => {
3701
+ let a = await e.transaction((e) => V(e, t.id));
3583
3702
  if (a === void 0 || !a.receiptsBound || a.workflowName !== n.workflowName || a.workflowName !== t.workflowName || a.tenantId !== t.tenantId || a.ledgerId !== t.ledgerId) throw Error("Admission acceptance callback no longer has its resident submission owner");
3584
3703
  if (a.executionId !== null) {
3585
3704
  if (a.failureId !== null || a.executionId.length === 0 || a.executionId !== a.preparedExecutionId) throw Error("Admission acceptance has contradictory resident execution evidence");
3586
3705
  return a.executionId;
3587
3706
  }
3588
- await Mr(e, a, n, {
3707
+ await zr(e, a, n, {
3589
3708
  admitted: 0,
3590
3709
  deferred: 0,
3591
3710
  dropped: 0,
@@ -3593,17 +3712,17 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3593
3712
  expired: 0,
3594
3713
  evicted: 0
3595
3714
  }, i, n.batch !== void 0, r);
3596
- let o = await e.transaction((e) => B(e, t.id));
3715
+ let o = await e.transaction((e) => V(e, t.id));
3597
3716
  if (o?.executionId == null || o.executionId !== o.preparedExecutionId) throw Error("Admission submission has no confirmed engine acceptance");
3598
3717
  return o.executionId;
3599
- }, Mr = async (e, t, n, r, i, a, o) => {
3718
+ }, zr = async (e, t, n, r, i, a, o) => {
3600
3719
  let s = t.dispatchAttempts === 0 ? 0 : void 0;
3601
3720
  try {
3602
3721
  if (e.acquireSubmissionCapacity !== void 0 && !await e.acquireSubmissionCapacity(t)) {
3603
3722
  r.deferred++;
3604
3723
  return;
3605
3724
  }
3606
- let c = a ? { items: w.decodeUnknownSync(w.Struct({ items: w.Array(w.Unknown) }))(t.payload).items.map((t) => G(e.store, n.workflowName, t)) } : G(e.store, n.workflowName, t.payload), l = await fr(e, t, c), u = await e.transaction((e) => St(e, t.id, i));
3725
+ let c = a ? { items: w.decodeUnknownSync(w.Struct({ items: w.Array(w.Unknown) }))(t.payload).items.map((t) => G(e.store, n.workflowName, t)) } : G(e.store, n.workflowName, t.payload), l = await vr(e, t, c), u = await e.transaction((e) => wt(e, t.id, i));
3607
3726
  if (u === null) return;
3608
3727
  s = u.dispatchAttempts === 1 ? 1 : void 0;
3609
3728
  let d = await e.startAdmitted(n.workflowName, c, t.callerContext, l);
@@ -3617,7 +3736,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3617
3736
  source: "flow-control",
3618
3737
  mode: "singleton"
3619
3738
  }
3620
- }), await Wt(e.store, t.eviction.executionId, i), await Y({
3739
+ }), await qt(e.store, t.eviction.executionId, i), await Y({
3621
3740
  store: e.store,
3622
3741
  control: n,
3623
3742
  keys: o,
@@ -3630,7 +3749,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3630
3749
  runId: t.eviction.runId || null,
3631
3750
  tenantId: t.tenantId,
3632
3751
  now: i
3633
- }), r.evicted++), await e.transaction((e) => yt(e, t.id, {
3752
+ }), r.evicted++), await e.transaction((e) => xt(e, t.id, {
3634
3753
  executionId: d.executionId,
3635
3754
  runId: d.runId ?? null
3636
3755
  })), r.admitted++;
@@ -3639,14 +3758,14 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3639
3758
  try {
3640
3759
  if (s !== void 0 && e.isPermanentStartError?.(r) === !0) {
3641
3760
  let o = s;
3642
- a = await e.transaction((e) => Ct(e, t.id, o, {
3761
+ a = await e.transaction((e) => Tt(e, t.id, o, {
3643
3762
  handler: n.onFailure ?? null,
3644
3763
  errorMessage: String(r),
3645
3764
  now: i
3646
3765
  })) !== void 0;
3647
3766
  }
3648
3767
  if (!a) {
3649
- let n = await e.transaction((n) => xt(n, t.id, String(r), i, e.deadLetterAfterAttempts ?? 50));
3768
+ let n = await e.transaction((n) => Ct(n, t.id, String(r), i, e.deadLetterAfterAttempts ?? 50));
3650
3769
  n.retry.stoppedAt !== null && e.log?.warn?.("workflow submission automatic retry stopped; engine acceptance unknown", {
3651
3770
  submissionId: t.id,
3652
3771
  workflow: t.workflowName,
@@ -3654,18 +3773,18 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3654
3773
  });
3655
3774
  }
3656
3775
  } catch (e) {
3657
- throw new Cr(t.id, AggregateError([r, e], "Submission and retry recording failed"));
3776
+ throw new kr(t.id, AggregateError([r, e], "Submission and retry recording failed"));
3658
3777
  }
3659
- throw new Cr(t.id, r, a);
3778
+ throw new kr(t.id, r, a);
3660
3779
  }
3661
- }, Nr = async (e, t) => {
3780
+ }, Br = async (e, t) => {
3662
3781
  if (e.listRunningRuns === void 0) return { cancelled: 0 };
3663
3782
  let n = 0, r;
3664
3783
  for (let i of e.controls.values()) {
3665
3784
  if (i.timeouts?.finishMs === void 0) continue;
3666
3785
  let a = await e.listRunningRuns(i.workflowName);
3667
3786
  for (let o of a) {
3668
- if (!Ge(i, {
3787
+ if (!Je(i, {
3669
3788
  startedAt: o.startedAt,
3670
3789
  terminal: !1
3671
3790
  }, t)) {
@@ -3680,50 +3799,43 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3680
3799
  executionId: o.executionId,
3681
3800
  reason: a,
3682
3801
  detail: {
3683
- source: "flow-control",
3684
- timeout: "finish"
3802
+ ...v,
3803
+ onFailure: i.onFailure ?? null
3685
3804
  }
3686
- }) && (await Wt(e.store, o.executionId, t), await e.onAbandoned({
3687
- workflowName: o.workflowName,
3688
- payload: o.payload,
3689
- callerContext: null,
3690
- reason: a,
3691
- runId: o.runId,
3692
- executionId: o.executionId
3693
- }), n++);
3805
+ }) && (await qt(e.store, o.executionId, t), n++);
3694
3806
  }
3695
3807
  }
3696
3808
  return {
3697
3809
  cancelled: n,
3698
3810
  ...r === void 0 ? {} : { nextDeadlineAt: r }
3699
3811
  };
3700
- }, Pr = 3e5, Fr, Ir = (e) => {
3701
- Fr = e !== void 0 && Number.isFinite(e) && e > 0 ? e : void 0;
3702
- }, Lr = () => {
3812
+ }, Vr = 3e5, Hr, Ur = (e) => {
3813
+ Hr = e !== void 0 && Number.isFinite(e) && e > 0 ? e : void 0;
3814
+ }, Wr = () => {
3703
3815
  let e = process.env.VOLTRO_WORKFLOW_SUSPEND_HINT_MS;
3704
3816
  if (e !== void 0) {
3705
3817
  let t = Number(e);
3706
3818
  if (Number.isFinite(t) && t > 0) return t;
3707
3819
  }
3708
- return Fr ?? 3e5;
3709
- }, Rr = /* @__PURE__ */ new Set(), zr = () => {
3710
- Rr.clear();
3711
- }, Br = (e) => {
3712
- let t = Lr();
3820
+ return Hr ?? 3e5;
3821
+ }, Gr = /* @__PURE__ */ new Set(), Kr = () => {
3822
+ Gr.clear();
3823
+ }, qr = (e) => {
3824
+ let t = Wr();
3713
3825
  if (!(e.timeoutMs > t)) return !1;
3714
3826
  let n = `${e.workflowName ?? ""}\u0000${e.signalName}`;
3715
- if (Rr.has(n)) return !1;
3716
- Rr.add(n);
3827
+ if (Gr.has(n)) return !1;
3828
+ Gr.add(n);
3717
3829
  let r = e.workflowName === void 0 ? "" : ` in workflow '${e.workflowName}'`;
3718
3830
  return (e.warn ?? ((e) => console.warn(e)))(`awaitSignal('${e.signalName}')${r} declares a ${Math.round(e.timeoutMs / 1e3)}s timeout — a wait that long holds a worker fiber for its whole duration. For human-approval-length waits, awaitSignalSuspending (same call shape, from @voltro/workflow) SUSPENDS the run and frees the slot until the signal arrives. This is a hint, not a behaviour change; it is logged once per workflow. Threshold: workflows.suspendSignalHintMs in app.config.ts, or VOLTRO_WORKFLOW_SUSPEND_HINT_MS.`), !0;
3719
- }, Vr = async (e, t) => {
3831
+ }, Jr = async (e, t) => {
3720
3832
  if (e) try {
3721
3833
  await e.recordEvent(t);
3722
3834
  } catch {}
3723
- }, Hr = (e, n) => {
3835
+ }, Yr = (e, n) => {
3724
3836
  let i = S.gen(function* () {
3725
- let i = n.pollIntervalMs ?? 200, a = n.maxPollIntervalMs ?? 5e3, o = n.timeoutMs ?? 864e5, s = yield* S.serviceOption(ye), c;
3726
- Br({
3837
+ let i = n.pollIntervalMs ?? 200, a = n.maxPollIntervalMs ?? 5e3, o = n.timeoutMs ?? 864e5, s = yield* S.serviceOption(xe), c;
3838
+ qr({
3727
3839
  workflowName: s._tag === "Some" ? s.value.workflow.name : void 0,
3728
3840
  signalName: n.name,
3729
3841
  timeoutMs: o,
@@ -3734,7 +3846,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3734
3846
  let l = yield* t, u = yield* S.serviceOption(r), d = u._tag === "Some" ? u.value : void 0;
3735
3847
  if (l === void 0) return yield* S.die(/* @__PURE__ */ Error("awaitSignal: no active workflow run id in scope"));
3736
3848
  let f = l;
3737
- yield* S.promise(() => Vr(d, {
3849
+ yield* S.promise(() => Jr(d, {
3738
3850
  runId: f,
3739
3851
  eventType: "signal-awaited",
3740
3852
  payload: { signalName: n.name }
@@ -3749,7 +3861,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3749
3861
  column: "occurredAt",
3750
3862
  direction: "asc"
3751
3863
  }],
3752
- predicate: T(O("runId", f), O("eventType", "signal-sent")),
3864
+ predicate: D(O("runId", f), O("eventType", "signal-sent")),
3753
3865
  projection: void 0,
3754
3866
  skip: void 0,
3755
3867
  take: 1e3
@@ -3759,7 +3871,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3759
3871
  })).find((e) => e.payload?.signalName === n.name);
3760
3872
  if (i !== void 0) {
3761
3873
  let e = yield* w.decodeUnknown(n.schema)(i.payload?.value);
3762
- return yield* S.promise(() => Vr(d, {
3874
+ return yield* S.promise(() => Jr(d, {
3763
3875
  runId: f,
3764
3876
  eventType: "signal-received",
3765
3877
  payload: {
@@ -3771,21 +3883,21 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3771
3883
  yield* S.sleep(`${m} millis`), m = Math.min(m * 2, a);
3772
3884
  }
3773
3885
  });
3774
- return _.make({
3886
+ return y.make({
3775
3887
  name: `await-signal:${n.name}`,
3776
3888
  success: n.schema,
3777
3889
  execute: i
3778
3890
  });
3779
- }, Ur = async (e, t) => {
3891
+ }, Xr = async (e, t) => {
3780
3892
  if (e !== void 0) try {
3781
3893
  await e.recordEvent(t);
3782
3894
  } catch {}
3783
- }, Wr = (e, n) => {
3895
+ }, Zr = (e, n) => {
3784
3896
  let i = S.gen(function* () {
3785
3897
  let i = n.pollIntervalMs ?? 200, a = n.maxPollIntervalMs ?? 5e3, o = n.timeoutMs ?? 864e5, s = n.take ?? 500, c = yield* t, l = yield* S.serviceOption(r), u = l._tag === "Some" ? l.value : void 0;
3786
3898
  if (c === void 0) return yield* S.die(/* @__PURE__ */ Error("awaitEvent: no active workflow run id in scope"));
3787
- let d = c, f = yield* n.since === "run-start" ? Gr(e, d) : S.succeed(/* @__PURE__ */ new Date());
3788
- yield* S.promise(() => Ur(u, {
3899
+ let d = c, f = yield* n.since === "run-start" ? Qr(e, d) : S.succeed(/* @__PURE__ */ new Date());
3900
+ yield* S.promise(() => Xr(u, {
3789
3901
  runId: d,
3790
3902
  eventType: "event-awaited",
3791
3903
  payload: {
@@ -3800,7 +3912,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3800
3912
  if (t > o) return yield* S.die(/* @__PURE__ */ Error(`awaitEvent('${n.event}') timed out after ${t}ms having examined ${h} candidate event(s). ${h === 0 ? "NONE were published under that name in the window — check the spelling against ctx.events.publish, and consider since: 'run-start' if the event may have arrived before this step began." : "The predicate rejected all of them — log one payload and compare it with what `match` expects."}`));
3801
3913
  let r = {
3802
3914
  table: "_voltro_workflow_events",
3803
- predicate: T(O("name", n.event), le("occurredAt", f)),
3915
+ predicate: D(O("name", n.event), de("occurredAt", f)),
3804
3916
  order: [{
3805
3917
  column: "occurredAt",
3806
3918
  direction: "asc"
@@ -3815,7 +3927,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3815
3927
  h = i.length;
3816
3928
  for (let e of i) {
3817
3929
  let t = yield* w.decodeUnknown(n.schema)(e.payload);
3818
- if (n.match(t)) return yield* S.promise(() => Ur(u, {
3930
+ if (n.match(t)) return yield* S.promise(() => Xr(u, {
3819
3931
  runId: d,
3820
3932
  eventType: "event-received",
3821
3933
  payload: {
@@ -3827,12 +3939,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3827
3939
  yield* S.sleep(`${m} millis`), m = Math.min(m * 2, a);
3828
3940
  }
3829
3941
  });
3830
- return _.make({
3942
+ return y.make({
3831
3943
  name: `awaitEvent:${n.event}`,
3832
3944
  success: n.schema,
3833
3945
  execute: i
3834
3946
  });
3835
- }, Gr = (e, t) => S.gen(function* () {
3947
+ }, Qr = (e, t) => S.gen(function* () {
3836
3948
  let n = (yield* S.tryPromise({
3837
3949
  try: () => e.store.query({
3838
3950
  table: "_voltro_workflow_runs",
@@ -3850,10 +3962,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3850
3962
  if (!Number.isNaN(e.getTime())) return e;
3851
3963
  }
3852
3964
  return /* @__PURE__ */ new Date(0);
3853
- }), Kr = (e) => new Promise((t) => setTimeout(t, e)), qr = () => {
3965
+ }), $r = (e) => new Promise((t) => setTimeout(t, e)), ei = () => {
3854
3966
  let e = globalThis.crypto;
3855
3967
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
3856
- }, Jr = () => `wfu_${qr()}`, Yr = async (e, t) => {
3968
+ }, ti = () => `wfu_${ei()}`, ni = async (e, t) => {
3857
3969
  let n = t.id ?? t.executionId;
3858
3970
  if (!n) throw Error("workflow message target requires target.id or target.executionId");
3859
3971
  let r = await e.query({
@@ -3875,18 +3987,27 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3875
3987
  }))[0];
3876
3988
  if (!i) throw Error(`workflow message target not found: ${n}`);
3877
3989
  return i;
3878
- }, Xr = async (e) => {
3879
- let t = await Yr(e.store, e.target);
3880
- return { eventId: (await e.recorder.recordEvent({
3990
+ }, ri = class extends Error {
3991
+ runId;
3992
+ eventType;
3993
+ eventId;
3994
+ _tag = "WorkflowMessageNotRecorded";
3995
+ constructor(e, t, n) {
3996
+ super(`workflow ${t} for run ${e} was NOT recorded (event ${n}): the run will not see it — the store refused the row, see the recorder's warning`), this.runId = e, this.eventType = t, this.eventId = n, this.name = "WorkflowMessageNotRecorded";
3997
+ }
3998
+ }, ii = async (e) => {
3999
+ let t = await ni(e.store, e.target), n = await e.recorder.recordEvent({
3881
4000
  runId: t.id,
3882
4001
  eventType: "signal-sent",
3883
4002
  payload: {
3884
4003
  signalName: e.signalName,
3885
4004
  value: e.payload
3886
4005
  }
3887
- })).id };
3888
- }, Zr = async (e) => {
3889
- let t = await Yr(e.store, e.target), n = Jr(), r = await e.recorder.recordEvent({
4006
+ });
4007
+ if (n.recorded === !1) throw new ri(t.id, "signal-sent", n.id);
4008
+ return { eventId: n.id };
4009
+ }, ai = async (e) => {
4010
+ let t = await ni(e.store, e.target), n = ti(), r = await e.recorder.recordEvent({
3890
4011
  runId: t.id,
3891
4012
  eventType: "update-requested",
3892
4013
  payload: {
@@ -3894,7 +4015,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3894
4015
  updateName: e.updateName,
3895
4016
  value: e.payload
3896
4017
  }
3897
- }), i = Date.now(), a = e.options?.timeoutMs ?? 3e4, o = e.options?.pollIntervalMs ?? 100;
4018
+ });
4019
+ if (r.recorded === !1) throw new ri(t.id, "update-requested", r.id);
4020
+ let i = Date.now(), a = e.options?.timeoutMs ?? 3e4, o = e.options?.pollIntervalMs ?? 100;
3898
4021
  for (;;) {
3899
4022
  let s = {
3900
4023
  table: "_voltro_workflow_run_events",
@@ -3923,24 +4046,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3923
4046
  }), t;
3924
4047
  }
3925
4048
  if (Date.now() - i >= a) throw Error(`Timed out waiting for workflow update '${e.updateName}' (${n})`);
3926
- await Kr(o);
4049
+ await $r(o);
3927
4050
  }
3928
- }, Qr = 864e5, $r = "voltro/suspending-signal", ei = (e, t) => `${$r}/${e}/${t}`, ti = (e) => y.make(e, { success: w.Unknown }), ni = async (e, t) => {
4051
+ }, oi = 864e5, si = "voltro/suspending-signal", ci = (e, t) => `${si}/${e}/${t}`, li = (e) => te.make(e, { success: w.Unknown }), ui = async (e, t) => {
3929
4052
  if (e) try {
3930
4053
  await e.recordEvent(t);
3931
4054
  } catch {}
3932
- }, ri = (e, n) => S.gen(function* () {
3933
- let e = n.timeoutMs ?? Qr, i = ti(ei((yield* b.WorkflowInstance).workflow.name, n.name)), a = yield* t, o = yield* S.serviceOption(r), s = o._tag === "Some" ? o.value : void 0;
3934
- a !== void 0 && (yield* S.promise(() => ni(s, {
4055
+ }, di = (e, n) => S.gen(function* () {
4056
+ let e = n.timeoutMs ?? oi, i = li(ci((yield* re.WorkflowInstance).workflow.name, n.name)), a = yield* t, o = yield* S.serviceOption(r), s = o._tag === "Some" ? o.value : void 0;
4057
+ a !== void 0 && (yield* S.promise(() => ui(s, {
3935
4058
  runId: a,
3936
4059
  eventType: "signal-awaited",
3937
4060
  payload: { signalName: n.name }
3938
4061
  })));
3939
- let c = y.await(i), l = Number.isFinite(e) ? yield* S.race(c, v.sleep({
4062
+ let c = te.await(i), l = Number.isFinite(e) ? yield* S.race(c, b.sleep({
3940
4063
  name: `await-signal-timeout/${n.name}`,
3941
4064
  duration: `${e} millis`
3942
4065
  }).pipe(S.andThen(S.die(/* @__PURE__ */ Error(`awaitSignalSuspending('${n.name}') timed out after ${e}ms`))))) : yield* c, u = yield* w.decodeUnknown(n.schema)(l);
3943
- return a !== void 0 && (yield* S.promise(() => ni(s, {
4066
+ return a !== void 0 && (yield* S.promise(() => ui(s, {
3944
4067
  runId: a,
3945
4068
  eventType: "signal-received",
3946
4069
  payload: {
@@ -3948,77 +4071,77 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
3948
4071
  value: u
3949
4072
  }
3950
4073
  }))), u;
3951
- }), ii = (e) => S.gen(function* () {
4074
+ }), fi = (e) => S.gen(function* () {
3952
4075
  let t = e.target.executionId, n = e.target.workflowName;
3953
4076
  if (t === void 0 || n === void 0) {
3954
4077
  let r = e.store;
3955
4078
  if (r === void 0) return yield* S.die(/* @__PURE__ */ Error("completeSuspendingSignal: provide a store, or target.executionId AND target.workflowName"));
3956
4079
  let i = yield* S.tryPromise({
3957
- try: () => Yr(r, e.target),
4080
+ try: () => ni(r, e.target),
3958
4081
  catch: (e) => e
3959
4082
  });
3960
4083
  t ??= i.executionId, n ??= i.tag;
3961
4084
  }
3962
4085
  if (t === void 0 || n === void 0) return { completed: !1 };
3963
- let r = ei(n, e.signalName), i = ti(r), a = new y.TokenParsed({
4086
+ let r = ci(n, e.signalName), i = li(r), a = new te.TokenParsed({
3964
4087
  workflowName: n,
3965
4088
  executionId: t,
3966
4089
  deferredName: r
3967
4090
  }).asToken;
3968
- return yield* y.done(i, {
4091
+ return yield* te.done(i, {
3969
4092
  token: a,
3970
- exit: te.succeed(e.payload)
4093
+ exit: ie.succeed(e.payload)
3971
4094
  }), { completed: !0 };
3972
- }), Z = "_voltro_budget_holds", ai = "budget-hold", oi = (e) => `${ai}:${e}`, si = (e) => `${e.executionId}/${e.stepName}/${e.budget}#${e.generation}`, ci = async (e, t) => (await e.query({
3973
- table: Z,
3974
- predicate: T(O("executionId", t.executionId), O("stepName", t.stepName), O("budget", t.budget)),
4095
+ }), Q = "_voltro_budget_holds", pi = "budget-hold", mi = (e) => `${pi}:${e}`, hi = (e) => `${e.executionId}/${e.stepName}/${e.budget}#${e.generation}`, gi = async (e, t) => (await e.query({
4096
+ table: Q,
4097
+ predicate: D(O("executionId", t.executionId), O("stepName", t.stepName), O("budget", t.budget)),
3975
4098
  order: []
3976
- })).length, li = P(Z, {
3977
- id: A({ prefix: "bhd" }),
3978
- holdKey: F().maxLength(191),
3979
- budget: F(),
3980
- tenantId: F().nullable(),
3981
- executionId: F(),
3982
- workflowName: F(),
3983
- signalName: F(),
3984
- stepName: F(),
3985
- spentMicroUsd: F().nullable(),
3986
- limitMicroUsd: F().nullable(),
3987
- heldAt: I().default("now"),
3988
- releasedAt: I().nullable(),
3989
- outcome: F().nullable()
3990
- }).index(["budget", "releasedAt"]), ui = () => {
3991
- ge({
4099
+ })).length, _i = F(Q, {
4100
+ id: j({ prefix: "bhd" }),
4101
+ holdKey: I().maxLength(191),
4102
+ budget: I(),
4103
+ tenantId: I().nullable(),
4104
+ executionId: I(),
4105
+ workflowName: I(),
4106
+ signalName: I(),
4107
+ stepName: I(),
4108
+ spentMicroUsd: I().nullable(),
4109
+ limitMicroUsd: I().nullable(),
4110
+ heldAt: L().default("now"),
4111
+ releasedAt: L().nullable(),
4112
+ outcome: I().nullable()
4113
+ }).index(["budget", "releasedAt"]), vi = () => {
4114
+ ve({
3992
4115
  source: "framework",
3993
- table: Z,
4116
+ table: Q,
3994
4117
  timeColumn: "releasedAt",
3995
- ttlMs: _e(process.env.VOLTRO_BUDGET_HOLDS_TTL_HOURS, 720)
4118
+ ttlMs: ye(process.env.VOLTRO_BUDGET_HOLDS_TTL_HOURS, 720)
3996
4119
  });
3997
- }, di = class extends Error {
4120
+ }, yi = class extends Error {
3998
4121
  budget;
3999
4122
  holdKey;
4000
4123
  constructor(e, t, n) {
4001
4124
  super(`budget '${e}': the run was suspended waiting for headroom and gave up after ${n}ms (hold ${t}). Nothing was spent. Raise the budget, reset its window, or lift the hold, then re-drive the run.`), this.name = "BudgetHoldExpired", this.budget = e, this.holdKey = t;
4002
4125
  }
4003
- }, fi = 6048e5, pi = (e) => S.gen(function* () {
4004
- ui();
4126
+ }, bi = 6048e5, xi = (e) => S.gen(function* () {
4127
+ vi();
4005
4128
  let t = e.timeoutMs ?? 6048e5, n = e.recheckEveryMs ?? 9e5, r = {
4006
4129
  executionId: e.executionId,
4007
4130
  stepName: e.stepName,
4008
4131
  budget: e.budget
4009
4132
  };
4010
4133
  for (;;) {
4011
- let i = yield* S.promise(() => hi(e.store, r)), a = i.length, o = i.length === 0 ? Date.now() : mi(i[0]?.heldAt), s = Number.isFinite(t) ? t - (Date.now() - o) : Infinity, c = si({
4134
+ let i = yield* S.promise(() => Ci(e.store, r)), a = i.length, o = i.length === 0 ? Date.now() : Si(i[0]?.heldAt), s = Number.isFinite(t) ? t - (Date.now() - o) : Infinity, c = hi({
4012
4135
  ...r,
4013
4136
  generation: a
4014
4137
  });
4015
- if (s <= 0) return yield* S.promise(() => gi(e.store, r, "expired")), yield* S.fail(new di(e.budget, c, t));
4016
- let l = oi(c);
4017
- yield* S.promise(() => e.store.insertIgnore(Z, {
4018
- id: ce({
4138
+ if (s <= 0) return yield* S.promise(() => wi(e.store, r, "expired")), yield* S.fail(new yi(e.budget, c, t));
4139
+ let l = mi(c);
4140
+ yield* S.promise(() => e.store.insertIgnore(Q, {
4141
+ id: k({
4019
4142
  kind: "typeid",
4020
4143
  prefix: "bhd"
4021
- }, Z),
4144
+ }, Q),
4022
4145
  holdKey: c,
4023
4146
  budget: e.budget,
4024
4147
  tenantId: e.tenantId,
@@ -4033,34 +4156,34 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4033
4156
  outcome: null
4034
4157
  }, { conflictColumns: ["holdKey"] }));
4035
4158
  let u = Math.min(n, s);
4036
- if (yield* ri({ store: e.store }, {
4159
+ if (yield* di({ store: e.store }, {
4037
4160
  name: l,
4038
4161
  schema: w.Unknown,
4039
4162
  timeoutMs: u
4040
- }).pipe(S.catchAllCause((e) => x.isInterruptedOnly(e) ? S.failCause(e) : S.void)), yield* S.promise(() => e.store.updateMany(Z, {
4163
+ }).pipe(S.catchAllCause((e) => x.isInterruptedOnly(e) ? S.failCause(e) : S.void)), yield* S.promise(() => e.store.updateMany(Q, {
4041
4164
  releasedAt: /* @__PURE__ */ new Date(),
4042
4165
  outcome: "recheck"
4043
- }, { where: T(O("holdKey", c), M("releasedAt")) })), yield* e.hasHeadroom) return;
4166
+ }, { where: D(O("holdKey", c), N("releasedAt")) })), yield* e.hasHeadroom) return;
4044
4167
  }
4045
- }), mi = (e) => e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : Date.now(), hi = async (e, t) => [...await e.query({
4046
- table: Z,
4047
- predicate: T(O("executionId", t.executionId), O("stepName", t.stepName), O("budget", t.budget)),
4168
+ }), Si = (e) => e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : Date.now(), Ci = async (e, t) => [...await e.query({
4169
+ table: Q,
4170
+ predicate: D(O("executionId", t.executionId), O("stepName", t.stepName), O("budget", t.budget)),
4048
4171
  order: []
4049
- })].sort((e, t) => String(e.id).localeCompare(String(t.id))), gi = async (e, t, n) => {
4050
- await e.updateMany(Z, {
4172
+ })].sort((e, t) => String(e.id).localeCompare(String(t.id))), wi = async (e, t, n) => {
4173
+ await e.updateMany(Q, {
4051
4174
  releasedAt: /* @__PURE__ */ new Date(),
4052
4175
  outcome: n
4053
- }, { where: T(O("executionId", t.executionId), O("stepName", t.stepName), O("budget", t.budget), M("releasedAt")) });
4054
- }, _i = (e) => S.gen(function* () {
4055
- let t = e.tenantId === void 0 ? T(O("budget", e.budget), M("releasedAt")) : T(O("budget", e.budget), O("tenantId", e.tenantId), M("releasedAt")), n = yield* S.promise(() => e.store.query({
4056
- table: Z,
4176
+ }, { where: D(O("executionId", t.executionId), O("stepName", t.stepName), O("budget", t.budget), N("releasedAt")) });
4177
+ }, Ti = (e) => S.gen(function* () {
4178
+ let t = e.tenantId === void 0 ? D(O("budget", e.budget), N("releasedAt")) : D(O("budget", e.budget), O("tenantId", e.tenantId), N("releasedAt")), n = yield* S.promise(() => e.store.query({
4179
+ table: Q,
4057
4180
  predicate: t,
4058
4181
  order: []
4059
4182
  })), r = 0;
4060
4183
  for (let t of n) (yield* S.promise(() => e.store.updateMany("_voltro_budget_holds", {
4061
4184
  releasedAt: /* @__PURE__ */ new Date(),
4062
4185
  outcome: e.outcome ?? "released"
4063
- }, { where: T(O("id", String(t.id)), M("releasedAt")) }))) === 1 && (yield* ii({
4186
+ }, { where: D(O("id", String(t.id)), N("releasedAt")) }))) === 1 && (yield* fi({
4064
4187
  target: {
4065
4188
  executionId: String(t.executionId),
4066
4189
  workflowName: String(t.workflowName)
@@ -4072,10 +4195,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4072
4195
  }
4073
4196
  }).pipe(S.catchAll(() => S.succeed({ completed: !1 }))), r += 1);
4074
4197
  return { released: r };
4075
- }), vi = async (e, t) => {
4076
- let n = t?.budget === void 0 ? M("releasedAt") : T(O("budget", t.budget), M("releasedAt"));
4198
+ }), Ei = async (e, t) => {
4199
+ let n = t?.budget === void 0 ? N("releasedAt") : D(O("budget", t.budget), N("releasedAt"));
4077
4200
  return (await e.query({
4078
- table: Z,
4201
+ table: Q,
4079
4202
  predicate: n,
4080
4203
  order: []
4081
4204
  })).map((e) => ({
@@ -4088,8 +4211,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4088
4211
  stepName: String(e.stepName),
4089
4212
  heldAt: e.heldAt instanceof Date ? e.heldAt.toISOString() : String(e.heldAt ?? "")
4090
4213
  }));
4091
- }, yi = async (e) => {
4092
- let t = await vi(e), n = /* @__PURE__ */ new Map();
4214
+ }, Di = async (e) => {
4215
+ let t = await Ei(e), n = /* @__PURE__ */ new Map();
4093
4216
  for (let e of t) {
4094
4217
  let t = `${e.budget}\u0000${e.tenantId ?? ""}`;
4095
4218
  n.has(t) || n.set(t, {
@@ -4098,17 +4221,17 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4098
4221
  });
4099
4222
  }
4100
4223
  return [...n.values()];
4101
- }, bi = async (e, t) => {
4224
+ }, Oi = async (e, t) => {
4102
4225
  if (e) try {
4103
4226
  await e.recordEvent(t);
4104
4227
  } catch {}
4105
- }, xi = (e) => {
4228
+ }, ki = (e) => {
4106
4229
  let t = x.failureOption(e), n = Array.from(x.defects(e)), r = t._tag === "Some" ? t.value : n[0] ?? x.squash(e);
4107
4230
  return {
4108
4231
  errorTag: r && typeof r == "object" && "_tag" in r ? String(r._tag) : null,
4109
4232
  errorMessage: r?.message ?? String(r)
4110
4233
  };
4111
- }, Si = (e, n) => {
4234
+ }, Ai = (e, n) => {
4112
4235
  let i = S.gen(function* () {
4113
4236
  let i = n.pollIntervalMs ?? 200, a = n.maxPollIntervalMs ?? 5e3, o = n.timeoutMs ?? 3e4, s = yield* t, c = yield* S.serviceOption(r), l = c._tag === "Some" ? c.value : void 0;
4114
4237
  if (s === void 0) return yield* S.die(/* @__PURE__ */ Error("awaitUpdate: no active workflow run id in scope"));
@@ -4132,7 +4255,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4132
4255
  }), s = new Set(i.filter((e) => e.eventType === "update-completed" || e.eventType === "update-failed").map((e) => e.payload?.updateId).filter((e) => typeof e == "string" && e.length > 0)), c = i.find((e) => e.eventType === "update-requested" && e.payload?.updateName === n.name && typeof e.payload.updateId == "string" && !s.has(e.payload.updateId));
4133
4256
  if (c !== void 0) {
4134
4257
  let e = c.payload.updateId;
4135
- yield* S.promise(() => bi(l, {
4258
+ yield* S.promise(() => Oi(l, {
4136
4259
  runId: u,
4137
4260
  eventType: "update-received",
4138
4261
  payload: {
@@ -4140,24 +4263,24 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4140
4263
  updateName: n.name
4141
4264
  }
4142
4265
  }));
4143
- let t = yield* w.decodeUnknown(n.schema)(c.payload?.value).pipe(S.tapErrorCause((t) => S.promise(() => bi(l, {
4266
+ let t = yield* w.decodeUnknown(n.schema)(c.payload?.value).pipe(S.tapErrorCause((t) => S.promise(() => Oi(l, {
4144
4267
  runId: u,
4145
4268
  eventType: "update-failed",
4146
4269
  payload: {
4147
4270
  updateId: e,
4148
4271
  updateName: n.name,
4149
- ...xi(t)
4272
+ ...ki(t)
4150
4273
  }
4151
- })))), r = yield* (n.handle ? n.handle(t) : S.succeed(t)).pipe(S.flatMap((e) => n.success ? w.decodeUnknown(n.success)(e) : S.succeed(e))).pipe(S.tapErrorCause((t) => S.promise(() => bi(l, {
4274
+ })))), r = yield* (n.handle ? n.handle(t) : S.succeed(t)).pipe(S.flatMap((e) => n.success ? w.decodeUnknown(n.success)(e) : S.succeed(e))).pipe(S.tapErrorCause((t) => S.promise(() => Oi(l, {
4152
4275
  runId: u,
4153
4276
  eventType: "update-failed",
4154
4277
  payload: {
4155
4278
  updateId: e,
4156
4279
  updateName: n.name,
4157
- ...xi(t)
4280
+ ...ki(t)
4158
4281
  }
4159
4282
  }))));
4160
- return yield* S.promise(() => bi(l, {
4283
+ return yield* S.promise(() => Oi(l, {
4161
4284
  runId: u,
4162
4285
  eventType: "update-completed",
4163
4286
  payload: {
@@ -4170,12 +4293,12 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4170
4293
  yield* S.sleep(`${f} millis`), f = Math.min(f * 2, a);
4171
4294
  }
4172
4295
  });
4173
- return _.make({
4296
+ return y.make({
4174
4297
  name: `await-update:${n.name}`,
4175
4298
  success: n.success ?? n.schema,
4176
4299
  execute: i
4177
4300
  });
4178
- }, Ci = (e) => {
4301
+ }, ji = (e) => {
4179
4302
  if (e == null) return null;
4180
4303
  if (e instanceof Date) return e;
4181
4304
  if (typeof e == "string" || typeof e == "number") {
@@ -4183,7 +4306,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4183
4306
  return Number.isNaN(t.getTime()) ? null : t;
4184
4307
  }
4185
4308
  return null;
4186
- }, wi = (e) => typeof e == "number" ? e : e == null ? null : Number(e), Q = (e) => e == null ? null : String(e), Ti = (e) => {
4309
+ }, Mi = (e) => typeof e == "number" ? e : e == null ? null : Number(e), Ni = (e) => e == null ? null : String(e), Pi = (e) => {
4187
4310
  let t = /* @__PURE__ */ new Map();
4188
4311
  for (let n of e) {
4189
4312
  let e = String(n.stepName), r = t.get(e);
@@ -4191,27 +4314,27 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4191
4314
  }
4192
4315
  let n = [];
4193
4316
  for (let [e, r] of t) {
4194
- r.sort((e, t) => (wi(e.attempt) ?? 0) - (wi(t.attempt) ?? 0));
4195
- let t = r[r.length - 1], i = Q(t.errorTag), a = Q(t.errorMessage), o = i !== null || a !== null ? {
4317
+ r.sort((e, t) => (Mi(e.attempt) ?? 0) - (Mi(t.attempt) ?? 0));
4318
+ let t = r[r.length - 1], i = Ni(t.errorTag), a = Ni(t.errorMessage), o = i !== null || a !== null ? {
4196
4319
  tag: i,
4197
4320
  message: a ?? ""
4198
4321
  } : null;
4199
4322
  n.push({
4200
4323
  name: e,
4201
- attempt: wi(t.attempt) ?? r.length,
4324
+ attempt: Mi(t.attempt) ?? r.length,
4202
4325
  attempts: r.length,
4203
4326
  status: t.status ?? "running",
4204
4327
  input: t.input ?? null,
4205
4328
  output: t.output ?? null,
4206
4329
  error: o,
4207
- durationMs: wi(t.durationMs)
4330
+ durationMs: Mi(t.durationMs)
4208
4331
  });
4209
4332
  }
4210
4333
  return n.sort((t, n) => {
4211
4334
  let r = e.find((e) => String(e.stepName) === t.name), i = e.find((e) => String(e.stepName) === n.name);
4212
- return (Ci(r?.startedAt)?.getTime() ?? 0) - (Ci(i?.startedAt)?.getTime() ?? 0);
4335
+ return (ji(r?.startedAt)?.getTime() ?? 0) - (ji(i?.startedAt)?.getTime() ?? 0);
4213
4336
  }), n;
4214
- }, Ei = (e) => {
4337
+ }, Fi = (e) => {
4215
4338
  if (e == null) return null;
4216
4339
  if (typeof e == "string") try {
4217
4340
  return JSON.parse(e);
@@ -4219,30 +4342,30 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4219
4342
  return null;
4220
4343
  }
4221
4344
  return typeof e == "object" ? e : null;
4222
- }, Di = async (e, t) => {
4223
- let n = me(xe), r = (await t.query(n.where(pe(O("id", e), O("executionId", e))).limit(1).descriptor))[0];
4345
+ }, Ii = async (e, t) => {
4346
+ let n = ge(Ce), r = (await t.query(n.where(he(O("id", e), O("executionId", e))).limit(1).descriptor))[0];
4224
4347
  if (r === void 0) return null;
4225
- let i = String(r.id), a = me(Se), o = await t.query(a.where(O("runId", i)).descriptor);
4348
+ let i = String(r.id), a = ge(we), o = await t.query(a.where(O("runId", i)).descriptor);
4226
4349
  return {
4227
4350
  id: i,
4228
- executionId: Q(r.executionId) ?? "",
4229
- name: Q(r.tag) ?? "",
4351
+ executionId: Ni(r.executionId) ?? "",
4352
+ name: Ni(r.tag) ?? "",
4230
4353
  status: r.status ?? "running",
4231
4354
  input: r.payload ?? null,
4232
4355
  output: r.output ?? null,
4233
- subject: Ei(r.subject),
4234
- source: Q(r.source),
4235
- steps: Ti(o),
4236
- startedAt: Ci(r.startedAt) ?? /* @__PURE__ */ new Date(0),
4237
- finishedAt: Ci(r.completedAt),
4238
- traceId: Q(r.traceId),
4239
- parentExecutionId: Q(r.parentExecutionId),
4240
- parentClosePolicy: Q(r.parentClosePolicy)
4356
+ subject: Fi(r.subject),
4357
+ source: Ni(r.source),
4358
+ steps: Pi(o),
4359
+ startedAt: ji(r.startedAt) ?? /* @__PURE__ */ new Date(0),
4360
+ finishedAt: ji(r.completedAt),
4361
+ traceId: Ni(r.traceId),
4362
+ parentExecutionId: Ni(r.parentExecutionId),
4363
+ parentClosePolicy: Ni(r.parentClosePolicy)
4241
4364
  };
4242
- }, Oi = () => {
4365
+ }, Li = () => {
4243
4366
  let e = [], t = [], n = 0, i = 0;
4244
4367
  return {
4245
- layer: ie.succeed(r, {
4368
+ layer: se.succeed(r, {
4246
4369
  startStep: async ({ runId: t, stepName: r, attempt: i, stepInput: a, retryPolicy: o }) => {
4247
4370
  let s = `wfstep_mem_${++n}`;
4248
4371
  return e.push({
@@ -4280,19 +4403,22 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4280
4403
  stepName: a ?? null,
4281
4404
  attempt: o ?? null,
4282
4405
  occurredAt: /* @__PURE__ */ new Date()
4283
- }), { id: s };
4406
+ }), {
4407
+ id: s,
4408
+ recorded: !0
4409
+ };
4284
4410
  }
4285
4411
  }),
4286
4412
  readSteps: () => e,
4287
4413
  readEvents: () => t
4288
4414
  };
4289
- }, ki = (e, t, n) => S.gen(function* () {
4290
- let r = yield* ye;
4415
+ }, Ri = (e, t, n) => S.gen(function* () {
4416
+ let r = yield* xe;
4291
4417
  for (;;) {
4292
- if (yield* S.tryPromise(() => u(t, e)).pipe(S.catchAll(() => S.sync(() => (n(), !1))))) return r.interrupted = !0, yield* S.interrupt;
4418
+ if (yield* S.tryPromise(() => g(t, e)).pipe(S.catchAll(() => S.sync(() => (n(), !1))))) return r.interrupted = !0, yield* S.interrupt;
4293
4419
  yield* S.sleep(1e3);
4294
4420
  }
4295
- }), Ai = 8192, ji = 3, Mi = 2e3, Ni = () => {
4421
+ }), zi = 8192, Bi = 3, Vi = 2e3, Hi = () => {
4296
4422
  let e = (e) => {
4297
4423
  if (e === void 0) return;
4298
4424
  let t = Number(e);
@@ -4302,7 +4428,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4302
4428
  ...t === void 0 ? {} : { maxRunReclaims: t },
4303
4429
  ...n === void 0 ? {} : { replayShapeLimit: n }
4304
4430
  };
4305
- }, Pi = (e) => {
4431
+ }, Ui = (e) => {
4306
4432
  let t = typeof e == "string" ? (() => {
4307
4433
  try {
4308
4434
  return JSON.parse(e);
@@ -4311,10 +4437,10 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4311
4437
  }
4312
4438
  })() : e;
4313
4439
  if (Array.isArray(t)) return t.filter((e) => typeof e == "string");
4314
- }, Fi = () => {
4440
+ }, Wi = () => {
4315
4441
  let e = globalThis.crypto;
4316
4442
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
4317
- }, Ii = (e) => `${e}_${Fi()}`, Li = (e, t = Ai) => {
4443
+ }, Gi = (e) => `${e}_${Wi()}`, Ki = (e, t = zi) => {
4318
4444
  if (e == null) return e;
4319
4445
  try {
4320
4446
  let n = JSON.stringify(e);
@@ -4330,8 +4456,8 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4330
4456
  let t = {};
4331
4457
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
4332
4458
  return t;
4333
- }, Ri = (e) => {
4334
- let t = e.truncateBytes ?? Ai, n = e.makeId ?? Ii, r = (t, n) => e.log?.warn(t, n), i = e.encryptStepPayload ?? ((e) => e), a = e.emit, o = e.recording === "coarse";
4459
+ }, qi = (e) => {
4460
+ let t = e.truncateBytes ?? zi, n = e.makeId ?? Gi, r = (t, n) => e.log?.warn(t, n), i = e.encryptStepPayload ?? ((e) => e), a = e.emit, o = e.recording === "coarse";
4335
4461
  return {
4336
4462
  startStep: async ({ runId: s, stepName: c, attempt: l, stepInput: u, retryPolicy: d }) => {
4337
4463
  if (!o) try {
@@ -4341,7 +4467,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4341
4467
  stepName: c,
4342
4468
  attempt: l,
4343
4469
  status: "running",
4344
- input: u === void 0 ? null : i(Li(u, t)),
4470
+ input: u === void 0 ? null : i(Ki(u, t)),
4345
4471
  retryPolicy: d ?? null,
4346
4472
  output: null,
4347
4473
  errorTag: null,
@@ -4368,7 +4494,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4368
4494
  if (!o) try {
4369
4495
  let r = await e.store.update("_voltro_workflow_run_steps", n, {
4370
4496
  status: "succeeded",
4371
- output: i(Li(s, t)),
4497
+ output: i(Ki(s, t)),
4372
4498
  completedAt: /* @__PURE__ */ new Date(),
4373
4499
  durationMs: c
4374
4500
  });
@@ -4389,7 +4515,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4389
4515
  status: "failed",
4390
4516
  errorTag: s,
4391
4517
  errorMessage: c,
4392
- errorCause: l === void 0 ? null : i(Li(l, t)),
4518
+ errorCause: l === void 0 ? null : i(Ki(l, t)),
4393
4519
  completedAt: /* @__PURE__ */ new Date(),
4394
4520
  durationMs: u
4395
4521
  });
@@ -4405,7 +4531,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4405
4531
  }
4406
4532
  },
4407
4533
  recordEvent: async ({ runId: t, eventType: i, payload: o, stepName: s, attempt: c }) => {
4408
- let l = n("wfev");
4534
+ let l = n("wfev"), u = !0;
4409
4535
  try {
4410
4536
  let n = await e.store.insert("_voltro_workflow_run_events", {
4411
4537
  id: l,
@@ -4421,7 +4547,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4421
4547
  row: $(n)
4422
4548
  });
4423
4549
  } catch (e) {
4424
- r("failed to record workflow event (continuing)", {
4550
+ u = !1, r("failed to record workflow event (continuing)", {
4425
4551
  runId: t,
4426
4552
  eventType: i,
4427
4553
  reason: e?.message ?? String(e)
@@ -4431,10 +4557,13 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4431
4557
  let n = o?.scheduledWakeAt, r = typeof n == "string" ? new Date(n) : void 0, a = o?.tenantId, s = typeof a == "string" ? a : void 0;
4432
4558
  i === "timer-set" && r !== void 0 && !Number.isNaN(r.getTime()) ? await e.wakeups.register(t, r, s).catch(() => {}) : (i === "timer-fired" || i === "run-succeeded" || i === "run-failed" || i === "run-cancelled") && await e.wakeups.cancel(t, s).catch(() => {});
4433
4559
  }
4434
- return { id: l };
4560
+ return {
4561
+ id: l,
4562
+ recorded: u
4563
+ };
4435
4564
  }
4436
4565
  };
4437
- }, zi = (e, t, n) => S.gen(function* () {
4566
+ }, Ji = (e, t, n) => S.gen(function* () {
4438
4567
  let r = e.store.query;
4439
4568
  if (r === void 0) return;
4440
4569
  let i = e.replayShapeLimit ?? 2e3, a = yield* S.promise(() => r.call(e.store, {
@@ -4464,9 +4593,9 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4464
4593
  return typeof t == "string" ? [{ stepName: t }] : [];
4465
4594
  });
4466
4595
  return o.length === 0 ? void 0 : s(o);
4467
- }), Bi = (s, l) => {
4468
- let u = s.truncateBytes ?? Ai, d = s.makeId ?? Ii, p = s.recorder ?? Ri(s), m = (e, t) => s.log?.warn(e, t), h = s.emit, g = (e) => S.gen(function* () {
4469
- yield* S.sync(() => h?.("workflowEvents", {
4596
+ }), Yi = (s, l) => {
4597
+ let u = s.truncateBytes ?? zi, d = s.makeId ?? Gi, f = s.recorder ?? qi(s), p = (e, t) => s.log?.warn(e, t), m = s.emit, g = (e) => S.gen(function* () {
4598
+ yield* S.sync(() => m?.("workflowEvents", {
4470
4599
  op: "insert",
4471
4600
  row: $(e)
4472
4601
  }));
@@ -4474,7 +4603,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4474
4603
  if (t !== void 0 && typeof n == "string") {
4475
4604
  let e = s.subject?.tenantId;
4476
4605
  yield* S.promise(() => t.cancel(n, typeof e == "string" ? e : void 0).catch(() => {
4477
- m("failed to clear terminal workflow wakeup", { runId: n });
4606
+ p("failed to clear terminal workflow wakeup", { runId: n });
4478
4607
  }));
4479
4608
  }
4480
4609
  }), _ = (e, t, n) => S.promise(async () => {
@@ -4486,7 +4615,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4486
4615
  status: t
4487
4616
  });
4488
4617
  } catch (n) {
4489
- m("failed to apply workflow parent-close policy", {
4618
+ p("failed to apply workflow parent-close policy", {
4490
4619
  tag: s.name,
4491
4620
  executionId: e,
4492
4621
  status: t,
@@ -4503,7 +4632,7 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4503
4632
  ...r === void 0 ? {} : r
4504
4633
  });
4505
4634
  } catch (n) {
4506
- m("workflow terminal observer failed", {
4635
+ p("workflow terminal observer failed", {
4507
4636
  tag: s.name,
4508
4637
  executionId: e,
4509
4638
  status: t,
@@ -4511,23 +4640,23 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4511
4640
  });
4512
4641
  }
4513
4642
  });
4514
- return (y, b) => S.gen(function* () {
4515
- let C = Date.now(), ie = yield* re.get(i), w = yield* re.get(a), ae = s.parentExecutionId ?? ie ?? null, oe = s.parentGeneration ?? (s.parentExecutionId == null ? w : void 0) ?? null, T = s.parentClosePolicy ?? null, E, D = (e, t) => t.pipe(S.catchAllCause((t) => x.isInterrupted(t) ? S.failCause(t) : S.sync(() => {
4643
+ return (ee, y) => S.gen(function* () {
4644
+ let b = Date.now(), te = yield* oe.get(i), re = yield* oe.get(a), C = s.parentExecutionId ?? te ?? null, se = s.parentGeneration ?? (s.parentExecutionId == null ? re : void 0) ?? null, w = s.parentClosePolicy ?? null, T, E = (e, t) => t.pipe(S.catchAllCause((t) => x.isInterrupted(t) ? S.failCause(t) : S.sync(() => {
4516
4645
  let n = x.squash(t);
4517
- m(e, {
4646
+ p(e, {
4518
4647
  tag: s.name,
4519
- executionId: b,
4648
+ executionId: y,
4520
4649
  reason: n?.message ?? String(n)
4521
4650
  });
4522
- }))), O = `wfrg_${Fi()}`, ce = yield* S.serviceOption(f), k = d("wr"), le = yield* S.sync(() => s.encodePayload === void 0 ? y : s.encodePayload(y)), A = yield* S.promise(() => s.transaction((e) => pn(e, {
4651
+ }))), D = `wfrg_${Wi()}`, le = yield* S.serviceOption(h), ue = d("wr"), O = yield* S.sync(() => s.encodePayload === void 0 ? ee : s.encodePayload(ee)), k = yield* S.promise(() => s.transaction((e) => yn(e, {
4523
4652
  workflowName: s.name,
4524
- executionId: b,
4525
- generation: O,
4526
- now: C,
4527
- delivery: ce._tag === "Some" ? ce.value : null,
4653
+ executionId: y,
4654
+ generation: D,
4655
+ now: b,
4656
+ delivery: le._tag === "Some" ? le.value : null,
4528
4657
  initialRow: {
4529
- id: k,
4530
- payload: le,
4658
+ id: ue,
4659
+ payload: O,
4531
4660
  workflowVersion: s.workflowVersion ?? null,
4532
4661
  workflowPatches: s.workflowPatches ?? null,
4533
4662
  output: null,
@@ -4536,42 +4665,42 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4536
4665
  errorTag: null,
4537
4666
  errorMessage: null,
4538
4667
  cancelled: !1,
4539
- startedAt: new Date(C),
4668
+ startedAt: new Date(b),
4540
4669
  completedAt: null,
4541
4670
  durationMs: null,
4542
4671
  traceId: s.traceId ?? null,
4543
- parentExecutionId: ae,
4544
- parentGeneration: oe,
4545
- parentClosePolicy: T
4672
+ parentExecutionId: C,
4673
+ parentGeneration: se,
4674
+ parentClosePolicy: w
4546
4675
  }
4547
4676
  })));
4548
- if (typeof A.row.id != "string") return yield* S.die(/* @__PURE__ */ Error("Recorded workflow entry has no run identity"));
4549
- if (E = A.row.id, A.kind === "cancelled" || A.kind === "already-cancelled") {
4550
- let e = yield* ye;
4551
- return e.interrupted = !0, A.kind === "cancelled" && (yield* D("failed to observe suspended workflow cancellation", S.gen(function* () {
4552
- if (h?.("workflowRuns", {
4677
+ if (typeof k.row.id != "string") return yield* S.die(/* @__PURE__ */ Error("Recorded workflow entry has no run identity"));
4678
+ if (T = k.row.id, k.kind === "cancelled" || k.kind === "already-cancelled") {
4679
+ let e = yield* xe;
4680
+ return e.interrupted = !0, k.kind === "cancelled" && (yield* E("failed to observe suspended workflow cancellation", S.gen(function* () {
4681
+ if (m?.("workflowRuns", {
4553
4682
  op: "update",
4554
- row: $(A.row)
4555
- }), A.terminalEvent === void 0) return yield* S.die(/* @__PURE__ */ Error("Cancelled entry has no terminal event"));
4556
- yield* g(A.terminalEvent), yield* _(b, "cancelled", E);
4557
- })), yield* v(b, "cancelled", E), yield* S.sync(() => s.recordRun?.({
4683
+ row: $(k.row)
4684
+ }), k.terminalEvent === void 0) return yield* S.die(/* @__PURE__ */ Error("Cancelled entry has no terminal event"));
4685
+ yield* g(k.terminalEvent), yield* _(y, "cancelled", T);
4686
+ })), yield* v(y, "cancelled", T), yield* S.sync(() => s.recordRun?.({
4558
4687
  name: s.name,
4559
4688
  status: "cancelled",
4560
4689
  durationMs: 0
4561
4690
  }))), yield* S.interrupt;
4562
4691
  }
4563
- let ue = A.previous, j = ue?.workflowVersion ?? null;
4564
- if (ue?.id !== void 0 && j !== null && s.workflowCompatibleVersions !== void 0 && s.workflowCompatibleVersions !== null && !s.workflowCompatibleVersions.includes(j)) {
4565
- let e = `Workflow '${s.name}' run '${b}' was started on version ${j}, but current code is compatible with ${s.workflowCompatibleVersions.join(", ")}`, t = s.failureContext ?? {
4692
+ let A = k.previous, de = A?.workflowVersion ?? null;
4693
+ if (A?.id !== void 0 && de !== null && s.workflowCompatibleVersions !== void 0 && s.workflowCompatibleVersions !== null && !s.workflowCompatibleVersions.includes(de)) {
4694
+ let e = `Workflow '${s.name}' run '${y}' was started on version ${de}, but current code is compatible with ${s.workflowCompatibleVersions.join(", ")}`, t = s.failureContext ?? {
4566
4695
  handler: null,
4567
4696
  callerContext: null,
4568
4697
  tenantId: null
4569
- }, n = yield* S.promise(() => s.transaction((n) => vn(n, {
4698
+ }, n = yield* S.promise(() => s.transaction((n) => wn(n, {
4570
4699
  owner: {
4571
- runId: E,
4700
+ runId: T,
4572
4701
  workflowName: s.name,
4573
- executionId: b,
4574
- generation: O
4702
+ executionId: y,
4703
+ generation: D
4575
4704
  },
4576
4705
  now: Date.now(),
4577
4706
  durationMs: 0,
@@ -4582,13 +4711,13 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4582
4711
  ...t
4583
4712
  }
4584
4713
  })));
4585
- return n.kind === "committed" && (yield* D("failed to observe workflow version rejection", S.gen(function* () {
4586
- h?.("workflowRuns", {
4714
+ return n.kind === "committed" && (yield* E("failed to observe workflow version rejection", S.gen(function* () {
4715
+ m?.("workflowRuns", {
4587
4716
  op: "update",
4588
4717
  row: $(n.row)
4589
- }), yield* g(n.terminalEvent), yield* _(b, "failed", E);
4590
- })), yield* v(b, "failed", E, {
4591
- payload: A.row.payload,
4718
+ }), yield* g(n.terminalEvent), yield* _(y, "failed", T);
4719
+ })), yield* v(y, "failed", T, {
4720
+ payload: k.row.payload,
4592
4721
  errorTag: "WorkflowVersionIncompatible",
4593
4722
  errorMessage: e
4594
4723
  }), yield* S.sync(() => s.recordRun?.({
@@ -4597,52 +4726,52 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4597
4726
  durationMs: 0
4598
4727
  }))), yield* S.fail(Error(e));
4599
4728
  }
4600
- let de = s.workflowPatches ?? [], M;
4601
- if (ue?.id !== void 0) {
4602
- E = ue.id, de = Pi(ue.workflowPatches) ?? de;
4603
- let e = A.row.reclaimCount;
4729
+ let j = s.workflowPatches ?? [], fe;
4730
+ if (A?.id !== void 0) {
4731
+ T = A.id, j = Ui(A.workflowPatches) ?? j;
4732
+ let e = k.row.reclaimCount;
4604
4733
  if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) return yield* S.die(/* @__PURE__ */ Error("Recorded workflow entry has an invalid reclaim counter"));
4605
4734
  let t = e > 0, n = s.maxRunReclaims ?? 3;
4606
4735
  if (t && e >= n) {
4607
- let t = `Workflow '${s.name}' run '${b}' killed its runner ${e} times in a row; parked instead of reclaimed again (maxRunReclaims=${n}).`, r = yield* S.promise(() => s.transaction((e) => gn(e, {
4608
- runId: E,
4736
+ let t = `Workflow '${s.name}' run '${y}' killed its runner ${e} times in a row; parked instead of reclaimed again (maxRunReclaims=${n}).`, r = yield* S.promise(() => s.transaction((e) => Sn(e, {
4737
+ runId: T,
4609
4738
  workflowName: s.name,
4610
- executionId: b,
4611
- generation: O
4739
+ executionId: y,
4740
+ generation: D
4612
4741
  }, {
4613
4742
  errorTag: "WorkflowCrashLooped",
4614
4743
  errorMessage: t
4615
4744
  })));
4616
- r.kind === "committed" && (yield* D("failed to observe workflow crash-loop park", S.gen(function* () {
4617
- h?.("workflowRuns", {
4745
+ r.kind === "committed" && (yield* E("failed to observe workflow crash-loop park", S.gen(function* () {
4746
+ m?.("workflowRuns", {
4618
4747
  op: "update",
4619
4748
  row: $(r.row)
4620
- }), yield* S.promise(() => p.recordEvent({
4621
- runId: E,
4749
+ }), yield* S.promise(() => f.recordEvent({
4750
+ runId: T,
4622
4751
  eventType: "run-crashlooped",
4623
4752
  payload: {
4624
4753
  reclaimCount: e,
4625
4754
  maxRunReclaims: n,
4626
- executionId: b,
4755
+ executionId: y,
4627
4756
  tag: s.name
4628
4757
  }
4629
4758
  }));
4630
- })), m("workflow run parked after repeated runner deaths", {
4759
+ })), p("workflow run parked after repeated runner deaths", {
4631
4760
  tag: s.name,
4632
- executionId: b,
4633
- runId: E,
4761
+ executionId: y,
4762
+ runId: T,
4634
4763
  reclaimCount: e,
4635
4764
  maxRunReclaims: n
4636
4765
  }));
4637
- let i = yield* ye;
4638
- return yield* ee.suspend(i);
4766
+ let i = yield* xe;
4767
+ return yield* ne.suspend(i);
4639
4768
  }
4640
- M = yield* zi(s, E, m), yield* D("failed to record workflow re-entry", S.gen(function* () {
4641
- h?.("workflowRuns", {
4769
+ fe = yield* Ji(s, T, p), yield* E("failed to record workflow re-entry", S.gen(function* () {
4770
+ m?.("workflowRuns", {
4642
4771
  op: "update",
4643
- row: $(A.row)
4644
- }), t && (yield* S.promise(() => p.recordEvent({
4645
- runId: E,
4772
+ row: $(k.row)
4773
+ }), t && (yield* S.promise(() => f.recordEvent({
4774
+ runId: T,
4646
4775
  eventType: "run-resumed",
4647
4776
  payload: {
4648
4777
  reason: "runner-reclaim",
@@ -4651,66 +4780,66 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4651
4780
  }
4652
4781
  })));
4653
4782
  }));
4654
- } else yield* D("failed to emit recorded workflow start", S.gen(function* () {
4655
- if (h?.("workflowRuns", {
4783
+ } else yield* E("failed to emit recorded workflow start", S.gen(function* () {
4784
+ if (m?.("workflowRuns", {
4656
4785
  op: "insert",
4657
- row: $(A.row)
4658
- }), E) {
4659
- let e = E;
4660
- yield* S.promise(() => p.recordEvent({
4786
+ row: $(k.row)
4787
+ }), T) {
4788
+ let e = T;
4789
+ yield* S.promise(() => f.recordEvent({
4661
4790
  runId: e,
4662
4791
  eventType: "run-started",
4663
4792
  payload: {
4664
4793
  tag: s.name,
4665
- executionId: b,
4794
+ executionId: y,
4666
4795
  source: s.source ?? null,
4667
4796
  workflowVersion: s.workflowVersion ?? null,
4668
4797
  workflowPatches: s.workflowPatches ?? null,
4669
- parentExecutionId: ae,
4670
- parentClosePolicy: T
4798
+ parentExecutionId: C,
4799
+ parentClosePolicy: w
4671
4800
  }
4672
4801
  }));
4673
4802
  }
4674
4803
  }));
4675
- let N = s.subject?.tenantId, fe = S.suspend(() => l(y, b, O)).pipe(S.locally(t, E), S.locally(i, b), S.locally(a, O), S.locally(n, typeof N == "string" ? N : void 0), S.locally(o, de), S.locally(c, M), S.provideService(r, p)), pe = s.pluginWorkflowStepLayer ? fe.pipe(S.provide(s.pluginWorkflowStepLayer)) : fe, me = yield* ee.intoResult(S.raceWith(pe, ki({
4676
- runId: E,
4804
+ let M = s.subject?.tenantId, pe = S.suspend(() => l(ee, y, D)).pipe(S.locally(t, T), S.locally(i, y), S.locally(a, D), S.locally(n, typeof M == "string" ? M : void 0), S.locally(o, j), S.locally(c, fe), S.provideService(r, f)), N = s.pluginWorkflowStepLayer ? pe.pipe(S.provide(s.pluginWorkflowStepLayer)) : pe, P = yield* ne.intoResult(S.raceWith(N, Ri({
4805
+ runId: T,
4677
4806
  workflowName: s.name,
4678
- executionId: b,
4679
- generation: O
4680
- }, async (e) => s.store.query(e), () => m("workflow control read failed; retrying without claiming cancellation", {
4681
- executionId: b,
4682
- runId: E
4807
+ executionId: y,
4808
+ generation: D
4809
+ }, async (e) => s.store.query(e), () => p("workflow control read failed; retrying without claiming cancellation", {
4810
+ executionId: y,
4811
+ runId: T
4683
4812
  })).pipe(S.interruptible), {
4684
- onSelfDone: (e, t) => ne.interrupt(t).pipe(S.zipRight(e)),
4685
- onOtherDone: (e, t) => ne.interrupt(t).pipe(S.zipRight(e))
4813
+ onSelfDone: (e, t) => ae.interrupt(t).pipe(S.zipRight(e)),
4814
+ onOtherDone: (e, t) => ae.interrupt(t).pipe(S.zipRight(e))
4686
4815
  }));
4687
- if (ee.isResult(me) && me._tag === "Suspended") {
4688
- let e = me.cause, t = e !== void 0 && !x.isEmpty(e), n = t ? x.squash(e) : void 0, r = n && typeof n == "object" && "_tag" in n ? String(n._tag) : null, i = t ? n?.message ?? String(n) : null, a = yield* S.promise(() => s.transaction((e) => gn(e, {
4689
- runId: E,
4816
+ if (ne.isResult(P) && P._tag === "Suspended") {
4817
+ let e = P.cause, t = e !== void 0 && !x.isEmpty(e), n = t ? x.squash(e) : void 0, r = n && typeof n == "object" && "_tag" in n ? String(n._tag) : null, i = t ? n?.message ?? String(n) : null, a = yield* S.promise(() => s.transaction((e) => Sn(e, {
4818
+ runId: T,
4690
4819
  workflowName: s.name,
4691
- executionId: b,
4692
- generation: O
4820
+ executionId: y,
4821
+ generation: D
4693
4822
  }, {
4694
4823
  errorTag: r,
4695
4824
  errorMessage: i
4696
4825
  })));
4697
- a.kind === "committed" && t && (yield* S.sync(() => se({
4826
+ a.kind === "committed" && t && (yield* S.sync(() => ce({
4698
4827
  error: n,
4699
4828
  source: "workflow",
4700
4829
  name: s.name,
4701
4830
  ...s.traceId ? { traceId: s.traceId } : {},
4702
4831
  fields: {
4703
- executionId: b,
4832
+ executionId: y,
4704
4833
  suspendedOnFailure: !0,
4705
4834
  ...r ? { errorTag: r } : {},
4706
- ...E ? { runId: E } : {}
4835
+ ...T ? { runId: T } : {}
4707
4836
  }
4708
- }))), a.kind === "committed" && (yield* D("failed to observe workflow suspend", S.gen(function* () {
4709
- h?.("workflowRuns", {
4837
+ }))), a.kind === "committed" && (yield* E("failed to observe workflow suspend", S.gen(function* () {
4838
+ m?.("workflowRuns", {
4710
4839
  op: "update",
4711
4840
  row: $(a.row)
4712
- }), yield* S.promise(() => p.recordEvent({
4713
- runId: E,
4841
+ }), yield* S.promise(() => f.recordEvent({
4842
+ runId: T,
4714
4843
  eventType: "run-suspended",
4715
4844
  payload: t ? {
4716
4845
  reason: "suspend-on-failure",
@@ -4719,21 +4848,21 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4719
4848
  } : { reason: "workflow-suspend" }
4720
4849
  }));
4721
4850
  })));
4722
- let o = yield* ye;
4723
- return yield* ee.suspend(o);
4851
+ let o = yield* xe;
4852
+ return yield* ne.suspend(o);
4724
4853
  }
4725
- let he = me;
4726
- if (M !== void 0 && E !== void 0) {
4727
- let t = M.settle();
4854
+ let me = P;
4855
+ if (fe !== void 0 && T !== void 0) {
4856
+ let t = fe.settle();
4728
4857
  if (t.length > 0) {
4729
- let n = E;
4730
- m("workflow replay reached a different step shape than this run recorded", {
4858
+ let n = T;
4859
+ p("workflow replay reached a different step shape than this run recorded", {
4731
4860
  tag: s.name,
4732
- executionId: b,
4861
+ executionId: y,
4733
4862
  runId: n,
4734
4863
  findings: t.map((e) => `${e.kind}:${e.stepName}`)
4735
- }), yield* D("failed to record nondeterminism findings", S.promise(async () => {
4736
- for (let r of t) await p.recordEvent({
4864
+ }), yield* E("failed to record nondeterminism findings", S.promise(async () => {
4865
+ for (let r of t) await f.recordEvent({
4737
4866
  runId: n,
4738
4867
  eventType: "nondeterminism-suspected",
4739
4868
  payload: e(r)
@@ -4741,44 +4870,44 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4741
4870
  }));
4742
4871
  }
4743
4872
  }
4744
- if (te.isFailure(he.exit)) {
4745
- let e = he.exit.cause;
4746
- if ((yield* ye).interrupted && x.isInterruptedOnly(e)) {
4747
- let t = Date.now(), n = yield* S.promise(() => s.transaction((e) => vn(e, {
4873
+ if (ie.isFailure(me.exit)) {
4874
+ let e = me.exit.cause;
4875
+ if ((yield* xe).interrupted && x.isInterruptedOnly(e)) {
4876
+ let t = Date.now(), n = yield* S.promise(() => s.transaction((e) => wn(e, {
4748
4877
  owner: {
4749
- runId: E,
4878
+ runId: T,
4750
4879
  workflowName: s.name,
4751
- executionId: b,
4752
- generation: O
4880
+ executionId: y,
4881
+ generation: D
4753
4882
  },
4754
4883
  now: t,
4755
- durationMs: t - C,
4884
+ durationMs: t - b,
4756
4885
  outcome: { status: "cancelled" }
4757
4886
  })));
4758
- return n.kind === "committed" && (yield* D("failed to observe workflow cancellation", S.gen(function* () {
4759
- h?.("workflowRuns", {
4887
+ return n.kind === "committed" && (yield* E("failed to observe workflow cancellation", S.gen(function* () {
4888
+ m?.("workflowRuns", {
4760
4889
  op: "update",
4761
4890
  row: $(n.row)
4762
- }), yield* g(n.terminalEvent), yield* _(b, "cancelled", E);
4763
- })), yield* v(b, "cancelled", E), yield* S.sync(() => s.recordRun?.({
4891
+ }), yield* g(n.terminalEvent), yield* _(y, "cancelled", T);
4892
+ })), yield* v(y, "cancelled", T), yield* S.sync(() => s.recordRun?.({
4764
4893
  name: s.name,
4765
4894
  status: "cancelled",
4766
- durationMs: t - C
4895
+ durationMs: t - b
4767
4896
  }))), yield* S.failCause(e);
4768
4897
  }
4769
4898
  let t = x.failureOption(e), n = t._tag === "Some" ? t.value : x.squash(e), r = n && typeof n == "object" && "_tag" in n ? String(n._tag) : null, i = n?.message ?? String(n), a = Date.now(), o = s.failureContext ?? {
4770
4899
  handler: null,
4771
4900
  callerContext: null,
4772
4901
  tenantId: null
4773
- }, c = yield* S.promise(() => s.transaction((e) => vn(e, {
4902
+ }, c = yield* S.promise(() => s.transaction((e) => wn(e, {
4774
4903
  owner: {
4775
- runId: E,
4904
+ runId: T,
4776
4905
  workflowName: s.name,
4777
- executionId: b,
4778
- generation: O
4906
+ executionId: y,
4907
+ generation: D
4779
4908
  },
4780
4909
  now: a,
4781
- durationMs: a - C,
4910
+ durationMs: a - b,
4782
4911
  outcome: {
4783
4912
  status: "failed",
4784
4913
  errorTag: r,
@@ -4786,57 +4915,57 @@ var pt = async (e, t, n) => (await mt(e, t, n)).map((e) => dt(e)), mt = async (e
4786
4915
  ...o
4787
4916
  }
4788
4917
  })));
4789
- return c.kind === "committed" ? (yield* S.sync(() => se({
4918
+ return c.kind === "committed" ? (yield* S.sync(() => ce({
4790
4919
  error: n,
4791
4920
  source: "workflow",
4792
4921
  name: s.name,
4793
4922
  ...s.traceId ? { traceId: s.traceId } : {},
4794
4923
  fields: {
4795
- executionId: b,
4924
+ executionId: y,
4796
4925
  ...r ? { errorTag: r } : {},
4797
- ...E ? { runId: E } : {}
4926
+ ...T ? { runId: T } : {}
4798
4927
  }
4799
- })), E && (yield* D("failed to record workflow failure", S.gen(function* () {
4800
- h?.("workflowRuns", {
4928
+ })), T && (yield* E("failed to record workflow failure", S.gen(function* () {
4929
+ m?.("workflowRuns", {
4801
4930
  op: "update",
4802
4931
  row: $(c.row)
4803
- }), yield* g(c.terminalEvent), yield* _(b, "failed", E);
4804
- }))), yield* v(b, "failed", E, {
4805
- payload: y,
4932
+ }), yield* g(c.terminalEvent), yield* _(y, "failed", T);
4933
+ }))), yield* v(y, "failed", T, {
4934
+ payload: ee,
4806
4935
  errorTag: r,
4807
4936
  errorMessage: i
4808
4937
  }), yield* S.sync(() => s.recordRun?.({
4809
4938
  name: s.name,
4810
4939
  status: "failed",
4811
- durationMs: Date.now() - C
4940
+ durationMs: Date.now() - b
4812
4941
  })), yield* S.failCause(e)) : yield* S.failCause(e);
4813
4942
  }
4814
- let ge = he.exit.value, _e = Date.now(), P = yield* S.promise(() => s.transaction((e) => vn(e, {
4943
+ let he = me.exit.value, ge = Date.now(), _e = yield* S.promise(() => s.transaction((e) => wn(e, {
4815
4944
  owner: {
4816
- runId: E,
4945
+ runId: T,
4817
4946
  workflowName: s.name,
4818
- executionId: b,
4819
- generation: O
4947
+ executionId: y,
4948
+ generation: D
4820
4949
  },
4821
- now: _e,
4822
- durationMs: _e - C,
4950
+ now: ge,
4951
+ durationMs: ge - b,
4823
4952
  outcome: {
4824
4953
  status: "succeeded",
4825
- output: Li(ge, u)
4954
+ output: Ki(he, u)
4826
4955
  }
4827
4956
  })));
4828
- return P.kind === "committed" ? (E && (yield* D("failed to record workflow success", S.gen(function* () {
4829
- h?.("workflowRuns", {
4957
+ return _e.kind === "committed" ? (T && (yield* E("failed to record workflow success", S.gen(function* () {
4958
+ m?.("workflowRuns", {
4830
4959
  op: "update",
4831
- row: $(P.row)
4832
- }), yield* g(P.terminalEvent), yield* _(b, "succeeded", E);
4833
- }))), yield* v(b, "succeeded", E), yield* S.sync(() => s.recordRun?.({
4960
+ row: $(_e.row)
4961
+ }), yield* g(_e.terminalEvent), yield* _(y, "succeeded", T);
4962
+ }))), yield* v(y, "succeeded", T), yield* S.sync(() => s.recordRun?.({
4834
4963
  name: s.name,
4835
4964
  status: "succeeded",
4836
- durationMs: Date.now() - C,
4965
+ durationMs: Date.now() - b,
4837
4966
  completedAtSec: Date.now() / 1e3
4838
- })), ge) : ge;
4967
+ })), he) : he;
4839
4968
  });
4840
4969
  };
4841
4970
  //#endregion
4842
- export { Hn as $, Ke as $t, Wr as A, zt as At, nr as B, vt as Bt, ri as C, Qt as Ct, Yr as D, Kt as Dt, Jr as E, Pt as Et, Lr as F, en as Ft, qn as G, B as Gt, rr as H, xt as Ht, Ir as I, At as It, Wn as J, it as Jt, Jn as K, Ct as Kt, Sr as L, Dt as Lt, Pr as M, Y as Mt, Br as N, Wt as Nt, Xr as O, Vt as Ot, zr as P, Rt as Pt, Un as Q, Le as Qt, jr as R, kt as Rt, pi as S, tn as St, ei as T, Lt as Tt, dr as U, pt as Ut, ir as V, St as Vt, Kn as W, bt as Wt, tr as X, z as Xt, Zn as Y, ot as Yt, Qn as Z, Ye as Zt, si as _, Ce as _n, $t as _t, Ni as a, R as an, Mn as at, vi as b, be as bn, Xt as bt, Bi as c, Me as cn, hn as ct, Si as d, Ee as dn, ln as dt, Ve as en, Bn as et, Z as f, Ne as fn, W as ft, ci as g, we as gn, qt as gt, li as h, ke as hn, U as ht, Pi as i, ze as in, Fn as it, Hr as j, It as jt, Zr as k, nn as kt, Oi as l, De as ln, vn as lt, fi as m, Ae as mn, jt as mt, Mi as n, We as nn, zn as nt, $ as o, Ie as on, Nn as ot, di as p, je as pn, Nt as pt, Gn as q, ht as qt, Ri as r, Be as rn, Pn as rt, Li as s, Te as sn, yn as st, ji as t, Ge as tn, Ln as tt, Di as u, Oe as un, pn as ut, oi as v, Se as vn, Jt as vt, ii as w, Ht as wt, _i as x, Gt as xt, yi as y, xe as yn, Yt as yt, wr as z, Ot as zt };
4971
+ export { Jn as $, ze as $t, Zr as A, on as At, cr as B, jt as Bt, di as C, an as Ct, ni as D, Lt as Dt, ti as E, Bt as Et, Wr as F, Vt as Ft, $n as G, St as Gt, lr as H, wt as Ht, Ur as I, rn as It, Xn as J, _t as Jt, er as K, V as Kt, Or as L, Nt as Lt, Vr as M, zt as Mt, qr as N, Y as Nt, ii as O, Yt as Ot, Kr as P, qt as Pt, Yn as Q, Qe as Qt, Rr as R, At as Rt, xi as S, Jt as St, ci as T, Gt as Tt, _r as U, Ct as Ut, ur as V, bt as Vt, Qn as W, ht as Wt, sr as X, ct as Xt, rr as Y, B as Yt, ir as Z, z as Zt, hi as _, Ee as _n, Xt as _t, Hi as a, Ve as an, Rn as at, Ei as b, Ce as bn, Qt as bt, Yi as c, De as cn, xn as ct, Ai as d, Ae as dn, pn as dt, Ye as en, Kn as et, Q as f, Oe as fn, fn as ft, gi as g, je as gn, U as gt, _i as h, Me as hn, Pt as ht, Ui as i, Ue as in, Vn as it, Yr as j, Ht as jt, ai as k, Wt as kt, Li as l, Pe as ln, wn as lt, bi as m, Ne as mn, It as mt, Vi as n, Je as nn, Gn as nt, $ as o, He as on, zn as ot, yi as p, Fe as pn, W as pt, Zn as q, Tt as qt, qi as r, qe as rn, Bn as rt, Ki as s, Re as sn, Tn as st, Bi as t, We as tn, Un as tt, Ii as u, ke as un, yn as ut, mi as v, Te as vn, nn as vt, fi as w, tn as wt, Ti as x, Se as xn, $t as xt, Di as y, we as yn, Zt as yt, Ar as z, Mt as zt };