@voltro/workflow 0.86.0 → 0.88.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.
- package/CHANGELOG.md +5484 -0
- package/THIRD-PARTY-NOTICES.md +3 -227
- package/dist/admission.js +1 -2
- package/dist/admissionDrainer.js +5 -3
- package/dist/admissionGate.js +1 -2
- package/dist/admissionStore.js +1 -2
- package/dist/admissionSubmission.js +1 -2
- package/dist/admissionTables.js +4 -4
- package/dist/admissionTransaction.js +1 -2
- package/dist/awaitEvent.js +1 -2
- package/dist/budgetHold.js +1 -2
- package/dist/cancelOnPlan.js +1 -2
- package/dist/cancelOnSweep.js +1 -2
- package/dist/cancelPendingStart.js +1 -2
- package/dist/cluster.d.ts +111 -27
- package/dist/cluster.js +12 -8
- package/dist/clusterCron.js +18 -11
- package/dist/clusterDiagnostics.js +1 -2
- package/dist/clusterDiagnosticsSql.js +1 -2
- package/dist/clusterLayer.js +105 -71
- package/dist/clusterMigrationGate.js +1 -2
- package/dist/clusterRunnerLayer.js +27 -18
- package/dist/clusterShardGroups.js +32 -0
- package/dist/clusterTestSuite.d.ts +45 -2
- package/dist/clusterTestSuite.js +225 -197
- package/dist/controlMonitor.js +1 -2
- package/dist/controlRequest.js +1 -2
- package/dist/executionRefusal.js +1 -2
- package/dist/failureHandoff.js +1 -2
- package/dist/failureMessage.js +1 -2
- package/dist/failureRecovery.js +1 -2
- package/dist/failureReportStore.js +1 -2
- package/dist/flowControl.js +1 -2
- package/dist/forwardStartReceipts.js +1 -2
- package/dist/inMemoryLayer.js +1 -2
- package/dist/inMemoryRecorder.js +1 -2
- package/dist/index.d.ts +50 -23
- package/dist/index.js +24 -23
- package/dist/inspectWorkflow.js +2 -3
- package/dist/journalEncryption.js +1 -2
- package/dist/journalRoutingGuard.js +49 -0
- package/dist/journalRoutingLayout.js +46 -0
- package/dist/journalRoutingLock.js +38 -0
- package/dist/journalRoutingMaintenance.js +23 -0
- package/dist/journalRoutingMessageStorage.js +31 -0
- package/dist/journalRoutingNamespace.js +22 -0
- package/dist/journalRoutingRuntime.js +32 -0
- package/dist/journalRoutingSharding.js +27 -0
- package/dist/journalRoutingState.js +92 -0
- package/dist/journalRoutingTable.js +10 -0
- package/dist/journalRoutingTransaction.js +15 -0
- package/dist/messages.js +1 -2
- package/dist/nondeterminism.js +1 -2
- package/dist/parentClosure.js +1 -2
- package/dist/parentClosureRecovery.js +1 -2
- package/dist/pendingSubmission.js +1 -2
- package/dist/prepareSubmissionDispatch.js +1 -2
- package/dist/preparedExecution.js +1 -2
- package/dist/primitives.js +1 -2
- package/dist/queuedCancellationRequest.js +1 -2
- package/dist/queuedControl.js +1 -2
- package/dist/recorder.js +1 -2
- package/dist/residentExecutionEvidence.js +1 -2
- package/dist/retryPolicy.js +1 -2
- package/dist/runEventsTable.js +1 -2
- package/dist/runGeneration.js +1 -2
- package/dist/runRecording.js +1 -2
- package/dist/runStepsTable.js +1 -2
- package/dist/runnerStorageGuard.js +1 -2
- package/dist/runsTable.js +1 -2
- package/dist/scheduleDeclaration.js +1 -2
- package/dist/signalHint.js +1 -2
- package/dist/signals.js +1 -2
- package/dist/signalsSuspending.js +1 -2
- package/dist/sqliteWorkflowOwnership.js +1 -2
- package/dist/stalenessSweep.js +1 -2
- package/dist/startContextsTable.js +1 -2
- package/dist/startReceipt.js +1 -2
- package/dist/submissionRecovery.js +1 -2
- package/dist/submissionRejection.js +1 -2
- package/dist/submissionRetry.js +1 -2
- package/dist/suspensionUnavailable.js +1 -2
- package/dist/updates.js +1 -2
- package/dist/watermarkTable.js +1 -2
- package/dist/webCrypto.js +4 -17
- package/dist/workflowDelivery.js +1 -2
- package/dist/workflowExecutorRouting.js +32 -0
- package/dist/workflowJournal.js +1 -2
- package/dist/workflowJournalReset.js +1 -2
- package/dist/workflowReadSelections.js +1 -2
- package/dist/workflowRestartDispatch.js +30 -25
- package/dist/workflowRestartObservation.js +1 -2
- package/dist/workflowRestartPreparation.js +1 -2
- package/dist/workflowRestartReservation.js +158 -157
- package/dist/workflowResumeDispatch.js +18 -18
- package/dist/workflowRuntimeReadiness.js +11 -0
- package/dist/workflowShardRelocation.js +57 -0
- package/dist/workflowShardRelocationSql.js +71 -0
- package/package.json +5 -11
|
@@ -1,50 +1,52 @@
|
|
|
1
1
|
import { resolveAdmissionKeys as e } from "./admission.js";
|
|
2
2
|
import { decodePendingPayload as t, evaluateAdmission as n, recordAdmission as r } from "./admissionStore.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
3
|
+
import { ownedJournalRoutingPromise as i } from "./journalRoutingGuard.js";
|
|
4
|
+
import { resetExpectedWorkflowReplies as a } from "./workflowJournalReset.js";
|
|
5
|
+
import { Effect as o, Schema as s } from "effect";
|
|
6
|
+
import { WorkflowRestartObservationSchema as c, WorkflowRestartSelectionSchema as l, WorkflowRestartTargetSchema as u } from "@voltro/protocol";
|
|
7
|
+
import { and as d, derivedRowId as f, eq as p, id as m, integer as h, json as g, or as _, table as v, text as y, timestamp as b } from "@voltro/database";
|
|
8
|
+
// src/workflowRestartReservation.ts
|
|
9
|
+
var x = v("_voltro_workflow_restart_requests", {
|
|
10
|
+
id: m({ prefix: "wfrs" }),
|
|
11
|
+
runId: y(),
|
|
12
|
+
workflowName: y(),
|
|
13
|
+
executionId: y(),
|
|
14
|
+
generation: y(),
|
|
15
|
+
token: y(),
|
|
16
|
+
ledgerId: y(),
|
|
17
|
+
tenantId: y().nullable(),
|
|
18
|
+
delivery: g(),
|
|
19
|
+
replies: g(),
|
|
20
|
+
selection: g().nullable(),
|
|
21
|
+
eviction: g().nullable(),
|
|
22
|
+
requestedAt: b(),
|
|
23
|
+
dispatchAttempts: h().default(0),
|
|
24
|
+
enteredGeneration: y().nullable(),
|
|
25
|
+
poolReleaseSettledAt: b().nullable()
|
|
26
|
+
}).unique(["runId", "generation"]).unique(["runId", "token"]).index("_voltro_workflow_restart_requests_pool_settlement_idx", ["poolReleaseSettledAt", "id"]).nonReactive(), S = s.NonEmptyString, C = s.Struct({
|
|
27
|
+
requestId: S,
|
|
28
|
+
restartToken: s.NullOr(S)
|
|
29
|
+
}), w = s.Struct({
|
|
30
|
+
requestId: S,
|
|
31
|
+
replyId: S
|
|
32
|
+
}), T = l, E = v("_voltro_workflow_restart_withdrawals", {
|
|
33
|
+
id: m({ prefix: "wfrw" }),
|
|
34
|
+
runId: y(),
|
|
35
|
+
workflowName: y(),
|
|
36
|
+
tenantId: y().nullable(),
|
|
37
|
+
selection: g(),
|
|
38
|
+
withdrawnAt: b()
|
|
39
|
+
}).nonReactive(), D = s.Struct({
|
|
40
|
+
id: s.NonEmptyString,
|
|
41
|
+
runId: s.NonEmptyString,
|
|
42
|
+
workflowName: s.NonEmptyString,
|
|
43
|
+
tenantId: s.NullOr(s.NonEmptyString),
|
|
44
|
+
selection: T,
|
|
45
|
+
withdrawnAt: s.Date
|
|
46
|
+
}), O = async (e, t) => {
|
|
47
|
+
let n = s.decodeUnknownSync(u)(t), [r] = await e.query({
|
|
48
|
+
table: E.tableName,
|
|
49
|
+
predicate: p("id", n.requestId),
|
|
48
50
|
lock: "update",
|
|
49
51
|
order: [],
|
|
50
52
|
take: 1,
|
|
@@ -52,35 +54,35 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
52
54
|
projection: void 0
|
|
53
55
|
});
|
|
54
56
|
if (r === void 0) return;
|
|
55
|
-
let i =
|
|
57
|
+
let i = s.decodeUnknownSync(D)(r);
|
|
56
58
|
if (i.runId !== n.runId) throw Error("Restart identity belongs to a different command");
|
|
57
59
|
if (!Number.isFinite(i.withdrawnAt.getTime())) throw Error("Invalid restart withdrawal timestamp");
|
|
58
60
|
return i;
|
|
59
|
-
},
|
|
60
|
-
if (await
|
|
61
|
-
},
|
|
62
|
-
id:
|
|
63
|
-
runId:
|
|
64
|
-
workflowName:
|
|
65
|
-
executionId:
|
|
66
|
-
generation:
|
|
67
|
-
token:
|
|
68
|
-
ledgerId:
|
|
69
|
-
tenantId:
|
|
70
|
-
delivery:
|
|
71
|
-
replies:
|
|
72
|
-
selection:
|
|
73
|
-
eviction:
|
|
74
|
-
executionId:
|
|
75
|
-
runId:
|
|
61
|
+
}, k = async (e, t) => {
|
|
62
|
+
if (await O(e, t) !== void 0) throw Error("Restart request was permanently withdrawn");
|
|
63
|
+
}, A = s.Struct({
|
|
64
|
+
id: S,
|
|
65
|
+
runId: S,
|
|
66
|
+
workflowName: S,
|
|
67
|
+
executionId: S,
|
|
68
|
+
generation: S,
|
|
69
|
+
token: S,
|
|
70
|
+
ledgerId: S,
|
|
71
|
+
tenantId: s.NullOr(S),
|
|
72
|
+
delivery: C,
|
|
73
|
+
replies: s.Array(w),
|
|
74
|
+
selection: T,
|
|
75
|
+
eviction: s.NullOr(s.Struct({
|
|
76
|
+
executionId: S,
|
|
77
|
+
runId: s.String
|
|
76
78
|
})),
|
|
77
|
-
requestedAt:
|
|
78
|
-
dispatchAttempts:
|
|
79
|
-
enteredGeneration:
|
|
80
|
-
}),
|
|
81
|
-
let n =
|
|
82
|
-
table:
|
|
83
|
-
predicate:
|
|
79
|
+
requestedAt: s.Date,
|
|
80
|
+
dispatchAttempts: s.Number.check(s.isInt(), s.isGreaterThanOrEqualTo(0)),
|
|
81
|
+
enteredGeneration: s.NullOr(S)
|
|
82
|
+
}), j = (e, t) => e.kind === t.kind && (e.kind === "failed-steps" || t.kind === "from-step" && e.stepName === t.stepName), M = async (e, t) => {
|
|
83
|
+
let n = s.decodeUnknownSync(u)(t), [r] = await e.query({
|
|
84
|
+
table: x.tableName,
|
|
85
|
+
predicate: p("id", n.requestId),
|
|
84
86
|
lock: "update",
|
|
85
87
|
order: [],
|
|
86
88
|
take: 1,
|
|
@@ -88,20 +90,20 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
88
90
|
projection: void 0
|
|
89
91
|
});
|
|
90
92
|
if (r === void 0) return;
|
|
91
|
-
let i =
|
|
93
|
+
let i = s.decodeUnknownSync(A)(r);
|
|
92
94
|
if (i.runId !== n.runId) throw Error("Restart identity belongs to a different command");
|
|
93
95
|
return i;
|
|
94
|
-
},
|
|
95
|
-
let n = await
|
|
96
|
-
if (n !== void 0) return
|
|
96
|
+
}, N = async (e, t) => {
|
|
97
|
+
let n = await O(e, t);
|
|
98
|
+
if (n !== void 0) return s.decodeUnknownSync(c)({
|
|
97
99
|
...t,
|
|
98
100
|
kind: "withdrawn",
|
|
99
101
|
workflowName: n.workflowName,
|
|
100
102
|
selection: n.selection,
|
|
101
103
|
withdrawnAt: n.withdrawnAt.getTime()
|
|
102
104
|
});
|
|
103
|
-
let r = await
|
|
104
|
-
if (r === void 0) return
|
|
105
|
+
let r = await M(e, t);
|
|
106
|
+
if (r === void 0) return s.decodeUnknownSync(c)({
|
|
105
107
|
...t,
|
|
106
108
|
kind: "not-found"
|
|
107
109
|
});
|
|
@@ -115,7 +117,7 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
115
117
|
requestedAt: r.requestedAt.getTime(),
|
|
116
118
|
dispatchAttempts: r.dispatchAttempts
|
|
117
119
|
};
|
|
118
|
-
return
|
|
120
|
+
return s.decodeUnknownSync(c)(r.enteredGeneration === null ? {
|
|
119
121
|
...i,
|
|
120
122
|
kind: "pending"
|
|
121
123
|
} : {
|
|
@@ -123,56 +125,56 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
123
125
|
kind: "entered",
|
|
124
126
|
enteredGeneration: r.enteredGeneration
|
|
125
127
|
});
|
|
126
|
-
},
|
|
128
|
+
}, P = async (e, t) => {
|
|
127
129
|
for (let e of [
|
|
128
130
|
t.id,
|
|
129
131
|
t.runId,
|
|
130
132
|
t.workflowName
|
|
131
|
-
])
|
|
133
|
+
]) s.decodeUnknownSync(S)(e);
|
|
132
134
|
if (t.id.length > 64) throw Error("Invalid restart request identity");
|
|
133
|
-
|
|
134
|
-
let n =
|
|
135
|
-
await
|
|
135
|
+
s.decodeUnknownSync(s.NullOr(S))(t.tenantId);
|
|
136
|
+
let n = s.decodeUnknownSync(T)(t.selection);
|
|
137
|
+
await k(e, {
|
|
136
138
|
requestId: t.id,
|
|
137
139
|
runId: t.runId
|
|
138
140
|
});
|
|
139
|
-
let r = await
|
|
141
|
+
let r = await M(e, {
|
|
140
142
|
requestId: t.id,
|
|
141
143
|
runId: t.runId
|
|
142
144
|
});
|
|
143
145
|
if (r !== void 0) {
|
|
144
|
-
if (r.runId !== t.runId || r.workflowName !== t.workflowName || r.tenantId !== t.tenantId || !
|
|
146
|
+
if (r.runId !== t.runId || r.workflowName !== t.workflowName || r.tenantId !== t.tenantId || !j(r.selection, n)) throw Error("Restart identity belongs to a different command");
|
|
145
147
|
return r;
|
|
146
148
|
}
|
|
147
|
-
},
|
|
148
|
-
let n =
|
|
149
|
+
}, F = async (e, t) => {
|
|
150
|
+
let n = s.decodeUnknownSync(D)({
|
|
149
151
|
...t,
|
|
150
152
|
withdrawnAt: new Date(t.now)
|
|
151
153
|
});
|
|
152
|
-
if (
|
|
154
|
+
if (s.decodeUnknownSync(u)({
|
|
153
155
|
requestId: n.id,
|
|
154
156
|
runId: n.runId
|
|
155
157
|
}), !Number.isFinite(n.withdrawnAt.getTime())) throw Error("Invalid restart withdrawal timestamp");
|
|
156
|
-
let r = await
|
|
158
|
+
let r = await O(e, {
|
|
157
159
|
requestId: n.id,
|
|
158
160
|
runId: n.runId
|
|
159
161
|
});
|
|
160
162
|
if (r !== void 0) {
|
|
161
|
-
if (r.workflowName !== n.workflowName || r.tenantId !== n.tenantId || !
|
|
163
|
+
if (r.workflowName !== n.workflowName || r.tenantId !== n.tenantId || !j(r.selection, n.selection)) throw Error("Restart identity belongs to a different command");
|
|
162
164
|
return {
|
|
163
165
|
kind: "withdrawn",
|
|
164
166
|
withdrawal: r,
|
|
165
167
|
reused: !0
|
|
166
168
|
};
|
|
167
169
|
}
|
|
168
|
-
let i = await
|
|
170
|
+
let i = await P(e, n);
|
|
169
171
|
if (i !== void 0) return {
|
|
170
172
|
kind: "reserved",
|
|
171
173
|
request: i
|
|
172
174
|
};
|
|
173
175
|
let [a] = await e.query({
|
|
174
176
|
table: "_voltro_workflow_runs",
|
|
175
|
-
predicate:
|
|
177
|
+
predicate: p("id", n.runId),
|
|
176
178
|
lock: "update",
|
|
177
179
|
order: [],
|
|
178
180
|
take: 1,
|
|
@@ -180,49 +182,49 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
180
182
|
projection: void 0
|
|
181
183
|
});
|
|
182
184
|
if (a === void 0 || a.tag !== n.workflowName) throw Error("Restart withdrawal requires its resident workflow");
|
|
183
|
-
if ((
|
|
184
|
-
return await e.insert(
|
|
185
|
+
if ((s.decodeUnknownSync(s.NullOr(s.Struct({ tenantId: s.NullOr(S) })))(a.subject ?? null)?.tenantId ?? null) !== n.tenantId) throw Error("Restart withdrawal belongs to another resident tenant");
|
|
186
|
+
return await e.insert(E.tableName, n), {
|
|
185
187
|
kind: "withdrawn",
|
|
186
188
|
withdrawal: n,
|
|
187
189
|
reused: !1
|
|
188
190
|
};
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
let n = await
|
|
191
|
+
}, I = async (e, t) => {
|
|
192
|
+
s.decodeUnknownSync(S)(t.generation);
|
|
193
|
+
let n = await P(e, t);
|
|
192
194
|
if (n !== void 0 && n.generation !== t.generation) throw Error("Restart identity belongs to a different command");
|
|
193
195
|
return n;
|
|
194
|
-
},
|
|
196
|
+
}, L = async (i, a) => {
|
|
195
197
|
for (let e of [
|
|
196
198
|
a.id,
|
|
197
199
|
a.runId,
|
|
198
200
|
a.generation,
|
|
199
201
|
a.token
|
|
200
|
-
])
|
|
202
|
+
]) s.decodeUnknownSync(S)(e);
|
|
201
203
|
if (a.id.length > 64 || !Number.isFinite(new Date(a.now).getTime())) throw Error("Invalid restart request identity or timestamp");
|
|
202
|
-
await
|
|
204
|
+
await k(i, {
|
|
203
205
|
requestId: a.id,
|
|
204
206
|
runId: a.runId
|
|
205
207
|
});
|
|
206
|
-
let
|
|
207
|
-
if (
|
|
208
|
-
let l =
|
|
208
|
+
let o = s.decodeUnknownSync(C)(a.delivery), c = s.decodeUnknownSync(T)(a.selection);
|
|
209
|
+
if (o.restartToken === a.token) throw Error("Restart requires a new delivery token");
|
|
210
|
+
let l = s.decodeUnknownSync(s.Array(w))(a.replies), u = /* @__PURE__ */ new Map();
|
|
209
211
|
for (let e of l) {
|
|
210
|
-
if (!/^[1-9]\d*$/.test(e.requestId) || !/^[1-9]\d*$/.test(e.replyId) ||
|
|
211
|
-
|
|
212
|
+
if (!/^[1-9]\d*$/.test(e.requestId) || !/^[1-9]\d*$/.test(e.replyId) || u.has(e.requestId)) throw Error("Restart requires distinct, exact journal reply identities");
|
|
213
|
+
u.set(e.requestId, e.replyId);
|
|
212
214
|
}
|
|
213
|
-
if (!
|
|
214
|
-
let [
|
|
215
|
-
table:
|
|
216
|
-
predicate:
|
|
215
|
+
if (!u.has(o.requestId)) throw Error("Restart selection must include its run reply");
|
|
216
|
+
let [f] = await i.query({
|
|
217
|
+
table: x.tableName,
|
|
218
|
+
predicate: p("id", a.id),
|
|
217
219
|
lock: "update",
|
|
218
220
|
order: [],
|
|
219
221
|
take: 1,
|
|
220
222
|
skip: void 0,
|
|
221
223
|
projection: void 0
|
|
222
224
|
});
|
|
223
|
-
if (
|
|
224
|
-
let e =
|
|
225
|
-
if (e.runId !== a.runId || e.generation !== a.generation || e.token !== a.token || e.workflowName !== a.control.workflowName || e.tenantId !== a.tenantId || e.delivery.requestId !==
|
|
225
|
+
if (f !== void 0) {
|
|
226
|
+
let e = s.decodeUnknownSync(A)(f);
|
|
227
|
+
if (e.runId !== a.runId || e.generation !== a.generation || e.token !== a.token || e.workflowName !== a.control.workflowName || e.tenantId !== a.tenantId || e.delivery.requestId !== o.requestId || e.delivery.restartToken !== o.restartToken || !j(e.selection, c) || e.replies.length !== u.size || e.replies.some((e) => u.get(e.requestId) !== e.replyId)) throw Error("Restart identity belongs to a different request");
|
|
226
228
|
return {
|
|
227
229
|
kind: "reserved",
|
|
228
230
|
request: e,
|
|
@@ -231,7 +233,7 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
231
233
|
}
|
|
232
234
|
let [m] = await i.query({
|
|
233
235
|
table: "_voltro_workflow_runs",
|
|
234
|
-
predicate:
|
|
236
|
+
predicate: p("id", a.runId),
|
|
235
237
|
lock: "update",
|
|
236
238
|
order: [],
|
|
237
239
|
take: 1,
|
|
@@ -239,23 +241,23 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
239
241
|
projection: void 0
|
|
240
242
|
});
|
|
241
243
|
if (m === void 0 || m.tag !== a.control.workflowName || m.runnerGeneration !== a.generation || m.status !== "failed" || m.discardedAt != null || typeof m.executionId != "string" || m.executionId.length === 0) throw Error("Restart requires its undiscarded failed resident generation");
|
|
242
|
-
if ((
|
|
243
|
-
let h =
|
|
244
|
-
if (h.requestId !==
|
|
245
|
-
let [
|
|
246
|
-
table:
|
|
247
|
-
predicate:
|
|
244
|
+
if ((s.decodeUnknownSync(s.NullOr(s.Struct({ tenantId: s.NullOr(S) })))(m.subject ?? null)?.tenantId ?? null) !== a.tenantId) throw Error("Restart belongs to another resident tenant");
|
|
245
|
+
let h = s.decodeUnknownSync(C)(m.engineDelivery);
|
|
246
|
+
if (h.requestId !== o.requestId || h.restartToken !== o.restartToken) throw Error("Restart journal delivery does not belong to its resident generation");
|
|
247
|
+
let [g] = await i.query({
|
|
248
|
+
table: x.tableName,
|
|
249
|
+
predicate: d(p("runId", a.runId), _(p("generation", a.generation), p("token", a.token))),
|
|
248
250
|
lock: "update",
|
|
249
251
|
order: [],
|
|
250
252
|
take: 1,
|
|
251
253
|
skip: void 0,
|
|
252
254
|
projection: ["id", "generation"]
|
|
253
255
|
});
|
|
254
|
-
if (
|
|
255
|
-
if (
|
|
256
|
+
if (g !== void 0) {
|
|
257
|
+
if (g.generation !== a.generation) throw Error("Restart delivery token was already used by this run");
|
|
256
258
|
return { kind: "already-requested" };
|
|
257
259
|
}
|
|
258
|
-
let v = t(i, a.control.workflowName, m.payload), y = e(a.control, v),
|
|
260
|
+
let v = t(i, a.control.workflowName, m.payload), y = e(a.control, v), b = await n({
|
|
259
261
|
store: i,
|
|
260
262
|
control: a.control,
|
|
261
263
|
keys: y,
|
|
@@ -263,9 +265,9 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
263
265
|
now: a.now,
|
|
264
266
|
reconsidering: !0
|
|
265
267
|
});
|
|
266
|
-
if (
|
|
268
|
+
if (b.kind !== "admit") return {
|
|
267
269
|
kind: "not-admitted",
|
|
268
|
-
decision:
|
|
270
|
+
decision: b
|
|
269
271
|
};
|
|
270
272
|
let E = await r({
|
|
271
273
|
store: i,
|
|
@@ -273,7 +275,7 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
273
275
|
keys: y,
|
|
274
276
|
outcome: "admitted",
|
|
275
277
|
mode: "restart",
|
|
276
|
-
reason:
|
|
278
|
+
reason: b.reason,
|
|
277
279
|
collapsed: 1,
|
|
278
280
|
waitedMs: 0,
|
|
279
281
|
executionId: null,
|
|
@@ -282,7 +284,7 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
282
284
|
now: a.now
|
|
283
285
|
});
|
|
284
286
|
if (E === void 0) throw Error("Restart has no admission reservation");
|
|
285
|
-
let D =
|
|
287
|
+
let D = s.decodeUnknownSync(A)({
|
|
286
288
|
id: a.id,
|
|
287
289
|
runId: a.runId,
|
|
288
290
|
workflowName: a.control.workflowName,
|
|
@@ -291,23 +293,23 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
291
293
|
token: a.token,
|
|
292
294
|
ledgerId: E,
|
|
293
295
|
tenantId: a.tenantId,
|
|
294
|
-
delivery:
|
|
296
|
+
delivery: o,
|
|
295
297
|
replies: l,
|
|
296
298
|
selection: c,
|
|
297
|
-
eviction:
|
|
299
|
+
eviction: b.evict ?? null,
|
|
298
300
|
requestedAt: new Date(a.now),
|
|
299
301
|
dispatchAttempts: 0,
|
|
300
302
|
enteredGeneration: null
|
|
301
303
|
});
|
|
302
|
-
return await i.insert(
|
|
304
|
+
return await i.insert(x.tableName, D), {
|
|
303
305
|
kind: "reserved",
|
|
304
306
|
request: D,
|
|
305
307
|
reused: !1
|
|
306
308
|
};
|
|
307
|
-
},
|
|
309
|
+
}, R = async (e, t) => {
|
|
308
310
|
let [n] = await e.query({
|
|
309
|
-
table:
|
|
310
|
-
predicate:
|
|
311
|
+
table: x.tableName,
|
|
312
|
+
predicate: p("id", t),
|
|
311
313
|
lock: "update",
|
|
312
314
|
order: [],
|
|
313
315
|
take: 1,
|
|
@@ -315,11 +317,11 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
315
317
|
projection: void 0
|
|
316
318
|
});
|
|
317
319
|
if (n === void 0) throw Error("Restart dispatch has no resident request");
|
|
318
|
-
let r =
|
|
320
|
+
let r = s.decodeUnknownSync(A)(n);
|
|
319
321
|
if (r.enteredGeneration !== null) throw Error("Restart request has already entered its resident generation");
|
|
320
322
|
let [i] = await e.query({
|
|
321
323
|
table: "_voltro_workflow_admissions",
|
|
322
|
-
predicate:
|
|
324
|
+
predicate: p("id", r.ledgerId),
|
|
323
325
|
lock: "update",
|
|
324
326
|
order: [],
|
|
325
327
|
take: 1,
|
|
@@ -329,7 +331,7 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
329
331
|
if (i === void 0 || i.outcome !== "admitted" || i.releasedAt !== null || i.workflowName !== r.workflowName || i.tenantId !== r.tenantId || i.executionId !== null || i.runId !== null) throw Error("Restart dispatch has no matching held resident reservation");
|
|
330
332
|
let [a] = await e.query({
|
|
331
333
|
table: "_voltro_workflow_runs",
|
|
332
|
-
predicate:
|
|
334
|
+
predicate: p("id", r.runId),
|
|
333
335
|
lock: "update",
|
|
334
336
|
order: [],
|
|
335
337
|
take: 1,
|
|
@@ -337,44 +339,44 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
337
339
|
projection: void 0
|
|
338
340
|
});
|
|
339
341
|
if (a === void 0 || a.tag !== r.workflowName || a.executionId !== r.executionId || a.runnerGeneration !== r.generation || a.status !== "failed" || a.discardedAt != null) throw Error("Restart dispatch no longer owns its failed resident generation");
|
|
340
|
-
let
|
|
341
|
-
if (
|
|
342
|
+
let o = s.decodeUnknownSync(C)(a.engineDelivery);
|
|
343
|
+
if (o.requestId !== r.delivery.requestId || o.restartToken !== r.delivery.restartToken) throw Error("Restart dispatch no longer owns its journal delivery");
|
|
342
344
|
return {
|
|
343
345
|
request: r,
|
|
344
346
|
run: a
|
|
345
347
|
};
|
|
346
|
-
},
|
|
347
|
-
let { request: n } = await
|
|
348
|
+
}, z = async (e, t) => {
|
|
349
|
+
let { request: n } = await R(e, t), r = n.dispatchAttempts + 1;
|
|
348
350
|
if (!Number.isSafeInteger(r)) throw Error("Restart dispatch attempt counter exhausted");
|
|
349
|
-
if (await e.update(
|
|
351
|
+
if (await e.update(x.tableName, t, { dispatchAttempts: r }) === null) throw Error("Restart request disappeared before dispatch");
|
|
350
352
|
return {
|
|
351
353
|
...n,
|
|
352
354
|
dispatchAttempts: r
|
|
353
355
|
};
|
|
354
|
-
},
|
|
355
|
-
let { request: t } = yield*
|
|
356
|
-
if (!(yield*
|
|
357
|
-
let n = yield*
|
|
358
|
-
return yield*
|
|
356
|
+
}, B = (e) => o.gen(function* () {
|
|
357
|
+
let { request: t } = yield* i(() => e.transaction((t) => R(t, e.requestId)));
|
|
358
|
+
if (!(yield* i(() => e.acquireCapacity(t)))) return { kind: "waiting-capacity" };
|
|
359
|
+
let n = yield* i(() => e.transaction((e) => z(e, t.id)));
|
|
360
|
+
return yield* a(n.replies, {
|
|
359
361
|
requestId: n.delivery.requestId,
|
|
360
362
|
previousToken: n.delivery.restartToken,
|
|
361
363
|
token: n.token,
|
|
362
364
|
workflowName: n.workflowName,
|
|
363
365
|
executionId: n.executionId
|
|
364
366
|
});
|
|
365
|
-
}),
|
|
367
|
+
}), V = async (e, t) => {
|
|
366
368
|
for (let e of [
|
|
367
369
|
t.runId,
|
|
368
370
|
t.workflowName,
|
|
369
371
|
t.executionId,
|
|
370
372
|
t.generation
|
|
371
|
-
])
|
|
373
|
+
]) s.decodeUnknownSync(S)(e);
|
|
372
374
|
if (!Number.isFinite(new Date(t.now).getTime())) throw Error("Restart entry requires a valid timestamp");
|
|
373
|
-
let n =
|
|
375
|
+
let n = s.decodeUnknownSync(C)(t.delivery);
|
|
374
376
|
if (n.restartToken === null) throw Error("Restart entry has no delivery token");
|
|
375
377
|
let [r] = await e.query({
|
|
376
|
-
table:
|
|
377
|
-
predicate:
|
|
378
|
+
table: x.tableName,
|
|
379
|
+
predicate: d(p("runId", t.runId), p("token", n.restartToken)),
|
|
378
380
|
lock: "update",
|
|
379
381
|
order: [],
|
|
380
382
|
take: 1,
|
|
@@ -382,15 +384,15 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
382
384
|
projection: ["id"]
|
|
383
385
|
});
|
|
384
386
|
if (r === void 0) throw Error("Restart delivery has no matching resident request");
|
|
385
|
-
let { request: i, run: a } = await
|
|
387
|
+
let { request: i, run: a } = await R(e, s.decodeUnknownSync(S)(r.id));
|
|
386
388
|
if (i.runId !== t.runId || i.workflowName !== t.workflowName || i.executionId !== t.executionId || i.generation === t.generation || i.delivery.requestId !== n.requestId || i.token !== n.restartToken) throw Error("Restart entry does not match its reserved delivery");
|
|
387
389
|
if (i.dispatchAttempts === 0) throw Error("Restart entry has no committed dispatch attempt");
|
|
388
390
|
if (await e.update("_voltro_workflow_admissions", i.ledgerId, {
|
|
389
391
|
executionId: i.executionId,
|
|
390
392
|
runId: i.runId
|
|
391
393
|
}) === null) throw Error("Restart reservation disappeared during entry");
|
|
392
|
-
if (await e.update(
|
|
393
|
-
let
|
|
394
|
+
if (await e.update(x.tableName, i.id, { enteredGeneration: t.generation }) === null) throw Error("Restart request disappeared during entry");
|
|
395
|
+
let o = await e.update("_voltro_workflow_runs", i.runId, {
|
|
394
396
|
runnerGeneration: t.generation,
|
|
395
397
|
engineDelivery: n,
|
|
396
398
|
runnerEnteredAt: new Date(t.now),
|
|
@@ -402,12 +404,12 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
402
404
|
completedAt: null,
|
|
403
405
|
durationMs: null
|
|
404
406
|
});
|
|
405
|
-
if (
|
|
407
|
+
if (o === null) throw Error("Restart run disappeared during entry");
|
|
406
408
|
return {
|
|
407
|
-
row:
|
|
409
|
+
row: o,
|
|
408
410
|
previous: a,
|
|
409
411
|
event: await e.insert("_voltro_workflow_run_events", {
|
|
410
|
-
id:
|
|
412
|
+
id: f("wfev", JSON.stringify(["restart", i.id])),
|
|
411
413
|
runId: i.runId,
|
|
412
414
|
eventType: "run-redriven",
|
|
413
415
|
occurredAt: new Date(t.now),
|
|
@@ -422,5 +424,4 @@ var b = _("_voltro_workflow_restart_requests", {
|
|
|
422
424
|
})
|
|
423
425
|
};
|
|
424
426
|
};
|
|
425
|
-
|
|
426
|
-
export { R as beginWorkflowRestartDispatchInTransaction, B as consumeWorkflowRestartInTransaction, N as readWorkflowRestartCommandInTransaction, M as readWorkflowRestartObservationInTransaction, F as readWorkflowRestartReservationInTransaction, I as reserveWorkflowRestartInTransaction, z as resetReservedWorkflowJournal, P as withdrawWorkflowRestartInTransaction, b as workflowRestartRequestsTable, T as workflowRestartWithdrawalsTable };
|
|
427
|
+
export { z as beginWorkflowRestartDispatchInTransaction, V as consumeWorkflowRestartInTransaction, P as readWorkflowRestartCommandInTransaction, N as readWorkflowRestartObservationInTransaction, I as readWorkflowRestartReservationInTransaction, L as reserveWorkflowRestartInTransaction, B as resetReservedWorkflowJournal, F as withdrawWorkflowRestartInTransaction, x as workflowRestartRequestsTable, E as workflowRestartWithdrawalsTable };
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { beginWorkflowControlDispatchInTransaction as e, bindWorkflowResumeJournalInTransaction as t } from "./controlRequest.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { JournalRoutingGuard as n, ownedJournalRoutingPromise as r, protectJournalRoutingEffect as i } from "./journalRoutingGuard.js";
|
|
3
|
+
import { observeWorkflowSuspension as a, resetExpectedWorkflowSuspension as o } from "./workflowJournalReset.js";
|
|
4
|
+
import { Context as s, Effect as c, Option as l } from "effect";
|
|
5
|
+
import { SqlClient as u } from "effect/sql";
|
|
6
|
+
import { Sharding as d } from "effect/cluster";
|
|
7
|
+
// src/workflowResumeDispatch.ts
|
|
8
|
+
var f = (n) => c.gen(function* () {
|
|
9
|
+
let i = yield* c.context(), s = yield* r(() => n.transaction((e) => t(e, n.requestId, (e) => c.runPromiseWith(i)(a(e)))));
|
|
10
|
+
if (s.kind !== "bound") return s;
|
|
11
|
+
let l = yield* r(() => n.transaction((t) => e(t, n.requestId)));
|
|
11
12
|
if (l.kind !== "dispatch") return l;
|
|
12
13
|
let { request: u } = l;
|
|
13
|
-
if (u.operation !== "resume" || u.resumeJournal === null) return yield*
|
|
14
|
-
let
|
|
14
|
+
if (u.operation !== "resume" || u.resumeJournal === null) return yield* c.die(/* @__PURE__ */ Error("Resume dispatch requires its committed suspension binding"));
|
|
15
|
+
let f = yield* o({
|
|
15
16
|
workflowName: u.workflowName,
|
|
16
17
|
executionId: u.executionId,
|
|
17
18
|
...u.resumeJournal
|
|
18
19
|
});
|
|
19
|
-
return yield* (yield*
|
|
20
|
+
return yield* (yield* d.Sharding).pollStorage, {
|
|
20
21
|
kind: "attempted",
|
|
21
22
|
request: u,
|
|
22
|
-
journal:
|
|
23
|
+
journal: f
|
|
23
24
|
};
|
|
24
|
-
}),
|
|
25
|
-
let e = yield*
|
|
26
|
-
return
|
|
25
|
+
}), p = class extends s.Service()("@voltro/workflow/WorkflowResumeDispatcher") {}, m = c.gen(function* () {
|
|
26
|
+
let e = l.getOrUndefined(yield* c.serviceOption(n)), t = yield* u.SqlClient, r = yield* d.Sharding;
|
|
27
|
+
return p.of({ dispatch: (n) => i(e, f(n)).pipe(c.provideService(u.SqlClient, t), c.provideService(d.Sharding, r)) });
|
|
27
28
|
});
|
|
28
|
-
|
|
29
|
-
export { l as WorkflowResumeDispatcher, c as dispatchWorkflowResume, u as makeWorkflowResumeDispatcher };
|
|
29
|
+
export { p as WorkflowResumeDispatcher, f as dispatchWorkflowResume, m as makeWorkflowResumeDispatcher };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JournalRoutingGuard as e } from "./journalRoutingGuard.js";
|
|
2
|
+
import { Context as t, Effect as n, Option as r } from "effect";
|
|
3
|
+
import { Sharding as i } from "effect/cluster";
|
|
4
|
+
// src/workflowRuntimeReadiness.ts
|
|
5
|
+
var a = class extends t.Service()("@voltro/workflow/WorkflowRuntimeReadiness") {}, o = n.gen(function* () {
|
|
6
|
+
let t = yield* i.Sharding, a = r.getOrUndefined(yield* n.serviceOption(e)), o = !0;
|
|
7
|
+
return yield* n.addFinalizer(() => n.sync(() => {
|
|
8
|
+
o = !1;
|
|
9
|
+
})), { isReady: () => o && !a?.isClosed() && !n.runSync(t.isShutdown) };
|
|
10
|
+
}), s = n.map(n.serviceOption(a), (e) => r.isSome(e) ? e.value.isReady : () => !0);
|
|
11
|
+
export { a as WorkflowRuntimeReadiness, s as captureWorkflowRuntimeReadiness, o as makeWorkflowRuntimeReadiness };
|