@milaboratories/pl-middle-layer 2.1.2 → 2.3.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/dist/middle_layer/block_status_fold.cjs +382 -0
- package/dist/middle_layer/block_status_fold.cjs.map +1 -0
- package/dist/middle_layer/block_status_fold.js +373 -0
- package/dist/middle_layer/block_status_fold.js.map +1 -0
- package/dist/middle_layer/block_status_tree.cjs +287 -0
- package/dist/middle_layer/block_status_tree.cjs.map +1 -0
- package/dist/middle_layer/block_status_tree.js +283 -0
- package/dist/middle_layer/block_status_tree.js.map +1 -0
- package/dist/middle_layer/build_stamp.cjs +1 -1
- package/dist/middle_layer/build_stamp.js +1 -1
- package/dist/middle_layer/instance_stats.cjs +2 -2
- package/dist/middle_layer/instance_stats.cjs.map +1 -1
- package/dist/middle_layer/instance_stats.js +2 -2
- package/dist/middle_layer/instance_stats.js.map +1 -1
- package/dist/middle_layer/project.cjs +73 -2
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +22 -1
- package/dist/middle_layer/project.d.ts.map +1 -1
- package/dist/middle_layer/project.js +74 -3
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/model/project_model.cjs +27 -0
- package/dist/model/project_model.cjs.map +1 -1
- package/dist/model/project_model.js +25 -1
- package/dist/model/project_model.js.map +1 -1
- package/dist/mutator/project.cjs +2 -1
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.d.ts.map +1 -1
- package/dist/mutator/project.js +3 -2
- package/dist/mutator/project.js.map +1 -1
- package/dist/mutator/template/render_block.cjs +24 -0
- package/dist/mutator/template/render_block.cjs.map +1 -1
- package/dist/mutator/template/render_block.js +23 -2
- package/dist/mutator/template/render_block.js.map +1 -1
- package/package.json +14 -14
- package/src/middle_layer/block_status_bench.test.ts +197 -0
- package/src/middle_layer/block_status_fold.test.ts +694 -0
- package/src/middle_layer/block_status_fold.ts +563 -0
- package/src/middle_layer/block_status_tree.test.ts +253 -0
- package/src/middle_layer/block_status_tree.ts +391 -0
- package/src/middle_layer/instance_stats.test.ts +7 -9
- package/src/middle_layer/instance_stats.ts +2 -2
- package/src/middle_layer/project.ts +111 -2
- package/src/middle_layer/project_pruning.test.ts +59 -0
- package/src/model/project_model.ts +30 -0
- package/src/mutator/project.ts +7 -1
- package/src/mutator/project_action_context.test.ts +13 -3
- package/src/mutator/template/render_block.ts +32 -2
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { blockStatusStatesRecord, isTerminalBlockStatusState } from "@milaboratories/pl-model-middle-layer";
|
|
2
|
+
// src/middle_layer/block_status_fold.ts
|
|
3
|
+
/**
|
|
4
|
+
* A key-value written as a JSON object, with its fields unchecked; undefined for anything else.
|
|
5
|
+
* A reporter may write any JSON, so `null` or a bare number must not reach a field read.
|
|
6
|
+
*/
|
|
7
|
+
function parseJsonObject(value) {
|
|
8
|
+
let parsed;
|
|
9
|
+
try {
|
|
10
|
+
parsed = JSON.parse(value);
|
|
11
|
+
} catch {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
15
|
+
return Object.fromEntries(Object.entries(parsed));
|
|
16
|
+
}
|
|
17
|
+
/** Prefix of the field names holding child contexts. */
|
|
18
|
+
const ChildFieldPrefix = "child/";
|
|
19
|
+
/** Prefix of the transition keys: `transition/<namespace>/<resource>/<ns>`. */
|
|
20
|
+
const TransitionPrefix = "transition/";
|
|
21
|
+
/** Prefix of the reading keys: `reading/<namespace>/<resource>/<key>`. */
|
|
22
|
+
const ReadingPrefix = "reading/";
|
|
23
|
+
/** The namespace the workflow controller reports a render's own lifecycle under. */
|
|
24
|
+
const RenderNamespace = "render";
|
|
25
|
+
/**
|
|
26
|
+
* The namespace the creator of a context reports under. The middle layer records `Terminated` here
|
|
27
|
+
* on the root when the user stops the run, see `recordBlockRunCancelled`.
|
|
28
|
+
*/
|
|
29
|
+
const CreatorNamespace = "core";
|
|
30
|
+
/** The namespace a command reports under; its `Running` means a job executing on a machine. */
|
|
31
|
+
const ExecNamespace = "exec";
|
|
32
|
+
/** The namespace a job's work folder reports under. */
|
|
33
|
+
const WorkdirNamespace = "workdir";
|
|
34
|
+
/** Compares non-negative decimal integers given as strings, shorter is smaller. */
|
|
35
|
+
function compareNs(a, b) {
|
|
36
|
+
return a.length !== b.length ? a.length - b.length : a < b ? -1 : a > b ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
/** Nanoseconds since the epoch, as the key carries them, to milliseconds. */
|
|
39
|
+
function nsToMs(ns) {
|
|
40
|
+
return Number(BigInt(ns) / 1000000n);
|
|
41
|
+
}
|
|
42
|
+
function earlier(a, b) {
|
|
43
|
+
return a === void 0 || b !== void 0 && compareNs(b, a) < 0 ? b : a;
|
|
44
|
+
}
|
|
45
|
+
function later(a, b) {
|
|
46
|
+
return a === void 0 || b !== void 0 && compareNs(b, a) > 0 ? b : a;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* How strongly a report claims to be what holds a node.
|
|
50
|
+
*
|
|
51
|
+
* The render's own `Running` means only that template code is being evaluated, and the workflow
|
|
52
|
+
* controller records it again on every evaluation, so it routinely carries a newer timestamp than
|
|
53
|
+
* the wait that actually holds the node. Anything else outranks it however old it is, including a
|
|
54
|
+
* command's `Running`, which is real work. Recency decides only between equal ranks.
|
|
55
|
+
*/
|
|
56
|
+
function rank(t) {
|
|
57
|
+
return t.state === blockStatusStatesRecord.Running && t.namespace === RenderNamespace ? 0 : 1;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The transitions of one context.
|
|
61
|
+
*
|
|
62
|
+
* A value that is not the JSON the reporters write is left out: a report is diagnostic, and a
|
|
63
|
+
* malformed one must not break the surface. Its timestamp still counts.
|
|
64
|
+
*/
|
|
65
|
+
function readTransitions(node) {
|
|
66
|
+
const out = { all: [] };
|
|
67
|
+
for (const { key, value } of node.listKeyValuesAsString(TransitionPrefix)) {
|
|
68
|
+
const parts = key.split("/");
|
|
69
|
+
if (parts.length !== 4) continue;
|
|
70
|
+
const [, namespace, reporter, ns] = parts;
|
|
71
|
+
if (!/^(0|[1-9]\d*)$/.test(ns)) continue;
|
|
72
|
+
out.firstNs = earlier(out.firstNs, ns);
|
|
73
|
+
out.lastNs = later(out.lastNs, ns);
|
|
74
|
+
const parsed = parseJsonObject(value);
|
|
75
|
+
if (parsed === void 0) continue;
|
|
76
|
+
const state = parsed.state;
|
|
77
|
+
if (typeof state !== "string") continue;
|
|
78
|
+
const detail = typeof parsed.detail === "string" ? parsed.detail : "";
|
|
79
|
+
const reason = typeof parsed.reason === "string" ? parsed.reason : "";
|
|
80
|
+
out.all.push({
|
|
81
|
+
namespace,
|
|
82
|
+
reporter,
|
|
83
|
+
ns,
|
|
84
|
+
state,
|
|
85
|
+
detail,
|
|
86
|
+
reason
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reduces one context to {@link FoldedNode}.
|
|
93
|
+
*
|
|
94
|
+
* A context carries the reports of several reporters: the render reports under `render`, and the
|
|
95
|
+
* commands and work dirs it created report under `exec` and `workdir`. The latest transition of
|
|
96
|
+
* each reporter is that reporter's current state, and the state holding the node is the strongest
|
|
97
|
+
* of those a reporter has not left, see {@link rank}.
|
|
98
|
+
*
|
|
99
|
+
* The node has ended when the render has reported its own end (`Completed` once its outputs are
|
|
100
|
+
* set, `Terminated` with its error, or `Completed` with detail `deduplicated`) and every other
|
|
101
|
+
* reporter in the context has ended too: the render's outputs being set does not stop a command it
|
|
102
|
+
* started, and that command's report must stay visible.
|
|
103
|
+
*/
|
|
104
|
+
function foldNode(transitions) {
|
|
105
|
+
const latestPerReporter = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const t of transitions) {
|
|
107
|
+
const reporterKey = `${t.namespace}/${t.reporter}`;
|
|
108
|
+
const previous = latestPerReporter.get(reporterKey);
|
|
109
|
+
if (previous === void 0 || compareNs(t.ns, previous.ns) > 0) latestPerReporter.set(reporterKey, t);
|
|
110
|
+
}
|
|
111
|
+
let render;
|
|
112
|
+
let holding;
|
|
113
|
+
let everyReporterEnded = true;
|
|
114
|
+
for (const t of latestPerReporter.values()) {
|
|
115
|
+
if (t.namespace === RenderNamespace) render = t;
|
|
116
|
+
if (isTerminalBlockStatusState(t.state)) continue;
|
|
117
|
+
everyReporterEnded = false;
|
|
118
|
+
if (holding === void 0) {
|
|
119
|
+
holding = t;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const byRank = rank(t) - rank(holding);
|
|
123
|
+
if (byRank > 0 || byRank === 0 && compareNs(t.ns, holding.ns) > 0) holding = t;
|
|
124
|
+
}
|
|
125
|
+
if (render !== void 0 && isTerminalBlockStatusState(render.state) && everyReporterEnded) return {
|
|
126
|
+
terminal: true,
|
|
127
|
+
onMachine: false,
|
|
128
|
+
failure: render.state === blockStatusStatesRecord.Terminated ? render.reason : void 0
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
terminal: false,
|
|
132
|
+
holding,
|
|
133
|
+
onMachine: holding?.state === blockStatusStatesRecord.Running && holding.namespace === ExecNamespace
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** The render's own latest transition in a context. */
|
|
137
|
+
function latestRender(transitions) {
|
|
138
|
+
let latest;
|
|
139
|
+
for (const t of transitions) if (t.namespace === RenderNamespace && (latest === void 0 || compareNs(t.ns, latest.ns) > 0)) latest = t;
|
|
140
|
+
return latest;
|
|
141
|
+
}
|
|
142
|
+
function readReadings(node) {
|
|
143
|
+
const out = [];
|
|
144
|
+
for (const { key, value } of node.listKeyValuesAsString(ReadingPrefix)) {
|
|
145
|
+
const parts = key.split("/");
|
|
146
|
+
if (parts.length !== 4) continue;
|
|
147
|
+
out.push({
|
|
148
|
+
namespace: parts[1],
|
|
149
|
+
resource: parts[2],
|
|
150
|
+
key: parts[3],
|
|
151
|
+
value
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
/** Reads one context: its transitions, its readings, and the state holding it. */
|
|
157
|
+
function foldContext(node) {
|
|
158
|
+
const reports = readTransitions(node);
|
|
159
|
+
const render = latestRender(reports.all);
|
|
160
|
+
return {
|
|
161
|
+
id: node.id,
|
|
162
|
+
data: node.getData(),
|
|
163
|
+
reports,
|
|
164
|
+
readings: readReadings(node),
|
|
165
|
+
folded: foldNode(reports.all),
|
|
166
|
+
job: reports.all.some((t) => t.namespace === ExecNamespace || t.namespace === WorkdirNamespace),
|
|
167
|
+
terminated: render?.state === blockStatusStatesRecord.Terminated ? {
|
|
168
|
+
reason: render.reason,
|
|
169
|
+
ns: render.ns
|
|
170
|
+
} : void 0
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const EmptyJobTally = {
|
|
174
|
+
total: 0,
|
|
175
|
+
done: 0,
|
|
176
|
+
failed: 0,
|
|
177
|
+
groups: {}
|
|
178
|
+
};
|
|
179
|
+
/** Files done of all, summed over the work folders' progress readings of one context. */
|
|
180
|
+
function workdirProgress(readings) {
|
|
181
|
+
let progress;
|
|
182
|
+
for (const r of readings) {
|
|
183
|
+
if (r.namespace !== WorkdirNamespace || r.key !== "progress") continue;
|
|
184
|
+
const parsed = parseJsonObject(r.value);
|
|
185
|
+
if (typeof parsed?.done !== "number" || typeof parsed.total !== "number") continue;
|
|
186
|
+
progress = addFiles(progress, {
|
|
187
|
+
done: parsed.done,
|
|
188
|
+
total: parsed.total
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return progress;
|
|
192
|
+
}
|
|
193
|
+
function addFiles(a, b) {
|
|
194
|
+
if (a === void 0) return b;
|
|
195
|
+
if (b === void 0) return a;
|
|
196
|
+
return {
|
|
197
|
+
done: a.done + b.done,
|
|
198
|
+
total: a.total + b.total
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function groupKey(group) {
|
|
202
|
+
return `${group.namespace}/${group.state}`;
|
|
203
|
+
}
|
|
204
|
+
function mergeGroup(groups, key, group) {
|
|
205
|
+
const previous = groups[key];
|
|
206
|
+
groups[key] = previous === void 0 ? group : {
|
|
207
|
+
namespace: group.namespace,
|
|
208
|
+
state: group.state,
|
|
209
|
+
count: previous.count + group.count,
|
|
210
|
+
sinceNs: earlier(previous.sinceNs, group.sinceNs),
|
|
211
|
+
files: addFiles(previous.files, group.files)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/** The job a context is, counted where it is now; empty when it is not one. */
|
|
215
|
+
function ownJobs(own) {
|
|
216
|
+
if (!own.job) return EmptyJobTally;
|
|
217
|
+
const { terminal, failure, holding } = own.folded;
|
|
218
|
+
if (terminal) return failure === void 0 ? {
|
|
219
|
+
...EmptyJobTally,
|
|
220
|
+
total: 1,
|
|
221
|
+
done: 1
|
|
222
|
+
} : {
|
|
223
|
+
...EmptyJobTally,
|
|
224
|
+
total: 1,
|
|
225
|
+
failed: 1
|
|
226
|
+
};
|
|
227
|
+
if (holding === void 0) return {
|
|
228
|
+
...EmptyJobTally,
|
|
229
|
+
total: 1
|
|
230
|
+
};
|
|
231
|
+
const group = {
|
|
232
|
+
namespace: holding.namespace,
|
|
233
|
+
state: holding.state,
|
|
234
|
+
count: 1,
|
|
235
|
+
sinceNs: holding.ns,
|
|
236
|
+
files: workdirProgress(own.readings)
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
...EmptyJobTally,
|
|
240
|
+
total: 1,
|
|
241
|
+
groups: { [groupKey(group)]: group }
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Merges a context with the folds of its children. One pass over the direct children, so a report
|
|
246
|
+
* re-merges each context on its path to the root and nothing else.
|
|
247
|
+
*/
|
|
248
|
+
function mergeSubtree(own, children) {
|
|
249
|
+
let contexts = 1;
|
|
250
|
+
let activeContexts = own.folded.terminal ? 0 : 1;
|
|
251
|
+
let firstNs = own.reports.firstNs;
|
|
252
|
+
let lastNs = own.reports.lastNs;
|
|
253
|
+
let failure = own.terminated;
|
|
254
|
+
let failedBelow = false;
|
|
255
|
+
const self = ownJobs(own);
|
|
256
|
+
let { total, done, failed } = self;
|
|
257
|
+
const groups = { ...self.groups };
|
|
258
|
+
for (const child of children) {
|
|
259
|
+
contexts += child.contexts;
|
|
260
|
+
activeContexts += child.activeContexts;
|
|
261
|
+
firstNs = earlier(firstNs, child.firstNs);
|
|
262
|
+
lastNs = later(lastNs, child.lastNs);
|
|
263
|
+
if (child.failure !== void 0) {
|
|
264
|
+
failedBelow = true;
|
|
265
|
+
if (failure === void 0 || compareNs(child.failure.ns, failure.ns) < 0) failure = child.failure;
|
|
266
|
+
}
|
|
267
|
+
total += child.jobs.total;
|
|
268
|
+
done += child.jobs.done;
|
|
269
|
+
failed += child.jobs.failed;
|
|
270
|
+
for (const [key, group] of Object.entries(child.jobs.groups)) mergeGroup(groups, key, group);
|
|
271
|
+
}
|
|
272
|
+
if (own.terminated !== void 0 && !failedBelow && !own.job) {
|
|
273
|
+
total++;
|
|
274
|
+
failed++;
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
own,
|
|
278
|
+
children,
|
|
279
|
+
contexts,
|
|
280
|
+
activeContexts,
|
|
281
|
+
firstNs,
|
|
282
|
+
lastNs,
|
|
283
|
+
failure,
|
|
284
|
+
jobs: {
|
|
285
|
+
total,
|
|
286
|
+
done,
|
|
287
|
+
failed,
|
|
288
|
+
groups
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* The child contexts a fold follows: each once, and none already on the path from the root, so a
|
|
294
|
+
* context linked twice or a cycle cannot count a subtree again.
|
|
295
|
+
*/
|
|
296
|
+
function childContexts(fields, traverse, path) {
|
|
297
|
+
if (path.size > 256) return [];
|
|
298
|
+
const out = [];
|
|
299
|
+
const seen = /* @__PURE__ */ new Set();
|
|
300
|
+
for (const field of fields) {
|
|
301
|
+
if (!field.startsWith(ChildFieldPrefix)) continue;
|
|
302
|
+
const child = traverse(field);
|
|
303
|
+
if (child === void 0) continue;
|
|
304
|
+
const id = String(child.id);
|
|
305
|
+
if (path.has(id) || seen.has(id)) continue;
|
|
306
|
+
seen.add(id);
|
|
307
|
+
out.push(child);
|
|
308
|
+
}
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
/** Where the backend nests the error of an input inside the error of what consumes it. */
|
|
312
|
+
const InputErrorMarker = "has input errors:";
|
|
313
|
+
/** Wrappers the workflow controller puts in front of a template's own error. */
|
|
314
|
+
const TemplateErrorPrefix = /^(cannot eval code: |cannot eval template: |tengo template error: )+/;
|
|
315
|
+
/** Longest headline, in characters. */
|
|
316
|
+
const MaxHeadlineLength = 200;
|
|
317
|
+
/**
|
|
318
|
+
* The innermost message of a termination reason, for a title: the backend wraps the error of each
|
|
319
|
+
* input in the error of its consumer, and tengo appends stack frames, so a reason can run to pages.
|
|
320
|
+
*/
|
|
321
|
+
function failureHeadline(reason) {
|
|
322
|
+
const marker = reason.lastIndexOf(InputErrorMarker);
|
|
323
|
+
const text = reason.slice(marker < 0 ? 0 : marker + 17).split("\n").map((line) => line.trim()).filter((line) => line !== "" && !/^@\S+:\d+:\d+$/.test(line)).join(" ");
|
|
324
|
+
const command = /Command name: "([^"]*)".*\bError: (.+)$/.exec(text);
|
|
325
|
+
const headline = command !== null ? `${command[1]} failed: ${command[2]}` : text.replace(TemplateErrorPrefix, "");
|
|
326
|
+
return headline.length > MaxHeadlineLength ? `${headline.slice(0, 199)}…` : headline;
|
|
327
|
+
}
|
|
328
|
+
function finishJobs(jobs) {
|
|
329
|
+
const byState = Object.values(jobs.groups).map((g) => ({
|
|
330
|
+
namespace: g.namespace,
|
|
331
|
+
state: g.state,
|
|
332
|
+
count: g.count,
|
|
333
|
+
since: g.sinceNs === void 0 ? void 0 : nsToMs(g.sinceNs),
|
|
334
|
+
files: g.files
|
|
335
|
+
})).sort((a, b) => b.count - a.count || groupKey(a).localeCompare(groupKey(b)));
|
|
336
|
+
return {
|
|
337
|
+
total: jobs.total,
|
|
338
|
+
done: jobs.done,
|
|
339
|
+
failed: jobs.failed,
|
|
340
|
+
byState
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/** The summary of a block run, from the fold of its root action context. */
|
|
344
|
+
function summarize(root) {
|
|
345
|
+
const runId = root.own.data?.["run-id"];
|
|
346
|
+
const jobs = finishJobs(root.jobs);
|
|
347
|
+
const summary = {
|
|
348
|
+
availability: "read",
|
|
349
|
+
runId: typeof runId === "string" ? runId : void 0,
|
|
350
|
+
activeContexts: root.activeContexts,
|
|
351
|
+
totalContexts: root.contexts,
|
|
352
|
+
jobs,
|
|
353
|
+
startedAt: root.firstNs === void 0 ? void 0 : nsToMs(root.firstNs)
|
|
354
|
+
};
|
|
355
|
+
let cancelledNs;
|
|
356
|
+
for (const t of root.own.reports.all) if (t.namespace === CreatorNamespace && t.state === blockStatusStatesRecord.Terminated) cancelledNs = later(cancelledNs, t.ns);
|
|
357
|
+
if (cancelledNs !== void 0) return {
|
|
358
|
+
...summary,
|
|
359
|
+
lastChangeAt: nsToMs(cancelledNs),
|
|
360
|
+
done: true,
|
|
361
|
+
cancelled: true
|
|
362
|
+
};
|
|
363
|
+
const working = jobs.byState.some((g) => g.namespace !== RenderNamespace);
|
|
364
|
+
return {
|
|
365
|
+
...summary,
|
|
366
|
+
lastChangeAt: root.lastNs === void 0 ? void 0 : nsToMs(root.lastNs),
|
|
367
|
+
done: root.own.folded.terminal && root.activeContexts === 0 || root.failure !== void 0 && !working,
|
|
368
|
+
failure: root.failure === void 0 ? void 0 : failureHeadline(root.failure.reason)
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
export { childContexts, compareNs, failureHeadline, foldContext, foldNode, latestRender, mergeSubtree, nsToMs, readTransitions, summarize };
|
|
372
|
+
|
|
373
|
+
//# sourceMappingURL=block_status_fold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_status_fold.js","names":[],"sources":["../../src/middle_layer/block_status_fold.ts"],"sourcesContent":["/**\n * Folds a block's action-context tree into the {@link BlockStatusSummary} the Desktop App shows.\n *\n * The fold runs bottom up: {@link foldContext} reads one context on its own, and\n * {@link mergeSubtree} merges it with the folds of its children. Over a synchronized tree each\n * context gets its own computable (see `block_status_tree.ts`), so a report re-reads only the\n * context it landed in and re-merges the contexts above it; the rest of the tree is not read\n * again.\n *\n * The fold attaches no meaning to the states the reporters write, beyond the lifecycle the backend\n * fixes: a context ends in `Completed` or `Terminated`, and a command's `Running` is work on a\n * machine. Jobs are counted per state as reported, so a state added on the backend reaches the\n * Desktop App without a middle layer release.\n */\n\nimport type {\n BlockStatusJobGroup,\n BlockStatusJobs,\n BlockStatusSummary,\n} from \"@milaboratories/pl-model-middle-layer\";\nimport {\n blockStatusStatesRecord,\n isTerminalBlockStatusState,\n} from \"@milaboratories/pl-model-middle-layer\";\n\n/**\n * A key-value written as a JSON object, with its fields unchecked; undefined for anything else.\n * A reporter may write any JSON, so `null` or a bare number must not reach a field read.\n */\nfunction parseJsonObject(value: string): Record<string, unknown> | undefined {\n let parsed: unknown;\n try {\n parsed = JSON.parse(value);\n } catch {\n return undefined;\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) return undefined;\n return Object.fromEntries(Object.entries(parsed));\n}\n\n/** The part of an action context a fold reads. A tree node accessor satisfies it. */\nexport interface ActionContextNode {\n /** Stable identity of the context, for deduplicating a walk. */\n readonly id: string;\n /** The context's baggage: `name`, `block-pack`, `block-id`, `run-id`. */\n getData(): Record<string, unknown> | undefined;\n /** KV entries under a prefix, values as text. */\n listKeyValuesAsString(prefix: string): { key: string; value: string }[];\n /** Field names, whatever their type: the children are `child/<render>`. */\n listFields(): string[];\n /** The context a field points at, or undefined while the field is unset. */\n traverse(field: string): ActionContextNode | undefined;\n}\n\n/**\n * How deep the fold follows `child/<render>`.\n *\n * A stack guard, not a correctness device: a context already on the path is skipped, and the depth\n * of a real tree is the nesting depth of the templates, far below this.\n */\nexport const MaxDepth = 256;\n\n/** Prefix of the field names holding child contexts. */\nconst ChildFieldPrefix = \"child/\";\n\n/** Prefix of the transition keys: `transition/<namespace>/<resource>/<ns>`. */\nconst TransitionPrefix = \"transition/\";\n\n/** Prefix of the reading keys: `reading/<namespace>/<resource>/<key>`. */\nconst ReadingPrefix = \"reading/\";\n\n/** The namespace the workflow controller reports a render's own lifecycle under. */\nconst RenderNamespace = \"render\";\n\n/**\n * The namespace the creator of a context reports under. The middle layer records `Terminated` here\n * on the root when the user stops the run, see `recordBlockRunCancelled`.\n */\nconst CreatorNamespace = \"core\";\n\n/** The namespace a command reports under; its `Running` means a job executing on a machine. */\nconst ExecNamespace = \"exec\";\n\n/** The namespace a job's work folder reports under. */\nconst WorkdirNamespace = \"workdir\";\n\n/** One transition, as stored under `transition/<namespace>/<resource>/<ns>`. */\nexport type Transition = {\n namespace: string;\n /** The resource that reported: the render itself, or a command or work dir it created. */\n reporter: string;\n /** The reporter's clock in nanoseconds, as the decimal string the key carries. */\n ns: string;\n /** As the reporter wrote it, whether or not this build knows the name. */\n state: string;\n detail: string;\n reason: string;\n};\n\n/** What one context reported. */\nexport type ContextReports = {\n /** Every transition whose key and value parse. */\n all: Transition[];\n /** The earliest and latest timestamp of any transition key, even one whose value does not\n * parse: a report arriving is evidence the run moved whatever it says. */\n firstNs?: string;\n lastNs?: string;\n};\n\n/** A node of the tree, reduced to what the summary needs. */\nexport type FoldedNode = {\n /** True when the render of this context has ended and nothing it started is still running. */\n terminal: boolean;\n /** The reason, set when the render itself ended in a termination rather than a completion. */\n failure?: string;\n /** The transition holding this node, undefined when it is terminal or has not reported. */\n holding?: Transition;\n /** True when {@link FoldedNode.holding} is `Running` reported by a command. */\n onMachine: boolean;\n};\n\n/** Compares non-negative decimal integers given as strings, shorter is smaller. */\nexport function compareNs(a: string, b: string): number {\n return a.length !== b.length ? a.length - b.length : a < b ? -1 : a > b ? 1 : 0;\n}\n\n/** Nanoseconds since the epoch, as the key carries them, to milliseconds. */\nexport function nsToMs(ns: string): number {\n return Number(BigInt(ns) / 1_000_000n);\n}\n\nfunction earlier(a: string | undefined, b: string | undefined): string | undefined {\n return a === undefined || (b !== undefined && compareNs(b, a) < 0) ? b : a;\n}\n\nfunction later(a: string | undefined, b: string | undefined): string | undefined {\n return a === undefined || (b !== undefined && compareNs(b, a) > 0) ? b : a;\n}\n\n/**\n * How strongly a report claims to be what holds a node.\n *\n * The render's own `Running` means only that template code is being evaluated, and the workflow\n * controller records it again on every evaluation, so it routinely carries a newer timestamp than\n * the wait that actually holds the node. Anything else outranks it however old it is, including a\n * command's `Running`, which is real work. Recency decides only between equal ranks.\n */\nfunction rank(t: Transition): number {\n return t.state === blockStatusStatesRecord.Running && t.namespace === RenderNamespace ? 0 : 1;\n}\n\n/**\n * The transitions of one context.\n *\n * A value that is not the JSON the reporters write is left out: a report is diagnostic, and a\n * malformed one must not break the surface. Its timestamp still counts.\n */\nexport function readTransitions(node: ActionContextNode): ContextReports {\n const out: ContextReports = { all: [] };\n\n for (const { key, value } of node.listKeyValuesAsString(TransitionPrefix)) {\n const parts = key.split(\"/\");\n if (parts.length !== 4) continue;\n const [, namespace, reporter, ns] = parts;\n // Leading zeros would break the length-first comparison, and no reporter writes them.\n if (!/^(0|[1-9]\\d*)$/.test(ns)) continue;\n\n out.firstNs = earlier(out.firstNs, ns);\n out.lastNs = later(out.lastNs, ns);\n\n const parsed = parseJsonObject(value);\n if (parsed === undefined) continue;\n const state = parsed.state;\n if (typeof state !== \"string\") continue;\n const detail = typeof parsed.detail === \"string\" ? parsed.detail : \"\";\n const reason = typeof parsed.reason === \"string\" ? parsed.reason : \"\";\n out.all.push({ namespace, reporter, ns, state, detail, reason });\n }\n\n return out;\n}\n\n/**\n * Reduces one context to {@link FoldedNode}.\n *\n * A context carries the reports of several reporters: the render reports under `render`, and the\n * commands and work dirs it created report under `exec` and `workdir`. The latest transition of\n * each reporter is that reporter's current state, and the state holding the node is the strongest\n * of those a reporter has not left, see {@link rank}.\n *\n * The node has ended when the render has reported its own end (`Completed` once its outputs are\n * set, `Terminated` with its error, or `Completed` with detail `deduplicated`) and every other\n * reporter in the context has ended too: the render's outputs being set does not stop a command it\n * started, and that command's report must stay visible.\n */\nexport function foldNode(transitions: readonly Transition[]): FoldedNode {\n const latestPerReporter = new Map<string, Transition>();\n for (const t of transitions) {\n const reporterKey = `${t.namespace}/${t.reporter}`;\n const previous = latestPerReporter.get(reporterKey);\n if (previous === undefined || compareNs(t.ns, previous.ns) > 0)\n latestPerReporter.set(reporterKey, t);\n }\n\n let render: Transition | undefined;\n let holding: Transition | undefined;\n let everyReporterEnded = true;\n for (const t of latestPerReporter.values()) {\n if (t.namespace === RenderNamespace) render = t;\n if (isTerminalBlockStatusState(t.state)) continue;\n everyReporterEnded = false;\n if (holding === undefined) {\n holding = t;\n continue;\n }\n const byRank = rank(t) - rank(holding);\n if (byRank > 0 || (byRank === 0 && compareNs(t.ns, holding.ns) > 0)) holding = t;\n }\n\n if (render !== undefined && isTerminalBlockStatusState(render.state) && everyReporterEnded)\n return {\n terminal: true,\n onMachine: false,\n failure: render.state === blockStatusStatesRecord.Terminated ? render.reason : undefined,\n };\n\n return {\n terminal: false,\n holding,\n onMachine:\n holding?.state === blockStatusStatesRecord.Running && holding.namespace === ExecNamespace,\n };\n}\n\n/** The render's own latest transition in a context. */\nexport function latestRender(transitions: readonly Transition[]): Transition | undefined {\n let latest: Transition | undefined;\n for (const t of transitions)\n if (t.namespace === RenderNamespace && (latest === undefined || compareNs(t.ns, latest.ns) > 0))\n latest = t;\n return latest;\n}\n\n/** One reading, as stored under `reading/<namespace>/<resource>/<key>`. */\nexport type Reading = { namespace: string; resource: string; key: string; value: string };\n\n/** One context read on its own, before its children are merged in. */\nexport type ContextFold = {\n readonly id: string;\n /** The baggage: `name`, `block-pack`, `block-id`, `run-id`. */\n readonly data: Record<string, unknown> | undefined;\n readonly reports: ContextReports;\n readonly readings: readonly Reading[];\n readonly folded: FoldedNode;\n /** True for a context a command or its work folder reports in: one job. */\n readonly job: boolean;\n /** The render's own latest transition, when it is a termination. */\n readonly terminated?: { readonly reason: string; readonly ns: string };\n};\n\nfunction readReadings(node: ActionContextNode): Reading[] {\n const out: Reading[] = [];\n for (const { key, value } of node.listKeyValuesAsString(ReadingPrefix)) {\n const parts = key.split(\"/\");\n if (parts.length !== 4) continue;\n out.push({ namespace: parts[1], resource: parts[2], key: parts[3], value });\n }\n return out;\n}\n\n/** Reads one context: its transitions, its readings, and the state holding it. */\nexport function foldContext(node: ActionContextNode): ContextFold {\n const reports = readTransitions(node);\n const render = latestRender(reports.all);\n return {\n id: node.id,\n data: node.getData(),\n reports,\n readings: readReadings(node),\n folded: foldNode(reports.all),\n job: reports.all.some((t) => t.namespace === ExecNamespace || t.namespace === WorkdirNamespace),\n terminated:\n render?.state === blockStatusStatesRecord.Terminated\n ? { reason: render.reason, ns: render.ns }\n : undefined,\n };\n}\n\n/** {@link BlockStatusJobGroup} being accumulated, its timestamp still in nanoseconds. */\ntype JobGroupTally = {\n readonly namespace: string;\n readonly state: string;\n readonly count: number;\n readonly sinceNs?: string;\n readonly files?: { readonly done: number; readonly total: number };\n};\n\n/**\n * {@link BlockStatusJobs} being accumulated over a subtree. Plain data throughout, no `Map`: it is\n * the value of a computable, which the computable types map over field by field.\n */\nexport type JobTally = {\n readonly total: number;\n readonly done: number;\n readonly failed: number;\n /** Jobs not ended, by `<namespace>/<state>` of the transition holding each. */\n readonly groups: Readonly<Record<string, JobGroupTally>>;\n};\n\nconst EmptyJobTally: JobTally = { total: 0, done: 0, failed: 0, groups: {} };\n\n/** A context and everything under it, folded. */\nexport type SubtreeFold = {\n readonly own: ContextFold;\n readonly children: readonly SubtreeFold[];\n /** This context and every context under it. */\n readonly contexts: number;\n /** Contexts in the subtree that have not ended. */\n readonly activeContexts: number;\n readonly firstNs?: string;\n readonly lastNs?: string;\n /** The earliest render in the subtree whose latest report is a termination. */\n readonly failure?: { readonly reason: string; readonly ns: string };\n readonly jobs: JobTally;\n};\n\n/** Files done of all, summed over the work folders' progress readings of one context. */\nfunction workdirProgress(readings: readonly Reading[]): JobGroupTally[\"files\"] {\n let progress: JobGroupTally[\"files\"];\n for (const r of readings) {\n if (r.namespace !== WorkdirNamespace || r.key !== \"progress\") continue;\n const parsed = parseJsonObject(r.value);\n if (typeof parsed?.done !== \"number\" || typeof parsed.total !== \"number\") continue;\n progress = addFiles(progress, { done: parsed.done, total: parsed.total });\n }\n return progress;\n}\n\nfunction addFiles(a: JobGroupTally[\"files\"], b: JobGroupTally[\"files\"]): JobGroupTally[\"files\"] {\n if (a === undefined) return b;\n if (b === undefined) return a;\n return { done: a.done + b.done, total: a.total + b.total };\n}\n\nfunction groupKey(group: Pick<JobGroupTally, \"namespace\" | \"state\">): string {\n return `${group.namespace}/${group.state}`;\n}\n\nfunction mergeGroup(\n groups: Record<string, JobGroupTally>,\n key: string,\n group: JobGroupTally,\n): void {\n const previous = groups[key];\n groups[key] =\n previous === undefined\n ? group\n : {\n namespace: group.namespace,\n state: group.state,\n count: previous.count + group.count,\n sinceNs: earlier(previous.sinceNs, group.sinceNs),\n files: addFiles(previous.files, group.files),\n };\n}\n\n/** The job a context is, counted where it is now; empty when it is not one. */\nfunction ownJobs(own: ContextFold): JobTally {\n if (!own.job) return EmptyJobTally;\n const { terminal, failure, holding } = own.folded;\n if (terminal)\n return failure === undefined\n ? { ...EmptyJobTally, total: 1, done: 1 }\n : { ...EmptyJobTally, total: 1, failed: 1 };\n if (holding === undefined) return { ...EmptyJobTally, total: 1 };\n const group: JobGroupTally = {\n namespace: holding.namespace,\n state: holding.state,\n count: 1,\n sinceNs: holding.ns,\n files: workdirProgress(own.readings),\n };\n return { ...EmptyJobTally, total: 1, groups: { [groupKey(group)]: group } };\n}\n\n/**\n * Merges a context with the folds of its children. One pass over the direct children, so a report\n * re-merges each context on its path to the root and nothing else.\n */\nexport function mergeSubtree(own: ContextFold, children: readonly SubtreeFold[]): SubtreeFold {\n let contexts = 1;\n let activeContexts = own.folded.terminal ? 0 : 1;\n let firstNs = own.reports.firstNs;\n let lastNs = own.reports.lastNs;\n let failure = own.terminated;\n let failedBelow = false;\n\n const self = ownJobs(own);\n let { total, done, failed } = self;\n const groups: Record<string, JobGroupTally> = { ...self.groups };\n\n for (const child of children) {\n contexts += child.contexts;\n activeContexts += child.activeContexts;\n firstNs = earlier(firstNs, child.firstNs);\n lastNs = later(lastNs, child.lastNs);\n if (child.failure !== undefined) {\n failedBelow = true;\n if (failure === undefined || compareNs(child.failure.ns, failure.ns) < 0)\n failure = child.failure;\n }\n total += child.jobs.total;\n done += child.jobs.done;\n failed += child.jobs.failed;\n for (const [key, group] of Object.entries(child.jobs.groups)) mergeGroup(groups, key, group);\n }\n\n // A render that failed on its own, e.g. one whose command could not start, is a failed job too;\n // one that only passes up the failure under it is not counted again.\n if (own.terminated !== undefined && !failedBelow && !own.job) {\n total++;\n failed++;\n }\n\n return {\n own,\n children,\n contexts,\n activeContexts,\n firstNs,\n lastNs,\n failure,\n jobs: { total, done, failed, groups },\n };\n}\n\n/**\n * The child contexts a fold follows: each once, and none already on the path from the root, so a\n * context linked twice or a cycle cannot count a subtree again.\n */\nexport function childContexts<T extends { readonly id: unknown }>(\n fields: readonly string[],\n traverse: (field: string) => T | undefined,\n path: ReadonlySet<string>,\n): T[] {\n if (path.size > MaxDepth) return [];\n const out: T[] = [];\n const seen = new Set<string>();\n for (const field of fields) {\n if (!field.startsWith(ChildFieldPrefix)) continue;\n const child = traverse(field);\n if (child === undefined) continue;\n const id = String(child.id);\n if (path.has(id) || seen.has(id)) continue;\n seen.add(id);\n out.push(child);\n }\n return out;\n}\n\n/**\n * Folds a context and everything under it in one walk: what the per-context computables compute,\n * for a tree that is read once.\n */\nexport function foldSubtree(\n node: ActionContextNode,\n path: ReadonlySet<string> = new Set(),\n): SubtreeFold {\n const below = new Set(path).add(node.id);\n const children = childContexts(node.listFields(), (f) => node.traverse(f), below);\n return mergeSubtree(\n foldContext(node),\n children.map((child) => foldSubtree(child, below)),\n );\n}\n\n/** Where the backend nests the error of an input inside the error of what consumes it. */\nconst InputErrorMarker = \"has input errors:\";\n\n/** Wrappers the workflow controller puts in front of a template's own error. */\nconst TemplateErrorPrefix = /^(cannot eval code: |cannot eval template: |tengo template error: )+/;\n\n/** Longest headline, in characters. */\nconst MaxHeadlineLength = 200;\n\n/**\n * The innermost message of a termination reason, for a title: the backend wraps the error of each\n * input in the error of its consumer, and tengo appends stack frames, so a reason can run to pages.\n */\nexport function failureHeadline(reason: string): string {\n const marker = reason.lastIndexOf(InputErrorMarker);\n const lines = reason\n .slice(marker < 0 ? 0 : marker + InputErrorMarker.length)\n .split(\"\\n\")\n .map((line) => line.trim())\n // Stack frames: `@platforma-sdk/workflow-tengo:tpl.base:595:5`.\n .filter((line) => line !== \"\" && !/^@\\S+:\\d+:\\d+$/.test(line));\n\n const text = lines.join(\" \");\n // A command that failed: `Command ID: … Command name: \"python\" … Error: docker is not set`.\n const command = /Command name: \"([^\"]*)\".*\\bError: (.+)$/.exec(text);\n const headline =\n command !== null\n ? `${command[1]} failed: ${command[2]}`\n : text.replace(TemplateErrorPrefix, \"\");\n return headline.length > MaxHeadlineLength\n ? `${headline.slice(0, MaxHeadlineLength - 1)}…`\n : headline;\n}\n\nfunction finishJobs(jobs: JobTally): BlockStatusJobs {\n const byState = Object.values(jobs.groups)\n .map((g): BlockStatusJobGroup => ({\n namespace: g.namespace,\n state: g.state,\n count: g.count,\n since: g.sinceNs === undefined ? undefined : nsToMs(g.sinceNs),\n files: g.files,\n }))\n .sort((a, b) => b.count - a.count || groupKey(a).localeCompare(groupKey(b)));\n return { total: jobs.total, done: jobs.done, failed: jobs.failed, byState };\n}\n\n/** The summary of a block run, from the fold of its root action context. */\nexport function summarize(root: SubtreeFold): BlockStatusSummary {\n const runId = root.own.data?.[\"run-id\"];\n const jobs = finishJobs(root.jobs);\n const summary = {\n availability: \"read\" as const,\n runId: typeof runId === \"string\" ? runId : undefined,\n activeContexts: root.activeContexts,\n totalContexts: root.contexts,\n jobs,\n startedAt: root.firstNs === undefined ? undefined : nsToMs(root.firstNs),\n };\n\n // A stopped run: its render is gone and reports nothing more, so the tree is frozen where it\n // stopped. The counters stay, to say where each node was; the run itself is over.\n let cancelledNs: string | undefined;\n for (const t of root.own.reports.all)\n if (t.namespace === CreatorNamespace && t.state === blockStatusStatesRecord.Terminated)\n cancelledNs = later(cancelledNs, t.ns);\n if (cancelledNs !== undefined)\n return { ...summary, lastChangeAt: nsToMs(cancelledNs), done: true, cancelled: true };\n\n // A terminated render fails the run. Renders waiting on its outputs never report again, so once\n // no job is held by its command or work folder the run is over, though they still look active.\n const working = jobs.byState.some((g) => g.namespace !== RenderNamespace);\n return {\n ...summary,\n lastChangeAt: root.lastNs === undefined ? undefined : nsToMs(root.lastNs),\n // The root's outputs can be set while work it started still runs, so done needs both.\n done:\n (root.own.folded.terminal && root.activeContexts === 0) ||\n (root.failure !== undefined && !working),\n failure: root.failure === undefined ? undefined : failureHeadline(root.failure.reason),\n };\n}\n\n/** The summary of a block run, from the root action context of its render. */\nexport function foldBlockStatus(root: ActionContextNode): BlockStatusSummary {\n return summarize(foldSubtree(root));\n}\n"],"mappings":";;;;;;AA6BA,SAAS,gBAAgB,OAAoD;CAC3E,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,KAAK;CAC3B,QAAQ;EACN;CACF;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,MAAM,QAAQ,MAAM,GAAG,OAAO,KAAA;CACnF,OAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC;AAClD;;AAyBA,MAAM,mBAAmB;;AAGzB,MAAM,mBAAmB;;AAGzB,MAAM,gBAAgB;;AAGtB,MAAM,kBAAkB;;;;;AAMxB,MAAM,mBAAmB;;AAGzB,MAAM,gBAAgB;;AAGtB,MAAM,mBAAmB;;AAsCzB,SAAgB,UAAU,GAAW,GAAmB;CACtD,OAAO,EAAE,WAAW,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