@prestyj/cli 5.39.3 → 5.40.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.
Files changed (63) hide show
  1. package/dist/cli/fleet.js +14 -2
  2. package/dist/cli/fleet.js.map +1 -1
  3. package/dist/cli/node.js +30 -1
  4. package/dist/cli/node.js.map +1 -1
  5. package/dist/core/fleet/fleet-scheduler.d.ts +5 -0
  6. package/dist/core/fleet/fleet-scheduler.js +4 -0
  7. package/dist/core/fleet/fleet-scheduler.js.map +1 -1
  8. package/dist/core/fleet/node/agents.js +4 -1
  9. package/dist/core/fleet/node/agents.js.map +1 -1
  10. package/dist/core/fleet/node/config.js +10 -0
  11. package/dist/core/fleet/node/config.js.map +1 -1
  12. package/dist/core/fleet/node/context.d.ts +8 -0
  13. package/dist/core/fleet/node/goals.js +4 -1
  14. package/dist/core/fleet/node/goals.js.map +1 -1
  15. package/dist/core/fleet/node/jobs.d.ts +12 -0
  16. package/dist/core/fleet/node/jobs.js +49 -2
  17. package/dist/core/fleet/node/jobs.js.map +1 -1
  18. package/dist/core/fleet/node/pressure.d.ts +30 -0
  19. package/dist/core/fleet/node/pressure.js +56 -0
  20. package/dist/core/fleet/node/pressure.js.map +1 -0
  21. package/dist/core/fleet/node/server.d.ts +18 -1
  22. package/dist/core/fleet/node/server.js +26 -4
  23. package/dist/core/fleet/node/server.js.map +1 -1
  24. package/dist/core/fleet/profiles.d.ts +50 -0
  25. package/dist/core/fleet/profiles.js +132 -0
  26. package/dist/core/fleet/profiles.js.map +1 -0
  27. package/dist/core/fleet/protocol.d.ts +7 -0
  28. package/dist/core/fleet/protocol.js.map +1 -1
  29. package/dist/core/fleet/remote-agent-nodes.js +5 -0
  30. package/dist/core/fleet/remote-agent-nodes.js.map +1 -1
  31. package/dist/core/fleet/remote-agent.d.ts +5 -0
  32. package/dist/core/fleet/remote-agent.js +16 -0
  33. package/dist/core/fleet/remote-agent.js.map +1 -1
  34. package/dist/core/fleet/report.d.ts +83 -0
  35. package/dist/core/fleet/report.js +255 -0
  36. package/dist/core/fleet/report.js.map +1 -0
  37. package/dist/core/fleet/service.d.ts +9 -0
  38. package/dist/core/fleet/service.js +47 -1
  39. package/dist/core/fleet/service.js.map +1 -1
  40. package/dist/core/fleet/types.d.ts +2 -0
  41. package/dist/core/goal-fleet.js +2 -0
  42. package/dist/core/goal-fleet.js.map +1 -1
  43. package/dist/core/subagent-manager.d.ts +8 -0
  44. package/dist/core/subagent-manager.js +27 -5
  45. package/dist/core/subagent-manager.js.map +1 -1
  46. package/dist/core/validation/backends.d.ts +5 -0
  47. package/dist/core/validation/backends.js +1 -1
  48. package/dist/core/validation/backends.js.map +1 -1
  49. package/dist/core/validation/local-backend.d.ts +17 -1
  50. package/dist/core/validation/local-backend.js +17 -1
  51. package/dist/core/validation/local-backend.js.map +1 -1
  52. package/dist/core/validation/node-backend.js +10 -3
  53. package/dist/core/validation/node-backend.js.map +1 -1
  54. package/dist/core/validation/scheduler.js +3 -0
  55. package/dist/core/validation/scheduler.js.map +1 -1
  56. package/dist/core/validation/service.d.ts +3 -0
  57. package/dist/core/validation/service.js +18 -2
  58. package/dist/core/validation/service.js.map +1 -1
  59. package/dist/core/validation/types.d.ts +6 -0
  60. package/dist/core/validation/types.js.map +1 -1
  61. package/dist/tools/index.js +3 -1
  62. package/dist/tools/index.js.map +1 -1
  63. package/package.json +5 -5
@@ -0,0 +1,83 @@
1
+ import type { ValidationJob } from "../validation/types.js";
2
+ import type { NodeView } from "./fleet-scheduler.js";
3
+ import { type WorkProfile } from "./profiles.js";
4
+ import type { FleetJob } from "./types.js";
5
+ export declare const THIS_COMPUTER = "this computer";
6
+ /** One finished or running piece of work, from either history. */
7
+ export interface RunRecord {
8
+ kind: "job" | "stage";
9
+ name: string;
10
+ machine?: string;
11
+ state: string;
12
+ createdAt: string;
13
+ dispatchedAt?: string;
14
+ startedAt?: string;
15
+ finishedAt?: string;
16
+ /** Machines the work was lost on and moved away from. */
17
+ lostOn: string[];
18
+ peakMemoryGb?: number;
19
+ }
20
+ export interface MachineStats {
21
+ name: string;
22
+ slots?: number;
23
+ online?: boolean;
24
+ /** Under memory/CPU pressure right now (self-tuning slots). */
25
+ pressure?: string;
26
+ runs: number;
27
+ passed: number;
28
+ failed: number;
29
+ /** Seconds spent running work. */
30
+ busySeconds: number;
31
+ /** busy / (slots x active span), 0..1; undefined without slots. */
32
+ utilization?: number;
33
+ /** Times work was lost on this machine and moved elsewhere. */
34
+ lost: number;
35
+ peakMemoryGb?: number;
36
+ }
37
+ export interface FleetReport {
38
+ since: string;
39
+ until: string;
40
+ /** From the first work created to the last finished (the span work existed). */
41
+ activeSeconds: number;
42
+ runs: number;
43
+ passed: number;
44
+ failed: number;
45
+ /** Seconds from queued to dispatched (median, 90th percentile, max). */
46
+ wait: {
47
+ median: number;
48
+ p90: number;
49
+ max: number;
50
+ samples: number;
51
+ };
52
+ recovered: number;
53
+ /** Lost work that still ended in error. */
54
+ unrecovered: number;
55
+ machines: MachineStats[];
56
+ /** Longest kinds of work by learned median time. */
57
+ slowest: Array<{
58
+ key: string;
59
+ seconds: number;
60
+ memoryGb?: number;
61
+ runs: number;
62
+ }>;
63
+ advice: string[];
64
+ }
65
+ export declare function fromFleetJob(j: FleetJob): RunRecord;
66
+ export declare function fromValidationJob(j: ValidationJob): RunRecord;
67
+ export interface ReportInput {
68
+ runs: RunRecord[];
69
+ nodes: NodeView[];
70
+ /** Slots of this computer's local validation stages. */
71
+ localSlots?: number;
72
+ profiles?: Record<string, WorkProfile>;
73
+ sinceMs: number;
74
+ now?: number;
75
+ }
76
+ export declare function buildFleetReport(input: ReportInput): FleetReport;
77
+ /** Plain advice from the measured numbers only. */
78
+ export declare function adviseFrom(r: FleetReport, nodes: readonly NodeView[], finished: number): string[];
79
+ export declare function formatFleetReport(r: FleetReport): string;
80
+ /** "24h", "7d", "90m" -> ms. */
81
+ export declare function parseSince(text: string | undefined): number;
82
+ /** "owner/repo|job:test" -> "test (owner/repo)"; stages and commands likewise. */
83
+ export declare function readableKey(key: string): string;
@@ -0,0 +1,255 @@
1
+ import { expectedOf, formatExpected } from "./profiles.js";
2
+ export const THIS_COMPUTER = "this computer";
3
+ const secs = (a, b) => {
4
+ if (!a || !b)
5
+ return undefined;
6
+ const s = (Date.parse(b) - Date.parse(a)) / 1000;
7
+ return Number.isFinite(s) && s >= 0 ? s : undefined;
8
+ };
9
+ function pct(sorted, p) {
10
+ if (!sorted.length)
11
+ return 0;
12
+ return sorted[Math.min(sorted.length - 1, Math.floor(p * sorted.length))];
13
+ }
14
+ export function fromFleetJob(j) {
15
+ return {
16
+ kind: "job",
17
+ name: j.name,
18
+ ...(j.node && { machine: j.node }),
19
+ state: j.state,
20
+ createdAt: j.createdAt,
21
+ ...(j.dispatchedAt && { dispatchedAt: j.dispatchedAt }),
22
+ ...(j.startedAt && { startedAt: j.startedAt }),
23
+ ...(j.finishedAt && { finishedAt: j.finishedAt }),
24
+ lostOn: (j.requeues ?? []).map((r) => r.from),
25
+ ...(j.peakMemoryGb && { peakMemoryGb: j.peakMemoryGb }),
26
+ };
27
+ }
28
+ export function fromValidationJob(j) {
29
+ const machine = j.backend === "local"
30
+ ? THIS_COMPUTER
31
+ : j.machine && j.machine !== j.backend
32
+ ? j.machine
33
+ : j.backend;
34
+ return {
35
+ kind: "stage",
36
+ name: j.stage,
37
+ ...(machine && { machine }),
38
+ state: j.state,
39
+ createdAt: j.createdAt,
40
+ ...(j.dispatchedAt && { dispatchedAt: j.dispatchedAt }),
41
+ ...(j.startedAt && { startedAt: j.startedAt }),
42
+ ...(j.finishedAt && { finishedAt: j.finishedAt }),
43
+ lostOn: (j.requeues ?? []).map((r) => r.from.split("/").pop() ?? r.from),
44
+ ...(j.peakMemoryGb && { peakMemoryGb: j.peakMemoryGb }),
45
+ };
46
+ }
47
+ export function buildFleetReport(input) {
48
+ const now = input.now ?? Date.now();
49
+ const since = now - input.sinceMs;
50
+ const runs = input.runs.filter((r) => Date.parse(r.finishedAt ?? r.createdAt) >= since);
51
+ const finished = runs.filter((r) => r.finishedAt);
52
+ const passed = runs.filter((r) => r.state === "passed").length;
53
+ const failed = runs.filter((r) => r.state === "failed").length;
54
+ const waits = runs
55
+ .map((r) => secs(r.createdAt, r.dispatchedAt))
56
+ .filter((s) => s !== undefined)
57
+ .sort((a, b) => a - b);
58
+ // Time any work existed (queued to finished), gaps between batches left out.
59
+ const spans = runs
60
+ .map((r) => [Date.parse(r.createdAt), Date.parse(r.finishedAt ?? new Date(now).toISOString())])
61
+ .filter(([a, b]) => Number.isFinite(a) && Number.isFinite(b) && b >= a)
62
+ .sort((x, y) => x[0] - y[0]);
63
+ let activeMs = 0;
64
+ let cur;
65
+ for (const [a, b] of spans) {
66
+ if (cur && a <= cur[1])
67
+ cur[1] = Math.max(cur[1], b);
68
+ else {
69
+ if (cur)
70
+ activeMs += cur[1] - cur[0];
71
+ cur = [a, b];
72
+ }
73
+ }
74
+ if (cur)
75
+ activeMs += cur[1] - cur[0];
76
+ const activeSeconds = runs.length ? Math.max(1, activeMs / 1000) : 0;
77
+ const byName = new Map();
78
+ const machine = (name) => {
79
+ let m = byName.get(name);
80
+ if (!m)
81
+ byName.set(name, (m = { name, runs: 0, passed: 0, failed: 0, busySeconds: 0, lost: 0 }));
82
+ return m;
83
+ };
84
+ for (const n of input.nodes) {
85
+ const m = machine(n.name);
86
+ if (n.info)
87
+ m.slots = n.info.slots;
88
+ m.online = n.online && !n.incompatible;
89
+ if (n.info?.pressure)
90
+ m.pressure = n.info.pressure;
91
+ }
92
+ if (input.localSlots)
93
+ machine(THIS_COMPUTER).slots = input.localSlots;
94
+ for (const r of runs) {
95
+ for (const from of r.lostOn)
96
+ machine(from).lost++;
97
+ if (!r.machine)
98
+ continue;
99
+ const m = machine(r.machine);
100
+ if (r.finishedAt || r.startedAt)
101
+ m.runs++;
102
+ if (r.state === "passed")
103
+ m.passed++;
104
+ if (r.state === "failed")
105
+ m.failed++;
106
+ const s = secs(r.startedAt ?? r.dispatchedAt, r.finishedAt ?? (r.startedAt ? new Date(now).toISOString() : undefined));
107
+ if (s !== undefined)
108
+ m.busySeconds += s;
109
+ if (r.peakMemoryGb && r.peakMemoryGb > (m.peakMemoryGb ?? 0))
110
+ m.peakMemoryGb = r.peakMemoryGb;
111
+ }
112
+ for (const m of byName.values()) {
113
+ if (m.slots && activeSeconds > 0) {
114
+ m.utilization = Math.min(1, m.busySeconds / (m.slots * activeSeconds));
115
+ }
116
+ }
117
+ const machines = [...byName.values()]
118
+ .filter((m) => m.name !== THIS_COMPUTER || m.runs > 0)
119
+ .sort((a, b) => b.busySeconds - a.busySeconds);
120
+ const lostRuns = runs.filter((r) => r.lostOn.length);
121
+ const recovered = lostRuns.filter((r) => r.state === "passed" || r.state === "failed").length;
122
+ const unrecovered = lostRuns.filter((r) => r.state === "error").length;
123
+ const slowest = Object.entries(input.profiles ?? {})
124
+ .map(([key, p]) => ({ key, e: expectedOf(p) }))
125
+ .filter((x) => !!x.e)
126
+ .sort((a, b) => b.e.seconds - a.e.seconds)
127
+ .slice(0, 5)
128
+ .map(({ key, e }) => ({
129
+ key,
130
+ seconds: e.seconds,
131
+ runs: e.runs,
132
+ ...(e.memoryGb && { memoryGb: e.memoryGb }),
133
+ }));
134
+ const report = {
135
+ since: new Date(since).toISOString(),
136
+ until: new Date(now).toISOString(),
137
+ activeSeconds: Math.round(activeSeconds),
138
+ runs: runs.length,
139
+ passed,
140
+ failed,
141
+ wait: {
142
+ median: Math.round(pct(waits, 0.5)),
143
+ p90: Math.round(pct(waits, 0.9)),
144
+ max: Math.round(waits.at(-1) ?? 0),
145
+ samples: waits.length,
146
+ },
147
+ recovered,
148
+ unrecovered,
149
+ machines,
150
+ slowest,
151
+ advice: [],
152
+ };
153
+ report.advice = adviseFrom(report, input.nodes, finished.length);
154
+ return report;
155
+ }
156
+ /** Plain advice from the measured numbers only. */
157
+ export function adviseFrom(r, nodes, finished) {
158
+ const out = [];
159
+ if (!nodes.length) {
160
+ out.push("No other machines are paired, so all work runs on this computer. Pair one with `ezcoder node init` there and `ezcoder fleet add` here.");
161
+ }
162
+ const remote = r.machines.filter((m) => m.name !== THIS_COMPUTER && m.slots);
163
+ const busy = remote.filter((m) => (m.utilization ?? 0) >= 0.7);
164
+ if (r.wait.samples >= 5 && r.wait.p90 >= 60 && remote.length && busy.length === remote.length) {
165
+ out.push(`Work often waited for a free slot (1 in 10 waited ${formatExpected(r.wait.p90).slice(1)} or more) while every machine was at least 70% busy. Another machine, or more slots on one with spare CPU and memory (\`ezcoder node config --slots N\` there), would cut the wait.`);
166
+ }
167
+ const idle = remote.filter((m) => m.online && (m.utilization ?? 0) < 0.1 && m.runs < 2);
168
+ if (finished >= 10 && idle.length && busy.length) {
169
+ out.push(`${idle.map((m) => m.name).join(", ")} took almost no work while ${busy.map((m) => m.name).join(", ")} stayed busy: check its labels, docker and model logins (\`ezcoder fleet nodes\`), since work that needs them can't go there.`);
170
+ }
171
+ for (const m of r.machines.filter((x) => x.lost > 0)) {
172
+ out.push(`${m.name} dropped work ${m.lost} time${m.lost === 1 ? "" : "s"} (it went offline or restarted mid-run; the work moved elsewhere). Check its power, sleep settings and network.`);
173
+ }
174
+ if (r.unrecovered) {
175
+ out.push(`${r.unrecovered} piece${r.unrecovered === 1 ? "" : "s"} of lost work could not be moved (deploys and custom jobs without "retry": true are never re-run on their own). Re-run ${r.unrecovered === 1 ? "it" : "them"} yourself.`);
176
+ }
177
+ for (const m of r.machines.filter((x) => x.pressure)) {
178
+ out.push(`${m.name} is taking no new work right now: ${m.pressure}.`);
179
+ }
180
+ const biggest = Math.max(0, ...nodes.map((n) => n.info?.memoryGb ?? 0));
181
+ for (const s of r.slowest) {
182
+ if (s.memoryGb && biggest && s.memoryGb > biggest * 0.8) {
183
+ out.push(`${readableKey(s.key)} peaks at ${s.memoryGb} GB, close to the biggest machine's ${Math.round(biggest)} GB; a machine with more memory would let it run beside other work.`);
184
+ }
185
+ }
186
+ if (!out.length) {
187
+ out.push(r.runs
188
+ ? "No bottleneck found: the machines kept up with the work."
189
+ : "No work in this period yet.");
190
+ }
191
+ return out;
192
+ }
193
+ const dur = (s) => s < 90
194
+ ? `${Math.round(s)} s`
195
+ : s < 5400
196
+ ? `${Math.round(s / 60)} min`
197
+ : `${(s / 3600).toFixed(1)} h`;
198
+ export function formatFleetReport(r) {
199
+ const lines = [];
200
+ lines.push(`Fleet report, ${r.since.slice(0, 16).replace("T", " ")} to ${r.until.slice(0, 16).replace("T", " ")} UTC`);
201
+ lines.push(`Work: ${r.runs} (${r.passed} passed, ${r.failed} failed), active for ${dur(r.activeSeconds)}`);
202
+ if (r.wait.samples) {
203
+ lines.push(`Wait for a free slot: median ${dur(r.wait.median)}, 1 in 10 over ${dur(r.wait.p90)}, longest ${dur(r.wait.max)}`);
204
+ }
205
+ if (r.recovered || r.unrecovered) {
206
+ lines.push(`Machine failures: ${r.recovered} recovered on another machine, ${r.unrecovered} not`);
207
+ }
208
+ if (r.machines.length) {
209
+ lines.push("", "Machines:");
210
+ for (const m of r.machines) {
211
+ const parts = [
212
+ `${m.runs} run${m.runs === 1 ? "" : "s"}`,
213
+ `busy ${dur(m.busySeconds)}`,
214
+ ...(m.utilization !== undefined
215
+ ? [`${Math.round(m.utilization * 100)}% of ${m.slots} slots`]
216
+ : []),
217
+ ...(m.lost ? [`dropped ${m.lost}`] : []),
218
+ ...(m.peakMemoryGb ? [`peak ${m.peakMemoryGb} GB`] : []),
219
+ ...(m.online === false ? ["offline now"] : []),
220
+ ...(m.pressure ? [`no new work now: ${m.pressure}`] : []),
221
+ ];
222
+ lines.push(` ${m.name}: ${parts.join(", ")}`);
223
+ }
224
+ }
225
+ if (r.slowest.length) {
226
+ lines.push("", "Longest work (learned):");
227
+ for (const s of r.slowest) {
228
+ lines.push(` ${readableKey(s.key)}: usually ${formatExpected(s.seconds).slice(1)}${s.memoryGb ? `, up to ${s.memoryGb} GB` : ""} (${s.runs} run${s.runs === 1 ? "" : "s"})`);
229
+ }
230
+ }
231
+ lines.push("", "Advice:");
232
+ for (const a of r.advice)
233
+ lines.push(` - ${a}`);
234
+ return lines.join("\n");
235
+ }
236
+ /** "24h", "7d", "90m" -> ms. */
237
+ export function parseSince(text) {
238
+ if (!text)
239
+ return 86_400_000;
240
+ const m = /^(\d+(?:\.\d+)?)\s*(m|h|d)$/i.exec(text.trim());
241
+ if (!m)
242
+ throw new Error(`--since must look like 90m, 24h or 7d (got "${text}")`);
243
+ const n = Number(m[1]);
244
+ return n * { m: 60_000, h: 3_600_000, d: 86_400_000 }[m[2].toLowerCase()];
245
+ }
246
+ /** "owner/repo|job:test" -> "test (owner/repo)"; stages and commands likewise. */
247
+ export function readableKey(key) {
248
+ const [project, what] = [key.slice(0, key.lastIndexOf("|")), key.slice(key.lastIndexOf("|") + 1)];
249
+ const m = /^(job|stage|cmd):(.*)$/.exec(what);
250
+ if (!m)
251
+ return key;
252
+ const name = m[1] === "stage" ? `stage ${m[2]}` : m[1] === "cmd" ? "a one-off command" : m[2];
253
+ return `${name} (${project.split("/").slice(-2).join("/")})`;
254
+ }
255
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../../../src/core/fleet/report.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAoB,MAAM,eAAe,CAAC;AAG7E,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAsD7C,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,CAAU,EAAE,EAAE;IACtC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/B,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACjD,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CA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E,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,WAAW,EAAqB,CAAC,CAAC;AAChG,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAClG,MAAM,CAAC,GAAG,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IACnB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9F,OAAO,GAAG,IAAI,KAAK,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/D,CAAC"}
@@ -1,3 +1,5 @@
1
+ import { type FleetReport } from "./report.js";
2
+ import { ProfileStore, type Expected } from "./profiles.js";
1
3
  import { type CloudSettings } from "../cloud/config.js";
2
4
  import { type CloudAvailability, type CloudProvider, type CloudProviderId } from "../cloud/types.js";
3
5
  import type { GateResult } from "../validation/service.js";
@@ -121,6 +123,8 @@ export declare class FleetService {
121
123
  private readonly cloudHooks;
122
124
  private readonly events;
123
125
  private readonly lastInfo;
126
+ /** Learned run time and memory per kind of job (profiles.ts). */
127
+ readonly profiles: ProfileStore;
124
128
  private readonly stuckServiceMs;
125
129
  private readonly cleanupEveryMs;
126
130
  private lastCleanup;
@@ -143,6 +147,8 @@ export declare class FleetService {
143
147
  get maxConcurrent(): number;
144
148
  /** Slots of this machine for local validation stages (backends.json localMaxConcurrent). */
145
149
  localCapacity(): number;
150
+ /** `ezcoder fleet report`: history of fleet jobs and validation stages, plus live nodes. */
151
+ report(sinceMs: number): Promise<FleetReport>;
146
152
  onEvent(listener: (e: FleetEvent) => void): () => void;
147
153
  client(node: FleetNode): FleetClient;
148
154
  private clientFor;
@@ -219,6 +225,9 @@ export declare class FleetService {
219
225
  services: string[];
220
226
  }>;
221
227
  private tickInner;
228
+ private profileKey;
229
+ /** What past runs of this kind of job took (undefined = no history). */
230
+ expectedFor(j: FleetJob): Expected | undefined;
222
231
  private dispatchQueued;
223
232
  /** A dispatch whose answer never arrived: ask the claimed node whether it took the job. */
224
233
  private reconcileClaim;
@@ -3,6 +3,8 @@
3
3
  // dispatches them to nodes with bounded concurrency, polls them, downloads
4
4
  // artifacts, requeues work lost with a node (never deploys) and records results.
5
5
  // Every process watches the shared store and tells its own sessions.
6
+ import { buildFleetReport, fromFleetJob, fromValidationJob } from "./report.js";
7
+ import { jobProfileKey, longestFirst, ProfileStore, runSeconds, } from "./profiles.js";
6
8
  import { EventEmitter } from "node:events";
7
9
  import { randomBytes } from "node:crypto";
8
10
  import fs from "node:fs";
@@ -117,6 +119,8 @@ export class FleetService {
117
119
  cloudHooks;
118
120
  events = new EventEmitter();
119
121
  lastInfo = new Map();
122
+ /** Learned run time and memory per kind of job (profiles.ts). */
123
+ profiles;
120
124
  stuckServiceMs;
121
125
  cleanupEveryMs;
122
126
  lastCleanup = 0;
@@ -136,6 +140,7 @@ export class FleetService {
136
140
  prune: pruneServices,
137
141
  });
138
142
  this.registry = new NodeRegistry(this.dir);
143
+ this.profiles = new ProfileStore(this.dir);
139
144
  this.validationDir = opts.validationDir ?? path.join(path.dirname(this.dir), "validation");
140
145
  this.exec = opts.exec ?? defaultExec;
141
146
  this.git = new FleetGit(this.exec);
@@ -175,6 +180,22 @@ export class FleetService {
175
180
  localCapacity() {
176
181
  return readBackendsFile(this.validationDir).localMaxConcurrent ?? DEFAULT_LOCAL_SLOTS;
177
182
  }
183
+ /** `ezcoder fleet report`: history of fleet jobs and validation stages, plus live nodes. */
184
+ async report(sinceMs) {
185
+ const { JobStore } = await import("../validation/store.js");
186
+ const [jobs, stages, nodes] = await Promise.all([
187
+ this.jobs.read(),
188
+ new JobStore(this.validationDir).read(),
189
+ this.nodeViews(),
190
+ ]);
191
+ return buildFleetReport({
192
+ runs: [...jobs.map(fromFleetJob), ...stages.map(fromValidationJob)],
193
+ nodes,
194
+ localSlots: this.localCapacity(),
195
+ profiles: { ...new ProfileStore(this.validationDir).all(), ...this.profiles.all() },
196
+ sinceMs,
197
+ });
198
+ }
178
199
  onEvent(listener) {
179
200
  this.events.on("event", listener);
180
201
  return () => this.events.off("event", listener);
@@ -852,6 +873,13 @@ export class FleetService {
852
873
  services = await this.services.read();
853
874
  this.observe(jobs, services);
854
875
  }
876
+ profileKey(j) {
877
+ return jobProfileKey(j.projectKey, j.name, j.command, j.adhoc);
878
+ }
879
+ /** What past runs of this kind of job took (undefined = no history). */
880
+ expectedFor(j) {
881
+ return this.profiles.expected(this.profileKey(j));
882
+ }
855
883
  async dispatchQueued(jobs, queued) {
856
884
  const inFlight = jobs
857
885
  .filter((j) => (j.state === "preparing" || j.state === "running") && j.node)
@@ -864,7 +892,8 @@ export class FleetService {
864
892
  }
865
893
  const views = await this.nodeViews();
866
894
  const cloud = this.cloudPass(jobs);
867
- for (const j of queued) {
895
+ // Longest expected work first: a batch finishes sooner (unknowns keep queue order).
896
+ for (const j of longestFirst(queued, (x) => this.expectedFor(x)?.seconds)) {
868
897
  if (count >= this.maxConcurrent)
869
898
  break;
870
899
  if (!canRequeue(j) && j.node && j.remoteId) {
@@ -920,6 +949,10 @@ export class FleetService {
920
949
  ...(last?.node ? { affinity: last.node } : {}),
921
950
  takesSlot: true,
922
951
  };
952
+ const learned = this.expectedFor(j)?.memoryGb;
953
+ if (learned && !j.resources?.memoryGb) {
954
+ req.expectedMemoryGb = Math.round(learned * 1.2 * 10) / 10;
955
+ }
923
956
  let p = chooseNode(req, views, inFlight);
924
957
  const pinnedNode = !!(j.pinned && j.node);
925
958
  if (!pinnedNode && !("node" in p)) {
@@ -1167,6 +1200,18 @@ export class FleetService {
1167
1200
  patch.startedAt = status.startedAt ?? nowIso();
1168
1201
  if (isFleetTerminal(state)) {
1169
1202
  patch.finishedAt = status.finishedAt ?? nowIso();
1203
+ if (status.peakMemoryGb)
1204
+ patch.peakMemoryGb = status.peakMemoryGb;
1205
+ if (state === "passed" || state === "failed") {
1206
+ const seconds = runSeconds(status.startedAt ?? j.startedAt, patch.finishedAt);
1207
+ if (seconds !== undefined) {
1208
+ this.profiles.record(this.profileKey(j), {
1209
+ seconds,
1210
+ ...(status.peakMemoryGb && { memoryGb: status.peakMemoryGb }),
1211
+ ...(j.node && { node: j.node }),
1212
+ });
1213
+ }
1214
+ }
1170
1215
  if (status.exitCode !== undefined)
1171
1216
  patch.exitCode = status.exitCode;
1172
1217
  if (status.artifacts)
@@ -1775,6 +1820,7 @@ export function describeNode(n) {
1775
1820
  `${i.cpus} cpu, ${i.memoryFreeGb}/${i.memoryGb} GB free, load ${i.load.toFixed(2)}${gpus}` +
1776
1821
  `${i.docker ? "" : "; no docker"}${labels.length ? `; labels ${labels.join(",")}` : ""}` +
1777
1822
  `${i.modelAuth ? (i.modelProviders?.length ? `; model login: ${i.modelProviders.join(", ")}` : "; model login ok") : "; no model login"}${n.active ? `; ${n.active} of our jobs` : ""}` +
1823
+ `${i.pressure ? `\n taking no new work right now: ${i.pressure}` : ""}` +
1778
1824
  `${n.updateNotice ? `\n notice: ${n.updateNotice}` : ""}`);
1779
1825
  }
1780
1826
  /** Notification for a job change, or undefined for routine ones. */