@jive-sh/workflow-platform 0.6.3 → 1.0.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 +66 -295
- package/component/_generated/api.ts +72 -0
- package/component/_generated/component.ts +621 -0
- package/component/_generated/dataModel.ts +60 -0
- package/component/_generated/server.ts +169 -0
- package/component/convex.config.ts +3 -0
- package/component/engine.ts +755 -0
- package/component/errors.ts +66 -0
- package/component/events.ts +17 -0
- package/component/notes.ts +13 -0
- package/component/places.ts +136 -0
- package/component/retention.ts +205 -0
- package/component/runEngine.ts +25 -0
- package/component/schema.ts +132 -0
- package/component/steps.ts +188 -0
- package/component/store.ts +512 -0
- package/component/tasks.ts +289 -0
- package/component/worker.ts +109 -0
- package/component/workflows.ts +83 -0
- package/dist/definition/agent-runner.js +9 -0
- package/dist/definition/agent-runner.js.map +1 -0
- package/dist/definition/file-store.js +9 -0
- package/dist/definition/file-store.js.map +1 -0
- package/dist/definition/program-build.js +10 -0
- package/dist/definition/program-build.js.map +1 -0
- package/dist/definition/step.js +1 -0
- package/dist/definition/step.js.map +1 -0
- package/dist/definition/task-schema.js +5 -0
- package/dist/definition/task-schema.js.map +1 -0
- package/dist/definition/tasks.js +9 -0
- package/dist/definition/tasks.js.map +1 -0
- package/dist/definition/workflow.js +111 -0
- package/dist/definition/workflow.js.map +1 -0
- package/dist/graph.js +301 -9
- package/dist/graph.js.map +1 -1
- package/dist/index.js +7 -133
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/src/definition/agent-runner.ts +59 -0
- package/src/definition/file-store.ts +20 -0
- package/src/definition/program-build.ts +30 -0
- package/src/definition/step.ts +106 -0
- package/src/definition/task-schema.ts +15 -0
- package/src/definition/tasks.ts +43 -0
- package/src/definition/workflow.ts +255 -0
- package/src/graph.ts +341 -19
- package/src/index.ts +8 -168
- package/worker/directory-file-store.ts +42 -0
- package/worker/index.ts +12 -0
- package/worker/platform-client.ts +138 -0
- package/worker/step-meter.ts +80 -0
- package/worker/worker-tasks.ts +27 -0
- package/worker/worker.test.ts +200 -0
- package/worker/worker.ts +240 -0
- package/dist/budget-states.js +0 -30
- package/dist/budget-states.js.map +0 -1
- package/dist/cpu-limit/limiter.js +0 -839
- package/dist/cpu-limit/limiter.js.map +0 -1
- package/dist/cpu-limit/use.js +0 -139
- package/dist/cpu-limit/use.js.map +0 -1
- package/dist/dashboard/agent-usage.js +0 -25
- package/dist/dashboard/agent-usage.js.map +0 -1
- package/dist/dashboard/dashboard.css +0 -134
- package/dist/dashboard/drilldown.js +0 -16
- package/dist/dashboard/drilldown.js.map +0 -1
- package/dist/dashboard/queue-lines.js +0 -44
- package/dist/dashboard/queue-lines.js.map +0 -1
- package/dist/dashboard/queue-table.js +0 -16
- package/dist/dashboard/queue-table.js.map +0 -1
- package/dist/dashboard/spending-words.js +0 -32
- package/dist/dashboard/spending-words.js.map +0 -1
- package/dist/failure.js +0 -35
- package/dist/failure.js.map +0 -1
- package/dist/keep-running.js +0 -77
- package/dist/keep-running.js.map +0 -1
- package/dist/outside-failure.js +0 -31
- package/dist/outside-failure.js.map +0 -1
- package/dist/pick-wakes.js +0 -125
- package/dist/pick-wakes.js.map +0 -1
- package/dist/project.js +0 -1
- package/dist/project.js.map +0 -1
- package/dist/queue-counts.js +0 -51
- package/dist/queue-counts.js.map +0 -1
- package/dist/reasons.js +0 -33
- package/dist/reasons.js.map +0 -1
- package/dist/spending-limit.js +0 -88
- package/dist/spending-limit.js.map +0 -1
- package/dist/step-files.js +0 -200
- package/dist/step-files.js.map +0 -1
- package/dist/step-meter.js +0 -97
- package/dist/step-meter.js.map +0 -1
- package/dist/step-usage.js +0 -19
- package/dist/step-usage.js.map +0 -1
- package/dist/steps.js +0 -920
- package/dist/steps.js.map +0 -1
- package/dist/storage/budgets.js +0 -85
- package/dist/storage/budgets.js.map +0 -1
- package/dist/storage/engine-records.js +0 -75
- package/dist/storage/engine-records.js.map +0 -1
- package/dist/storage/engine-storage.js +0 -67
- package/dist/storage/engine-storage.js.map +0 -1
- package/dist/storage/input-records.js +0 -12
- package/dist/storage/input-records.js.map +0 -1
- package/dist/storage/move-store.js +0 -251
- package/dist/storage/move-store.js.map +0 -1
- package/dist/storage/sqlite-store.js +0 -723
- package/dist/storage/sqlite-store.js.map +0 -1
- package/dist/storage/step-records.js +0 -11
- package/dist/storage/step-records.js.map +0 -1
- package/dist/storage/storage-error.js +0 -19
- package/dist/storage/storage-error.js.map +0 -1
- package/dist/storage/task-store.js +0 -24
- package/dist/storage/task-store.js.map +0 -1
- package/dist/tasks.js +0 -475
- package/dist/tasks.js.map +0 -1
- package/dist/views/format.js +0 -37
- package/dist/views/format.js.map +0 -1
- package/dist/views/runs-now.js +0 -75
- package/dist/views/runs-now.js.map +0 -1
- package/dist/views/step-funnel.js +0 -98
- package/dist/views/step-funnel.js.map +0 -1
- package/dist/views/step-graph.js +0 -34
- package/dist/views/step-graph.js.map +0 -1
- package/dist/views/workflow-flows.js +0 -53
- package/dist/views/workflow-flows.js.map +0 -1
- package/dist/views/workflows-view.js +0 -230
- package/dist/views/workflows-view.js.map +0 -1
- package/src/budget-states.ts +0 -55
- package/src/cpu-limit/limiter.ts +0 -935
- package/src/cpu-limit/use.ts +0 -166
- package/src/dashboard/agent-usage-line.tsx +0 -28
- package/src/dashboard/agent-usage.ts +0 -48
- package/src/dashboard/dashboard.css +0 -134
- package/src/dashboard/drilldown.ts +0 -43
- package/src/dashboard/index.tsx +0 -4
- package/src/dashboard/machine-controls.tsx +0 -53
- package/src/dashboard/queue-bar.tsx +0 -43
- package/src/dashboard/queue-chart.tsx +0 -150
- package/src/dashboard/queue-lines.ts +0 -87
- package/src/dashboard/queue-table.ts +0 -37
- package/src/dashboard/spending-limit-control.tsx +0 -50
- package/src/dashboard/spending-words.ts +0 -50
- package/src/dashboard/step-graph.tsx +0 -106
- package/src/dashboard/workflow-dag.tsx +0 -204
- package/src/dashboard/workflow-drilldown.tsx +0 -89
- package/src/dashboard/workflows-dashboard.tsx +0 -414
- package/src/failure.ts +0 -36
- package/src/keep-running.ts +0 -83
- package/src/outside-failure.ts +0 -39
- package/src/pick-wakes.ts +0 -182
- package/src/project.ts +0 -115
- package/src/queue-counts.ts +0 -64
- package/src/reasons.ts +0 -30
- package/src/spending-limit.ts +0 -156
- package/src/step-files.ts +0 -208
- package/src/step-meter.ts +0 -120
- package/src/step-usage.ts +0 -23
- package/src/steps.ts +0 -1239
- package/src/storage/budgets.ts +0 -113
- package/src/storage/engine-records.ts +0 -102
- package/src/storage/engine-storage.ts +0 -82
- package/src/storage/input-records.ts +0 -43
- package/src/storage/move-store.ts +0 -265
- package/src/storage/sqlite-store.ts +0 -829
- package/src/storage/step-records.ts +0 -306
- package/src/storage/storage-error.ts +0 -35
- package/src/storage/task-store.ts +0 -235
- package/src/tasks.ts +0 -561
- package/src/views/format.ts +0 -40
- package/src/views/runs-now.ts +0 -120
- package/src/views/step-funnel.ts +0 -163
- package/src/views/step-graph.ts +0 -68
- package/src/views/workflow-flows.ts +0 -97
- package/src/views/workflows-view.ts +0 -443
package/src/views/runs-now.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE RUNS GOING NOW, by phase, workflow and step: each unfinished run counted once, on the step its newest record names.
|
|
3
|
-
* Pure, so it is tested alone; its inputs are the engine's unfinished runs (`EngineRecords.unfinishedRuns`) and their newest
|
|
4
|
-
* step records (`StepRecords.newestStepRecords`).
|
|
5
|
-
*
|
|
6
|
-
* Alex, 2026-11-06: "showing current run counts for each phase and workflow and step, and then this implies a certain
|
|
7
|
-
* number of agents running based on how many of the running steps involve agentic work". So a run is on an agent only
|
|
8
|
-
* while the step it is in is an agent step and that step's record is still open; between steps it waits after the step
|
|
9
|
-
* it last ended, and uses no agent.
|
|
10
|
-
*/
|
|
11
|
-
import { isSpendingLimitWait } from '../spending-limit';
|
|
12
|
-
import type { UnfinishedRun } from '../storage/engine-records';
|
|
13
|
-
import type { NewestStepRecord } from '../storage/step-records';
|
|
14
|
-
import type { StepDeclaration } from '../steps';
|
|
15
|
-
|
|
16
|
-
export interface StepRunsNow {
|
|
17
|
-
readonly step: string;
|
|
18
|
-
readonly agent: boolean;
|
|
19
|
-
/** Runs whose newest record is this step, still open. */
|
|
20
|
-
readonly inStep: number;
|
|
21
|
-
/** Runs whose newest record is this step, ended, with no next step started. */
|
|
22
|
-
readonly waitingAfter: number;
|
|
23
|
-
/** When the longest of those ended this step, unix seconds; none with none waiting. */
|
|
24
|
-
readonly waitingSince: number | null;
|
|
25
|
-
/** What a run in it waits on, in the step's own words (a Pick with nothing it can claim); none while each works. */
|
|
26
|
-
readonly waitingOn: string | null;
|
|
27
|
-
/** Runs in it that the spending limit holds before their agent call (`spending-limit.ts`). */
|
|
28
|
-
readonly heldBySpendingLimit: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface WorkflowRunsNow {
|
|
32
|
-
readonly workflow: string;
|
|
33
|
-
/** Every unfinished run: its steps' `inStep` and `waitingAfter`, and `notStarted`. */
|
|
34
|
-
readonly runs: number;
|
|
35
|
-
/** Runs an agent is working for now: those in an agent step that wait on nothing (a run waiting there for a free agent is on none). */
|
|
36
|
-
readonly onAgents: number;
|
|
37
|
-
/** Runs with no step record yet. */
|
|
38
|
-
readonly notStarted: number;
|
|
39
|
-
/** Its declared steps in order, then any step its records name that it no longer declares. */
|
|
40
|
-
readonly steps: ReadonlyArray<StepRunsNow>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface PhaseRunsNow<Phase extends string = string> {
|
|
44
|
-
readonly phase: Phase;
|
|
45
|
-
readonly runs: number;
|
|
46
|
-
readonly onAgents: number;
|
|
47
|
-
readonly workflows: ReadonlyArray<WorkflowRunsNow>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type Declared<Phase extends string> = { readonly name: string; readonly phase: Phase; readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs' | 'workflow'>> };
|
|
51
|
-
|
|
52
|
-
const sum = <T>(xs: ReadonlyArray<T>, f: (x: T) => number) => xs.reduce((a, x) => a + f(x), 0);
|
|
53
|
-
|
|
54
|
-
const workflowRunsNow = <Phase extends string>(d: Declared<Phase>, runs: ReadonlyArray<string>, newest: ReadonlyMap<string, NewestStepRecord>): WorkflowRunsNow => {
|
|
55
|
-
const records = runs.flatMap((run) => {
|
|
56
|
-
const r = newest.get(run);
|
|
57
|
-
return r === undefined ? [] : [r];
|
|
58
|
-
});
|
|
59
|
-
/**
|
|
60
|
-
* Whether a run is on an agent now: its open step is an agent's and waits on none, or it is a sub-workflow step whose own
|
|
61
|
-
* run is. A run inside a sub-workflow's agent step read as on no agent, on the page of the workflow above (2026-11-19).
|
|
62
|
-
*/
|
|
63
|
-
const onAnAgent = (r: NewestStepRecord, depth = 0): boolean => {
|
|
64
|
-
if (r.ended !== null) return false;
|
|
65
|
-
if (r.agent === 1) return r.waiting === null;
|
|
66
|
-
const under = r.childRun === undefined || r.childRun === null || depth > 8 ? undefined : newest.get(r.childRun);
|
|
67
|
-
return under !== undefined && onAnAgent(under, depth + 1);
|
|
68
|
-
};
|
|
69
|
-
const declared = d.steps().map((s) => ({ name: s.name, agent: s.runs === 'agentic' }));
|
|
70
|
-
const undeclared = [...new Set(records.map((r) => r.step))].filter((name) => !declared.some((s) => s.name === name))
|
|
71
|
-
.map((name) => ({ name, agent: records.some((r) => r.step === name && r.agent === 1) }));
|
|
72
|
-
const steps = [...declared, ...undeclared].map((s): StepRunsNow => {
|
|
73
|
-
const on = records.filter((r) => r.step === s.name);
|
|
74
|
-
const waiting = on.flatMap((r) => (r.ended === null ? [] : [r.ended]));
|
|
75
|
-
return {
|
|
76
|
-
step: s.name, agent: s.agent,
|
|
77
|
-
inStep: on.length - waiting.length,
|
|
78
|
-
waitingAfter: waiting.length,
|
|
79
|
-
waitingSince: waiting.length === 0 ? null : Math.min(...waiting),
|
|
80
|
-
waitingOn: on.find((r) => r.ended === null && r.waiting !== null)?.waiting ?? null,
|
|
81
|
-
heldBySpendingLimit: on.filter((r) => r.ended === null && r.waiting !== null && isSpendingLimitWait(r.waiting)).length,
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
return {
|
|
85
|
-
workflow: d.name,
|
|
86
|
-
runs: runs.length,
|
|
87
|
-
// A run waiting at an agent step for a free agent (its record says what it waits on) is on no agent.
|
|
88
|
-
onAgents: records.filter((r) => onAnAgent(r)).length,
|
|
89
|
-
notStarted: runs.length - records.length,
|
|
90
|
-
steps,
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Every phase in the project's order, each with every workflow that declares it, running or not. A run of a workflow no file
|
|
96
|
-
* defines now still counts, under `undefinedPhase`.
|
|
97
|
-
*/
|
|
98
|
-
export const runsNow = <Phase extends string>(input: {
|
|
99
|
-
readonly phases: ReadonlyArray<Phase>;
|
|
100
|
-
readonly undefinedPhase: Phase;
|
|
101
|
-
readonly declared: ReadonlyArray<Declared<Phase>>;
|
|
102
|
-
readonly unfinished: ReadonlyArray<UnfinishedRun>;
|
|
103
|
-
readonly newest: ReadonlyArray<NewestStepRecord>;
|
|
104
|
-
}): ReadonlyArray<PhaseRunsNow<Phase>> => {
|
|
105
|
-
const newest = new Map(input.newest.map((r) => [r.run, r]));
|
|
106
|
-
const names = new Set(input.declared.map((d) => d.name));
|
|
107
|
-
const asAStep = new Set(input.declared.flatMap((d) => d.steps().flatMap((s) => (s.workflow === undefined ? [] : [s.workflow]))));
|
|
108
|
-
const all: ReadonlyArray<Declared<Phase>> = [
|
|
109
|
-
...input.declared,
|
|
110
|
-
...[...new Set(input.unfinished.map((u) => u.workflow))].filter((w) => !names.has(w)).map((name): Declared<Phase> => ({ name, phase: input.undefinedPhase, steps: () => [] })),
|
|
111
|
-
];
|
|
112
|
-
return input.phases.map((phase): PhaseRunsNow<Phase> => {
|
|
113
|
-
const workflows = all.filter((d) => d.phase === phase)
|
|
114
|
-
.map((d) => workflowRunsNow(d, input.unfinished.filter((u) => u.workflow === d.name).map((u) => u.run), newest));
|
|
115
|
-
// A phase's runs and agents are those of its workflows that start by themselves: a sub-workflow's run is part of the run
|
|
116
|
-
// above it, which already counts once.
|
|
117
|
-
const own = workflows.filter((w) => !asAStep.has(w.workflow));
|
|
118
|
-
return { phase, runs: sum(own, (w) => w.runs), onAgents: sum(own, (w) => w.onAgents), workflows };
|
|
119
|
-
});
|
|
120
|
-
};
|
package/src/views/step-funnel.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WHERE A WORKFLOW'S RUNS STOP: for each step in declared order, the runs of a window that reached it, the runs that
|
|
3
|
-
* ended there without finishing, the runs that ended there finished, and the typical (median) time a run spent in it.
|
|
4
|
-
* Under the step most runs stopped at, why they stopped. Pure, so it is tested alone; its inputs are the step records
|
|
5
|
-
* and item outcomes of the window's runs (`StepRecords.funnelRecordsSince`) and the engine's unfinished runs.
|
|
6
|
-
*
|
|
7
|
-
* Alex, 2026-11-06: "per workflow to have a distribution on which step is reached in a workflow before getting stuck. Or
|
|
8
|
-
* perhaps time spent on each step? … we want visibility into where current work isn't able to get past".
|
|
9
|
-
*
|
|
10
|
-
* A run is in the window when its first step started in it, and only its records started by `now` count. It reached a step when it has a record of that step. It
|
|
11
|
-
* ended at the step of its newest record, once the engine has finished it. It finished when one of its items' recorded
|
|
12
|
-
* outcomes says finished; a workflow with no item finishes a run whose last step succeeded. Every other ended run
|
|
13
|
-
* stopped, for the first of: its last step's error, its item's outcome, its Pick finding nothing, an interruption.
|
|
14
|
-
*/
|
|
15
|
-
import type { RunOutcomeRow, FunnelStepRecord } from '../storage/step-records';
|
|
16
|
-
import type { StepDeclaration } from '../steps';
|
|
17
|
-
import { oneLine } from '../reasons';
|
|
18
|
-
|
|
19
|
-
export interface FunnelStep {
|
|
20
|
-
readonly step: string;
|
|
21
|
-
readonly agent: boolean;
|
|
22
|
-
/** Runs with a record of this step. */
|
|
23
|
-
readonly reached: number;
|
|
24
|
-
/** Ended runs whose last step was this one, not finished. */
|
|
25
|
-
readonly stopped: number;
|
|
26
|
-
/** Ended runs whose last step was this one, finished. */
|
|
27
|
-
readonly finished: number;
|
|
28
|
-
/** The median, over runs with an ended record of it, of a run's time in it; none with none. */
|
|
29
|
-
readonly medianSeconds: number | null;
|
|
30
|
-
/** Whether every run that reached it stopped here and none reached the step declared after it. */
|
|
31
|
-
readonly noneGotPast: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface StopReason {
|
|
35
|
-
readonly reason: string;
|
|
36
|
-
readonly runs: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface StepFunnel {
|
|
40
|
-
readonly hours: number;
|
|
41
|
-
/** Runs whose first step started at or after this, unix seconds, up to `now`. */
|
|
42
|
-
readonly since: number;
|
|
43
|
-
readonly now: number;
|
|
44
|
-
readonly runs: number;
|
|
45
|
-
/** Of those, not finished by the engine now. */
|
|
46
|
-
readonly going: number;
|
|
47
|
-
/** Its declared steps in order, then any step its records name that it no longer declares. */
|
|
48
|
-
readonly steps: ReadonlyArray<FunnelStep>;
|
|
49
|
-
/** The step most runs stopped at, earliest on a tie, with its commonest reasons; none when no run stopped. */
|
|
50
|
-
readonly mostStopped: { readonly step: string; readonly stopped: number; readonly reasons: ReadonlyArray<StopReason>; readonly otherRuns: number } | null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface WorkflowFunnels {
|
|
54
|
-
readonly workflow: string;
|
|
55
|
-
/** One per window, shortest first. */
|
|
56
|
-
readonly windows: ReadonlyArray<StepFunnel>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** The windows the page offers: the last hour, and the last day. */
|
|
60
|
-
export const FUNNEL_WINDOW_HOURS = [1, 24] as const;
|
|
61
|
-
|
|
62
|
-
/** Reasons listed under the step most runs stopped at; the rest are counted together. */
|
|
63
|
-
export const TOP_STOP_REASONS = 3;
|
|
64
|
-
|
|
65
|
-
type Declared = { readonly item: string | null } & { readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs'>> };
|
|
66
|
-
|
|
67
|
-
/** The commonest of a run's item outcomes, so a batch run gives one reason. */
|
|
68
|
-
const commonest = (xs: ReadonlyArray<string>): string => {
|
|
69
|
-
const counts = new Map<string, number>();
|
|
70
|
-
for (const x of xs) counts.set(x, (counts.get(x) ?? 0) + 1);
|
|
71
|
-
return [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]![0];
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/** Why a run stopped where it did: its item's outcome first, then the reason its last step recorded (`reasons.ts`). */
|
|
75
|
-
const stopReason = (last: FunnelStepRecord, outcomes: ReadonlyArray<RunOutcomeRow>): string => {
|
|
76
|
-
if (last.outcome === 'failure') return last.error === null ? last.reason ?? 'its step failed with no error recorded' : oneLine(last.error);
|
|
77
|
-
if (outcomes.length > 0) return oneLine(commonest(outcomes.map((o) => o.outcome)));
|
|
78
|
-
if (last.reason !== null && last.reason !== 'succeeded') return last.reason;
|
|
79
|
-
if (last.scope === 'nothing') return 'found nothing to work on';
|
|
80
|
-
if (last.outcome === 'interrupted') return 'interrupted';
|
|
81
|
-
if (last.ended === null) return 'ended during the step, with no end recorded';
|
|
82
|
-
return 'ended with no outcome recorded';
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/** Rows by their run, each run's in the order given. */
|
|
86
|
-
const groupBy = <T extends { readonly run: string }>(rows: ReadonlyArray<T>): Map<string, T[]> => {
|
|
87
|
-
const out = new Map<string, T[]>();
|
|
88
|
-
for (const r of rows) {
|
|
89
|
-
const list = out.get(r.run);
|
|
90
|
-
if (list === undefined) out.set(r.run, [r]);
|
|
91
|
-
else list.push(r);
|
|
92
|
-
}
|
|
93
|
-
return out;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const median = (xs: ReadonlyArray<number>): number | null => {
|
|
97
|
-
if (xs.length === 0) return null;
|
|
98
|
-
const sorted = [...xs].sort((a, b) => a - b);
|
|
99
|
-
const mid = Math.floor(sorted.length / 2);
|
|
100
|
-
return sorted.length % 2 === 1 ? sorted[mid]! : (sorted[mid - 1]! + sorted[mid]!) / 2;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/** One workflow's funnel over the `hours` before `now`, from its records in that window or a wider one. */
|
|
104
|
-
export const stepFunnel = (input: {
|
|
105
|
-
readonly declaration: Declared;
|
|
106
|
-
/** This workflow's records, oldest first; runs that began before `since` are left out here. */
|
|
107
|
-
readonly records: ReadonlyArray<FunnelStepRecord>;
|
|
108
|
-
readonly outcomes: ReadonlyArray<RunOutcomeRow>;
|
|
109
|
-
readonly unfinished: ReadonlySet<string>;
|
|
110
|
-
readonly hours: number;
|
|
111
|
-
readonly since: number;
|
|
112
|
-
readonly now: number;
|
|
113
|
-
}): StepFunnel => {
|
|
114
|
-
// Records are read after `now` was fixed: what started later is outside the window the page states.
|
|
115
|
-
const byRun = groupBy(input.records.filter((r) => r.started <= input.now));
|
|
116
|
-
const runs = [...byRun.entries()].filter(([, rs]) => Math.min(...rs.map((r) => r.started)) >= input.since);
|
|
117
|
-
const outcomesOf = groupBy(input.outcomes);
|
|
118
|
-
|
|
119
|
-
const ends = runs.filter(([run]) => !input.unfinished.has(run)).map(([run, rs]) => {
|
|
120
|
-
const last = rs[rs.length - 1]!;
|
|
121
|
-
const theirs = outcomesOf.get(run) ?? [];
|
|
122
|
-
const finished = input.declaration.item === null ? last.outcome === 'success' : theirs.some((o) => o.finished === 1);
|
|
123
|
-
return { step: last.step, finished, reason: finished ? null : stopReason(last, theirs) };
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const declared = input.declaration.steps().map((s) => ({ name: s.name, agent: s.runs === 'agentic' }));
|
|
127
|
-
const undeclared = [...new Set(runs.flatMap(([, rs]) => rs.map((r) => r.step)))].filter((name) => !declared.some((s) => s.name === name))
|
|
128
|
-
.map((name) => ({ name, agent: runs.some(([, rs]) => rs.some((r) => r.step === name && r.agent === 1)) }));
|
|
129
|
-
const counted = [...declared, ...undeclared].map((s) => {
|
|
130
|
-
const timed = runs.flatMap(([, rs]) => {
|
|
131
|
-
const ended = rs.filter((r) => r.step === s.name && r.ended !== null);
|
|
132
|
-
return ended.length === 0 ? [] : [ended.reduce((a, r) => a + (r.ended! - r.started), 0)];
|
|
133
|
-
});
|
|
134
|
-
return {
|
|
135
|
-
step: s.name, agent: s.agent,
|
|
136
|
-
reached: runs.filter(([, rs]) => rs.some((r) => r.step === s.name)).length,
|
|
137
|
-
stopped: ends.filter((e) => e.step === s.name && !e.finished).length,
|
|
138
|
-
finished: ends.filter((e) => e.step === s.name && e.finished).length,
|
|
139
|
-
medianSeconds: median(timed),
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
const steps = counted.map((s, i): FunnelStep => ({
|
|
143
|
-
...s,
|
|
144
|
-
noneGotPast: i < declared.length - 1 && s.reached > 0 && s.stopped === s.reached && counted[i + 1]!.reached === 0,
|
|
145
|
-
}));
|
|
146
|
-
|
|
147
|
-
const most = steps.reduce<FunnelStep | null>((best, s) => (s.stopped > 0 && (best === null || s.stopped > best.stopped) ? s : best), null);
|
|
148
|
-
const mostStopped = most === null ? null : (() => {
|
|
149
|
-
const counts = new Map<string, number>();
|
|
150
|
-
for (const e of ends) if (e.step === most.step && e.reason !== null) counts.set(e.reason, (counts.get(e.reason) ?? 0) + 1);
|
|
151
|
-
const reasons = [...counts.entries()].map(([reason, n]) => ({ reason, runs: n })).sort((a, b) => b.runs - a.runs || a.reason.localeCompare(b.reason));
|
|
152
|
-
const top = reasons.slice(0, TOP_STOP_REASONS);
|
|
153
|
-
return { step: most.step, stopped: most.stopped, reasons: top, otherRuns: most.stopped - top.reduce((a, r) => a + r.runs, 0) };
|
|
154
|
-
})();
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
hours: input.hours, since: input.since, now: input.now,
|
|
158
|
-
runs: runs.length,
|
|
159
|
-
going: runs.filter(([run]) => input.unfinished.has(run)).length,
|
|
160
|
-
steps,
|
|
161
|
-
mostStopped,
|
|
162
|
-
};
|
|
163
|
-
};
|
package/src/views/step-graph.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EACH WORKFLOW'S STEP GRAPH WITH THE WINDOW'S RUNS ON IT. The graph is the workflow's own declaration (`StepEdge` in
|
|
3
|
-
* `steps.ts`); the runs are its step records' moves (`StepRecords.stepEdgesSince`). A move the graph does not
|
|
4
|
-
* declare is listed as undeclared, never added to it. Pure, so it is tested alone.
|
|
5
|
-
*/
|
|
6
|
-
import type { LastStepNow, StepEdgeTaken } from '../storage/step-records';
|
|
7
|
-
import { A_STEP_FAILS, isRetry, RUN_ENDS, RUN_STARTS, type StepEdge } from '../graph';
|
|
8
|
-
import type { StepDeclaration, StepRuns } from '../steps';
|
|
9
|
-
|
|
10
|
-
/** A step-to-step edge of a workflow's graph, and how many runs took it in the window. */
|
|
11
|
-
export interface GraphEdge {
|
|
12
|
-
readonly from: string;
|
|
13
|
-
readonly to: string;
|
|
14
|
-
readonly when: string;
|
|
15
|
-
readonly runs: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** A workflow's declared graph with the window's runs on it, and the moves it does not declare. */
|
|
19
|
-
export interface WorkflowGraph {
|
|
20
|
-
readonly workflow: string;
|
|
21
|
-
/** False until the workflow declares its graph: then `edges` is empty and a page says so. */
|
|
22
|
-
readonly declared: boolean;
|
|
23
|
-
readonly steps: ReadonlyArray<{ readonly name: string; readonly runs: StepRuns | null; readonly description: string; readonly workflow: string | null }>;
|
|
24
|
-
readonly edges: ReadonlyArray<GraphEdge>;
|
|
25
|
-
readonly undeclared: ReadonlyArray<{ readonly from: string; readonly to: string; readonly runs: number }>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** What of a declaration the graph reads. */
|
|
29
|
-
interface Declared {
|
|
30
|
-
readonly name: string;
|
|
31
|
-
readonly steps: () => ReadonlyArray<Pick<StepDeclaration, 'name' | 'runs' | 'description' | 'workflow'>>;
|
|
32
|
-
readonly graph?: (() => ReadonlyArray<StepEdge>) | undefined;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const workflowGraphs = (input: {
|
|
36
|
-
readonly declared: ReadonlyArray<Declared>;
|
|
37
|
-
readonly taken: ReadonlyArray<StepEdgeTaken>;
|
|
38
|
-
readonly lasts: ReadonlyArray<LastStepNow>;
|
|
39
|
-
/** Runs not ended: their last step has no edge to the end yet. */
|
|
40
|
-
readonly going: ReadonlySet<string>;
|
|
41
|
-
}): ReadonlyArray<WorkflowGraph> =>
|
|
42
|
-
input.declared.map((d) => {
|
|
43
|
-
const graph = d.graph?.() ?? [];
|
|
44
|
-
const runs = new Map(graph.map((e) => [`${e.from}\u0000${e.to}`, 0]));
|
|
45
|
-
const undeclared = new Map<string, { from: string; to: string; runs: number }>();
|
|
46
|
-
const count = (from: string, failed: boolean, to: string, n: number) => {
|
|
47
|
-
if (isRetry({ step: from, failed }, to)) return;
|
|
48
|
-
const exact = `${from}\u0000${to}`;
|
|
49
|
-
const onFailure = `${A_STEP_FAILS}\u0000${to}`;
|
|
50
|
-
const key = runs.has(exact) ? exact : failed && runs.has(onFailure) ? onFailure : null;
|
|
51
|
-
if (key !== null) {
|
|
52
|
-
runs.set(key, (runs.get(key) ?? 0) + n);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const shown = { from: failed ? `${from} (failed)` : from, to };
|
|
56
|
-
const k = `${shown.from}\u0000${to}`;
|
|
57
|
-
undeclared.set(k, { ...shown, runs: (undeclared.get(k)?.runs ?? 0) + n });
|
|
58
|
-
};
|
|
59
|
-
for (const e of input.taken) if (e.workflow === d.name) count(e.from ?? RUN_STARTS, e.fromFailed, e.to, e.runs);
|
|
60
|
-
for (const l of input.lasts) if (l.workflow === d.name && !input.going.has(l.run)) count(l.step, l.failed, RUN_ENDS, 1);
|
|
61
|
-
return {
|
|
62
|
-
workflow: d.name,
|
|
63
|
-
declared: d.graph !== undefined,
|
|
64
|
-
steps: d.steps().map((s) => ({ name: s.name, runs: s.runs, description: s.description, workflow: s.workflow ?? null })),
|
|
65
|
-
edges: graph.map((e) => ({ ...e, runs: runs.get(`${e.from}\u0000${e.to}`) ?? 0 })),
|
|
66
|
-
undeclared: [...undeclared.values()].sort((a, b) => b.runs - a.runs),
|
|
67
|
-
};
|
|
68
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WHERE WORK FLOWS BETWEEN WORKFLOWS: the edges of a project's DAG of workflows, and each workflow's place in its pipeline.
|
|
3
|
-
* Built from what the platform knows and nothing written for the page:
|
|
4
|
-
*
|
|
5
|
-
* feeds a workflow declares the other among those whose results it works on (`fedBy`);
|
|
6
|
-
* sends back a step of a workflow returned a task of one upstream of it, through feeds, to that one's queue (`requeue`);
|
|
7
|
-
* gives input it returned to its queue a task of one that is not upstream of it, with no feed declared between them;
|
|
8
|
-
* waits on its list puts tasks on a wait that names another workflow (`PendingWork.waits`), not the one that feeds it:
|
|
9
|
-
* the list's own words say why (`why`).
|
|
10
|
-
*
|
|
11
|
-
* Its place: its stage (the project's phases, in order), then how many feeds lead into it within its stage. Pure.
|
|
12
|
-
*/
|
|
13
|
-
import type { ListedWait, ReturnedBetween } from '../storage/task-store';
|
|
14
|
-
|
|
15
|
-
export type FlowKind = 'feeds' | 'sends back' | 'gives input' | 'waits on';
|
|
16
|
-
|
|
17
|
-
/** One edge: work going from one workflow to another. */
|
|
18
|
-
export interface WorkflowFlow {
|
|
19
|
-
readonly from: string;
|
|
20
|
-
readonly to: string;
|
|
21
|
-
readonly kind: FlowKind;
|
|
22
|
-
/** Whether a declaration says it (`fedBy`); a recorded one only is not declared. */
|
|
23
|
-
readonly declared: boolean;
|
|
24
|
-
/** The returns to the queue recorded along it, and the last one's time; 0 and none where none was recorded. */
|
|
25
|
-
readonly notes: number;
|
|
26
|
-
readonly last: number | null;
|
|
27
|
-
/** Along a `waits on` edge: the tasks waiting, and the list's words for the wait; 0 and none on any other. */
|
|
28
|
-
readonly waiting: number;
|
|
29
|
-
readonly why: string | null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** A workflow's place in its pipeline: its stage's index, then its depth within the stage through feeds. */
|
|
33
|
-
export interface PipelinePlace {
|
|
34
|
-
readonly workflow: string;
|
|
35
|
-
readonly stage: number;
|
|
36
|
-
readonly depth: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Whether `to` reaches `from` through `feeds`: work goes from `to`, by way of others, to `from`. */
|
|
40
|
-
const reaches = (feeds: ReadonlyArray<{ readonly from: string; readonly to: string }>, start: string, target: string): boolean => {
|
|
41
|
-
const seen = new Set<string>([start]);
|
|
42
|
-
const next = [start];
|
|
43
|
-
while (next.length > 0) {
|
|
44
|
-
const at = next.pop()!;
|
|
45
|
-
for (const f of feeds) {
|
|
46
|
-
if (f.from !== at || seen.has(f.to)) continue;
|
|
47
|
-
if (f.to === target) return true;
|
|
48
|
-
seen.add(f.to);
|
|
49
|
-
next.push(f.to);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const workflowFlows = (input: {
|
|
56
|
-
readonly declared: ReadonlyArray<{ readonly name: string; readonly fedBy?: ReadonlyArray<string> }>;
|
|
57
|
-
readonly returned: ReadonlyArray<ReturnedBetween>;
|
|
58
|
-
readonly waits: ReadonlyArray<ListedWait>;
|
|
59
|
-
}): ReadonlyArray<WorkflowFlow> => {
|
|
60
|
-
const names = new Set(input.declared.map((d) => d.name));
|
|
61
|
-
const recorded = (from: string, to: string) => input.returned.find((n) => n.from === from && n.to === to);
|
|
62
|
-
const feeds = input.declared.flatMap((d) => (d.fedBy ?? []).filter((f) => names.has(f) && f !== d.name).map((f) => ({ from: f, to: d.name })));
|
|
63
|
-
const declaredFlows: ReadonlyArray<WorkflowFlow> = feeds.map((f) => {
|
|
64
|
-
const r = recorded(f.from, f.to);
|
|
65
|
-
return { from: f.from, to: f.to, kind: 'feeds', declared: true, notes: r?.notes ?? 0, last: r?.last ?? null, waiting: 0, why: null };
|
|
66
|
-
});
|
|
67
|
-
const recordedOnly: ReadonlyArray<WorkflowFlow> = input.returned
|
|
68
|
-
.filter((n) => names.has(n.from) && names.has(n.to) && !feeds.some((f) => f.from === n.from && f.to === n.to))
|
|
69
|
-
.map((n) => ({ from: n.from, to: n.to, kind: reaches(feeds, n.to, n.from) ? 'sends back' : 'gives input', declared: false, notes: n.notes, last: n.last, waiting: 0, why: null }));
|
|
70
|
-
// A wait on the workflow that feeds it is that feed's work still to come, drawn as the feed; one on another is an edge.
|
|
71
|
-
const waitedOn: ReadonlyArray<WorkflowFlow> = input.waits
|
|
72
|
-
.filter((w) => names.has(w.on) && w.on !== w.workflow && !feeds.some((f) => f.from === w.on && f.to === w.workflow))
|
|
73
|
-
.map((w) => ({ from: w.workflow, to: w.on, kind: 'waits on', declared: false, notes: 0, last: null, waiting: w.tasks, why: w.label }));
|
|
74
|
-
return [...declaredFlows, ...recordedOnly, ...waitedOn];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/** Each workflow's place: its stage by `stageOf` in `stages`' order (one not among them after them), then its depth there. */
|
|
78
|
-
export const pipelinePlaces = (input: {
|
|
79
|
-
readonly workflows: ReadonlyArray<{ readonly name: string; readonly stage: string }>;
|
|
80
|
-
readonly stages: ReadonlyArray<string>;
|
|
81
|
-
readonly flows: ReadonlyArray<WorkflowFlow>;
|
|
82
|
-
}): ReadonlyArray<PipelinePlace> => {
|
|
83
|
-
const stageIndex = (s: string) => (input.stages.includes(s) ? input.stages.indexOf(s) : input.stages.length);
|
|
84
|
-
const stageOf = new Map(input.workflows.map((w) => [w.name, stageIndex(w.stage)]));
|
|
85
|
-
// Forward work only: feeds, and input given to one not upstream. A send-back points against the pipeline.
|
|
86
|
-
const forward = input.flows.filter((f) => f.kind !== 'sends back');
|
|
87
|
-
const depth = new Map<string, number>();
|
|
88
|
-
const depthOf = (name: string, path: ReadonlySet<string>): number => {
|
|
89
|
-
const known = depth.get(name);
|
|
90
|
-
if (known !== undefined) return known;
|
|
91
|
-
const into = forward.filter((f) => f.to === name && !path.has(f.from) && stageOf.get(f.from) === stageOf.get(name));
|
|
92
|
-
const d = into.length === 0 ? 0 : Math.max(...into.map((f) => depthOf(f.from, new Set([...path, name])) + 1));
|
|
93
|
-
depth.set(name, d);
|
|
94
|
-
return d;
|
|
95
|
-
};
|
|
96
|
-
return input.workflows.map((w) => ({ workflow: w.name, stage: stageIndex(w.stage), depth: depthOf(w.name, new Set()) }));
|
|
97
|
-
};
|