@foldrun/core 15.0.0 → 16.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/dist/src/a2a-publish.d.ts +7 -0
- package/dist/src/a2a-publish.js +15 -1
- package/dist/src/a2a-reach.d.ts +156 -0
- package/dist/src/a2a-reach.js +446 -0
- package/dist/src/browse-egress.d.ts +1 -1
- package/dist/src/browse-egress.js +7 -6
- package/dist/src/capture.js +2 -1
- package/dist/src/env-names.d.ts +12 -0
- package/dist/src/env-names.js +49 -0
- package/dist/src/failure.d.ts +92 -0
- package/dist/src/failure.js +294 -0
- package/dist/src/frontmatter-fields.js +1 -1
- package/dist/src/install-helper.js +10 -5
- package/dist/src/mail.js +2 -1
- package/dist/src/network.js +1 -1
- package/dist/src/notify.js +12 -7
- package/dist/src/ops-log.d.ts +55 -0
- package/dist/src/ops-log.js +393 -0
- package/dist/src/otel.d.ts +16 -1
- package/dist/src/otel.js +121 -5
- package/dist/src/run-container.d.ts +55 -3
- package/dist/src/run-container.js +109 -17
- package/dist/src/run-event.d.ts +179 -0
- package/dist/src/run-event.js +473 -0
- package/dist/src/runner.js +14 -5
- package/dist/src/runtime.d.ts +113 -16
- package/dist/src/runtime.js +528 -44
- package/dist/src/scan.js +80 -18
- package/dist/src/secrets.js +4 -3
- package/dist/src/starter.js +1 -1
- package/dist/src/step-exec.d.ts +4 -2
- package/dist/src/step-exec.js +10 -4
- package/dist/src/storage.js +2 -1
- package/dist/src/store.d.ts +25 -3
- package/dist/src/store.js +40 -10
- package/dist/src/triggers.js +6 -5
- package/dist/src/webhook.js +3 -2
- package/package.json +2 -1
- package/src/a2a-publish.ts +19 -1
- package/src/a2a-reach.ts +503 -0
- package/src/browse-egress.ts +8 -7
- package/src/capture.ts +2 -1
- package/src/env-names.ts +53 -0
- package/src/failure.ts +368 -0
- package/src/frontmatter-fields.ts +1 -1
- package/src/install-helper.ts +10 -5
- package/src/mail.ts +2 -1
- package/src/network.ts +1 -1
- package/src/notify.ts +12 -9
- package/src/ops-log.ts +403 -0
- package/src/otel.ts +122 -7
- package/src/run-container.ts +112 -21
- package/src/run-event.ts +563 -0
- package/src/runner.ts +14 -5
- package/src/runtime.ts +543 -45
- package/src/scan.ts +91 -20
- package/src/secrets.ts +4 -5
- package/src/starter.ts +1 -1
- package/src/step-exec.ts +10 -4
- package/src/storage.ts +2 -1
- package/src/store.ts +59 -11
- package/src/triggers.ts +6 -5
- package/src/webhook.ts +3 -2
package/src/failure.ts
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// Why a step failed, said to the customer (FOL-124).
|
|
2
|
+
//
|
|
3
|
+
// A failed step's record keeps every error it wrote; the runs list, the run
|
|
4
|
+
// page, the API and `foldrun report` used to print the last one as it was —
|
|
5
|
+
// "sandbox ended: OOMKilled (exit 137)" — which is true and says nothing
|
|
6
|
+
// about what to do. This is the one place that turns a failed step into
|
|
7
|
+
// three things every surface shows alike:
|
|
8
|
+
//
|
|
9
|
+
// · its class, in the ops log's vocabulary (ops-log.ts ERROR_CLASSES), so
|
|
10
|
+
// the operator's dashboards and the customer's view count the same
|
|
11
|
+
// failure the same way;
|
|
12
|
+
// · a sentence for the customer: exact where the cause is a limit ("used
|
|
13
|
+
// 3.9 GiB of the 4 GiB its size allows"), naming the site where it is a
|
|
14
|
+
// network refusal (the list is the customer's own), and generic — never
|
|
15
|
+
// how it was found — where it is a security control;
|
|
16
|
+
// · what to do: a lighter setting, a larger one, or a plan that allows
|
|
17
|
+
// more.
|
|
18
|
+
//
|
|
19
|
+
// Pure: the web tier, the platform and the CLI read the same answer.
|
|
20
|
+
|
|
21
|
+
import type { ErrorClass } from "./ops-log.ts";
|
|
22
|
+
import { platformCause } from "./issues.ts";
|
|
23
|
+
|
|
24
|
+
/** What went wrong, one level finer than the class: what the message and
|
|
25
|
+
* the fix are about. */
|
|
26
|
+
export const FAILURE_KINDS = [
|
|
27
|
+
"memory", // out of memory, or a step that asks for more than it may hold
|
|
28
|
+
"cpu", // a step that asks for more cores than it may hold
|
|
29
|
+
"disk", // out of disk, or more than it may hold
|
|
30
|
+
"timeout", // ran past its timeout:
|
|
31
|
+
"network", // a site its network: list does not allow
|
|
32
|
+
"security", // stopped by a platform security control
|
|
33
|
+
"budget", // a budget: ran out
|
|
34
|
+
"check", // its verify:, output: json or schema did not hold
|
|
35
|
+
"model", // the model refused, is at its cap, or is overloaded
|
|
36
|
+
"credential", // the model credential was refused
|
|
37
|
+
"stopped", // a person or a key stopped it
|
|
38
|
+
"code", // the account's own code failed: a script, a tool, a hook
|
|
39
|
+
"platform", // ours: a sandbox that could not start, a lost worker
|
|
40
|
+
"other", // none of the above; the step's own words
|
|
41
|
+
] as const;
|
|
42
|
+
export type FailureKind = (typeof FAILURE_KINDS)[number];
|
|
43
|
+
|
|
44
|
+
export interface FailureExplained {
|
|
45
|
+
/** The ops log's class (ops-log.ts) — the same word the operator sees. */
|
|
46
|
+
class: ErrorClass;
|
|
47
|
+
kind: FailureKind;
|
|
48
|
+
/** What happened, for the customer, in one sentence. */
|
|
49
|
+
message: string;
|
|
50
|
+
/** What to do about it, or null when there is nothing they can do. */
|
|
51
|
+
fix: string | null;
|
|
52
|
+
/** A limit's figures, when the cause is one: what the step used or asked
|
|
53
|
+
* for (null when the sandbox ended before it could be read) and what it
|
|
54
|
+
* may hold, in `unit`. */
|
|
55
|
+
used?: number | null;
|
|
56
|
+
allowed?: number;
|
|
57
|
+
unit?: "GiB" | "vCPU" | "s";
|
|
58
|
+
/** Whose limit it was, for a limit: the step's own maximum, its run's,
|
|
59
|
+
* workspace's or account's pool, the install's, or the largest node. */
|
|
60
|
+
scope?: LimitScope;
|
|
61
|
+
/** The site a network refusal named. */
|
|
62
|
+
host?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type LimitScope = "step" | "run" | "workspace" | "account" | "install" | "node";
|
|
66
|
+
|
|
67
|
+
/** The one text a security control writes as a step's error. What it found
|
|
68
|
+
* and how goes to the platform's security record, never to the step's
|
|
69
|
+
* trail: the trail is the customer's. */
|
|
70
|
+
export const SECURITY_STOP = "stopped by a platform security control";
|
|
71
|
+
|
|
72
|
+
/** The only way to write a security stop onto a step: the fixed sentence and
|
|
73
|
+
* the `security` flag, set host-side. It takes no argument on purpose —
|
|
74
|
+
* there is nowhere to put evidence. Text alone never counts as one: a
|
|
75
|
+
* step's own output can say anything (run-container.ts parseDriverLine
|
|
76
|
+
* never copies the flag from a sandbox). */
|
|
77
|
+
export function securityStopEvent(at = new Date()): { t: string; type: "error"; text: string; security: true } {
|
|
78
|
+
return { t: at.toISOString(), type: "error", text: SECURITY_STOP, security: true };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** What a step's row in the runs index keeps so a list can say a limit's
|
|
82
|
+
* figures and a refused site without reading the whole record
|
|
83
|
+
* (store.ts summarizeRun). Absent on rows written before 5 Nov 2026. */
|
|
84
|
+
export interface FailureFacts {
|
|
85
|
+
size?: string;
|
|
86
|
+
memGiB?: number;
|
|
87
|
+
diskGiB?: number;
|
|
88
|
+
peakMemBytes?: number | null;
|
|
89
|
+
/** Sites the egress proxy refused this step — off its network: list, or
|
|
90
|
+
* a site none of its secrets is bound to — newest last, at most five. */
|
|
91
|
+
refusedHosts?: string[];
|
|
92
|
+
secretHosts?: string[];
|
|
93
|
+
/** Its error was a security stop (securityStopEvent). */
|
|
94
|
+
security?: true;
|
|
95
|
+
/** Its error was a failed check's (verify:, output: json, schema:). */
|
|
96
|
+
check?: true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** As much of a step as this reads. */
|
|
100
|
+
export interface FailedStepLike {
|
|
101
|
+
events: { type: string; text: string; check?: boolean; security?: boolean }[];
|
|
102
|
+
size?: string;
|
|
103
|
+
reserved?: { cpus: number; memGiB: number; diskGiB?: number } | null;
|
|
104
|
+
actual?: { peakMemBytes: number | null } | null;
|
|
105
|
+
failureFacts?: FailureFacts;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const GIB = 1024 ** 3;
|
|
109
|
+
/** A figure as the platform's messages write one: 4, 0.5, 3.9. */
|
|
110
|
+
const fmt = (n: number) => String(Math.round(n * 10) / 10);
|
|
111
|
+
|
|
112
|
+
/** The refusal line the egress proxy writes (network.ts refusalText). */
|
|
113
|
+
const REFUSED_SITE = /network: (\S+?) is not a site this step may reach/;
|
|
114
|
+
/** And the bound-secret refusal: a host the step's secrets were not granted to. */
|
|
115
|
+
const REFUSED_SECRET_HOST = /^egress: [A-Z]+ (\S+?) refused — not a host this step's secrets were granted to/;
|
|
116
|
+
|
|
117
|
+
/** The sites the egress proxy refused this step, newest last: from its
|
|
118
|
+
* trail, else what its index row kept. `secret`: refused because no secret
|
|
119
|
+
* is bound to it, not for the network: list. */
|
|
120
|
+
export function refusedSites(step: Pick<FailedStepLike, "events" | "failureFacts">): { host: string; secret: boolean }[] {
|
|
121
|
+
const out: { host: string; secret: boolean }[] = [];
|
|
122
|
+
for (const e of step.events) {
|
|
123
|
+
if (e.type === "error") continue;
|
|
124
|
+
const site = REFUSED_SITE.exec(e.text);
|
|
125
|
+
if (site && /Refused\.\s*$/.test(e.text)) out.push({ host: site[1].toLowerCase(), secret: false });
|
|
126
|
+
const sec = REFUSED_SECRET_HOST.exec(e.text);
|
|
127
|
+
if (sec) out.push({ host: sec[1].toLowerCase(), secret: true });
|
|
128
|
+
}
|
|
129
|
+
if (out.length || !step.failureFacts) return out;
|
|
130
|
+
const secret = new Set(step.failureFacts.secretHosts ?? []);
|
|
131
|
+
return (step.failureFacts.refusedHosts ?? []).map((host) => ({ host, secret: secret.has(host) }));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function refusedHost(line: string): { host: string; secret: boolean } | null {
|
|
135
|
+
const site = REFUSED_SITE.exec(line);
|
|
136
|
+
if (site) return { host: site[1].toLowerCase(), secret: false };
|
|
137
|
+
const sec = REFUSED_SECRET_HOST.exec(line);
|
|
138
|
+
return sec ? { host: sec[1].toLowerCase(), secret: true } : null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** A host as the index may keep one: a DNS name or an address, nothing else. */
|
|
142
|
+
const HOST = /^[a-z0-9._:\[\]-]{1,253}$/;
|
|
143
|
+
|
|
144
|
+
/** What the index row of a failed step keeps for explainFailure: figures and
|
|
145
|
+
* host names, never prose. */
|
|
146
|
+
export function failureFactsOf(step: FailedStepLike): FailureFacts | undefined {
|
|
147
|
+
const sites = refusedSites({ events: step.events }).filter((r) => HOST.test(r.host));
|
|
148
|
+
const hosts = [...new Set(sites.map((r) => r.host))].slice(-5);
|
|
149
|
+
const secretHosts = [...new Set(sites.filter((r) => r.secret).map((r) => r.host))].filter((h) => hosts.includes(h));
|
|
150
|
+
const facts: FailureFacts = {
|
|
151
|
+
...(step.size ? { size: step.size } : {}),
|
|
152
|
+
...(step.reserved?.memGiB ? { memGiB: step.reserved.memGiB } : {}),
|
|
153
|
+
...(step.reserved?.diskGiB ? { diskGiB: step.reserved.diskGiB } : {}),
|
|
154
|
+
...(typeof step.actual?.peakMemBytes === "number" ? { peakMemBytes: step.actual.peakMemBytes } : {}),
|
|
155
|
+
...(hosts.length ? { refusedHosts: hosts } : {}),
|
|
156
|
+
...(secretHosts.length ? { secretHosts } : {}),
|
|
157
|
+
...(step.events.some((e) => e.type === "error" && e.security === true) ? { security: true as const } : {}),
|
|
158
|
+
...(step.events.filter((e) => e.type === "error").at(-1)?.check ? { check: true as const } : {}),
|
|
159
|
+
};
|
|
160
|
+
return Object.keys(facts).length ? facts : undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const UPGRADE = "or a plan that allows more (Settings → Billing)";
|
|
164
|
+
|
|
165
|
+
const SCOPES: Record<string, LimitScope> = {
|
|
166
|
+
"this run's": "run",
|
|
167
|
+
"this workspace's": "workspace",
|
|
168
|
+
"this account's": "account",
|
|
169
|
+
"the install's": "install",
|
|
170
|
+
"the largest node's": "node",
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** The room gate's "never fits" sentences (platform pod-room.ts tooBig —
|
|
174
|
+
* its tests feed every one of them through here). */
|
|
175
|
+
function tooBig(reason: string): FailureExplained | null {
|
|
176
|
+
const kindOf = (unit: string): FailureKind => (unit === "vCPU" ? "cpu" : unit === "GiB" ? "memory" : "disk");
|
|
177
|
+
const one = /this step holds ([\d.]+) (GiB of disk|GiB|vCPU) and one step on this account may hold ([\d.]+)/.exec(reason);
|
|
178
|
+
if (one) {
|
|
179
|
+
const need = Number(one[1]);
|
|
180
|
+
const cap = Number(one[3]);
|
|
181
|
+
const kind = kindOf(one[2]);
|
|
182
|
+
const what = kind === "memory" ? "GiB of memory" : one[2];
|
|
183
|
+
return {
|
|
184
|
+
class: "policy_denied",
|
|
185
|
+
kind,
|
|
186
|
+
message: `This step asks for ${fmt(need)} ${what}; one step on this account may hold ${fmt(cap)} ${kind === "cpu" ? "vCPU" : "GiB"}.`,
|
|
187
|
+
fix: `Ask for less with size: or resources: on the agent, ${UPGRADE}.`,
|
|
188
|
+
used: need,
|
|
189
|
+
allowed: cap,
|
|
190
|
+
unit: kind === "cpu" ? "vCPU" : "GiB",
|
|
191
|
+
scope: "step",
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const pool = /this step holds ([\d.]+) (GiB of disk|GiB|vCPU), more than (this run's|this workspace's|this account's|the install's|the largest node's) ([\d.]+)/.exec(reason);
|
|
195
|
+
if (pool) {
|
|
196
|
+
const need = Number(pool[1]);
|
|
197
|
+
const cap = Number(pool[4]);
|
|
198
|
+
const kind = kindOf(pool[2]);
|
|
199
|
+
const scope = SCOPES[pool[3]];
|
|
200
|
+
const what = kind === "memory" ? "GiB of memory" : pool[2];
|
|
201
|
+
const fix =
|
|
202
|
+
scope === "run" ? "Ask for less with size: or resources: on the agent, or raise the flow's compute:."
|
|
203
|
+
: scope === "workspace" ? "Ask for less with size: or resources: on the agent, or raise the workspace's compute: (its AGENTS.md)."
|
|
204
|
+
: scope === "account" ? `Ask for less with size: or resources: on the agent, raise the account's compute: (Settings → Governance), ${UPGRADE}.`
|
|
205
|
+
: "Ask for less with size: or resources: on the agent: no machine here can hold a step this big.";
|
|
206
|
+
return {
|
|
207
|
+
class: "policy_denied",
|
|
208
|
+
kind,
|
|
209
|
+
message:
|
|
210
|
+
scope === "node"
|
|
211
|
+
? `This step asks for ${fmt(need)} ${what}; the largest machine here holds ${fmt(cap)}.`
|
|
212
|
+
: `This step alone asks for ${fmt(need)} ${what}, more than ${pool[3]} ${fmt(cap)} for all its steps together.`,
|
|
213
|
+
fix,
|
|
214
|
+
used: need,
|
|
215
|
+
allowed: cap,
|
|
216
|
+
unit: kind === "cpu" ? "vCPU" : "GiB",
|
|
217
|
+
scope,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const MEMORY = /\bOOMKilled\b|JavaScript heap out of memory|out of memory|Cannot allocate memory|\bENOMEM\b/i;
|
|
224
|
+
const DISK = /no space left on device|\bENOSPC\b|\bEDQUOT\b|disk quota exceeded|ephemeral local storage usage exceeds/i;
|
|
225
|
+
/** The cluster evicting a step because the MACHINE ran short — not the
|
|
226
|
+
* step over its own limit. */
|
|
227
|
+
const NODE_PRESSURE = /\bEvicted\b[^\n]*\bThe node (was|had) (low on|condition)|\bnode (was )?low on resource\b/i;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Why this failed step failed, for the customer. `reason` is its last error
|
|
231
|
+
* (store.ts runFailure); the step gives the figures a limit's message says.
|
|
232
|
+
*/
|
|
233
|
+
export function explainFailure(reason: string, step?: FailedStepLike | null): FailureExplained {
|
|
234
|
+
const facts = step?.failureFacts;
|
|
235
|
+
const text = String(reason ?? "");
|
|
236
|
+
|
|
237
|
+
// A security control — only the flag a host-side writer sets
|
|
238
|
+
// (securityStopEvent), never words that could come from the step itself.
|
|
239
|
+
if (facts?.security || step?.events.some((e) => e.type === "error" && e.security === true)) {
|
|
240
|
+
return {
|
|
241
|
+
class: "policy_denied",
|
|
242
|
+
kind: "security",
|
|
243
|
+
message: "This step was stopped by a platform security control.",
|
|
244
|
+
fix: "If you think this is a mistake, write to hello@foldrun.io with the run's id.",
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const big = tooBig(text);
|
|
249
|
+
if (big) return big;
|
|
250
|
+
|
|
251
|
+
const memGiB = step?.reserved?.memGiB ?? facts?.memGiB;
|
|
252
|
+
const diskGiB = step?.reserved?.diskGiB ?? facts?.diskGiB;
|
|
253
|
+
const peak = typeof step?.actual?.peakMemBytes === "number" ? step.actual.peakMemBytes : facts?.peakMemBytes ?? null;
|
|
254
|
+
|
|
255
|
+
if (NODE_PRESSURE.test(text)) {
|
|
256
|
+
return {
|
|
257
|
+
class: /ephemeral|disk/i.test(text) ? "disk_full" : "oom",
|
|
258
|
+
kind: "platform",
|
|
259
|
+
message: `The machine the step ran on ran short of ${/ephemeral|disk/i.test(text) ? "disk" : "memory"} and the cluster evicted the step.`,
|
|
260
|
+
fix: "Rerun it; if it happens again, a smaller size: or resources: makes the step easier to place.",
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (DISK.test(text)) {
|
|
264
|
+
const limit = /total limit of containers ([\d.]+)Gi\b/.exec(text);
|
|
265
|
+
const allowed = diskGiB ?? (limit ? Number(limit[1]) : undefined);
|
|
266
|
+
return {
|
|
267
|
+
class: "disk_full",
|
|
268
|
+
kind: "disk",
|
|
269
|
+
message: allowed ? `The step ran out of disk. Disk limit: ${fmt(allowed)} GiB.` : "The step ran out of disk.",
|
|
270
|
+
fix: "Give it more with resources: { disk: … } or a larger size: (up to what your plan allows one step), or have it write less at once — large files in parts.",
|
|
271
|
+
...(allowed ? { used: null, allowed, unit: "GiB" as const, scope: "step" as const } : {}),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (MEMORY.test(text)) {
|
|
275
|
+
const used = peak !== null && peak / GIB > 0.05 ? Math.round((peak / GIB) * 10) / 10 : null;
|
|
276
|
+
return {
|
|
277
|
+
class: "oom",
|
|
278
|
+
kind: "memory",
|
|
279
|
+
message: memGiB
|
|
280
|
+
? `The step ran out of memory. Memory limit: ${fmt(memGiB)} GiB${used !== null ? `; last recorded peak: ${fmt(used)} GiB` : ""}.`
|
|
281
|
+
: "The step ran out of memory.",
|
|
282
|
+
fix: `Give it more with a larger size: (large, heavy) or resources: { memory: … } — up to what your plan allows one step, ${UPGRADE} — or have it hold less at once.`,
|
|
283
|
+
...(memGiB ? { used, allowed: memGiB, unit: "GiB" as const, scope: "step" as const } : {}),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const timedOut = /timed out after (\d+)s \(timeout: in the flow file\)/.exec(text);
|
|
288
|
+
if (timedOut) {
|
|
289
|
+
const secs = Number(timedOut[1]);
|
|
290
|
+
return {
|
|
291
|
+
class: "timeout",
|
|
292
|
+
kind: "timeout",
|
|
293
|
+
message: `The step ran past its timeout: ${secs} seconds.`,
|
|
294
|
+
fix: "Raise timeout: on the step (in seconds), or give it less to do in one step.",
|
|
295
|
+
used: null,
|
|
296
|
+
allowed: secs,
|
|
297
|
+
unit: "s",
|
|
298
|
+
scope: "step",
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
if (/\bDeadlineExceeded\b/.test(text)) {
|
|
302
|
+
return { class: "timeout", kind: "timeout", message: "The step's sandbox ran past its time limit and was ended.", fix: "Rerun it; if it happens again, give the step less to do or a longer timeout:." };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// The error itself is the egress proxy's refusal.
|
|
306
|
+
const direct = refusedHost(text);
|
|
307
|
+
if (direct) return networkRefusal(direct, false);
|
|
308
|
+
|
|
309
|
+
if (/^over budget|is at its budget/.test(text)) {
|
|
310
|
+
return { class: "policy_denied", kind: "budget", message: firstSentence(text), fix: "Raise the budget: it names, or wait for its period to reset." };
|
|
311
|
+
}
|
|
312
|
+
if (/^(run )?stopped by |stopped while waiting for room/.test(text)) {
|
|
313
|
+
return { class: "cancelled", kind: "stopped", message: firstSentence(text), fix: null };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const cause = platformCause(text);
|
|
317
|
+
if (cause) {
|
|
318
|
+
const kind: FailureKind = cause.key === "model-auth" ? "credential" : cause.key === "sandbox" || cause.key === "worker" ? "platform" : "model";
|
|
319
|
+
return {
|
|
320
|
+
class: kind === "platform" ? "platform_error" : kind === "credential" ? "policy_denied" : "model_error",
|
|
321
|
+
kind,
|
|
322
|
+
message: `${cause.label}.`,
|
|
323
|
+
fix: cause.fix.charAt(0).toUpperCase() + cause.fix.slice(1),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const lastError = step?.events.filter((e) => e.type === "error").at(-1);
|
|
328
|
+
if (lastError?.check || facts?.check || /^verify\b|^output: json|^schema:/.test(text)) {
|
|
329
|
+
return { class: "user_code_error", kind: "check", message: `The step's check did not hold: ${firstSentence(text)}`, fix: "Read the step's reply against what the check asks; change the check or the agent's instructions." };
|
|
330
|
+
}
|
|
331
|
+
if (/\b(Claude Code process|model process|the model stream ended|api\.anthropic\.com)\b/.test(text)) {
|
|
332
|
+
return { class: "model_error", kind: "model", message: `The model's process failed: ${firstSentence(text)}`, fix: "Rerun it; if it fails the same way, the step's trail has the model's last words." };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// The step's own program gave up, and the proxy had also refused it a
|
|
336
|
+
// site: both said, the failure first — the trail does not prove which
|
|
337
|
+
// came first, let alone that one caused the other.
|
|
338
|
+
const refused = step ? refusedSites(step).at(-1) : undefined;
|
|
339
|
+
if (refused) return networkRefusal(refused, true, firstSentence(text));
|
|
340
|
+
|
|
341
|
+
if (/exited \(code \d+\)|exit code \d+|\(exit \d+\)|Traceback \(most recent call last\)|^hook\b|^script\b|^tool\b|SyntaxError|TypeError|ReferenceError/.test(text)) {
|
|
342
|
+
return { class: "user_code_error", kind: "code", message: firstSentence(text), fix: "The step's trail has the program's output; fix the script, tool or hook it names and rerun." };
|
|
343
|
+
}
|
|
344
|
+
// A bucket, not a diagnosis: the ops log counts the unknown as ours.
|
|
345
|
+
return { class: "platform_error", kind: "other", message: firstSentence(text), fix: null };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** A site the egress proxy refused, said with the site — the list is the
|
|
349
|
+
* customer's own. `onTrail`: the refusal is only on the trail and the
|
|
350
|
+
* step's error, `after`, is something else. */
|
|
351
|
+
function networkRefusal(r: { host: string; secret: boolean }, onTrail: boolean, after = ""): FailureExplained {
|
|
352
|
+
const why = r.secret ? "none of its secrets is bound to that site" : "it is not on this agent's network: list";
|
|
353
|
+
return {
|
|
354
|
+
class: "policy_denied",
|
|
355
|
+
kind: "network",
|
|
356
|
+
message: onTrail ? `${after.replace(/[.\s]+$/, "")}. A request to ${r.host} was also refused: ${why}.` : `The step was refused ${r.host}: ${why}.`,
|
|
357
|
+
fix: r.secret
|
|
358
|
+
? `If a secret is meant for ${r.host}, bind it there: \`foldrun secrets sites NAME ${r.host}\`.`
|
|
359
|
+
: `If this agent should reach ${r.host}, add just this site: network: [${r.host}] on the agent — the rest of its network: stays as it is.`,
|
|
360
|
+
host: r.host,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The reason's first line, trimmed to a sentence a table cell can hold. */
|
|
365
|
+
function firstSentence(text: string): string {
|
|
366
|
+
const line = (text.split("\n").find((l) => l.trim()) ?? "").trim();
|
|
367
|
+
return line.length > 300 ? `${line.slice(0, 297)}…` : line || "The step failed without saying why.";
|
|
368
|
+
}
|
|
@@ -177,7 +177,7 @@ const FLOW: FieldSpec[] = [
|
|
|
177
177
|
{ key: "budget", type: ["number", "string"], help: "USD per run" },
|
|
178
178
|
{ key: "compute", type: "object", help: "{vcpu, memory, disk} one run's steps may hold together at once — only narrows the workspace's and account's" },
|
|
179
179
|
{ key: "live", type: "boolean", help: "true: steps may act for real in a test run" },
|
|
180
|
-
{ key: "a2a", type: "object", help: "serve this flow to outside agents over A2A 1.0 — {publish: true, name?, description?, examples?, public_card?, input
|
|
180
|
+
{ key: "a2a", type: "object", help: "serve this flow to outside agents over A2A 1.0 — {publish: true, name?, description?, examples?, public_card?, input?, accept_risk?: [agent]}; changing it needs workspace:manage" },
|
|
181
181
|
];
|
|
182
182
|
|
|
183
183
|
const TOOL: FieldSpec[] = [
|
package/src/install-helper.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
// The agent never becomes root. It can only ask this process, over a unix
|
|
7
7
|
// socket, to install Debian packages BY NAME — each name re-checked against
|
|
8
8
|
// Debian's naming rule here, so nothing but a package name reaches apt, and
|
|
9
|
-
// apt is driven by the same snippet the start-up uses (systemInstallSh)
|
|
10
|
-
// account's
|
|
11
|
-
//
|
|
12
|
-
//
|
|
9
|
+
// apt is driven by the same snippet the start-up uses (systemInstallSh), so a
|
|
10
|
+
// package set the account's steps declare in `runtime: system:` is restored
|
|
11
|
+
// from its snapshot in about a second. This helper never SAVES one (FOL-129):
|
|
12
|
+
// it runs while the agent's code does, and what it would seal is a disk the
|
|
13
|
+
// agent has had its hands on — only a start-up, before any agent code exists
|
|
14
|
+
// in the pod, seals. Requests are served one at a time; the process dies with
|
|
15
|
+
// the container.
|
|
13
16
|
//
|
|
14
17
|
// pip and npm need no root and are installed by the tool itself, as the agent.
|
|
15
18
|
|
|
@@ -49,7 +52,9 @@ export function refuse(req: unknown): string | null {
|
|
|
49
52
|
export function installApt(packages: string[], cacheDir: string): Promise<InstallReply> {
|
|
50
53
|
const logDir = fs.mkdtempSync(path.join(os.tmpdir(), "foldrun-install-"));
|
|
51
54
|
return new Promise((resolve) => {
|
|
52
|
-
|
|
55
|
+
// The environment the start-up gave this process (rootStartSh: the
|
|
56
|
+
// step's own reset away, the snapshot key's path in), plus the names.
|
|
57
|
+
const child = spawn("sh", ["-c", systemInstallSh(cacheDir, logDir, { save: false })], {
|
|
53
58
|
env: { ...process.env, FOLDRUN_SYSTEM_PACKAGES: packages.join(" ") },
|
|
54
59
|
stdio: "ignore",
|
|
55
60
|
});
|
package/src/mail.ts
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
// — the platform keeps them as records. A laptop has no preferences store and
|
|
25
25
|
// sends everything, which is what it always did.
|
|
26
26
|
|
|
27
|
+
import { opsError } from "./ops-log.ts";
|
|
27
28
|
import crypto from "node:crypto";
|
|
28
29
|
import { platform } from "./platform.ts";
|
|
29
30
|
import { installKey, publicUrl } from "./webhook.ts";
|
|
@@ -247,7 +248,7 @@ export async function mailWanted(tenant: string, email: string, category: MailCa
|
|
|
247
248
|
} catch (err) {
|
|
248
249
|
// A preferences store that cannot be read sends: a missed alert is
|
|
249
250
|
// worse than one unwanted mail, and the next send asks again.
|
|
250
|
-
|
|
251
|
+
opsError("mail.preference_unreadable", err, { tenant, kind: category, outcome: "sent" }, "warn");
|
|
251
252
|
return true;
|
|
252
253
|
}
|
|
253
254
|
}
|
package/src/network.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
// The rule is enforced at the egress proxy, which every request from a
|
|
24
24
|
// sandbox goes through (HTTPS_PROXY in the pod), and, on the Kubernetes
|
|
25
25
|
// tier, by the pod's network policy: a `trusted` or `none` pod reaches the
|
|
26
|
-
// proxy and DNS
|
|
26
|
+
// proxy and nothing else (DNS too, unless the platform walls it — FOL-128), so a program that ignores the proxy
|
|
27
27
|
// variables fails instead of going round. This file is the vocabulary; the
|
|
28
28
|
// proxy (foldrun-platform egress-proxy.ts) holds the rule per request.
|
|
29
29
|
|
package/src/notify.ts
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
// that works is the quiet kind of good news, and a channel that pings on
|
|
32
32
|
// every success gets muted, which un-pings the failures too.
|
|
33
33
|
|
|
34
|
+
import { opsLog, opsError } from "./ops-log.ts";
|
|
34
35
|
import crypto from "node:crypto";
|
|
35
36
|
import { readAgentsMd } from "./runner.ts";
|
|
36
37
|
import { accountDir, workspaceDir, runCost, readFlow, runVerdict, type RunRecord } from "./store.ts";
|
|
@@ -179,9 +180,7 @@ export function signatureHeaders(
|
|
|
179
180
|
if (!config.signingSecret) return {};
|
|
180
181
|
const secret = getSecret(tenant, config.signingSecret, workspace);
|
|
181
182
|
if (!secret) {
|
|
182
|
-
|
|
183
|
-
`[foldrun] notify: signing_secret names ${signingSecretShown(config.signingSecret)}, which is not in the vault for ${tenant}/${workspace} — sending unsigned`,
|
|
184
|
-
);
|
|
183
|
+
opsLog("warn", "notify.signing_secret_missing", { tenant, workspace, outcome: "sent_unsigned" });
|
|
185
184
|
return {};
|
|
186
185
|
}
|
|
187
186
|
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
@@ -503,7 +502,7 @@ export async function sendPlainNotificationOutcome(
|
|
|
503
502
|
const r = await platform.deliverWebhook(tenant, workspace, { event: msg.event, body: JSON.stringify(body), retry: true });
|
|
504
503
|
return { ok: r.ok, retrying: r.retrying === true };
|
|
505
504
|
} catch (err) {
|
|
506
|
-
|
|
505
|
+
opsError("notify.event_failed", err, { tenant, workspace, kind: msg.event });
|
|
507
506
|
return no;
|
|
508
507
|
}
|
|
509
508
|
}
|
|
@@ -672,7 +671,9 @@ export async function sendRunNotification(
|
|
|
672
671
|
if (config.email) {
|
|
673
672
|
const mail = notifyMail(tenant, workspace);
|
|
674
673
|
if (!mail) {
|
|
675
|
-
|
|
674
|
+
// RESEND_API_KEY (and EMAIL_FROM) on the account, or
|
|
675
|
+
// FOLDRUN_RESEND_API_KEY on the platform.
|
|
676
|
+
opsLog("error", "notify.no_mail_credential", { tenant, workspace });
|
|
676
677
|
return false;
|
|
677
678
|
}
|
|
678
679
|
// A gate is its own category: a person may want failures and not
|
|
@@ -707,7 +708,9 @@ export async function sendRunNotification(
|
|
|
707
708
|
// Resend's body says WHY — "domain not verified", "can only send to
|
|
708
709
|
// your own address" — and a status alone sent someone to the wrong
|
|
709
710
|
// dashboard for twenty minutes on 2026-09-06.
|
|
710
|
-
|
|
711
|
+
// The provider's words stay out of our log (they quote what was
|
|
712
|
+
// sent); the status is what an operator can act on.
|
|
713
|
+
opsLog("error", "notify.email_failed", { tenant, workspace, status: r.status });
|
|
711
714
|
return false;
|
|
712
715
|
}
|
|
713
716
|
return true;
|
|
@@ -717,18 +720,18 @@ export async function sendRunNotification(
|
|
|
717
720
|
// vault instead of in a file that gets committed.
|
|
718
721
|
const target = webhookTarget(tenant, workspace, config);
|
|
719
722
|
if (!target.url) {
|
|
720
|
-
|
|
723
|
+
opsLog("error", "notify.no_webhook_url", { tenant, workspace, reason: target.refused ? "refused" : "secret_not_set" });
|
|
721
724
|
return false;
|
|
722
725
|
}
|
|
723
726
|
const event = blocked ? "blocked" : run.status;
|
|
724
727
|
const r = await platform.deliverWebhook(tenant, workspace, { event, body: JSON.stringify(body), retry: true });
|
|
725
728
|
if (!r.ok) {
|
|
726
|
-
|
|
729
|
+
opsLog("error", "notify.webhook_failed", { tenant, workspace, status: r.statusCode, retrying: r.retrying === true });
|
|
727
730
|
return false;
|
|
728
731
|
}
|
|
729
732
|
return true;
|
|
730
733
|
} catch (err) {
|
|
731
|
-
|
|
734
|
+
opsError("notify.failed", err, { tenant, workspace });
|
|
732
735
|
return false;
|
|
733
736
|
}
|
|
734
737
|
}
|