@jive-sh/workflow-platform 0.3.2 → 0.4.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/README.md +64 -20
- package/dist/cpu-limit/limiter.js +5 -4
- package/dist/cpu-limit/limiter.js.map +1 -1
- package/dist/dashboard/agent-usage.js +25 -0
- package/dist/dashboard/agent-usage.js.map +1 -0
- package/dist/dashboard/drilldown.js +16 -0
- package/dist/dashboard/drilldown.js.map +1 -0
- package/dist/dashboard/queue-lines.js +44 -0
- package/dist/dashboard/queue-lines.js.map +1 -0
- package/dist/dashboard/queue-table.js +8 -0
- package/dist/dashboard/queue-table.js.map +1 -0
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/keep-running.js +1 -1
- package/dist/keep-running.js.map +1 -1
- package/dist/pick-wakes.js +4 -4
- package/dist/pick-wakes.js.map +1 -1
- package/dist/queue-counts.js +7 -9
- package/dist/queue-counts.js.map +1 -1
- package/dist/steps.js +133 -30
- package/dist/steps.js.map +1 -1
- package/dist/storage/sqlite-store.js +115 -40
- package/dist/storage/sqlite-store.js.map +1 -1
- package/dist/storage/task-store.js +14 -1
- package/dist/storage/task-store.js.map +1 -1
- package/dist/tasks.js +215 -267
- package/dist/tasks.js.map +1 -1
- package/dist/views/runs-now.js +2 -1
- package/dist/views/runs-now.js.map +1 -1
- package/dist/views/workflows-view.js +74 -15
- package/dist/views/workflows-view.js.map +1 -1
- package/package.json +1 -1
- package/src/cpu-limit/limiter.ts +8 -5
- package/src/dashboard/agent-usage-line.tsx +28 -0
- package/src/dashboard/agent-usage.ts +48 -0
- package/src/dashboard/dashboard.css +68 -29
- package/src/dashboard/drilldown.ts +44 -0
- package/src/dashboard/index.tsx +1 -0
- package/src/dashboard/machine-controls.tsx +53 -0
- package/src/dashboard/queue-bar.tsx +43 -0
- package/src/dashboard/queue-chart.tsx +89 -76
- package/src/dashboard/queue-lines.ts +87 -0
- package/src/dashboard/queue-table.ts +23 -0
- package/src/dashboard/workflow-drilldown.tsx +89 -0
- package/src/dashboard/workflows-dashboard.tsx +103 -37
- package/src/index.ts +11 -10
- package/src/keep-running.ts +3 -3
- package/src/pick-wakes.ts +14 -9
- package/src/queue-counts.ts +10 -14
- package/src/steps.ts +179 -42
- package/src/storage/sqlite-store.ts +123 -46
- package/src/storage/step-records.ts +14 -3
- package/src/storage/task-store.ts +88 -36
- package/src/tasks.ts +235 -301
- package/src/views/runs-now.ts +3 -2
- package/src/views/workflows-view.ts +102 -32
- package/dist/views/workflow-flows.js +0 -53
- package/dist/views/workflow-flows.js.map +0 -1
- package/src/dashboard/workflow-dag.tsx +0 -256
- package/src/views/workflow-flows.ts +0 -97
package/dist/pick-wakes.js
CHANGED
|
@@ -96,18 +96,18 @@ export const makePickWakes = () => {
|
|
|
96
96
|
},
|
|
97
97
|
untilPickWoken: (input) => Effect.callback((resume) => {
|
|
98
98
|
if (released)
|
|
99
|
-
return resume(Effect.
|
|
99
|
+
return resume(Effect.succeed('released'));
|
|
100
100
|
if (pickWakesSoFar(input.workflow) !== input.after)
|
|
101
|
-
return resume(Effect.
|
|
101
|
+
return resume(Effect.succeed('woken'));
|
|
102
102
|
const waiter = {
|
|
103
103
|
workflow: input.workflow,
|
|
104
104
|
wake: () => {
|
|
105
105
|
waiters.delete(waiter);
|
|
106
|
-
resume(Effect.
|
|
106
|
+
resume(Effect.succeed('woken'));
|
|
107
107
|
},
|
|
108
108
|
release: () => {
|
|
109
109
|
waiters.delete(waiter);
|
|
110
|
-
resume(Effect.
|
|
110
|
+
resume(Effect.succeed('released'));
|
|
111
111
|
},
|
|
112
112
|
};
|
|
113
113
|
waiters.add(waiter);
|
package/dist/pick-wakes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick-wakes.js","sourceRoot":"","sources":["../../../src/pick-wakes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,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gBACD,OAAO,EAAE,GAAG,EAAE;oBACZ,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACvB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;gBACrC,CAAC;aACF,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;gBACtB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QACJ,WAAW,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE;YAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;YACzD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/queue-counts.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* EACH QUEUE'S COUNTS, RECORDED WHEN ITS QUEUE MAY HAVE CHANGED (`queue_counts`), so a page reads the newest row and
|
|
3
|
-
* counts. A workflow's tasks by
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* one that has read each task's inputs as its Pick reads them, so the page and the Pick put a task in the same bucket.
|
|
2
|
+
* EACH QUEUE'S COUNTS, RECORDED WHEN ITS QUEUE MAY HAVE CHANGED (`queue_counts`), so a page reads the newest row and its
|
|
3
|
+
* history and never counts. A workflow's tasks by status are read from its tasks' notes (`tasks.ts` `taskSummaries`), once
|
|
4
|
+
* per change, in the one process that runs the project's workflows. A count only counts: blocking a task is its Pick's
|
|
5
|
+
* step, never a page's or this (`tasks.ts` `settleQueue`).
|
|
7
6
|
*
|
|
8
7
|
* WHAT COUNTS AS A CHANGE: every wake of a workflow's Picks (`pick-wakes.ts`: a note on one of its tasks, an item new to
|
|
9
8
|
* its list, one of its runs ending, a limit set), and a Pick claiming an item (`changed`). Every change within
|
|
@@ -11,14 +10,13 @@
|
|
|
11
10
|
* change shows within 5 seconds. A row is written only where a count moved.
|
|
12
11
|
*/
|
|
13
12
|
import { Effect } from 'effect';
|
|
14
|
-
import {
|
|
13
|
+
import { statusCounts } from './tasks';
|
|
15
14
|
/** How long after a queue's first change it is counted: every change in that time is in the one count. */
|
|
16
15
|
export const COUNT_AFTER_MS = 5_000;
|
|
17
16
|
export const makeQueueCounts = (deps) => {
|
|
18
|
-
/** Counts one workflow's queue now and records it.
|
|
17
|
+
/** Counts one workflow's queue now and records it. */
|
|
19
18
|
const count = (workflow) => Effect.gen(function* () {
|
|
20
|
-
yield*
|
|
21
|
-
const counts = bucketCounts(yield* deps.tasks.taskSummaries({ workflow }));
|
|
19
|
+
const counts = statusCounts(yield* deps.tasks.taskSummaries({ workflow }));
|
|
22
20
|
yield* deps.store.recordQueueCounts({ at: Date.now() / 1000, counts: Object.entries(counts).map(([bucket, tasks]) => ({ workflow, bucket, tasks })) });
|
|
23
21
|
});
|
|
24
22
|
let countSoon = () => undefined;
|
package/dist/queue-counts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue-counts.js","sourceRoot":"","sources":["../../../src/queue-counts.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"queue-counts.js","sourceRoot":"","sources":["../../../src/queue-counts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,EAAE,YAAY,EAAc,MAAM,SAAS,CAAC;AAEnD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,cAAc,GAAG,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AAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,QAAQ,kBAAkB,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3J,CAAC,EAAE,IAAI,CAAC,YAAY,IAAI,cAAc,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACpD,CAAC,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3I,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE;YAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAChE,CAAC,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,QAAgB,EAAQ,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;AACrF,CAAC,CAAC"}
|
package/dist/steps.js
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* the same way. The step fails with `STOOD_DOWN`, and the run ends through its failure path, or through its normal one where
|
|
32
32
|
* it asks `isStoodDown`.
|
|
33
33
|
*
|
|
34
|
-
* EVERY ITEM IS A TASK, in
|
|
34
|
+
* EVERY ITEM IS A TASK, in one of four statuses read from its notes (`tasks.ts`). A Pick orders its own candidates through `pickOrder`, or
|
|
35
35
|
* takes its queue's head; a Pick that finds nothing waits for an event that can change that (`picked`, `pick-wakes.ts`),
|
|
36
36
|
* so a run never ends for want of an item.
|
|
37
37
|
*
|
|
@@ -58,9 +58,26 @@ export class AgentStep extends Context.Service()('AgentStep') {
|
|
|
58
58
|
export const CLEARED_BY_TEST = 'cleared by its test, no agent';
|
|
59
59
|
/** What an agent step fails with when its run is one too many for its workflow's budget. Stored as the step's result. */
|
|
60
60
|
export const STOOD_DOWN = 'stood down: its workflow has more runs going than its budget';
|
|
61
|
-
|
|
61
|
+
/**
|
|
62
|
+
* What a step waiting for work or for an agent fails with when its process hands its runs to the next one
|
|
63
|
+
* (`pick-wakes.ts` `releaseWaiting`): its run stands down untried, and the next process starts one.
|
|
64
|
+
*/
|
|
65
|
+
export const HANDED_OVER = 'stood down: its process is handing its runs to the next';
|
|
66
|
+
export const isStoodDown = (failure) => failure === STOOD_DOWN || failure === HANDED_OVER;
|
|
62
67
|
/** Whether a run is surplus: it is past the budget in the workflow's runs, oldest first. A run not listed is not counted. Pure. */
|
|
63
68
|
export const surplusRun = (oldestFirst, run, budget) => oldestFirst.indexOf(run) >= budget;
|
|
69
|
+
/**
|
|
70
|
+
* WHAT A STEP IS, as a page says it in words. Alex, 2026-11-19: "there are different kinds of workflow steps. like a check,
|
|
71
|
+
* like a sub workflow."
|
|
72
|
+
*
|
|
73
|
+
* step plain code;
|
|
74
|
+
* agent calls an agent;
|
|
75
|
+
* check decides whether the work passes;
|
|
76
|
+
* sub-workflow a workflow used as a step of another workflow (`StepDeclaration.workflow` names it).
|
|
77
|
+
*/
|
|
78
|
+
export const STEP_KINDS = ['step', 'agent', 'check', 'sub-workflow'];
|
|
79
|
+
/** A step's kind, from its declaration: an agent step is an agent, the kind it states otherwise, and plain code with none. Pure. */
|
|
80
|
+
export const stepKindOf = (s) => s.agent ? 'agent' : s.kind ?? (s.test === true ? 'check' : 'step');
|
|
64
81
|
/** What the test said of an item: it passes now, the exact failure the agent gets, or why it cannot be tested. */
|
|
65
82
|
export const ItemTest = Schema.Union([
|
|
66
83
|
Schema.Struct({ result: Schema.Literal('passes'), detail: Schema.String }),
|
|
@@ -77,8 +94,12 @@ const REFUSED_SAID_EVERY_MS = 10 * 60 * 1000;
|
|
|
77
94
|
* (`runLimit`); for any other its run limit, none meaning no limit. 0 starts nothing new. Pure.
|
|
78
95
|
*/
|
|
79
96
|
export const runLimitOf = (d, limits) => keptRunningByItsBudget(d) ? runLimit(limits) : limits.runs;
|
|
80
|
-
/** Whether a workflow
|
|
81
|
-
export const
|
|
97
|
+
/** Whether a workflow declares a list, of either kind: it has tasks and a queue. Pure. */
|
|
98
|
+
export const hasAList = (d) => d.pending !== undefined || d.items !== undefined;
|
|
99
|
+
/** Whether a step uses an agent: it is an agent step, or a sub-workflow step whose workflow has one at any depth. Pure. */
|
|
100
|
+
export const stepUsesAnAgent = (s) => s.agent || s.agentUnder?.() === true;
|
|
101
|
+
/** Whether a workflow's budget rules it: a declared list, and an agent step of its own or under a sub-workflow step. Pure. */
|
|
102
|
+
export const keptRunningByItsBudget = (d) => hasAList(d) && d.steps().some(stepUsesAnAgent);
|
|
82
103
|
const CurrentMeter = Context.Reference('CurrentStepMeter', { defaultValue: () => null });
|
|
83
104
|
/** The definer of one project's workflows and steps, on its stores. */
|
|
84
105
|
export const makeSteps = (deps) => {
|
|
@@ -160,26 +181,42 @@ export const makeSteps = (deps) => {
|
|
|
160
181
|
* slot, each until the next wake reads them again. Read as no limits, a store that failed would start agents at 0.
|
|
161
182
|
*/
|
|
162
183
|
const unreadLimits = (workflow, held) => (e) => Effect.as(Effect.logError(`[budget] ${workflow}: its limits could not be read (${e.reason}); its runs wait`), held(e.reason));
|
|
184
|
+
/**
|
|
185
|
+
* THE RUN AT THE TOP OF A RUN: itself, or, for a run a sub-workflow step started, the run at the top of those above it
|
|
186
|
+
* (`StepRecords.rootOfRun`). A workflow's limits govern every run under its runs, so a sub-workflow's agent step counts
|
|
187
|
+
* against the agents' limit of the workflow at the top. Kept while the run goes: it never changes.
|
|
188
|
+
*/
|
|
189
|
+
const TOPS = new Map();
|
|
190
|
+
const topOf = (workflow, run) => {
|
|
191
|
+
const known = TOPS.get(run);
|
|
192
|
+
if (known !== undefined)
|
|
193
|
+
return Effect.succeed(known);
|
|
194
|
+
return Effect.map(records.rootOfRun(run), (root) => {
|
|
195
|
+
const top = root ?? { run, workflow };
|
|
196
|
+
TOPS.set(run, top);
|
|
197
|
+
return top;
|
|
198
|
+
});
|
|
199
|
+
};
|
|
163
200
|
const AgentBudgets = Context.Reference('AgentBudgets', {
|
|
164
201
|
defaultValue: () => ({
|
|
165
202
|
// Among its workflow's unfinished runs, oldest first, the run is past those its run limit keeps (`runLimit`). A run not
|
|
166
|
-
// listed is not counted.
|
|
167
|
-
standsDown: (workflow, run) => pipe(pastItsRunLimit(workflow, run), Effect.catchTag('StorageError', unreadLimits(workflow, () => false))),
|
|
203
|
+
// listed is not counted. A run a sub-workflow step started stands down with the run at its top.
|
|
204
|
+
standsDown: (workflow, run) => pipe(topOf(workflow, run), Effect.flatMap((top) => Effect.zipWith(pastItsRunLimit(workflow, run), top.run === run ? Effect.succeed(false) : pastItsRunLimit(top.workflow, top.run), (own, above) => own || above)), Effect.catchTag('StorageError', unreadLimits(workflow, () => false))),
|
|
168
205
|
waitsForWork: (workflow, run) => pipe(pastItsRunLimit(workflow, run), Effect.map((past) => !past), Effect.catchTag('StorageError', unreadLimits(workflow, () => true))),
|
|
169
|
-
//
|
|
170
|
-
// runs wait at their first agent step until the limit is raised.
|
|
171
|
-
agentSlot: (workflow, run) => pipe(
|
|
206
|
+
// The other runs of the workflow at its top that an agent works for, a waiting one not counted, against that
|
|
207
|
+
// workflow's agents' limit: at 0 none is ever free, and its runs wait at their first agent step until the limit is raised.
|
|
208
|
+
agentSlot: (workflow, run) => pipe(topOf(workflow, run), Effect.flatMap((top) => Effect.flatMap(limitsOf(top.workflow), (w) => {
|
|
172
209
|
const agents = w === null ? null : w.agents;
|
|
173
210
|
if (agents === null)
|
|
174
211
|
return Effect.succeed({ free: true });
|
|
175
212
|
if (agents === 0)
|
|
176
213
|
return Effect.succeed({ free: false, why: 'waits for an agent: its agents\x27 limit is 0' });
|
|
177
|
-
return Effect.map(Effect.all({ runs: runsOldestFirst([workflow]), inAgentStep: records.runsInAgentStep(workflow) }), ({ runs, inAgentStep }) => {
|
|
214
|
+
return Effect.map(Effect.all({ runs: runsOldestFirst([top.workflow]), inAgentStep: records.runsInAgentStep(top.workflow) }), ({ runs, inAgentStep }) => {
|
|
178
215
|
const going = new Set(runs);
|
|
179
|
-
const busy = inAgentStep.filter((r) => r !== run && going.has(r)).length;
|
|
216
|
+
const busy = inAgentStep.filter((r) => r !== top.run && going.has(r)).length;
|
|
180
217
|
return busy < agents ? { free: true } : { free: false, why: `waits for an agent: ${busy} of its ${agents} in use` };
|
|
181
218
|
});
|
|
182
|
-
}), Effect.catchTag('StorageError', unreadLimits(workflow, (why) => ({ free: false, why: `waits for an agent: its limits could not be read (${why})` })))),
|
|
219
|
+
})), Effect.catchTag('StorageError', unreadLimits(workflow, (why) => ({ free: false, why: `waits for an agent: its limits could not be read (${why})` })))),
|
|
183
220
|
}),
|
|
184
221
|
});
|
|
185
222
|
/**
|
|
@@ -190,9 +227,11 @@ export const makeSteps = (deps) => {
|
|
|
190
227
|
const untilAgentSlot = (instance, record) => Effect.gen(function* () {
|
|
191
228
|
const rules = yield* AgentBudgets;
|
|
192
229
|
const workflow = instance.workflow._tag;
|
|
230
|
+
// An agent is freed, and a limit set, on the workflow at the top of this run: its wakes are the ones this wait hears.
|
|
231
|
+
const heardOn = (yield* Effect.orElseSucceed(topOf(workflow, instance.executionId), () => ({ run: instance.executionId, workflow }))).workflow;
|
|
193
232
|
let waited = false;
|
|
194
233
|
for (;;) {
|
|
195
|
-
const wakes = deps.wakes.pickWakesSoFar(
|
|
234
|
+
const wakes = deps.wakes.pickWakesSoFar(heardOn);
|
|
196
235
|
if (yield* rules.standsDown(workflow, instance.executionId))
|
|
197
236
|
return yield* Effect.fail(STOOD_DOWN);
|
|
198
237
|
const slot = yield* rules.agentSlot(workflow, instance.executionId);
|
|
@@ -207,7 +246,8 @@ export const makeSteps = (deps) => {
|
|
|
207
246
|
if (id !== null)
|
|
208
247
|
yield* recorded('say what it waits on', records.setStepWaiting({ id, waiting: slot.why }));
|
|
209
248
|
waited = true;
|
|
210
|
-
yield* deps.wakes.untilPickWoken({ workflow, after: wakes })
|
|
249
|
+
if ((yield* deps.wakes.untilPickWoken({ workflow: heardOn, after: wakes })) === 'released')
|
|
250
|
+
return yield* Effect.fail(HANDED_OVER);
|
|
211
251
|
}
|
|
212
252
|
});
|
|
213
253
|
/** Checks the move to `step` against its workflow's graph: in tests an undeclared one fails the run; live, it is said once. */
|
|
@@ -231,7 +271,7 @@ export const makeSteps = (deps) => {
|
|
|
231
271
|
}
|
|
232
272
|
});
|
|
233
273
|
/** Runs `execute` as this step of the workflow it is in, and writes its record. */
|
|
234
|
-
const measured = (step, call, subject, subjectOf, reasonOf, mayWrite, execute) => Effect.flatMap(WorkflowEngine.WorkflowInstance, (instance) => {
|
|
274
|
+
const measured = (step, call, subject, subjectOf, reasonOf, mayWrite, execute, childRun = null) => Effect.flatMap(WorkflowEngine.WorkflowInstance, (instance) => {
|
|
235
275
|
// A call's running sum is by request; its final figures replace it. `settled` is what finished calls reported.
|
|
236
276
|
const settled = noSpend();
|
|
237
277
|
const running = new Map();
|
|
@@ -272,7 +312,10 @@ export const makeSteps = (deps) => {
|
|
|
272
312
|
let meter = new StepMeter(null, step.agent, [], null);
|
|
273
313
|
return Effect.acquireUseRelease(Effect.flatMap(Effect.gen(function* () {
|
|
274
314
|
yield* checkEdge(instance.workflow._tag, instance.executionId, step.name);
|
|
275
|
-
|
|
315
|
+
// A sub-workflow step is run again when its workflow has ended: it takes its open record up again, and names the run it started.
|
|
316
|
+
const id = yield* recorded('open its record', records.openStepRun({ workflow: instance.workflow._tag, run: instance.executionId, step: step.name, call, agent: step.agent, subject, ...(childRun === null ? {} : { resume: true }) }));
|
|
317
|
+
if (id !== null && childRun !== null)
|
|
318
|
+
yield* recorded('name the run it started', records.setStepChild({ id, childRun }));
|
|
276
319
|
const beat = step.agent && id !== null ? setInterval(() => recordNow('its heartbeat', records.beatStepRun(id)), AGENT_BEAT_MS) : null;
|
|
277
320
|
recordId = id;
|
|
278
321
|
meter = new StepMeter(id, step.agent, step.writes ?? [], null);
|
|
@@ -312,7 +355,7 @@ export const makeSteps = (deps) => {
|
|
|
312
355
|
clearInterval(beat);
|
|
313
356
|
// Its agent slot is free for its workflow's next run waiting on one.
|
|
314
357
|
if (step.agent)
|
|
315
|
-
deps.wakes.wakePicksOf(instance.workflow._tag, 'an agent step ended');
|
|
358
|
+
deps.wakes.wakePicksOf(TOPS.get(instance.executionId)?.workflow ?? instance.workflow._tag, 'an agent step ended');
|
|
316
359
|
// An interrupted step is no move: the run does it again.
|
|
317
360
|
if (Exit.isSuccess(exit) || !Cause.hasInterrupts(exit.cause))
|
|
318
361
|
lastStepRan.set(instance.executionId, { step: step.name, failed: !Exit.isSuccess(exit) });
|
|
@@ -327,6 +370,9 @@ export const makeSteps = (deps) => {
|
|
|
327
370
|
const scope = meter.items > 0 ? 'functions' : step.shared === true ? 'shared' : idleBatch ? 'none due' : subjectOf !== undefined && Exit.isSuccess(exit) && named === null ? 'nothing' : 'undeclared';
|
|
328
371
|
if (Exit.isSuccess(exit))
|
|
329
372
|
yield* recorded('close its record', records.closeStepRun({ id, outcome: 'success', reason: (reasonOf ?? standardReason)(exit.value), error: null, spend, subject: named, used, scope }));
|
|
373
|
+
// A sub-workflow step whose run is suspended until its workflow ends is still in that step: its record stays open.
|
|
374
|
+
else if (Cause.hasInterrupts(exit.cause) && childRun !== null && instance.suspended)
|
|
375
|
+
yield* Effect.void;
|
|
330
376
|
else if (Cause.hasInterrupts(exit.cause))
|
|
331
377
|
yield* recorded('close its record', records.closeStepRun({ id, outcome: 'interrupted', reason: 'interrupted', error: null, spend, subject: null, used, scope }));
|
|
332
378
|
else
|
|
@@ -374,7 +420,7 @@ export const makeSteps = (deps) => {
|
|
|
374
420
|
return lock.withPermits(1)(pick);
|
|
375
421
|
};
|
|
376
422
|
/** Why a Pick waits, on its open record: its queued tasks, none of which it can claim now, and what wakes it. */
|
|
377
|
-
const nothingToClaim = (workflow) => pipe(deps.tasks.taskSummaries({ workflow }), Effect.map((tasks) => `${queueOrder(tasks).length} queued${queueOrder(tasks).length === 0 ? '' : ', none it can claim now'}`), Effect.catchTag('StorageError', (e) => Effect.succeed(`its tasks could not be read: ${e.reason}`)), Effect.map((queued) => `no task it can claim (${queued}); it waits for
|
|
423
|
+
const nothingToClaim = (workflow) => pipe(deps.tasks.taskSummaries({ workflow }), Effect.map((tasks) => `${queueOrder(tasks).length} queued${queueOrder(tasks).length === 0 ? '' : ', none it can claim now'}`), Effect.catchTag('StorageError', (e) => Effect.succeed(`its tasks could not be read: ${e.reason}`)), Effect.map((queued) => `no task it can claim (${queued}); it waits for a task returned to its queue, a new item, a run ending or a limit change`));
|
|
378
424
|
/**
|
|
379
425
|
* A PICK THAT FINDS NOTHING IT CAN CLAIM WAITS FOR AN EVENT THAT CAN CHANGE THAT (`pick-wakes.ts`), and never polls: one
|
|
380
426
|
* open record, its `waiting` saying on what, and no new record while nothing changes. The run keeps its place in its
|
|
@@ -406,14 +452,15 @@ export const makeSteps = (deps) => {
|
|
|
406
452
|
if (record !== null)
|
|
407
453
|
yield* recorded('say what it waits on', records.setStepWaiting({ id: record, waiting: yield* nothingToClaim(workflow) }));
|
|
408
454
|
waited = true;
|
|
409
|
-
yield* deps.wakes.untilPickWoken({ workflow, after: wakes })
|
|
455
|
+
if ((yield* deps.wakes.untilPickWoken({ workflow, after: wakes })) === 'released')
|
|
456
|
+
return yield* Effect.fail(HANDED_OVER);
|
|
410
457
|
}
|
|
411
458
|
});
|
|
412
459
|
/** A step: its declaration, and `run`, the only way to run it. */
|
|
413
460
|
const defineStep = (d) => {
|
|
414
461
|
const writes = [...(d.mayWrite ?? []), ...(d.writes ?? [])];
|
|
415
462
|
const declaration = {
|
|
416
|
-
name: d.name, agent: d.agent, description: d.description, ...(d.test === undefined ? {} : { test: true }), ...(d.shared === undefined ? {} : { shared: true }), ...(d.perItem === undefined ? {} : { perItem: true }), ...(d.picked === undefined ? {} : { picks: true }),
|
|
463
|
+
name: d.name, agent: d.agent, description: d.description, ...(d.kind === undefined ? {} : { kind: d.kind }), ...(d.test === undefined ? {} : { test: true }), ...(d.shared === undefined ? {} : { shared: true }), ...(d.perItem === undefined ? {} : { perItem: true }), ...(d.picked === undefined ? {} : { picks: true }),
|
|
417
464
|
...(writes.length === 0 ? {} : { writes }),
|
|
418
465
|
source: d.prompt ?? { path: sourcePath(d.at), anchor: `'${d.name}'` },
|
|
419
466
|
};
|
|
@@ -453,6 +500,54 @@ export const makeSteps = (deps) => {
|
|
|
453
500
|
const step = defineStep({ name: 'Test', agent: false, test: true, description: d.description, at: d.at, prompt: { path: sourcePath(d.at), anchor: 'defineItemTest(' }, success: ItemTest });
|
|
454
501
|
return { ...step, run: (test, options) => step.run(heldToItsList(test, options?.subject ?? null), options) };
|
|
455
502
|
};
|
|
503
|
+
/** The sub-workflows whose agent steps are being asked for now: a workflow that used itself as a step would ask for ever. */
|
|
504
|
+
const askingForAgents = new Set();
|
|
505
|
+
/**
|
|
506
|
+
* A SUB-WORKFLOW STEP: a workflow used as a step of another. Alex, 2026-11-19: "decompile is itself a workflow composed of
|
|
507
|
+
* other workflows. the long term goal of Jive is to be workflows all the way down".
|
|
508
|
+
*
|
|
509
|
+
* Running it starts `workflow` as a run of its own on `payload` and waits for it: the engine suspends the run above until
|
|
510
|
+
* it ends, across restarts, and then runs this step again, which reads the result. The step keeps ONE record in the
|
|
511
|
+
* workflow above, open while its workflow runs and naming that run, so:
|
|
512
|
+
*
|
|
513
|
+
* the page shows the run above in this step, and the workflow's own view shows its steps and what they cost;
|
|
514
|
+
* the workflow's steps work on the item the run above works on, with no code naming it (`StepRecords.openStepRun`);
|
|
515
|
+
* its agent steps count against the agents' limit of the workflow at the top, and stand down with its run (`topOf`).
|
|
516
|
+
*
|
|
517
|
+
* Its own run limit applies as to any start: at 0 the step fails, saying so, and the workflow above decides what follows.
|
|
518
|
+
*/
|
|
519
|
+
const defineSubWorkflow = (d) => {
|
|
520
|
+
const child = d.workflow._tag;
|
|
521
|
+
// What its workflow gave is what the step declares, or the step fails saying so: no result is taken on trust.
|
|
522
|
+
const isDeclared = Schema.is(d.success);
|
|
523
|
+
const given = (result) => (isDeclared(result) ? Effect.succeed(result) : Effect.fail(`${child} gave a result that is not what this step declares`));
|
|
524
|
+
const name = d.as ?? child;
|
|
525
|
+
const declaration = {
|
|
526
|
+
name, agent: false, kind: 'sub-workflow', workflow: child,
|
|
527
|
+
description: DECLARED.get(child)?.description ?? `Runs ${child}.`,
|
|
528
|
+
source: DECLARED.get(child)?.source ?? { path: sourcePath(d.at), anchor: `'${child}'` },
|
|
529
|
+
agentUnder: () => {
|
|
530
|
+
if (askingForAgents.has(child))
|
|
531
|
+
return false;
|
|
532
|
+
askingForAgents.add(child);
|
|
533
|
+
try {
|
|
534
|
+
return DECLARED.get(child)?.steps().some(stepUsesAnAgent) === true;
|
|
535
|
+
}
|
|
536
|
+
finally {
|
|
537
|
+
askingForAgents.delete(child);
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
};
|
|
541
|
+
return {
|
|
542
|
+
...declaration,
|
|
543
|
+
run: (payload, options) => Activity.make({
|
|
544
|
+
name: options?.call === undefined ? name : `${name} ${options.call}`,
|
|
545
|
+
success: d.success,
|
|
546
|
+
error: Schema.String,
|
|
547
|
+
execute: pipe(standDownIfSurplus({ agent: false, picks: false }), Effect.andThen(Effect.flatMap(d.workflow.executionId(payload), (childRun) => measured(declaration, options?.call ?? null, null, undefined, undefined, undefined, Effect.flatMap(d.workflow.execute(payload), given), childRun))), Effect.mapError(describeFailure)),
|
|
548
|
+
}),
|
|
549
|
+
};
|
|
550
|
+
};
|
|
456
551
|
/** Every workflow defined so far, in the order defined. */
|
|
457
552
|
const declaredWorkflows = () => [...DECLARED.values()];
|
|
458
553
|
/** Calls `listener` shortly after any run ends, when the engine has stored its end. */
|
|
@@ -475,10 +570,16 @@ export const makeSteps = (deps) => {
|
|
|
475
570
|
deps.tasks.recordTaskInputs(workflow, byItem);
|
|
476
571
|
return byItem;
|
|
477
572
|
});
|
|
478
|
-
/**
|
|
573
|
+
/** The step a Pick's notes are written by: every Pick is the step that reads its queue. */
|
|
574
|
+
const pickedBy = (input) => ({ workflow: input.workflow, run: input.run, step: 'Pick' });
|
|
575
|
+
/**
|
|
576
|
+
* A WORKFLOW'S QUEUE AS ITS PICK TAKES IT: first in, first out (`tasks.ts` `queueOrder`), another run's tasks left out.
|
|
577
|
+
* The Pick first reads what its tasks run on and settles its queue (`tasks.ts` `settleQueue`): a task a standard reason
|
|
578
|
+
* holds for is blocked, and a blocked one whose reason lapsed is back in the queue.
|
|
579
|
+
*/
|
|
479
580
|
const queueNow = (input) => Effect.gen(function* () {
|
|
480
581
|
yield* readTaskInputs(input.workflow);
|
|
481
|
-
return queueOrder(yield* deps.tasks.
|
|
582
|
+
return queueOrder(yield* deps.tasks.settleQueue({ workflow: input.workflow, excludingRun: input.run, by: pickedBy(input) }));
|
|
482
583
|
});
|
|
483
584
|
/** A workflow: what it states about itself, then `Workflow.make`'s own name and options. */
|
|
484
585
|
const defineWorkflow = (d) => ((name, options) => {
|
|
@@ -494,7 +595,7 @@ export const makeSteps = (deps) => {
|
|
|
494
595
|
let refusedSaidAt = 0;
|
|
495
596
|
const startAllowed = (payload) => Effect.gen(function* () {
|
|
496
597
|
const limits = yield* deps.budgets.limitsOf(name);
|
|
497
|
-
const limit = limits === null ? null : runLimitOf({ pending: d.pending, steps: d.steps }, limits);
|
|
598
|
+
const limit = limits === null ? null : runLimitOf({ pending: d.pending, items: d.items, steps: d.steps }, limits);
|
|
498
599
|
if (limit === null)
|
|
499
600
|
return { allowed: true };
|
|
500
601
|
const going = (yield* deps.engine.unfinishedRuns()).filter((u) => u.workflow === name).map((u) => u.run);
|
|
@@ -514,8 +615,8 @@ export const makeSteps = (deps) => {
|
|
|
514
615
|
...(d.graph === undefined ? {} : { graph: d.graph }),
|
|
515
616
|
source: { path: sourcePath(d.at), anchor: `'${name}'` },
|
|
516
617
|
...(d.pending === undefined ? {} : { pending: d.pending }),
|
|
618
|
+
...(d.items === undefined ? {} : { items: d.items }),
|
|
517
619
|
...(d.picksQueueHead === undefined ? {} : { picksQueueHead: d.picksQueueHead }),
|
|
518
|
-
...(d.fedBy === undefined ? {} : { fedBy: d.fedBy }),
|
|
519
620
|
...(d.inputs === undefined ? {} : { inputs: d.inputs }),
|
|
520
621
|
...(d.taskInputs === undefined ? {} : { taskInputs: d.taskInputs }),
|
|
521
622
|
item: d.item,
|
|
@@ -542,13 +643,13 @@ export const makeSteps = (deps) => {
|
|
|
542
643
|
if (!interrupted && d.item !== null) {
|
|
543
644
|
if (Exit.isSuccess(exit)) {
|
|
544
645
|
for (const o of d.outcomes(exit.value))
|
|
545
|
-
yield* deps.tasks.appendOutcome({ workflow: name, run: executionId, subject: o.subject ?? null, outcome: o.outcome, finished: o.finished || o.outcome === CLEARED_BY_TEST, inputs: inputsLeft(o.subject ?? null) });
|
|
646
|
+
yield* deps.tasks.appendOutcome({ workflow: name, run: executionId, subject: o.subject ?? null, outcome: o.outcome, finished: o.finished || o.outcome === CLEARED_BY_TEST, inputs: inputsLeft(o.subject ?? null), blocked: o.blocked ?? null });
|
|
546
647
|
}
|
|
547
648
|
else {
|
|
548
649
|
// With its cause, as its step's record has it: a bare "failed" sent whoever read it to the records for why.
|
|
549
650
|
const failure = Cause.squash(exit.cause);
|
|
550
651
|
const outcome = isStoodDown(failure) ? 'stood down' : `failed: ${startAndEnd(describeFailure(failure), { cap: 1000, end: 400, what: 'the failure' })}`;
|
|
551
|
-
yield* deps.tasks.appendOutcome({ workflow: name, run: executionId, subject: null, outcome, finished: false, inputs: inputsLeft(null) });
|
|
652
|
+
yield* deps.tasks.appendOutcome({ workflow: name, run: executionId, subject: null, outcome, finished: false, inputs: inputsLeft(null), blocked: null });
|
|
552
653
|
}
|
|
553
654
|
}
|
|
554
655
|
// What it ran on gave this result, which stands until its inputs change. Only a run its trigger started on its
|
|
@@ -561,6 +662,7 @@ export const makeSteps = (deps) => {
|
|
|
561
662
|
}), 'StorageError', (e) => Effect.logError(`[inputs] ${name} run ${executionId}: its end could not be recorded: ${e.reason}`));
|
|
562
663
|
}
|
|
563
664
|
lastStepRan.delete(executionId);
|
|
665
|
+
TOPS.delete(executionId);
|
|
564
666
|
runEnded();
|
|
565
667
|
// Its claim and its item are free now for its workflow's other runs, once the engine has stored its end. Only its
|
|
566
668
|
// own: about 25 short runs end a minute, and waking every Pick on each re-read every task twice each time.
|
|
@@ -592,10 +694,11 @@ export const makeSteps = (deps) => {
|
|
|
592
694
|
/** The items a workflow's other unfinished runs are on, lower case, so a budget above 1 never puts two agents on one. */
|
|
593
695
|
const itemsOfOtherRuns = (workflow, run) => Effect.flatMap(runningRunIds(workflow), (runs) => Effect.map(Effect.forEach(runs.filter((r) => r !== run), (r) => records.subjectOfRun(r)), (subjects) => new Set(subjects.flatMap((subject) => (subject === null ? [] : [subject.toLowerCase()])))));
|
|
594
696
|
/**
|
|
595
|
-
* The candidates of this run's Pick in the order it takes them (`tasks.ts` `inPickOrder`),
|
|
596
|
-
*
|
|
697
|
+
* The candidates of this run's Pick in the order it takes them (`tasks.ts` `inPickOrder`), its queue settled first as
|
|
698
|
+
* `queueNow` settles it: none blocked, another run's left out. `fromItem` builds a candidate for a task a step or a person
|
|
699
|
+
* returned to the queue that the candidates do not hold.
|
|
597
700
|
*/
|
|
598
|
-
const pickOrder = (input) => Effect.map(deps.tasks.
|
|
701
|
+
const pickOrder = (input) => Effect.map(deps.tasks.settleQueue({ workflow: input.workflow, excludingRun: input.run, by: pickedBy(input) }), (tasks) => inPickOrder({ candidates: input.candidates, subjectOf: input.subjectOf, tasks, ...(input.fromItem === undefined ? {} : { fromItem: input.fromItem }) }));
|
|
599
702
|
/**
|
|
600
703
|
* A workflow of one code step, run each turn of its trigger: `run` waits for the run to finish (a heavy one, in line with
|
|
601
704
|
* the other heavy jobs), `start` leaves it to the engine.
|
|
@@ -619,7 +722,7 @@ export const makeSteps = (deps) => {
|
|
|
619
722
|
};
|
|
620
723
|
};
|
|
621
724
|
return {
|
|
622
|
-
defineStep, defineItemTest, defineWorkflow, oneStepWorkflow, declaredWorkflows, onRunEnded,
|
|
725
|
+
defineStep, defineItemTest, defineSubWorkflow, defineWorkflow, oneStepWorkflow, declaredWorkflows, onRunEnded,
|
|
623
726
|
eachItem, undoAgentStep, AgentBudgets, pickingOneAtATime, pickOrder, itemsOfOtherRuns,
|
|
624
727
|
runsOldestFirst, runningRunIds, runningRuns, sourcePath, runIfInputsChanged, queueNow, readTaskInputs,
|
|
625
728
|
};
|