@foldrun/core 15.1.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/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/network.js +1 -1
- package/dist/src/ops-log.js +4 -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 +8 -1
- 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/starter.js +1 -1
- package/dist/src/store.d.ts +25 -3
- package/dist/src/store.js +40 -10
- 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/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/network.ts +1 -1
- package/src/ops-log.ts +4 -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 +8 -1
- package/src/runtime.ts +543 -45
- package/src/scan.ts +91 -20
- package/src/starter.ts +1 -1
- package/src/store.ts +59 -11
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/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/ops-log.ts
CHANGED
|
@@ -109,6 +109,10 @@ export const FIELDS: Record<string, Kind> = {
|
|
|
109
109
|
// What kind.
|
|
110
110
|
op: "word", role: "word", outcome: "word", reason: "word", stream: "word", kind: "word",
|
|
111
111
|
verdict: "word", phase: "word", signal: "code", where: "word",
|
|
112
|
+
// A run's sandbox (FOL-122): the runner image and size class — the
|
|
113
|
+
// platform's own words — and the model, an identifier like a flow's name
|
|
114
|
+
// (one with `/` or `:` in it does not fit, and is dropped).
|
|
115
|
+
image: "word", size: "word", model: "id",
|
|
112
116
|
// A failure.
|
|
113
117
|
errorClass: "class", errorName: "errorName", code: "code", syscall: "word", cause: "cause",
|
|
114
118
|
at: "frame", frames: "frames", retrying: "bool", ok: "bool",
|
package/src/otel.ts
CHANGED
|
@@ -13,16 +13,42 @@
|
|
|
13
13
|
// whole, like notify:). Ids are derived from the run and span ids, so a run
|
|
14
14
|
// sent twice is the same trace, not two. No OpenTelemetry SDK: the wire
|
|
15
15
|
// format is small, and a dependency in every runner image is not.
|
|
16
|
+
//
|
|
17
|
+
// Names follow the OpenTelemetry GenAI semantic conventions — since 2026 in
|
|
18
|
+
// their own repository, github.com/open-telemetry/semantic-conventions-genai
|
|
19
|
+
// (docs/gen-ai/gen-ai-agent-spans.md, gen-ai-spans.md, client-inference.md;
|
|
20
|
+
// read at 58daeb9, 5 Nov 2026, status Development):
|
|
21
|
+
//
|
|
22
|
+
// run invoke_workflow {flow} INTERNAL gen_ai.workflow.name
|
|
23
|
+
// step invoke_agent {agent} INTERNAL gen_ai.agent.name
|
|
24
|
+
// model call chat {model} CLIENT gen_ai.provider.name, usage
|
|
25
|
+
// tool call execute_tool {tool} INTERNAL gen_ai.tool.name, call.id
|
|
26
|
+
//
|
|
27
|
+
// each with gen_ai.operation.name, and error.type on a failed span. A direct
|
|
28
|
+
// agent run (flow "adhoc:<agent>") is not a workflow — the spec says not to
|
|
29
|
+
// report one for a standalone agent — so its root stays `run adhoc:<agent>`
|
|
30
|
+
// with no operation, and the step under it is the invoke_agent.
|
|
31
|
+
//
|
|
32
|
+
// Content stays out: no gen_ai.input/output.messages, no tool call
|
|
33
|
+
// arguments or results — the spec makes every one of them Opt-In, and a
|
|
34
|
+
// trace is built from the run record alone, which holds none of them (a
|
|
35
|
+
// captured call's content is under runs/<run>/calls/, never read here).
|
|
36
|
+
// What a span says of a failure is its class (error.type) and the step's
|
|
37
|
+
// own error line as the status message, capped.
|
|
16
38
|
|
|
17
39
|
import crypto from "node:crypto";
|
|
18
|
-
import type
|
|
40
|
+
import { isSplicedRecord, type RunRecord, type StepRecord } from "./store.ts";
|
|
19
41
|
import { buildTraceTree, type TraceSpan } from "./trace-tree.ts";
|
|
42
|
+
import { errorClass, type ErrorClass } from "./ops-log.ts";
|
|
43
|
+
import { platformCause } from "./issues.ts";
|
|
20
44
|
|
|
21
45
|
export { parseTelemetry, telemetrySecretNames, telemetryHeaders, type TelemetryConfig } from "./otel-config.ts";
|
|
22
46
|
|
|
23
|
-
type AttrValue = { stringValue: string } | { intValue: string } | { doubleValue: number } | { boolValue: boolean };
|
|
47
|
+
type AttrValue = { stringValue: string } | { intValue: string } | { doubleValue: number } | { boolValue: boolean } | { arrayValue: { values: { stringValue: string }[] } };
|
|
24
48
|
type Attr = { key: string; value: AttrValue };
|
|
25
49
|
|
|
50
|
+
const strings = (key: string, v: readonly string[]): Attr[] => (v.length ? [{ key, value: { arrayValue: { values: v.map((x) => ({ stringValue: x })) } } }] : []);
|
|
51
|
+
|
|
26
52
|
const attr = (key: string, v: string | number | boolean | null | undefined): Attr[] => {
|
|
27
53
|
if (v === null || v === undefined || v === "") return [];
|
|
28
54
|
if (typeof v === "boolean") return [{ key, value: { boolValue: v } }];
|
|
@@ -36,6 +62,55 @@ const nanos = (msEpoch: number) => (BigInt(Math.round(msEpoch)) * BigInt(1_000_0
|
|
|
36
62
|
/** OTLP span kinds: INTERNAL, and CLIENT for a call that leaves the platform. */
|
|
37
63
|
const SPAN_KIND = { internal: 1, client: 3 } as const;
|
|
38
64
|
|
|
65
|
+
/** What `error.type` may say: one of the platform's error classes
|
|
66
|
+
* (ops-log.ts, FOL-121), or the spec's `_OTHER` when the words of the
|
|
67
|
+
* failure match none. The spec asks an instrumentation to document the
|
|
68
|
+
* list it reports; this is it. */
|
|
69
|
+
export const SPAN_ERROR_TYPES = ["timeout", "cancelled", "model_error", "oom", "disk_full", "network_error", "not_found", "policy_denied", "platform_error", "_OTHER"] as const;
|
|
70
|
+
export type SpanErrorType = (typeof SPAN_ERROR_TYPES)[number];
|
|
71
|
+
|
|
72
|
+
/** A failure's class from its words, the way an operator counts them.
|
|
73
|
+
* Only the class leaves: the words stay where they were. */
|
|
74
|
+
export function spanErrorType(text: string | null | undefined, stopped = false): SpanErrorType {
|
|
75
|
+
if (stopped) return "cancelled";
|
|
76
|
+
if (!text) return "_OTHER";
|
|
77
|
+
// What stopRun writes on the step it interrupted, and on the run.
|
|
78
|
+
if (/\b(stopped by a person|cancelled by .+) — sandbox destroyed|^run (stopped|cancelled)\b/.test(text)) return "cancelled";
|
|
79
|
+
const cause = platformCause(text)?.key;
|
|
80
|
+
if (cause === "model-auth" || cause === "model-cap" || cause === "model-busy") return "model_error";
|
|
81
|
+
if (cause === "sandbox" || cause === "worker") return "platform_error";
|
|
82
|
+
if (/\btimed out\b/i.test(text)) return "timeout";
|
|
83
|
+
const cls: ErrorClass = errorClass({ message: text });
|
|
84
|
+
return cls !== "platform_error" && (SPAN_ERROR_TYPES as readonly string[]).includes(cls) ? (cls as SpanErrorType) : "_OTHER";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The step that failed the run, by the runner's own rule (runner.ts: a
|
|
88
|
+
* failed step that is not optional, carried from an earlier run or a
|
|
89
|
+
* spliced record); else any failed one. */
|
|
90
|
+
const failingStep = (run: RunRecord) =>
|
|
91
|
+
run.steps.find((s) => s.status === "failed" && !s.optional && !s.carriedFrom && !isSplicedRecord(s)) ?? run.steps.find((s) => s.status === "failed");
|
|
92
|
+
|
|
93
|
+
const lastError = (s: StepRecord | undefined) => {
|
|
94
|
+
const errors = (s?.events ?? []).filter((e) => e.type === "error");
|
|
95
|
+
return errors[errors.length - 1]?.text ?? null;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** gen_ai.provider.name — the spec's well-known value, only where the record
|
|
99
|
+
* says whose model it was: the platform's own Claude credential, or one of
|
|
100
|
+
* foldrun's models. An account's own provider: block could be anyone's, so
|
|
101
|
+
* it says nothing rather than guess. */
|
|
102
|
+
const PROVIDER: Record<string, string> = { anthropic: "anthropic", openai: "openai", gemini: "gcp.gemini", deepseek: "deepseek", moonshot: "moonshot_ai" };
|
|
103
|
+
function providerOf(step: StepRecord | undefined): string | null {
|
|
104
|
+
if (!step) return null;
|
|
105
|
+
// A refusal retried on the fallback supply (runner.ts) runs calls the
|
|
106
|
+
// step's `supply` does not describe; the record does not say which call
|
|
107
|
+
// went where, so none of them claims a provider.
|
|
108
|
+
if (step.events.some((e) => e.type === "info" && /retrying this step on the fallback provider/.test(e.text))) return null;
|
|
109
|
+
if (step.supply === "operator") return "anthropic";
|
|
110
|
+
if (step.supply === "foldrun" && step.supplyProvider) return PROVIDER[step.supplyProvider] ?? step.supplyProvider;
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
39
114
|
export interface TraceContext {
|
|
40
115
|
tenant: string;
|
|
41
116
|
workspace: string;
|
|
@@ -50,32 +125,72 @@ export function runToOtlp(run: RunRecord, ctx: TraceContext, now = Date.now()) {
|
|
|
50
125
|
const tree = buildTraceTree(run, now);
|
|
51
126
|
const traceId = hex(`foldrun-trace\0${ctx.tenant}\0${ctx.workspace}\0${run.id}`, 32);
|
|
52
127
|
const spans: unknown[] = [];
|
|
128
|
+
const adhoc = run.flow.startsWith("adhoc:");
|
|
53
129
|
const visit = (s: TraceSpan, parent: string | null, inherited: { start: number; agent?: string }) => {
|
|
54
130
|
const spanId = hex(`${traceId}\0${s.id}`, 16);
|
|
55
131
|
const start = s.start ?? inherited.start;
|
|
56
132
|
const end = Math.max(start, s.end ?? s.start ?? now);
|
|
57
133
|
const step = s.step !== undefined ? run.steps[s.step] : undefined;
|
|
58
134
|
const agent = s.kind === "step" ? step?.agent : inherited.agent;
|
|
135
|
+
const operation =
|
|
136
|
+
s.kind === "run" ? (adhoc ? null : "invoke_workflow") : s.kind === "step" ? "invoke_agent" : s.kind === "model" ? "chat" : s.kind === "tool" ? "execute_tool" : null;
|
|
137
|
+
const name =
|
|
138
|
+
s.kind === "run" ? (adhoc ? `run ${s.label}` : `invoke_workflow ${s.label}`)
|
|
139
|
+
: s.kind === "step" ? `invoke_agent ${s.label}`
|
|
140
|
+
: s.kind === "model" ? `chat ${s.model ?? s.label}`
|
|
141
|
+
: s.kind === "tool" ? `execute_tool ${s.label}`
|
|
142
|
+
: s.label;
|
|
143
|
+
// Why it failed, as a class: the run by its failing step, a step by its
|
|
144
|
+
// last error line, an error leaf by its own words. A failed tool call's
|
|
145
|
+
// record holds no words, only that it erred.
|
|
146
|
+
const failed = s.status === "error";
|
|
147
|
+
// A person (or a caller) stopping the run is why the run failed; a step
|
|
148
|
+
// that failed before the stop failed for its own reason — the step the
|
|
149
|
+
// stop interrupted is marked skipped, and its error line says cancelled.
|
|
150
|
+
const stopped = run.stopRequested === true && s.kind === "run";
|
|
151
|
+
const errorText = !failed ? null
|
|
152
|
+
: s.kind === "run" ? lastError(failingStep(run))
|
|
153
|
+
: s.kind === "step" ? lastError(step)
|
|
154
|
+
: s.text ?? null;
|
|
59
155
|
spans.push({
|
|
60
156
|
traceId,
|
|
61
157
|
spanId,
|
|
62
158
|
...(parent ? { parentSpanId: parent } : {}),
|
|
63
|
-
name
|
|
159
|
+
name,
|
|
64
160
|
kind: s.kind === "model" ? SPAN_KIND.client : SPAN_KIND.internal,
|
|
65
161
|
startTimeUnixNano: nanos(start),
|
|
66
162
|
endTimeUnixNano: nanos(end),
|
|
67
163
|
attributes: [
|
|
164
|
+
...attr("gen_ai.operation.name", operation),
|
|
68
165
|
...attr("foldrun.span.kind", s.kind),
|
|
69
166
|
...attr("foldrun.status", s.status),
|
|
70
|
-
...(s.kind === "
|
|
167
|
+
...(s.kind === "run" && !adhoc ? attr("gen_ai.workflow.name", s.label) : []),
|
|
168
|
+
...(s.kind === "step" ? [...attr("gen_ai.agent.name", agent), ...attr("foldrun.agent", agent), ...attr("foldrun.owner", agent ? ctx.owners?.[agent] ?? null : null), ...attr("foldrun.step", s.step)] : []),
|
|
169
|
+
...(s.kind === "model" ? attr("gen_ai.provider.name", providerOf(step)) : []),
|
|
71
170
|
...attr("gen_ai.request.model", s.model),
|
|
72
|
-
...(s.tokens
|
|
171
|
+
...(s.tokens
|
|
172
|
+
? [
|
|
173
|
+
...attr("gen_ai.usage.input_tokens", s.tokens.input),
|
|
174
|
+
...attr("gen_ai.usage.output_tokens", s.tokens.output),
|
|
175
|
+
// The spec's names: "when available and non-zero".
|
|
176
|
+
...(s.tokens.cacheRead ? attr("gen_ai.usage.cache_read.input_tokens", s.tokens.cacheRead) : []),
|
|
177
|
+
...(s.tokens.cacheWrite ? attr("gen_ai.usage.cache_write.input_tokens", s.tokens.cacheWrite) : []),
|
|
178
|
+
// Deprecated (5 Nov 2026): the names this export sent before the
|
|
179
|
+
// spec named them. Kept for one release; read the ones above.
|
|
180
|
+
...attr("gen_ai.usage.cache_read_tokens", s.tokens.cacheRead),
|
|
181
|
+
...attr("gen_ai.usage.cache_write_tokens", s.tokens.cacheWrite),
|
|
182
|
+
]
|
|
183
|
+
: []),
|
|
184
|
+
...(s.stop ? strings("gen_ai.response.finish_reasons", [s.stop]) : []),
|
|
185
|
+
// Deprecated (5 Nov 2026): the singular this export sent before; the
|
|
186
|
+
// spec's is the array above. Kept for one release.
|
|
73
187
|
...attr("gen_ai.response.finish_reason", s.stop),
|
|
74
188
|
...(typeof s.costUsd === "number" ? attr("foldrun.cost_usd", s.costUsd) : []),
|
|
75
|
-
...(s.kind === "tool" ? [...attr("gen_ai.tool.name", s.label), ...attr("gen_ai.tool.call.id", s.call)] : []),
|
|
189
|
+
...(s.kind === "tool" ? [...attr("gen_ai.tool.name", s.label), ...attr("gen_ai.tool.call.id", s.call), ...attr("gen_ai.agent.name", s.subagent ?? agent)] : []),
|
|
76
190
|
...attr("foldrun.subagent", s.subagent),
|
|
191
|
+
...(failed ? attr("error.type", spanErrorType(errorText, stopped)) : []),
|
|
77
192
|
],
|
|
78
|
-
status:
|
|
193
|
+
status: failed ? { code: 2, ...(errorText ? { message: errorText.slice(0, 500) } : {}) } : { code: 0 },
|
|
79
194
|
});
|
|
80
195
|
for (const c of s.children) visit(c, spanId, { start, agent });
|
|
81
196
|
};
|