@operad-io/dev 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +12 -2
- package/dev.schema.json +631 -0
- package/flows/chat-worktree.flow.ts +18 -0
- package/flows/dev.flow.ts +7 -0
- package/package.json +29 -4
- package/src/actions.ts +591 -0
- package/src/announce.ts +225 -0
- package/src/chat.ts +234 -0
- package/src/check.ts +80 -0
- package/src/commands.ts +417 -0
- package/src/editor.ts +55 -0
- package/src/flaky.ts +716 -0
- package/src/flow-compiler.ts +858 -0
- package/src/followups.ts +223 -0
- package/src/gate.ts +2950 -0
- package/src/git.ts +138 -0
- package/src/index.ts +227 -0
- package/src/integrate.ts +1213 -0
- package/src/integration-queue.ts +393 -0
- package/src/lock.ts +36 -0
- package/src/mainclone.ts +102 -0
- package/src/marks.ts +126 -0
- package/src/model.ts +1171 -0
- package/src/notcode.ts +305 -0
- package/src/place-order.ts +161 -0
- package/src/place-wait.ts +64 -0
- package/src/places.ts +368 -0
- package/src/prepare.ts +106 -0
- package/src/progress.ts +115 -0
- package/src/project-flows.ts +160 -0
- package/src/project-settings.ts +192 -0
- package/src/refusals.ts +336 -0
- package/src/rerun.ts +390 -0
- package/src/reruns.ts +62 -0
- package/src/retry.ts +212 -0
- package/src/rework.ts +366 -0
- package/src/schedule.ts +1052 -0
- package/src/service.ts +2160 -0
- package/src/settings.ts +1495 -0
- package/src/standing.ts +87 -0
- package/src/stdin.ts +105 -0
- package/src/steps.ts +1775 -0
- package/src/stops.ts +103 -0
- package/src/throughput.ts +347 -0
- package/src/timeouts.ts +60 -0
- package/src/views.ts +1167 -0
- package/src/waits.ts +105 -0
package/src/stops.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells a step that stopped because of operad or the machine from one that
|
|
3
|
+
* stopped because of the task's own work. It reads structured data only: the
|
|
4
|
+
* result the flow took, the reason dev recorded, the kind of the host's error.
|
|
5
|
+
* It never reads what an agent wrote.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** What the classifier is given about one stopped or failed step. */
|
|
9
|
+
export interface StopFacts {
|
|
10
|
+
/** The step that stopped. */
|
|
11
|
+
readonly step: string;
|
|
12
|
+
/** The result the flow took: `failed`, `interrupted` (a recovered run) and so on. */
|
|
13
|
+
readonly result: string;
|
|
14
|
+
/** The reason dev recorded for a failed result, when it recorded one. */
|
|
15
|
+
readonly reason?: string | undefined;
|
|
16
|
+
/** The step that was not loaded, when the reason is `step_not_loaded`. */
|
|
17
|
+
readonly use?: string | undefined;
|
|
18
|
+
/** A person cancelled the task: nothing is retried. */
|
|
19
|
+
readonly cancelled?: boolean | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Where a failure came from: outside the task's work, or in it. */
|
|
23
|
+
export type StopKind = "environment" | "task";
|
|
24
|
+
|
|
25
|
+
export interface StopVerdict {
|
|
26
|
+
readonly kind: StopKind;
|
|
27
|
+
/** What was wrong, as a waiting line says it; set for an environment failure. */
|
|
28
|
+
readonly cause?: string | undefined;
|
|
29
|
+
/** What the retry waits for; absent when it may run at once. */
|
|
30
|
+
readonly waitFor?: "step" | "settings" | undefined;
|
|
31
|
+
readonly use?: string | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The reasons dev records when a step stops for a cause outside the task. */
|
|
35
|
+
export const STOP_REASONS = {
|
|
36
|
+
stepNotLoaded: "step_not_loaded",
|
|
37
|
+
settingsUnreadable: "settings_unreadable",
|
|
38
|
+
stopped: "stopped",
|
|
39
|
+
/** A harness or model connection that dropped: the socket closed, a reset, a failed fetch. */
|
|
40
|
+
connection: "connection_error",
|
|
41
|
+
/** A repair run that only puts a task whose run ended in front of a person. */
|
|
42
|
+
runEnded: "run_ended",
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
const CONNECTION_ERROR = new RegExp(
|
|
46
|
+
[
|
|
47
|
+
"socket connection was closed unexpectedly",
|
|
48
|
+
"socket hang up",
|
|
49
|
+
"ECONNRESET",
|
|
50
|
+
"ECONNREFUSED",
|
|
51
|
+
"ETIMEDOUT",
|
|
52
|
+
"EAI_AGAIN",
|
|
53
|
+
"ENOTFOUND",
|
|
54
|
+
"EPIPE",
|
|
55
|
+
"fetch failed",
|
|
56
|
+
"network error",
|
|
57
|
+
"connection (?:error|reset|closed|lost)",
|
|
58
|
+
"unable to connect",
|
|
59
|
+
].join("|"),
|
|
60
|
+
"i",
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* True when text a harness or the host printed for a failed step says the
|
|
65
|
+
* connection to the model dropped. This reads the error the host gave, never
|
|
66
|
+
* what an agent wrote in its answer.
|
|
67
|
+
*/
|
|
68
|
+
export function isConnectionError(...texts: readonly (string | undefined)[]): boolean {
|
|
69
|
+
return texts.some((text) => text !== undefined && CONNECTION_ERROR.test(text));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const TASK: StopVerdict = { kind: "task" };
|
|
73
|
+
|
|
74
|
+
export function classifyStop(facts: StopFacts): StopVerdict {
|
|
75
|
+
if (facts.cancelled === true) return TASK;
|
|
76
|
+
if (facts.reason === STOP_REASONS.runEnded) return TASK;
|
|
77
|
+
// A run that was recovered or stopped never reached a verdict on the work.
|
|
78
|
+
if (facts.result === "interrupted") {
|
|
79
|
+
return { kind: "environment", cause: `run stopped during ${facts.step}` };
|
|
80
|
+
}
|
|
81
|
+
switch (facts.reason) {
|
|
82
|
+
case STOP_REASONS.stepNotLoaded:
|
|
83
|
+
if (facts.use === undefined || facts.use.length === 0) return TASK;
|
|
84
|
+
return {
|
|
85
|
+
kind: "environment",
|
|
86
|
+
cause: `${facts.use} is not loaded`,
|
|
87
|
+
waitFor: "step",
|
|
88
|
+
use: facts.use,
|
|
89
|
+
};
|
|
90
|
+
case STOP_REASONS.settingsUnreadable:
|
|
91
|
+
return {
|
|
92
|
+
kind: "environment",
|
|
93
|
+
cause: "settings could not be read",
|
|
94
|
+
waitFor: "settings",
|
|
95
|
+
};
|
|
96
|
+
case STOP_REASONS.connection:
|
|
97
|
+
return { kind: "environment", cause: `model connection dropped during ${facts.step}` };
|
|
98
|
+
case STOP_REASONS.stopped:
|
|
99
|
+
return { kind: "environment", cause: `run stopped during ${facts.step}` };
|
|
100
|
+
default:
|
|
101
|
+
return TASK;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A repository's Metrics: what merged in the last 24 hours and the last 7
|
|
3
|
+
* days, and where the time of those tasks went. Everything is computed when
|
|
4
|
+
* the section is opened, from dev's own facts: each task's facts say when it
|
|
5
|
+
* merged, what it cost and why it stopped; each run's facts say how long its
|
|
6
|
+
* steps and its waits for a person took. Nothing comes from git.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
foldObjectFacts,
|
|
11
|
+
type PluginFact,
|
|
12
|
+
type StoredObject,
|
|
13
|
+
type ViewContext,
|
|
14
|
+
} from "@operad-io/engine";
|
|
15
|
+
import {
|
|
16
|
+
listAll,
|
|
17
|
+
repositoryData,
|
|
18
|
+
taskData,
|
|
19
|
+
type TaskAttempt,
|
|
20
|
+
type TaskData,
|
|
21
|
+
} from "./model.ts";
|
|
22
|
+
import { classifyStop, STOP_REASONS } from "./stops.ts";
|
|
23
|
+
|
|
24
|
+
const HOUR = 3_600_000;
|
|
25
|
+
const DAY = 24 * HOUR;
|
|
26
|
+
|
|
27
|
+
/** The steps of the time table, in the order the work takes them. */
|
|
28
|
+
const STEP_ROWS = [
|
|
29
|
+
"work",
|
|
30
|
+
"verify",
|
|
31
|
+
"review",
|
|
32
|
+
"wait for a person",
|
|
33
|
+
"waiting to integrate",
|
|
34
|
+
"integrate",
|
|
35
|
+
] as const;
|
|
36
|
+
type StepRow = (typeof STEP_ROWS)[number];
|
|
37
|
+
|
|
38
|
+
/** How many runs are read at once. */
|
|
39
|
+
const BATCH = 16;
|
|
40
|
+
/** How many reasons the table names. */
|
|
41
|
+
const TOP_REASONS = 5;
|
|
42
|
+
|
|
43
|
+
/** What one merged task contributes. */
|
|
44
|
+
interface MergedTask {
|
|
45
|
+
readonly mergedAt: number;
|
|
46
|
+
readonly cost: number | undefined;
|
|
47
|
+
readonly reworks: number;
|
|
48
|
+
readonly runs: readonly string[];
|
|
49
|
+
/** The time it waited for a turn to integrate, from its own facts. */
|
|
50
|
+
readonly integrateWaitMs: number;
|
|
51
|
+
/** Why it stopped for a person, each reason once; empty when it never did. */
|
|
52
|
+
readonly reasons: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The nearest-rank percentile of the values; they are sorted here. */
|
|
56
|
+
export function percentile(values: readonly number[], p: number): number {
|
|
57
|
+
if (values.length === 0) return 0;
|
|
58
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
59
|
+
const rank = Math.max(1, Math.ceil((p / 100) * sorted.length));
|
|
60
|
+
return sorted[Math.min(sorted.length, rank) - 1] ?? 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function duration(ms: number): string {
|
|
64
|
+
const total = Math.max(0, Math.round(ms / 1000));
|
|
65
|
+
if (total < 60) return `${total}s`;
|
|
66
|
+
const minutes = Math.round(total / 60);
|
|
67
|
+
if (minutes < 60) return `${minutes}m`;
|
|
68
|
+
return `${Math.floor(minutes / 60)}h${String(minutes % 60).padStart(2, "0")}m`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function pad(value: number): string {
|
|
72
|
+
return String(value).padStart(2, "0");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function hourLabel(start: number): string {
|
|
76
|
+
const d = new Date(start);
|
|
77
|
+
return `${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())} ${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function dayLabel(start: number): string {
|
|
81
|
+
const d = new Date(start);
|
|
82
|
+
return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function table(header: readonly string[], rows: readonly (readonly string[])[]): string {
|
|
86
|
+
return [
|
|
87
|
+
`| ${header.join(" | ")} |`,
|
|
88
|
+
`| ${header.map(() => "---").join(" | ")} |`,
|
|
89
|
+
...rows.map((row) => `| ${row.join(" | ")} |`),
|
|
90
|
+
].join("\n");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The reason a task stopped for a person, from the step and the attempt it recorded. */
|
|
94
|
+
function stopReason(step: string, attempt: TaskAttempt | undefined): string {
|
|
95
|
+
const result = attempt?.result;
|
|
96
|
+
if (step === "verify") {
|
|
97
|
+
return attempt?.verify?.result === "fail" ? "verify failed" : "verify";
|
|
98
|
+
}
|
|
99
|
+
if (step === "review") {
|
|
100
|
+
const review = attempt?.review;
|
|
101
|
+
if (review === undefined || review === null) return "review";
|
|
102
|
+
if (review.result === "findings" || review.result === "fail") return "review: findings";
|
|
103
|
+
return `review ${review.result.replace("_", " ")}`;
|
|
104
|
+
}
|
|
105
|
+
if (step === "integrate") {
|
|
106
|
+
const integration = attempt?.integration?.result;
|
|
107
|
+
if (integration === "conflict") return "conflict";
|
|
108
|
+
if (integration === "fail" || integration === "failed") return "integrate failed";
|
|
109
|
+
return "integrate";
|
|
110
|
+
}
|
|
111
|
+
if (
|
|
112
|
+
(step === "worktree" || step === "reverify" || step === "work") &&
|
|
113
|
+
(result === "failed" || result === "blocked" || result === "nothing")
|
|
114
|
+
) {
|
|
115
|
+
return `${step} ${result}`;
|
|
116
|
+
}
|
|
117
|
+
return step === "" ? "stopped" : step.replaceAll("_", " ");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Why a task stopped for a person: the cause dev recorded for a spent retry or
|
|
122
|
+
* a stopped run when it did, else what the step and its attempt say.
|
|
123
|
+
*/
|
|
124
|
+
function reasonOf(data: TaskData, cause: string): string {
|
|
125
|
+
const retry = data.retry;
|
|
126
|
+
if (retry !== undefined && retry !== null && retry.state === "asked" && retry.cause.length > 0) {
|
|
127
|
+
return retry.cause;
|
|
128
|
+
}
|
|
129
|
+
const stop = data.stop;
|
|
130
|
+
if (stop !== undefined && stop !== null) {
|
|
131
|
+
if (stop.reason === STOP_REASONS.runEnded) return "run stopped";
|
|
132
|
+
const verdict = classifyStop({
|
|
133
|
+
step: stop.step,
|
|
134
|
+
result: stop.result,
|
|
135
|
+
reason: stop.reason,
|
|
136
|
+
use: stop.use,
|
|
137
|
+
});
|
|
138
|
+
if (verdict.cause !== undefined) return verdict.cause;
|
|
139
|
+
}
|
|
140
|
+
const step = /^dev:(\w+)$/.exec(cause)?.[1] ?? "";
|
|
141
|
+
return stopReason(step, data.attempt);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Reads one merged task's facts; undefined when it did not merge in the window. */
|
|
145
|
+
async function readTask(
|
|
146
|
+
ctx: ViewContext,
|
|
147
|
+
object: StoredObject,
|
|
148
|
+
since: number,
|
|
149
|
+
): Promise<MergedTask | undefined> {
|
|
150
|
+
let mergedAt: number | undefined;
|
|
151
|
+
let previous = "";
|
|
152
|
+
let maxAttempt = 0;
|
|
153
|
+
let waitFrom: number | undefined;
|
|
154
|
+
let integrateWaitMs = 0;
|
|
155
|
+
const runs: string[] = [];
|
|
156
|
+
// Each attempt's cost, the latest recorded for it: a rework is paid for too.
|
|
157
|
+
const attemptCosts = new Map<number, number>();
|
|
158
|
+
const reasons = new Set<string>();
|
|
159
|
+
const facts: PluginFact[] = [];
|
|
160
|
+
let cursor: string | undefined;
|
|
161
|
+
for (;;) {
|
|
162
|
+
const page = await ctx.store.facts(
|
|
163
|
+
{ type: object.type, id: object.id },
|
|
164
|
+
cursor === undefined ? {} : { cursor },
|
|
165
|
+
);
|
|
166
|
+
facts.push(...page.facts);
|
|
167
|
+
if (page.next === undefined) break;
|
|
168
|
+
cursor = page.next;
|
|
169
|
+
}
|
|
170
|
+
for (const version of foldObjectFacts(facts)) {
|
|
171
|
+
const data = taskData(version.data);
|
|
172
|
+
const attempt = data.attempt;
|
|
173
|
+
if (data.phase === "merged" && mergedAt === undefined) mergedAt = version.fact.at;
|
|
174
|
+
if (data.phase === "waiting" && previous !== "waiting") {
|
|
175
|
+
reasons.add(reasonOf(data, version.fact.cause));
|
|
176
|
+
}
|
|
177
|
+
previous = data.phase;
|
|
178
|
+
if (attempt !== undefined) {
|
|
179
|
+
maxAttempt = Math.max(maxAttempt, attempt.number);
|
|
180
|
+
if (typeof attempt.cost === "number" && Number.isFinite(attempt.cost)) {
|
|
181
|
+
attemptCosts.set(attempt.number, attempt.cost);
|
|
182
|
+
}
|
|
183
|
+
if (typeof attempt.run === "string" && !runs.includes(attempt.run)) runs.push(attempt.run);
|
|
184
|
+
const waiting = typeof attempt.integrationWait === "string" && attempt.integrationWait.length > 0;
|
|
185
|
+
if (waiting && waitFrom === undefined) waitFrom = version.fact.at;
|
|
186
|
+
if (!waiting && waitFrom !== undefined) {
|
|
187
|
+
integrateWaitMs += Math.max(0, version.fact.at - waitFrom);
|
|
188
|
+
waitFrom = undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (mergedAt === undefined || mergedAt < since) return undefined;
|
|
193
|
+
const own = taskData(object.data).cost;
|
|
194
|
+
const total = [...attemptCosts.values()].reduce((sum, cost) => sum + cost, 0);
|
|
195
|
+
return {
|
|
196
|
+
mergedAt,
|
|
197
|
+
cost:
|
|
198
|
+
attemptCosts.size > 0
|
|
199
|
+
? total
|
|
200
|
+
: typeof own === "number" && Number.isFinite(own)
|
|
201
|
+
? own
|
|
202
|
+
: undefined,
|
|
203
|
+
reworks: Math.max(0, maxAttempt - 1),
|
|
204
|
+
runs,
|
|
205
|
+
integrateWaitMs,
|
|
206
|
+
reasons: [...reasons],
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** One task's time in each step, from its runs; undefined when no run could be read. */
|
|
211
|
+
async function stepTimes(
|
|
212
|
+
ctx: ViewContext,
|
|
213
|
+
task: MergedTask,
|
|
214
|
+
): Promise<Record<StepRow, number> | undefined> {
|
|
215
|
+
if (ctx.runTimes === undefined) return undefined;
|
|
216
|
+
const times: Record<StepRow, number> = {
|
|
217
|
+
work: 0,
|
|
218
|
+
verify: 0,
|
|
219
|
+
review: 0,
|
|
220
|
+
"wait for a person": 0,
|
|
221
|
+
"waiting to integrate": 0,
|
|
222
|
+
integrate: 0,
|
|
223
|
+
};
|
|
224
|
+
let read = false;
|
|
225
|
+
for (const runId of task.runs) {
|
|
226
|
+
const run = await ctx.runTimes(runId);
|
|
227
|
+
if (run === undefined) continue;
|
|
228
|
+
read = true;
|
|
229
|
+
for (const segment of run.segments) {
|
|
230
|
+
const spent = Math.max(0, (segment.to ?? task.mergedAt) - segment.from);
|
|
231
|
+
if (segment.person) times["wait for a person"] += spent;
|
|
232
|
+
else if (segment.step === "work") times.work += spent;
|
|
233
|
+
else if (segment.step === "verify" || segment.step === "reverify") times.verify += spent;
|
|
234
|
+
else if (segment.step === "review") times.review += spent;
|
|
235
|
+
else if (segment.step === "integrate") times.integrate += spent;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (!read) return undefined;
|
|
239
|
+
// The turn in the queue is part of the integrate step's stretch; it has its own row.
|
|
240
|
+
const queued = Math.min(task.integrateWaitMs, times.integrate);
|
|
241
|
+
times["waiting to integrate"] = queued;
|
|
242
|
+
times.integrate -= queued;
|
|
243
|
+
return times;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function perMerge(tasks: readonly MergedTask[]): string {
|
|
247
|
+
const costs = tasks.flatMap((task) => (task.cost === undefined ? [] : [task.cost]));
|
|
248
|
+
if (costs.length === 0) return "-";
|
|
249
|
+
return `$${(costs.reduce((sum, cost) => sum + cost, 0) / costs.length).toFixed(2)}`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function countTable(
|
|
253
|
+
label: string,
|
|
254
|
+
starts: readonly number[],
|
|
255
|
+
size: number,
|
|
256
|
+
name: (start: number) => string,
|
|
257
|
+
tasks: readonly MergedTask[],
|
|
258
|
+
/** True for a bucket that includes its end and not its start. */
|
|
259
|
+
endClosed: boolean = false,
|
|
260
|
+
): string {
|
|
261
|
+
const rows = starts.map((start) => {
|
|
262
|
+
const inside = tasks.filter((task) =>
|
|
263
|
+
endClosed
|
|
264
|
+
? task.mergedAt > start && task.mergedAt <= start + size
|
|
265
|
+
: task.mergedAt >= start && task.mergedAt < start + size,
|
|
266
|
+
);
|
|
267
|
+
return [name(start), String(inside.length), perMerge(inside)];
|
|
268
|
+
});
|
|
269
|
+
return table([label, "merged", "cost per merge"], rows);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The repository's Metrics at `now`. Hour rows are the 24 hours ending at
|
|
274
|
+
* `now`; day rows are UTC calendar days, the last one the day `now` is in.
|
|
275
|
+
*/
|
|
276
|
+
export async function repositoryMetrics(
|
|
277
|
+
ctx: ViewContext,
|
|
278
|
+
repository: StoredObject,
|
|
279
|
+
now: number = Date.now(),
|
|
280
|
+
): Promise<string> {
|
|
281
|
+
const name = repositoryData(repository.data).name;
|
|
282
|
+
const dayStart = Math.floor(now / DAY) * DAY;
|
|
283
|
+
const since = dayStart - 6 * DAY;
|
|
284
|
+
const tasks = (await listAll(ctx.store, "task")).filter((object) => {
|
|
285
|
+
const data = taskData(object.data);
|
|
286
|
+
// A merged task was last written at or after its merge.
|
|
287
|
+
return data.repository === name && data.phase === "merged" && object.at >= since;
|
|
288
|
+
});
|
|
289
|
+
const merged: MergedTask[] = [];
|
|
290
|
+
for (let index = 0; index < tasks.length; index += BATCH) {
|
|
291
|
+
const read = await Promise.all(
|
|
292
|
+
tasks.slice(index, index + BATCH).map((object) => readTask(ctx, object, since)),
|
|
293
|
+
);
|
|
294
|
+
for (const task of read) if (task !== undefined && task.mergedAt <= now) merged.push(task);
|
|
295
|
+
}
|
|
296
|
+
if (merged.length === 0) return "_No merged tasks in the last 7 days._";
|
|
297
|
+
|
|
298
|
+
// Rolling hours, each (start, start + 1h]: the rows add up to the (now - 24h, now] summary.
|
|
299
|
+
const hours = Array.from({ length: 24 }, (_, i) => now - (24 - i) * HOUR);
|
|
300
|
+
const days = Array.from({ length: 7 }, (_, i) => dayStart - (6 - i) * DAY);
|
|
301
|
+
const lastDay = merged.filter((task) => task.mergedAt > now - 24 * HOUR && task.mergedAt <= now);
|
|
302
|
+
|
|
303
|
+
const timed: Record<StepRow, number>[] = [];
|
|
304
|
+
for (let index = 0; index < merged.length; index += BATCH) {
|
|
305
|
+
const read = await Promise.all(
|
|
306
|
+
merged.slice(index, index + BATCH).map((task) => stepTimes(ctx, task)),
|
|
307
|
+
);
|
|
308
|
+
for (const times of read) if (times !== undefined) timed.push(times);
|
|
309
|
+
}
|
|
310
|
+
const stepRows = STEP_ROWS.map((step) => {
|
|
311
|
+
const values = timed.map((times) => times[step]);
|
|
312
|
+
return [step, duration(percentile(values, 50)), duration(percentile(values, 90))];
|
|
313
|
+
});
|
|
314
|
+
const reworks = merged.map((task) => task.reworks);
|
|
315
|
+
const rounds = (value: number): string => String(value);
|
|
316
|
+
const stopped = merged.filter((task) => task.reasons.length > 0);
|
|
317
|
+
const counts = new Map<string, number>();
|
|
318
|
+
for (const task of stopped) for (const reason of task.reasons) counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
319
|
+
const top = [...counts]
|
|
320
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
321
|
+
.slice(0, TOP_REASONS);
|
|
322
|
+
const share = `${Math.round((stopped.length / merged.length) * 100)}%`;
|
|
323
|
+
|
|
324
|
+
const sections = [
|
|
325
|
+
`**Last 24 hours** ${lastDay.length} merged · ${perMerge(lastDay)} per merge`,
|
|
326
|
+
countTable("hour (UTC)", hours, HOUR, hourLabel, merged, true),
|
|
327
|
+
`**Last 7 days** ${merged.length} merged · ${perMerge(merged)} per merge`,
|
|
328
|
+
countTable("day (UTC)", days, DAY, dayLabel, merged),
|
|
329
|
+
`**Time per step** ${merged.length} tasks merged in the last 7 days`,
|
|
330
|
+
table(["step", "median", "90th percentile"], [
|
|
331
|
+
...stepRows,
|
|
332
|
+
["rework rounds", rounds(percentile(reworks, 50)), rounds(percentile(reworks, 90))],
|
|
333
|
+
]),
|
|
334
|
+
`**Stopped for a person** ${stopped.length} of ${merged.length} tasks (${share})`,
|
|
335
|
+
top.length === 0
|
|
336
|
+
? "_No task stopped for a person._"
|
|
337
|
+
: table(["reason", "tasks"], top.map(([reason, count]) => [reason.replace(/\|/g, "\\|"), String(count)])),
|
|
338
|
+
];
|
|
339
|
+
if (timed.length < merged.length) {
|
|
340
|
+
sections.splice(
|
|
341
|
+
6,
|
|
342
|
+
0,
|
|
343
|
+
`_Times are from ${timed.length} of ${merged.length} tasks; the others have no run on record._`,
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
return sections.join("\n\n");
|
|
347
|
+
}
|
package/src/timeouts.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long work, verify, review and integrate may take: above the worker's
|
|
3
|
+
* two-hour wall time and the reviewer's one-hour timeout in `.operad/dev.json`.
|
|
4
|
+
*/
|
|
5
|
+
export const STEP_TIMEOUT_SECS = 3 * 60 * 60;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* How long one `dev/review_due` run waits. It stays clear of the step timeout,
|
|
9
|
+
* so a `reviewer.retrySecs` longer than that timeout is waited in pieces: the
|
|
10
|
+
* step ends before the runner stops it, and the flow comes back to the same
|
|
11
|
+
* wait. Only the last piece is followed by a real review.
|
|
12
|
+
*/
|
|
13
|
+
export const REVIEW_WAIT_CHUNK_MS = (STEP_TIMEOUT_SECS - 60) * 1000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The longest one review wait lasts. The waits double from
|
|
17
|
+
* `reviewer.retrySecs`, so an outage of an hour or two is waited out in a
|
|
18
|
+
* handful of tries instead of dozens.
|
|
19
|
+
*/
|
|
20
|
+
export const MAX_REVIEW_WAIT_SECS = 30 * 60;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How long the `n`th wait (1-based) of a review round lasts: `retrySecs`, then
|
|
24
|
+
* double each time, up to `MAX_REVIEW_WAIT_SECS` (or `retrySecs` itself when
|
|
25
|
+
* that is longer).
|
|
26
|
+
*/
|
|
27
|
+
export function reviewWaitMs(retrySecs: number, n: number): number {
|
|
28
|
+
const cap = Math.max(retrySecs, MAX_REVIEW_WAIT_SECS);
|
|
29
|
+
const doublings = Math.min(Math.max(n - 1, 0), 30);
|
|
30
|
+
return Math.min(retrySecs * 2 ** doublings, cap) * 1000;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* How many times one review round may wait for an unavailable model before it
|
|
35
|
+
* waits for a person instead. It was 36 waits of a flat `retrySecs` (about 72
|
|
36
|
+
* minutes at the default 120 seconds); it is now 6 waits that double (2, 4, 8,
|
|
37
|
+
* 16, 30 and 30 minutes: about 90 minutes at the default). The count is the
|
|
38
|
+
* number of primary runs of the round recorded as unavailable in the task's
|
|
39
|
+
* review runs, so a crash and a replay agree on it.
|
|
40
|
+
*/
|
|
41
|
+
export const MAX_REVIEW_WAITS = 6;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* How many times one attempt's work step may wait for an unavailable model
|
|
45
|
+
* before the failure goes to a person. The work wait stays flat at
|
|
46
|
+
* `reviewer.retrySecs`.
|
|
47
|
+
*/
|
|
48
|
+
export const MAX_WORK_WAITS = 36;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The most the visits of one step may add up to in a dev run: the kernel's
|
|
52
|
+
* default of ten for ordinary loops plus one visit of `work` and of
|
|
53
|
+
* `work_retry` for each allowed work wait.
|
|
54
|
+
*
|
|
55
|
+
* The count is for the whole run, not for one rework or attempt. A long model
|
|
56
|
+
* outage that spans several reworks (each wait is a visit of `work_retry` or
|
|
57
|
+
* `review_retry`) can therefore use the budget up and end the run with
|
|
58
|
+
* `visit_limit_reached` before any one attempt reaches its own wait bound.
|
|
59
|
+
*/
|
|
60
|
+
export const DEV_MAX_VISITS = 10 + MAX_WORK_WAITS;
|