@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
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* THE GENERIC VIEW OF A PROJECT'S WORKFLOWS, A WORKFLOW AT A TIME (`drilldown.ts`): the page enters at the project's top
|
|
5
|
-
* workflow and opens one sub-workflow step at a time, a breadcrumb saying where it is. A workflow's view shows its tasks as
|
|
6
|
-
* an addition (queued + in progress + blocked + done), its runs and limits, its tasks over time, its own steps with their
|
|
7
|
-
* kinds, and, read from its own records while it is open, why its blocked tasks are blocked, what its steps cost, its step
|
|
8
|
-
* graph and where its runs stopped. At the top it also shows what the project gives of its machine and its agents'
|
|
9
|
-
* account: the CPU limit, the stop of everything, and usage; and on every level the spending limit (`spending-limit-control.tsx`). It reads the platform's two readings
|
|
10
|
-
* (`views/workflows-view.ts`) and runs now (`views/runs-now.ts`). Uses React, which the host page brings.
|
|
11
|
-
*/
|
|
12
|
-
import { Fragment, useEffect, useState, type ReactNode } from 'react';
|
|
13
|
-
import type { PhaseRunsNow, StepRunsNow, WorkflowRunsNow } from '../views/runs-now';
|
|
14
|
-
import type { StepFunnel } from '../views/step-funnel';
|
|
15
|
-
import type { WorkflowGraph } from '../views/step-graph';
|
|
16
|
-
import type { SourceLink, StepCost, StepSummary, WorkflowFigures, WorkflowView, WorkflowsView } from '../views/workflows-view';
|
|
17
|
-
import { compact, duration, localTime, whenAgo } from '../views/format';
|
|
18
|
-
import { drillLevel } from './drilldown';
|
|
19
|
-
import { QueueBar } from './queue-bar';
|
|
20
|
-
import { QueueChart } from './queue-chart';
|
|
21
|
-
import { Breadcrumb, StepList } from './workflow-drilldown';
|
|
22
|
-
import { StepGraph } from './step-graph';
|
|
23
|
-
import { WorkflowDag } from './workflow-dag';
|
|
24
|
-
import { AgentUsageLine } from './agent-usage-line';
|
|
25
|
-
import type { AgentUsage } from './agent-usage';
|
|
26
|
-
import { MachineControls } from './machine-controls';
|
|
27
|
-
import { SpendingLimitControl } from './spending-limit-control';
|
|
28
|
-
import { heldSteps } from './spending-words';
|
|
29
|
-
|
|
30
|
-
/** What the page is given at each poll, all of it read at the request: every workflow, and where runs are now. */
|
|
31
|
-
export interface WorkflowsPageData {
|
|
32
|
-
readonly view: WorkflowsView;
|
|
33
|
-
readonly runsNow: ReadonlyArray<PhaseRunsNow>;
|
|
34
|
-
/**
|
|
35
|
-
* The one CPU limit and the newest reading of what the project used (`CpuLimit`); `threads`, how many the machine has,
|
|
36
|
-
* the most the limit can be set to.
|
|
37
|
-
*/
|
|
38
|
-
readonly cpu: { readonly limit: number; readonly threads?: number; readonly use: { readonly at: number; readonly cores: number; readonly held: number; readonly waiting: number } | null };
|
|
39
|
-
/** When everything was stopped by hand, unix seconds; none, or absent, while the project runs. */
|
|
40
|
-
readonly stopped?: { readonly at: number } | null;
|
|
41
|
-
/** What the agents' account has used of its limits (`agent-usage.ts`); absent where the project reads none. */
|
|
42
|
-
readonly usage?: AgentUsage;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type WorkflowLimits = NonNullable<WorkflowView['limits']>;
|
|
46
|
-
|
|
47
|
-
/** Which of a workflow's two limits a control sets. */
|
|
48
|
-
export type LimitName = 'runs' | 'agents';
|
|
49
|
-
|
|
50
|
-
/** Stores one of a workflow's limits: a whole number, or none for the run limit's default (its agents' limit). The project's own route. */
|
|
51
|
-
export type SetLimit = (r: { readonly workflow: string; readonly limit: LimitName; readonly value: number | null }) => Promise<void>;
|
|
52
|
-
/** What starts a workflow's runs, in words. */
|
|
53
|
-
const startsLine = (w: WorkflowView): string =>
|
|
54
|
-
w.startsOn.kind === 'a step' ? `Runs as a step of ${w.startsOn.of.join(', ')}.`
|
|
55
|
-
: w.startsOn.kind === 'queue' ? 'Runs on its queue.'
|
|
56
|
-
: w.startsOn.kind === 'inputs' ? `Runs when its inputs change: ${w.startsOn.says}.`
|
|
57
|
-
: 'Runs on a timer or a request.';
|
|
58
|
-
|
|
59
|
-
/** Where the project stands against its one CPU limit, in words. */
|
|
60
|
-
const cpuLine = (cpu: WorkflowsPageData['cpu'], now: number): string =>
|
|
61
|
-
cpu.use === null
|
|
62
|
-
? `CPU limit: ${cpu.limit} cores; no reading of what the project uses yet.`
|
|
63
|
-
: `CPU: the project used ${cpu.use.cores.toFixed(1)} of its ${cpu.limit}-core limit at ${whenAgo(cpu.use.at, now)}; ${cpu.use.held} slot${cpu.use.held === 1 ? '' : 's'} held, ${cpu.use.waiting} waiting.`;
|
|
64
|
-
|
|
65
|
-
export interface WorkflowsDashboardProps {
|
|
66
|
-
readonly data: WorkflowsPageData | null;
|
|
67
|
-
/** Why the data could not be read, if it could not; the last data read stays shown. */
|
|
68
|
-
readonly error: string | null;
|
|
69
|
-
/** Where one workflow's figures are read from when it is opened (`WorkflowFigures`): the project's route for them. */
|
|
70
|
-
readonly figuresUrl: (workflow: string) => string;
|
|
71
|
-
/** Where a definition's link goes, where the project has somewhere to show its source; with none, no link shows. */
|
|
72
|
-
readonly sourceHref?: (source: SourceLink) => string;
|
|
73
|
-
/** The project's own lines above everything: its title. */
|
|
74
|
-
readonly header?: ReactNode;
|
|
75
|
-
/** The project's name for one phase, in its own words; the phase's key where it gives none. */
|
|
76
|
-
readonly phaseLabel?: (phase: string) => string;
|
|
77
|
-
/** How the page sets a limit; with none the limits show without controls. */
|
|
78
|
-
readonly setLimit?: SetLimit;
|
|
79
|
-
/** Stores a new CPU limit; with none the limit shows without buttons (`machine-controls.tsx`). */
|
|
80
|
-
readonly setCpuLimit?: (limit: number) => Promise<void>;
|
|
81
|
-
/** Stops everything the project runs, and resumes it; with neither, no button shows. */
|
|
82
|
-
readonly stopEverything?: () => Promise<void>;
|
|
83
|
-
readonly resume?: () => Promise<void>;
|
|
84
|
-
/** Stores a new spending limit, a whole percent of the week; with none the limit shows without buttons (`spending-limit-control.tsx`). */
|
|
85
|
-
readonly setSpendingLimit?: (weekPercent: number) => Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* THE DRILL-DOWN (`drilldown.ts`): the sub-workflow steps opened below the top workflow, top first, and each level's
|
|
88
|
-
* address, which the host page routes back here as `path`.
|
|
89
|
-
*/
|
|
90
|
-
readonly path: ReadonlyArray<string>;
|
|
91
|
-
readonly hrefOf: (path: ReadonlyArray<string>) => string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Polls a JSON route one request at a time, the next asked for when this one has answered. */
|
|
95
|
-
export const usePolledJson = <A,>(url: string, everyMs: number): { readonly data: A | null; readonly error: string | null } => {
|
|
96
|
-
const [data, setData] = useState<A | null>(null);
|
|
97
|
-
const [error, setError] = useState<string | null>(null);
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
let alive = true;
|
|
100
|
-
let next: ReturnType<typeof setTimeout> | undefined;
|
|
101
|
-
const tick = async () => {
|
|
102
|
-
try {
|
|
103
|
-
const r = await fetch(url, { cache: 'no-store' });
|
|
104
|
-
if (!r.ok) throw new Error(`${r.status} ${(await r.text()).slice(0, 200)}`);
|
|
105
|
-
const body = (await r.json()) as A;
|
|
106
|
-
if (alive) { setData(body); setError(null); }
|
|
107
|
-
} catch (e) {
|
|
108
|
-
if (alive) setError(e instanceof Error ? e.message : String(e));
|
|
109
|
-
}
|
|
110
|
-
if (alive) next = setTimeout(() => void tick(), everyMs);
|
|
111
|
-
};
|
|
112
|
-
void tick();
|
|
113
|
-
return () => { alive = false; clearTimeout(next); };
|
|
114
|
-
}, [url, everyMs]);
|
|
115
|
-
return { data, error };
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const costCells = (c: StepCost | null, agentic: boolean): ReactNode => (
|
|
119
|
-
<>
|
|
120
|
-
<td className="wp-r">{c === null ? '' : c.calls.toLocaleString('en-US')}</td>
|
|
121
|
-
<td className={c !== null && c.failed > 0 ? 'wp-r wp-bad' : 'wp-r'}>{c === null || c.failed === 0 ? '' : c.failed.toLocaleString('en-US')}</td>
|
|
122
|
-
<td className="wp-r">{c === null ? '' : duration(c.seconds)}</td>
|
|
123
|
-
<td className="wp-r">{c === null || !agentic ? '' : `${compact(c.inputTokens)} / ${compact(c.outputTokens)}`}</td>
|
|
124
|
-
<td className="wp-r">{c === null ? '' : duration(c.cpuSeconds)}</td>
|
|
125
|
-
<td className="wp-r">{c === null || c.items === 0 ? '' : c.items.toLocaleString('en-US')}</td>
|
|
126
|
-
</>
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
/** Where a step's runs are now, in words: "2 in it", "1 waiting after it since 5:04 AM · 3 min ago". */
|
|
130
|
-
const nowCell = (s: StepRunsNow | undefined, now: number): string => {
|
|
131
|
-
if (s === undefined) return '';
|
|
132
|
-
const parts = [
|
|
133
|
-
...(s.inStep > 0 ? [`${s.inStep} in it`] : []),
|
|
134
|
-
...(s.waitingAfter > 0 ? [`${s.waitingAfter} after it${s.waitingSince === null ? '' : `, since ${whenAgo(s.waitingSince, now)}`}`] : []),
|
|
135
|
-
];
|
|
136
|
-
return parts.join(', ');
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
function StepsTable({ workflow, usesAgents, runs, now }: { readonly workflow: WorkflowFigures; readonly usesAgents: boolean; readonly runs: WorkflowRunsNow | undefined; readonly now: number }) {
|
|
140
|
-
const runsOf = (step: string) => runs?.steps.find((s) => s.step === step);
|
|
141
|
-
return (
|
|
142
|
-
<div className="wp-tablewrap"><table className="wp-table">
|
|
143
|
-
<thead>
|
|
144
|
-
<tr>
|
|
145
|
-
<th>step</th><th title="Deterministic: code only. Agentic: an agent does it. Classification: a separate classifier model decides.">how it runs</th><th>runs now</th>
|
|
146
|
-
<th className="wp-r">calls</th><th className="wp-r">failed</th><th className="wp-r">time</th>
|
|
147
|
-
<th className="wp-r" title="Input tokens, fresh and cached / output tokens">tokens in / out</th>
|
|
148
|
-
<th className="wp-r" title="Its own and its processes' CPU">CPU</th><th className="wp-r">items</th>
|
|
149
|
-
<th title="How its records ended, commonest first; the rest in the hover">ended</th>
|
|
150
|
-
</tr>
|
|
151
|
-
</thead>
|
|
152
|
-
<tbody>
|
|
153
|
-
{workflow.steps.map((s) => {
|
|
154
|
-
const at = runsOf(s.name);
|
|
155
|
-
return (
|
|
156
|
-
<Fragment key={s.name}>
|
|
157
|
-
<tr>
|
|
158
|
-
<td title={s.description} className={s.declared ? '' : 'wp-bad'}>{s.name}{s.declared ? '' : ' (not declared)'}</td>
|
|
159
|
-
<td>{s.runs ?? ''}</td>
|
|
160
|
-
<td className="wp-mut">{nowCell(at, now)}</td>
|
|
161
|
-
{costCells(s.cost, s.runs === 'agentic')}
|
|
162
|
-
<td className="wp-mut" title={s.endings.map((e) => `${e.records} ${e.outcome}: ${e.reason}`).join('\n')}>{s.endings.length === 0 ? '' : `${s.endings[0]!.reason} (${s.endings[0]!.records})`}</td>
|
|
163
|
-
</tr>
|
|
164
|
-
{at?.waitingOn === null || at?.waitingOn === undefined ? null : (
|
|
165
|
-
<tr><td /><td /><td colSpan={8} className="wp-mut">waits: {at.waitingOn}</td></tr>
|
|
166
|
-
)}
|
|
167
|
-
</Fragment>
|
|
168
|
-
);
|
|
169
|
-
})}
|
|
170
|
-
<tr className="wp-total">
|
|
171
|
-
<td>total</td><td /><td className="wp-mut">{runs === undefined || runs.runs === 0 ? '' : `${runs.runs} run${runs.runs === 1 ? '' : 's'}`}</td>
|
|
172
|
-
{costCells(workflow.total, usesAgents)}
|
|
173
|
-
<td />
|
|
174
|
-
</tr>
|
|
175
|
-
</tbody>
|
|
176
|
-
</table></div>
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function FunnelTable({ funnel }: { readonly funnel: StepFunnel }) {
|
|
181
|
-
if (funnel.runs === 0) return <p className="wp-line wp-mut">No run began since {localTime(funnel.since)}.</p>;
|
|
182
|
-
return (
|
|
183
|
-
<>
|
|
184
|
-
<p className="wp-line">
|
|
185
|
-
{funnel.runs.toLocaleString('en-US')} run{funnel.runs === 1 ? '' : 's'} began since {localTime(funnel.since)}, {funnel.going.toLocaleString('en-US')} still going.
|
|
186
|
-
</p>
|
|
187
|
-
<div className="wp-tablewrap"><table className="wp-table">
|
|
188
|
-
<thead><tr><th>step</th><th className="wp-r">reached</th><th className="wp-r">stopped here</th><th className="wp-r">finished here</th><th className="wp-r">median time</th></tr></thead>
|
|
189
|
-
<tbody>
|
|
190
|
-
{funnel.steps.map((s) => (
|
|
191
|
-
<tr key={s.step} className={s.noneGotPast ? 'wp-bad' : ''}>
|
|
192
|
-
<td>{s.step}{s.noneGotPast ? ' (none got past)' : ''}</td>
|
|
193
|
-
<td className="wp-r">{s.reached.toLocaleString('en-US')}</td>
|
|
194
|
-
<td className="wp-r">{s.stopped === 0 ? '' : s.stopped.toLocaleString('en-US')}</td>
|
|
195
|
-
<td className="wp-r">{s.finished === 0 ? '' : s.finished.toLocaleString('en-US')}</td>
|
|
196
|
-
<td className="wp-r">{s.medianSeconds === null ? '' : duration(s.medianSeconds)}</td>
|
|
197
|
-
</tr>
|
|
198
|
-
))}
|
|
199
|
-
</tbody>
|
|
200
|
-
</table></div>
|
|
201
|
-
{funnel.mostStopped === null ? null : (
|
|
202
|
-
<p className="wp-line">
|
|
203
|
-
Most stopped at {funnel.mostStopped.step} ({funnel.mostStopped.stopped.toLocaleString('en-US')}):{' '}
|
|
204
|
-
{funnel.mostStopped.reasons.map((r) => `${r.reason} (${r.runs})`).join('; ')}
|
|
205
|
-
{funnel.mostStopped.otherRuns > 0 ? `; ${funnel.mostStopped.otherRuns} for other reasons` : ''}.
|
|
206
|
-
</p>
|
|
207
|
-
)}
|
|
208
|
-
</>
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** A figure to two places, or "none" where there was nothing to divide by. */
|
|
213
|
-
const per = (n: number | null): string => (n === null ? 'none' : n === 0 ? '0' : n < 0.01 ? n.toPrecision(2) : n.toFixed(n >= 10 ? 0 : 2));
|
|
214
|
-
|
|
215
|
-
/** What its runs finished over the window, per run, per million tokens and per compile, with the window before beside it. */
|
|
216
|
-
const yieldLine = (w: WorkflowFigures, finishedWord: string | null): string => {
|
|
217
|
-
const { now, before } = w.yields;
|
|
218
|
-
const word = finishedWord ?? 'finished';
|
|
219
|
-
const trend = now.finished === before.finished ? 'the same as' : now.finished > before.finished ? 'up from' : 'down from';
|
|
220
|
-
return `${now.finished.toLocaleString('en-US')} ${word} in ${now.runs.toLocaleString('en-US')} runs, ${trend} ${before.finished.toLocaleString('en-US')} in the ${before.runs.toLocaleString('en-US')} before: `
|
|
221
|
-
+ `${per(now.perRun)} a run, ${per(now.perMillionTokens)} per million tokens, ${per(now.perCompile)} a compile (before: ${per(before.perRun)}, ${per(before.perMillionTokens)}, ${per(before.perCompile)}).`;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
/** What a run of it costs: the median run's time, tokens, CPU (its processes' part) and compiles, and its costliest run. */
|
|
225
|
-
const runCostLine = (w: WorkflowFigures): string => {
|
|
226
|
-
const c = w.runCosts;
|
|
227
|
-
if (c.median === null) return 'No run ended in the window.';
|
|
228
|
-
const tokens = c.median.tokens === 0 ? '' : `, ${compact(c.median.tokens)} tokens`;
|
|
229
|
-
const compiles = c.median.compiles === 0 ? '' : `, ${compact(c.median.compiles)} compiles`;
|
|
230
|
-
const costliest = c.costliest === null ? '' : `; costliest ${duration(c.costliest.cpuSeconds)} of CPU, started ${localTime(c.costliest.started)}`;
|
|
231
|
-
return `A run costs ${duration(c.median.seconds)}${tokens}, ${duration(c.median.cpuSeconds)} of CPU (${duration(c.median.childCpuSeconds)} in its processes)${compiles}, the median of ${c.runs.toLocaleString('en-US')} runs${costliest}.`;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
/** What each limit sets, said on its control. */
|
|
235
|
-
const LIMIT_WORDS: Readonly<Record<LimitName, { readonly unit: (n: number) => string; readonly says: string }>> = {
|
|
236
|
-
runs: { unit: (n) => `run${n === 1 ? '' : 's'}`, says: 'Run limit: how many runs of it may go at once, however they start; at 0 none starts. With none set: its agents\' limit where it has one, else no limit.' },
|
|
237
|
-
agents: { unit: (n) => `agent${n === 1 ? '' : 's'}`, says: 'Agents\' limit: how many of its runs may be in an agent step at once. A run at an agent step with none free waits there; at 0 none goes past its first agent step.' },
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* ONE LIMIT AND ITS BUTTONS. A click shows at once, as asked, until the page's next reading says the same; a failed one says
|
|
242
|
-
* why. A run limit set can go back to its default.
|
|
243
|
-
*/
|
|
244
|
-
function LimitControl({ workflow, limit, value, isDefault, setLimit }: { readonly workflow: string; readonly limit: LimitName; readonly value: number | null; readonly isDefault: boolean; readonly setLimit: SetLimit | undefined }) {
|
|
245
|
-
const [asked, setAsked] = useState<{ readonly value: number | null } | null>(null);
|
|
246
|
-
const [failed, setFailed] = useState<string | null>(null);
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
if (asked !== null && (asked.value === null ? isDefault : asked.value === value && !isDefault)) setAsked(null);
|
|
249
|
-
}, [asked, value, isDefault]);
|
|
250
|
-
const words = LIMIT_WORDS[limit];
|
|
251
|
-
const shown = asked === null || asked.value === null ? value : asked.value;
|
|
252
|
-
const set = (next: number | null) => {
|
|
253
|
-
if (setLimit === undefined) return;
|
|
254
|
-
setAsked({ value: next });
|
|
255
|
-
setFailed(null);
|
|
256
|
-
setLimit({ workflow, limit, value: next }).catch((e: unknown) => { setAsked(null); setFailed(e instanceof Error ? e.message : String(e)); });
|
|
257
|
-
};
|
|
258
|
-
return (
|
|
259
|
-
<span className="wp-limit" title={words.says} onClick={(e) => e.preventDefault()}>
|
|
260
|
-
{setLimit === undefined ? null : <button type="button" aria-label={`Lower the ${limit === 'runs' ? 'run limit' : 'agents\' limit'} of ${workflow}`} disabled={shown === 0} onClick={() => set(shown === null ? 0 : shown - 1)}>−</button>}
|
|
261
|
-
<span className={shown === 0 ? 'wp-bad' : 'wp-mut'}>{shown === null ? 'runs: no limit' : `${shown} ${words.unit(shown)}`}{limit === 'runs' && isDefault && shown !== null && asked === null ? ' (default)' : ''}</span>
|
|
262
|
-
{setLimit === undefined ? null : <button type="button" aria-label={`Raise the ${limit === 'runs' ? 'run limit' : 'agents\' limit'} of ${workflow}`} onClick={() => set(shown === null ? 1 : shown + 1)}>+</button>}
|
|
263
|
-
{setLimit === undefined || limit !== 'runs' || isDefault ? null : <button type="button" aria-label={`Put the run limit of ${workflow} back to its default`} onClick={() => set(null)}>default</button>}
|
|
264
|
-
{failed === null ? null : <span className="wp-bad">not saved: {failed}</span>}
|
|
265
|
-
</span>
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/** A workflow's runs and agents now, and its limits with their controls: what its node shows below its queue. */
|
|
270
|
-
function WorkflowStatus({ workflow, runs, limits, setLimit }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined; readonly limits: WorkflowLimits | null; readonly setLimit: SetLimit | undefined }) {
|
|
271
|
-
const going = runs?.runs ?? 0;
|
|
272
|
-
return (
|
|
273
|
-
<>
|
|
274
|
-
<span className={going === 0 ? 'wp-mut' : ''}>{going === 0 ? 'no run going' : `${going} run${going === 1 ? '' : 's'} going`}</span>
|
|
275
|
-
{workflow.usesAgents ? <span className="wp-count" title="Its runs in an agent step now">{runs?.onAgents ?? 0} on agents</span> : null}
|
|
276
|
-
{limits === null ? null : (
|
|
277
|
-
<>
|
|
278
|
-
<LimitControl workflow={workflow.name} limit="runs" value={limits.runs} isDefault={!limits.runsSet} setLimit={setLimit} />
|
|
279
|
-
{limits.agents === null ? null : <LimitControl workflow={workflow.name} limit="agents" value={limits.agents} isDefault={false} setLimit={setLimit} />}
|
|
280
|
-
</>
|
|
281
|
-
)}
|
|
282
|
-
</>
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/** What its Pick does with its tasks marked as needing an agent, in words. */
|
|
287
|
-
const needingAnAgentLine = (passedOverBecause: string | null): string =>
|
|
288
|
-
passedOverBecause === null
|
|
289
|
-
? 'Each ended a run at an agent step when no agent could be had. An agent can be had now, so its Pick takes them in their queue\'s order again.'
|
|
290
|
-
: `Each ended a run at an agent step when no agent could be had. Its Pick passes over them now, because ${passedOverBecause}, and takes them in their queue's order once an agent can be had.`;
|
|
291
|
-
|
|
292
|
-
/** How often an open workflow's figures are read again. */
|
|
293
|
-
const FIGURES_EVERY_MS = 15_000;
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* An open workflow: what it gave and cost, its steps, its step graph and where its runs stopped, read from its own records
|
|
297
|
-
* while it is open. The figures of the workflow opened before it are never shown under this one's name.
|
|
298
|
-
*/
|
|
299
|
-
function WorkflowDetail({ workflow, runs, now, figuresUrl, hrefOfWorkflow }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined; readonly now: number; readonly figuresUrl: (workflow: string) => string; readonly hrefOfWorkflow: (workflow: string) => string }) {
|
|
300
|
-
const read = usePolledJson<WorkflowFigures>(figuresUrl(workflow.name), FIGURES_EVERY_MS);
|
|
301
|
-
const figures = read.data !== null && read.data.workflow === workflow.name ? read.data : null;
|
|
302
|
-
return (
|
|
303
|
-
<>
|
|
304
|
-
<h3 className="wp-h3">{workflow.name}: its steps</h3>
|
|
305
|
-
{figures === null ? <p className={read.error === null ? 'wp-line wp-mut' : 'wp-line wp-bad'}>{read.error === null ? 'Reading its figures…' : `Its figures could not be read: ${read.error}`}</p> : (
|
|
306
|
-
<>
|
|
307
|
-
<p className="wp-line wp-mut">Its figures over the last {figures.hours} h, read {whenAgo(figures.at, now)}.</p>
|
|
308
|
-
{figures.blocked.length === 0 ? null : (
|
|
309
|
-
<>
|
|
310
|
-
<h4 className="wp-h4">Blocked, by reason</h4>
|
|
311
|
-
<table className="wp-reasons">
|
|
312
|
-
<tbody>
|
|
313
|
-
{figures.blocked.map((b) => <tr key={b.why}><td className="wp-r">{b.tasks.toLocaleString("en-US")}</td><td>{b.why}</td></tr>)}
|
|
314
|
-
</tbody>
|
|
315
|
-
</table>
|
|
316
|
-
</>
|
|
317
|
-
)}
|
|
318
|
-
{figures.needingAnAgent.reasons.length === 0 ? null : (
|
|
319
|
-
<>
|
|
320
|
-
<h4 className="wp-h4">Queued, needing an agent</h4>
|
|
321
|
-
<p className={figures.needingAnAgent.passedOverBecause === null ? 'wp-line' : 'wp-line wp-bad'}>{needingAnAgentLine(figures.needingAnAgent.passedOverBecause)}</p>
|
|
322
|
-
<table className="wp-reasons">
|
|
323
|
-
<tbody>
|
|
324
|
-
{figures.needingAnAgent.reasons.map((b) => <tr key={b.why}><td className="wp-r">{b.tasks.toLocaleString("en-US")}</td><td>{b.why}</td></tr>)}
|
|
325
|
-
</tbody>
|
|
326
|
-
</table>
|
|
327
|
-
</>
|
|
328
|
-
)}
|
|
329
|
-
{workflow.item === null ? null : <p className="wp-line">{yieldLine(figures, workflow.finishedWord)}</p>}
|
|
330
|
-
<p className="wp-line">{runCostLine(figures)}</p>
|
|
331
|
-
<StepsTable workflow={figures} usesAgents={workflow.usesAgents} runs={runs} now={now} />
|
|
332
|
-
<h4 className="wp-h4">Step graph</h4>
|
|
333
|
-
<div className="wp-tablewrap"><StepGraph graph={figures.graph} hrefOfWorkflow={hrefOfWorkflow} /></div>
|
|
334
|
-
<h4 className="wp-h4">Where runs stopped</h4>
|
|
335
|
-
<FunnelTable funnel={figures.funnel} />
|
|
336
|
-
</>
|
|
337
|
-
)}
|
|
338
|
-
</>
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* ONE LEVEL OF THE DRILL-DOWN: the breadcrumb, then the workflow opened: what it is, its tasks as an addition, its runs and
|
|
344
|
-
* limits, and its own steps, each with its kind, a sub-workflow step a link one level down. Below the top, its figures too.
|
|
345
|
-
*/
|
|
346
|
-
function DrillLevelView({ data, path, hrefOf, now, figuresUrl, sourceHref, phaseLabel, setLimit }: {
|
|
347
|
-
readonly data: WorkflowsPageData; readonly path: ReadonlyArray<string>; readonly hrefOf: (path: ReadonlyArray<string>) => string; readonly now: number;
|
|
348
|
-
readonly figuresUrl: (workflow: string) => string; readonly sourceHref: ((source: SourceLink) => string) | undefined; readonly phaseLabel: (phase: string) => string; readonly setLimit: SetLimit | undefined;
|
|
349
|
-
}) {
|
|
350
|
-
const level = drillLevel(data.view, path);
|
|
351
|
-
const all = data.view.groups.flatMap((g) => g.workflows);
|
|
352
|
-
const workflowOf = (name: string) => all.find((w) => w.name === name);
|
|
353
|
-
const runsOf = (name: string) => data.runsNow.flatMap((p) => p.workflows).find((r) => r.workflow === name);
|
|
354
|
-
const w = level.workflow;
|
|
355
|
-
const runs = w === null ? undefined : runsOf(w.name);
|
|
356
|
-
// At the top, each step is a workflow of one of the project's stages, which heads its steps.
|
|
357
|
-
const stageOf = (workflow: string | null) => (workflow === null ? null : workflowOf(workflow)?.phase ?? null);
|
|
358
|
-
return (
|
|
359
|
-
<section className="wp-drill">
|
|
360
|
-
{/* The breadcrumb is the title: its last part names the workflow opened. */}
|
|
361
|
-
<Breadcrumb crumbs={level.crumbs} hrefOf={hrefOf} after={w === null || sourceHref === undefined ? null : <a className="wp-mut wp-drill-source" href={sourceHref(w.source)}>source</a>} />
|
|
362
|
-
{level.notFound === null ? null : <p className="wp-line wp-bad">{level.name} has no sub-workflow step named {level.notFound}.</p>}
|
|
363
|
-
<p className="wp-line">{level.description}</p>
|
|
364
|
-
{w === null ? null : <p className="wp-line wp-mut">{startsLine(w)}</p>}
|
|
365
|
-
{w === null || w.queue === null ? null : <QueueBar queue={w.queue} queuedNeedingAnAgent={w.queuedNeedingAnAgent} />}
|
|
366
|
-
{w === null ? null : <div className="wp-node-status wp-drill-status"><WorkflowStatus workflow={w} runs={runs} limits={w.limits} setLimit={setLimit} /></div>}
|
|
367
|
-
{/* Its tasks over time: at the top a row for each step that has tasks; below it, the workflow opened and each such step of its own. */}
|
|
368
|
-
<QueueChart view={data.view} level={path.join("/")} rowWord={w === null ? "step" : "workflow"}
|
|
369
|
-
workflows={[...(w === null ? [] : [w]), ...level.steps.flatMap((s) => { const sub = s.workflow === null ? undefined : workflowOf(s.workflow); return sub === undefined || sub.name === w?.name ? [] : [sub]; })]} />
|
|
370
|
-
{/* At the top, the map of its steps: each workflow a box whose name opens it, with the arrows work takes between them. */}
|
|
371
|
-
{w !== null ? null : (
|
|
372
|
-
<>
|
|
373
|
-
<h3 className="wp-h3">Map</h3>
|
|
374
|
-
<WorkflowDag view={data.view} phaseLabel={phaseLabel} hrefOfWorkflow={(name) => hrefOf([name])}
|
|
375
|
-
nodeStatus={(node) => <WorkflowStatus workflow={node} runs={runsOf(node.name)} limits={node.limits} setLimit={setLimit} />} />
|
|
376
|
-
</>
|
|
377
|
-
)}
|
|
378
|
-
<h3 className="wp-h3">Steps</h3>
|
|
379
|
-
<StepList
|
|
380
|
-
steps={level.steps} path={level.crumbs[level.crumbs.length - 1]!.path} hrefOf={hrefOf} workflowOf={workflowOf} runsOf={runsOf} runs={runs}
|
|
381
|
-
{...(w === null ? { groupKey: (s: StepSummary) => stageOf(s.workflow), groupOf: (s: StepSummary) => { const stage = stageOf(s.workflow); return stage === null ? null : phaseLabel(stage); } } : {})}
|
|
382
|
-
/>
|
|
383
|
-
{w === null ? null : <WorkflowDetail workflow={w} runs={runs} now={now} figuresUrl={figuresUrl} hrefOfWorkflow={(name) => hrefOf([...level.crumbs[level.crumbs.length - 1]!.path, name])} />}
|
|
384
|
-
</section>
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
export function WorkflowsDashboard({ data, error, figuresUrl, sourceHref, header, phaseLabel, setLimit, setCpuLimit, stopEverything, resume, setSpendingLimit, path, hrefOf }: WorkflowsDashboardProps) {
|
|
389
|
-
const now = Date.now() / 1000;
|
|
390
|
-
const atTheTop = path.length === 0;
|
|
391
|
-
return (
|
|
392
|
-
<div className="wp-page">
|
|
393
|
-
{header}
|
|
394
|
-
<p className={error === null ? 'wp-line wp-mut' : 'wp-line wp-bad'}>
|
|
395
|
-
{error !== null ? `The workflows could not be read: ${error}` : data === null ? 'Reading the workflows…' : `Read from the records ${whenAgo(data.view.at, now)}.`}
|
|
396
|
-
</p>
|
|
397
|
-
{data === null ? null : <p className={data.cpu.use !== null && data.cpu.use.cores > data.cpu.limit ? 'wp-line wp-bad' : 'wp-line'}>{cpuLine(data.cpu, now)}</p>}
|
|
398
|
-
{/* The spending limit holds agent steps at every level, so every level says where it stands. */}
|
|
399
|
-
{data === null || data.view.spending === null ? null : (
|
|
400
|
-
<SpendingLimitControl spending={data.view.spending} held={heldSteps(data.runsNow)} now={now} {...(setSpendingLimit === undefined ? {} : { setSpendingLimit })} />
|
|
401
|
-
)}
|
|
402
|
-
{/* Nothing a level decides is drawn before the first read: a server draws one page for every level's address. */}
|
|
403
|
-
{data === null || !atTheTop ? null : (
|
|
404
|
-
<>
|
|
405
|
-
<MachineControls cpu={data.cpu} stopped={data.stopped ?? null} now={now} {...(setCpuLimit === undefined ? {} : { setCpuLimit })} {...(stopEverything === undefined ? {} : { stopEverything })} {...(resume === undefined ? {} : { resume })} />
|
|
406
|
-
{data.usage === undefined ? null : <AgentUsageLine usage={data.usage} now={now} />}
|
|
407
|
-
</>
|
|
408
|
-
)}
|
|
409
|
-
{data === null ? null : (
|
|
410
|
-
<DrillLevelView data={data} path={path} hrefOf={hrefOf} now={now} figuresUrl={figuresUrl} sourceHref={sourceHref} phaseLabel={(phase) => (phaseLabel === undefined ? phase : phaseLabel(phase))} setLimit={setLimit} />
|
|
411
|
-
)}
|
|
412
|
-
</div>
|
|
413
|
-
);
|
|
414
|
-
}
|
package/src/failure.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What a failure actually was, as one line.
|
|
3
|
-
*
|
|
4
|
-
* `Effect.runPromise` rejects with the typed failure itself, and a
|
|
5
|
-
* `Schema.TaggedError` has an empty `message`: reading only that printed a
|
|
6
|
-
* worker's label and nothing else, which reads as a successful quiet tick --
|
|
7
|
-
* and recorded the gate canary's Docker failure as "", which hid from both a
|
|
8
|
-
* reader and `/api/health` that the cause was outside the service.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* A long failure text as it is kept: whole when it fits in `cap`, else its start and its last `end` characters, with
|
|
12
|
-
* how much was left out between. Never only the start: a failure's own words are usually last, and a step error cut
|
|
13
|
-
* at 500 characters kept a compiler's source echo and ended "Refere", its `ReferenceError` lost (2026-11-07).
|
|
14
|
-
*/
|
|
15
|
-
export const startAndEnd = (text: string, kept: { readonly cap: number; readonly end: number; readonly what: string }): string =>
|
|
16
|
-
text.length <= kept.cap
|
|
17
|
-
? text
|
|
18
|
-
: `${text.slice(0, kept.cap - kept.end)}\n[... ${text.length - kept.cap} characters of ${kept.what} left out ...]\n${text.slice(-kept.end)}`;
|
|
19
|
-
|
|
20
|
-
export const describeFailure = (cause: unknown): string => {
|
|
21
|
-
if (cause !== null && typeof cause === 'object') {
|
|
22
|
-
const tagged = cause as { _tag?: unknown; message?: unknown };
|
|
23
|
-
if (typeof tagged._tag === 'string') {
|
|
24
|
-
const fields = Object.entries(cause as Record<string, unknown>)
|
|
25
|
-
.filter(([key]) => key !== '_tag')
|
|
26
|
-
.map(([key, value]) => `${key}=${typeof value === 'string' ? value : JSON.stringify(value)}`)
|
|
27
|
-
.join(' ');
|
|
28
|
-
return fields === '' ? tagged._tag : `${tagged._tag}: ${fields}`;
|
|
29
|
-
}
|
|
30
|
-
if (cause instanceof Error) {
|
|
31
|
-
return cause.message === '' ? (cause.stack ?? String(cause)) : cause.message;
|
|
32
|
-
}
|
|
33
|
-
return JSON.stringify(cause);
|
|
34
|
-
}
|
|
35
|
-
return String(cause);
|
|
36
|
-
};
|
package/src/keep-running.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EACH WORKFLOW KEEPS THE RUNS GOING THAT ITS BUDGET SAYS, AND NOTHING ELSE DECIDES IT.
|
|
3
|
-
*
|
|
4
|
-
* Alex, 2026-11-06: "We simply have desire concurrent run rate per phase", then "move the concurrent run controls on the
|
|
5
|
-
* workflow level rather than on the phase level, then you can eliminate any logic that goes into decideing which workflows
|
|
6
|
-
* get the available runs". A workflow with an agent step and a list of work (`keptRunningByItsBudget`) is kept running by
|
|
7
|
-
* one trigger, with no code of its own: each turn it starts as many runs as the workflow's run limit keeps (`runLimit`) above
|
|
8
|
-
* the runs going, as soon as a run ends and otherwise on a fallback timer. There is no sharing between workflows, no order,
|
|
9
|
-
* no cap per item and no check of usage: a run with nothing to pick waits for an item (`steps.ts` `untilPicked`), and the
|
|
10
|
-
* blocking a Pick runs and the queue's order keep a run off what it cannot finish. A run limit of 0 holds one workflow.
|
|
11
|
-
*
|
|
12
|
-
* NO RUN STARTS THAT COULD TAKE NO WORK: while no agent can be had for a workflow and its Pick would pass over every task
|
|
13
|
-
* in its queue (`steps.ts` `whyNoRunCanTakeWork`), it starts none, and a run waiting in its Pick ends. Alex, relayed on 2026-11-20:
|
|
14
|
-
* "if the number of queued tasks that require agents is all of them, and if there is no remaining agentic budget or all
|
|
15
|
-
* agents are in use, then the workflow runner doesn't just continually cycle picking up tasks and moving them to the back
|
|
16
|
-
* of the queue again". The next turn after an agent can be had, a mark clears or new input lands starts runs again.
|
|
17
|
-
*/
|
|
18
|
-
import { keptRunningByItsBudget, type WorkflowDeclaration } from './steps';
|
|
19
|
-
import { runLimit, type WorkflowLimits } from './storage/budgets';
|
|
20
|
-
|
|
21
|
-
/** With no run ending to wake it, how often the trigger looks. */
|
|
22
|
-
export const KEEP_RUNNING_EVERY_SECONDS = 60;
|
|
23
|
-
/** How long one turn of the trigger may take, less than its minute; a turn past it is abandoned and the next one runs. */
|
|
24
|
-
export const TURN_LIMIT_MS = 50_000;
|
|
25
|
-
/** How long one run's start may take. */
|
|
26
|
-
export const START_LIMIT_SECONDS = 20;
|
|
27
|
-
|
|
28
|
-
/** The workflows this trigger keeps running, each with a budget. Pure. */
|
|
29
|
-
export const budgetedWorkflows = <D extends Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'items' | 'steps'>>(declared: ReadonlyArray<D>): ReadonlyArray<D> =>
|
|
30
|
-
declared.filter(keptRunningByItsBudget);
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* How many runs of one workflow to start now: the runs its run limit keeps above the runs going. Its agents' limit plays
|
|
34
|
-
* no part: at 0 agents its runs wait at their first agent step. Pure.
|
|
35
|
-
*/
|
|
36
|
-
export const runsToStart = (w: { readonly kept: number; readonly running: number }): number => Math.max(w.kept - w.running, 0);
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* One turn's plan: for each budgeted workflow, the runs going and how many to start; none where no run could take work
|
|
40
|
-
* (`noWork`, from `steps.ts` `whyNoRunCanTakeWork`), which says why. Pure but for the reads it is given.
|
|
41
|
-
*/
|
|
42
|
-
export const planRunStarts = <D extends Pick<WorkflowDeclaration<string, unknown>, 'name' | 'pending' | 'items' | 'steps'>>(input: {
|
|
43
|
-
readonly declared: ReadonlyArray<D>;
|
|
44
|
-
readonly limitsOf: (workflow: string) => WorkflowLimits;
|
|
45
|
-
readonly runningRuns: (workflow: string) => number;
|
|
46
|
-
readonly noWork: (workflow: string) => string | null;
|
|
47
|
-
}): ReadonlyArray<{ readonly declaration: D; readonly running: number; readonly start: number; readonly noWork: string | null }> =>
|
|
48
|
-
budgetedWorkflows(input.declared).map((d) => {
|
|
49
|
-
const running = input.runningRuns(d.name);
|
|
50
|
-
const noWork = input.noWork(d.name);
|
|
51
|
-
return { declaration: d, running, noWork, start: noWork !== null ? 0 : runsToStart({ kept: runLimit(input.limitsOf(d.name)), running }) };
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* ONE TURN AT A TIME, AND NO TURN HOLDS THE NEXT UP FOR LONG. A call during a turn shares its result and asks for one more
|
|
56
|
-
* after it. A turn past `limitMs` fails, so nothing it hung on can leave the trigger shut, and `stillCurrent` turns false
|
|
57
|
-
* for it, so if it wakes later it starts nothing on figures that have gone old.
|
|
58
|
-
*/
|
|
59
|
-
export const oneTurnAtATime = (turn: (stillCurrent: () => boolean) => Promise<void>, limitMs: number): (() => Promise<void>) => {
|
|
60
|
-
let going: Promise<void> | null = null;
|
|
61
|
-
let again = false;
|
|
62
|
-
let current = 0;
|
|
63
|
-
const trigger = (): Promise<void> => {
|
|
64
|
-
if (going !== null) { again = true; return going; }
|
|
65
|
-
current += 1;
|
|
66
|
-
const mine = current;
|
|
67
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
68
|
-
const limit = new Promise<never>((_, reject) => {
|
|
69
|
-
timer = setTimeout(() => reject(new Error(`a turn of the trigger was abandoned after ${limitMs / 1000} s`)), limitMs);
|
|
70
|
-
});
|
|
71
|
-
going = Promise.race([turn(() => current === mine), limit]).finally(() => {
|
|
72
|
-
clearTimeout(timer);
|
|
73
|
-
current += 1;
|
|
74
|
-
going = null;
|
|
75
|
-
if (again) { again = false; void trigger().catch(() => undefined); }
|
|
76
|
-
});
|
|
77
|
-
return going;
|
|
78
|
-
};
|
|
79
|
-
return trigger;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/** A run's id: the time it was made, and a random tail so two made in one millisecond differ. */
|
|
83
|
-
export const newRunId = () => `${Date.now().toString(36)}${Math.floor(Math.random() * 1296).toString(36).padStart(2, '0')}`;
|
package/src/outside-failure.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A RUN AN OUTSIDE SERVICE FAILED IS NO TRY. A task is blocked after `BLOCK_AFTER_TRIES` failed tries (`tasks.ts`), and
|
|
3
|
-
* only a run that did its work and ended without success is one. A run that failed because a service outside it could
|
|
4
|
-
* not do the work (a Claude usage limit, a model server that does not answer) says nothing about its item: counted, two
|
|
5
|
-
* weekly-limit failures took an item of skill-sync's skill refinement workflow from 9 tries to 11, and it was blocked
|
|
6
|
-
* for good once the limit reset (2026-11-25).
|
|
7
|
-
*
|
|
8
|
-
* A step says so by failing with `OutsideServiceUnavailable`. Claude's own usage-limit and rate-limit words are read the
|
|
9
|
-
* same way whatever error carries them, so outcomes recorded before this error existed count right too.
|
|
10
|
-
*
|
|
11
|
-
* The task store counts tries in SQL, from each outcome's text (`storage/sqlite-store.ts`): `OUTSIDE_FAILURE_PATTERNS`
|
|
12
|
-
* are its `LIKE` patterns, which SQLite matches without regard to ASCII case, and `isOutsideFailure` reads them the same
|
|
13
|
-
* way in code.
|
|
14
|
-
*/
|
|
15
|
-
import { Data } from 'effect';
|
|
16
|
-
|
|
17
|
-
/** What a step fails with when a service outside it could not do its work: its run's outcome is no try. */
|
|
18
|
-
export class OutsideServiceUnavailable extends Data.TaggedError('OutsideServiceUnavailable')<{
|
|
19
|
-
/** The service, by its own name: `claude`, `jev`. */
|
|
20
|
-
readonly service: string;
|
|
21
|
-
/** Its own words on why, such as "You've hit your weekly limit · resets 6am (UTC)". */
|
|
22
|
-
readonly reason: string;
|
|
23
|
-
}> {}
|
|
24
|
-
|
|
25
|
-
/** The outcomes of runs an outside service failed, as SQL `LIKE` patterns on an outcome's text. */
|
|
26
|
-
export const OUTSIDE_FAILURE_PATTERNS: ReadonlyArray<string> = [
|
|
27
|
-
'failed: OutsideServiceUnavailable:%',
|
|
28
|
-
// Claude's own words: "You've hit your weekly limit · resets 6am (UTC)", "Claude usage limit reached", a 429's "rate limit".
|
|
29
|
-
'failed: %hit your % limit%',
|
|
30
|
-
'failed: %usage limit%',
|
|
31
|
-
'failed: %rate limit%',
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
const asRegExp = (pattern: string): RegExp =>
|
|
35
|
-
new RegExp(`^${pattern.split('%').map((part) => part.replace(/[.*+?^$()|[\]\\{}_]/g, (c) => (c === '_' ? '.' : `\\${c}`))).join('.*')}$`, 'is');
|
|
36
|
-
const OUTSIDE_FAILURES = OUTSIDE_FAILURE_PATTERNS.map(asRegExp);
|
|
37
|
-
|
|
38
|
-
/** Whether a run's outcome says an outside service failed it, as the task store reads it. */
|
|
39
|
-
export const isOutsideFailure = (outcome: string): boolean => OUTSIDE_FAILURES.some((p) => p.test(outcome));
|