@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.
Files changed (63) hide show
  1. package/dist/src/a2a-publish.d.ts +7 -0
  2. package/dist/src/a2a-publish.js +15 -1
  3. package/dist/src/a2a-reach.d.ts +156 -0
  4. package/dist/src/a2a-reach.js +446 -0
  5. package/dist/src/browse-egress.d.ts +1 -1
  6. package/dist/src/browse-egress.js +7 -6
  7. package/dist/src/capture.js +2 -1
  8. package/dist/src/env-names.d.ts +12 -0
  9. package/dist/src/env-names.js +49 -0
  10. package/dist/src/failure.d.ts +92 -0
  11. package/dist/src/failure.js +294 -0
  12. package/dist/src/frontmatter-fields.js +1 -1
  13. package/dist/src/install-helper.js +10 -5
  14. package/dist/src/mail.js +2 -1
  15. package/dist/src/network.js +1 -1
  16. package/dist/src/notify.js +12 -7
  17. package/dist/src/ops-log.d.ts +55 -0
  18. package/dist/src/ops-log.js +393 -0
  19. package/dist/src/otel.d.ts +16 -1
  20. package/dist/src/otel.js +121 -5
  21. package/dist/src/run-container.d.ts +55 -3
  22. package/dist/src/run-container.js +109 -17
  23. package/dist/src/run-event.d.ts +179 -0
  24. package/dist/src/run-event.js +473 -0
  25. package/dist/src/runner.js +14 -5
  26. package/dist/src/runtime.d.ts +113 -16
  27. package/dist/src/runtime.js +528 -44
  28. package/dist/src/scan.js +80 -18
  29. package/dist/src/secrets.js +4 -3
  30. package/dist/src/starter.js +1 -1
  31. package/dist/src/step-exec.d.ts +4 -2
  32. package/dist/src/step-exec.js +10 -4
  33. package/dist/src/storage.js +2 -1
  34. package/dist/src/store.d.ts +25 -3
  35. package/dist/src/store.js +40 -10
  36. package/dist/src/triggers.js +6 -5
  37. package/dist/src/webhook.js +3 -2
  38. package/package.json +2 -1
  39. package/src/a2a-publish.ts +19 -1
  40. package/src/a2a-reach.ts +503 -0
  41. package/src/browse-egress.ts +8 -7
  42. package/src/capture.ts +2 -1
  43. package/src/env-names.ts +53 -0
  44. package/src/failure.ts +368 -0
  45. package/src/frontmatter-fields.ts +1 -1
  46. package/src/install-helper.ts +10 -5
  47. package/src/mail.ts +2 -1
  48. package/src/network.ts +1 -1
  49. package/src/notify.ts +12 -9
  50. package/src/ops-log.ts +403 -0
  51. package/src/otel.ts +122 -7
  52. package/src/run-container.ts +112 -21
  53. package/src/run-event.ts +563 -0
  54. package/src/runner.ts +14 -5
  55. package/src/runtime.ts +543 -45
  56. package/src/scan.ts +91 -20
  57. package/src/secrets.ts +4 -5
  58. package/src/starter.ts +1 -1
  59. package/src/step-exec.ts +10 -4
  60. package/src/storage.ts +2 -1
  61. package/src/store.ts +59 -11
  62. package/src/triggers.ts +6 -5
  63. package/src/webhook.ts +3 -2
@@ -15,11 +15,12 @@
15
15
  // executor can wall the step's network (the k8s tier, with the install's
16
16
  // FOLDRUN_BROWSE_ENFORCE=1 — Platform.confinesBrowsing). Such a step gets the
17
17
  // forward proxy like any other, so its run pod is `filtered`: it reaches the
18
- // egress proxy and DNS and nothing else, and the browser runs inside it, in
19
- // the step's own pod. A client that sets another proxy, a CDP context with
20
- // its own proxyServer, a curl that ignores HTTPS_PROXY — each finds no route,
21
- // never a way round the list. Not covered: DNS lookups through the cluster's
22
- // resolver, which the wall admits and nothing here restricts. browseVerdict
18
+ // egress proxy and nothing else, and the browser runs inside it, in the
19
+ // step's own pod. A client that sets another proxy, a CDP context with its
20
+ // own proxyServer, a curl that ignores HTTPS_PROXY — each finds no route,
21
+ // never a way round the list. DNS is the platform's to wall too (FOL-128:
22
+ // foldrun-platform run-dns.ts, FOLDRUN_RUN_DNS_WALL), and its trace says on
23
+ // a `dns:` line whether this sandbox may look names up. browseVerdict
23
24
  // says, for one step, which of the three ways it goes; everywhere else (no
24
25
  // wall, an open or report-only list) the step browses as it did before
25
26
  // phase 3, and the trace says so.
@@ -70,7 +71,7 @@ export function browseVerdict(o) {
70
71
  export function browseNetworkLine(policy, vendor, opts = {}) {
71
72
  const what = networkLine(policy, true);
72
73
  if (opts.hosted) {
73
- return `${what} — enforced — hosted: the browser runs inside this step's sandbox, whose network reaches only the egress proxy (which holds the list) and DNS, so a page, a script or a changed proxy setting reaches no site off the list; DNS lookups themselves are not restricted.`;
74
+ return `${what} — enforced — hosted: the browser runs inside this step's sandbox, whose network reaches only the egress proxy (which holds the list), so a page, a script or a changed proxy setting reaches no site off the list.`;
74
75
  }
75
76
  const { tier, title } = browseTier(vendor);
76
77
  const now = " — not enforced in this step: it may browse, and browsing does not go through the egress proxy here, so the browser and every other program in this step reach sites directly";
@@ -4,6 +4,7 @@
4
4
  // credential or a private key — a key the agent read from a file or a page
5
5
  // is not in the vault, and is still a key. Masked first, cut second, so a
6
6
  // secret on the cap's edge is never kept half. Recording never fails the step.
7
+ import { opsError } from "./ops-log.js";
7
8
  import { redactText } from "./scan.js";
8
9
  import { writeCapturedCall, CAPTURE_CAP } from "./store.js";
9
10
  import { isFileValue, fileContent, isApiValue, apiConfigOf, isClientCertValue, clientCertOf } from "./secrets.js";
@@ -112,7 +113,7 @@ redactSecrets) {
112
113
  return true;
113
114
  }
114
115
  catch (err) {
115
- console.error(`[capture] ${tool} (${callId}) for ${runId}:`, err instanceof Error ? err.message : err);
116
+ opsError("capture.write_failed", err, { tool, runId });
116
117
  return false;
117
118
  }
118
119
  }
@@ -0,0 +1,12 @@
1
+ /** Names that tell the dynamic loader, a shell or a language runtime what to
2
+ * load or run before the program's own code: prefixes end in `*`. */
3
+ export declare const LOADER_ENV: readonly string[];
4
+ /** Names every shell and program reads for where to look and who it is.
5
+ * The root shell keeps the image's values of these; a secret named after
6
+ * one still replaces it for every program the agent runs. */
7
+ export declare const SHELL_ENV: readonly string[];
8
+ /** LOADER_ENV as the arms of a shell `case` (`LD_*|GCONV_PATH|…`). */
9
+ export declare const LOADER_ENV_CASE: string;
10
+ /** Why an environment name is not one to give a secret, or null when it is
11
+ * an ordinary name. */
12
+ export declare function reservedEnvName(name: string): string | null;
@@ -0,0 +1,49 @@
1
+ // Environment names that steer what a program loads or runs rather than
2
+ // carry data (FOL-130). One list, read twice:
3
+ //
4
+ // - run-container.ts strips them from a run container's root shell before
5
+ // anything runs as root (ROOT_SHELL_GUARD_SH) — that shell's environment is
6
+ // the platform's own (the image's, the pod spec's), so this is a second
7
+ // lock, not the boundary: the step's environment never reaches root at all.
8
+ // - scan.ts warns when a `secrets:` entry is named after one of them
9
+ // (secret/reserved-env-name): a secret is exported to the sandbox under its
10
+ // own name, so a secret called LD_PRELOAD or PATH re-points every program
11
+ // the agent runs, which is almost never what its author meant.
12
+ //
13
+ // Pure data, no imports: both the shell snippet and the scanner load it.
14
+ /** Names that tell the dynamic loader, a shell or a language runtime what to
15
+ * load or run before the program's own code: prefixes end in `*`. */
16
+ export const LOADER_ENV = [
17
+ "LD_*",
18
+ "GCONV_PATH",
19
+ "GLIBC_TUNABLES",
20
+ "BASH_ENV",
21
+ "ENV",
22
+ "CDPATH",
23
+ "NODE_OPTIONS",
24
+ "PYTHONPATH",
25
+ "PYTHONHOME",
26
+ "PYTHONSTARTUP",
27
+ "PYTHONUSERBASE",
28
+ "PERL5OPT",
29
+ "PERL5LIB",
30
+ "PERLLIB",
31
+ "RUBYOPT",
32
+ "RUBYLIB",
33
+ ];
34
+ /** Names every shell and program reads for where to look and who it is.
35
+ * The root shell keeps the image's values of these; a secret named after
36
+ * one still replaces it for every program the agent runs. */
37
+ export const SHELL_ENV = ["PATH", "IFS", "HOME", "SHELL", "USER", "LOGNAME", "PWD"];
38
+ /** LOADER_ENV as the arms of a shell `case` (`LD_*|GCONV_PATH|…`). */
39
+ export const LOADER_ENV_CASE = LOADER_ENV.join("|");
40
+ const matches = (name, list) => list.some((p) => (p.endsWith("*") ? name.startsWith(p.slice(0, -1)) : name === p));
41
+ /** Why an environment name is not one to give a secret, or null when it is
42
+ * an ordinary name. */
43
+ export function reservedEnvName(name) {
44
+ if (matches(name, LOADER_ENV))
45
+ return "it tells the loader, the shell or a language runtime what to load into every program the agent starts";
46
+ if (matches(name, SHELL_ENV))
47
+ return "every shell and program in the sandbox reads it, and the secret's value replaces the sandbox's own";
48
+ return null;
49
+ }
@@ -0,0 +1,92 @@
1
+ import type { ErrorClass } from "./ops-log.ts";
2
+ /** What went wrong, one level finer than the class: what the message and
3
+ * the fix are about. */
4
+ export declare const FAILURE_KINDS: readonly ["memory", "cpu", "disk", "timeout", "network", "security", "budget", "check", "model", "credential", "stopped", "code", "platform", "other"];
5
+ export type FailureKind = (typeof FAILURE_KINDS)[number];
6
+ export interface FailureExplained {
7
+ /** The ops log's class (ops-log.ts) — the same word the operator sees. */
8
+ class: ErrorClass;
9
+ kind: FailureKind;
10
+ /** What happened, for the customer, in one sentence. */
11
+ message: string;
12
+ /** What to do about it, or null when there is nothing they can do. */
13
+ fix: string | null;
14
+ /** A limit's figures, when the cause is one: what the step used or asked
15
+ * for (null when the sandbox ended before it could be read) and what it
16
+ * may hold, in `unit`. */
17
+ used?: number | null;
18
+ allowed?: number;
19
+ unit?: "GiB" | "vCPU" | "s";
20
+ /** Whose limit it was, for a limit: the step's own maximum, its run's,
21
+ * workspace's or account's pool, the install's, or the largest node. */
22
+ scope?: LimitScope;
23
+ /** The site a network refusal named. */
24
+ host?: string;
25
+ }
26
+ export type LimitScope = "step" | "run" | "workspace" | "account" | "install" | "node";
27
+ /** The one text a security control writes as a step's error. What it found
28
+ * and how goes to the platform's security record, never to the step's
29
+ * trail: the trail is the customer's. */
30
+ export declare const SECURITY_STOP = "stopped by a platform security control";
31
+ /** The only way to write a security stop onto a step: the fixed sentence and
32
+ * the `security` flag, set host-side. It takes no argument on purpose —
33
+ * there is nowhere to put evidence. Text alone never counts as one: a
34
+ * step's own output can say anything (run-container.ts parseDriverLine
35
+ * never copies the flag from a sandbox). */
36
+ export declare function securityStopEvent(at?: Date): {
37
+ t: string;
38
+ type: "error";
39
+ text: string;
40
+ security: true;
41
+ };
42
+ /** What a step's row in the runs index keeps so a list can say a limit's
43
+ * figures and a refused site without reading the whole record
44
+ * (store.ts summarizeRun). Absent on rows written before 5 Nov 2026. */
45
+ export interface FailureFacts {
46
+ size?: string;
47
+ memGiB?: number;
48
+ diskGiB?: number;
49
+ peakMemBytes?: number | null;
50
+ /** Sites the egress proxy refused this step — off its network: list, or
51
+ * a site none of its secrets is bound to — newest last, at most five. */
52
+ refusedHosts?: string[];
53
+ secretHosts?: string[];
54
+ /** Its error was a security stop (securityStopEvent). */
55
+ security?: true;
56
+ /** Its error was a failed check's (verify:, output: json, schema:). */
57
+ check?: true;
58
+ }
59
+ /** As much of a step as this reads. */
60
+ export interface FailedStepLike {
61
+ events: {
62
+ type: string;
63
+ text: string;
64
+ check?: boolean;
65
+ security?: boolean;
66
+ }[];
67
+ size?: string;
68
+ reserved?: {
69
+ cpus: number;
70
+ memGiB: number;
71
+ diskGiB?: number;
72
+ } | null;
73
+ actual?: {
74
+ peakMemBytes: number | null;
75
+ } | null;
76
+ failureFacts?: FailureFacts;
77
+ }
78
+ /** The sites the egress proxy refused this step, newest last: from its
79
+ * trail, else what its index row kept. `secret`: refused because no secret
80
+ * is bound to it, not for the network: list. */
81
+ export declare function refusedSites(step: Pick<FailedStepLike, "events" | "failureFacts">): {
82
+ host: string;
83
+ secret: boolean;
84
+ }[];
85
+ /** What the index row of a failed step keeps for explainFailure: figures and
86
+ * host names, never prose. */
87
+ export declare function failureFactsOf(step: FailedStepLike): FailureFacts | undefined;
88
+ /**
89
+ * Why this failed step failed, for the customer. `reason` is its last error
90
+ * (store.ts runFailure); the step gives the figures a limit's message says.
91
+ */
92
+ export declare function explainFailure(reason: string, step?: FailedStepLike | null): FailureExplained;
@@ -0,0 +1,294 @@
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
+ import { platformCause } from "./issues.js";
21
+ /** What went wrong, one level finer than the class: what the message and
22
+ * the fix are about. */
23
+ export const FAILURE_KINDS = [
24
+ "memory", // out of memory, or a step that asks for more than it may hold
25
+ "cpu", // a step that asks for more cores than it may hold
26
+ "disk", // out of disk, or more than it may hold
27
+ "timeout", // ran past its timeout:
28
+ "network", // a site its network: list does not allow
29
+ "security", // stopped by a platform security control
30
+ "budget", // a budget: ran out
31
+ "check", // its verify:, output: json or schema did not hold
32
+ "model", // the model refused, is at its cap, or is overloaded
33
+ "credential", // the model credential was refused
34
+ "stopped", // a person or a key stopped it
35
+ "code", // the account's own code failed: a script, a tool, a hook
36
+ "platform", // ours: a sandbox that could not start, a lost worker
37
+ "other", // none of the above; the step's own words
38
+ ];
39
+ /** The one text a security control writes as a step's error. What it found
40
+ * and how goes to the platform's security record, never to the step's
41
+ * trail: the trail is the customer's. */
42
+ export const SECURITY_STOP = "stopped by a platform security control";
43
+ /** The only way to write a security stop onto a step: the fixed sentence and
44
+ * the `security` flag, set host-side. It takes no argument on purpose —
45
+ * there is nowhere to put evidence. Text alone never counts as one: a
46
+ * step's own output can say anything (run-container.ts parseDriverLine
47
+ * never copies the flag from a sandbox). */
48
+ export function securityStopEvent(at = new Date()) {
49
+ return { t: at.toISOString(), type: "error", text: SECURITY_STOP, security: true };
50
+ }
51
+ const GIB = 1024 ** 3;
52
+ /** A figure as the platform's messages write one: 4, 0.5, 3.9. */
53
+ const fmt = (n) => String(Math.round(n * 10) / 10);
54
+ /** The refusal line the egress proxy writes (network.ts refusalText). */
55
+ const REFUSED_SITE = /network: (\S+?) is not a site this step may reach/;
56
+ /** And the bound-secret refusal: a host the step's secrets were not granted to. */
57
+ const REFUSED_SECRET_HOST = /^egress: [A-Z]+ (\S+?) refused — not a host this step's secrets were granted to/;
58
+ /** The sites the egress proxy refused this step, newest last: from its
59
+ * trail, else what its index row kept. `secret`: refused because no secret
60
+ * is bound to it, not for the network: list. */
61
+ export function refusedSites(step) {
62
+ const out = [];
63
+ for (const e of step.events) {
64
+ if (e.type === "error")
65
+ continue;
66
+ const site = REFUSED_SITE.exec(e.text);
67
+ if (site && /Refused\.\s*$/.test(e.text))
68
+ out.push({ host: site[1].toLowerCase(), secret: false });
69
+ const sec = REFUSED_SECRET_HOST.exec(e.text);
70
+ if (sec)
71
+ out.push({ host: sec[1].toLowerCase(), secret: true });
72
+ }
73
+ if (out.length || !step.failureFacts)
74
+ return out;
75
+ const secret = new Set(step.failureFacts.secretHosts ?? []);
76
+ return (step.failureFacts.refusedHosts ?? []).map((host) => ({ host, secret: secret.has(host) }));
77
+ }
78
+ function refusedHost(line) {
79
+ const site = REFUSED_SITE.exec(line);
80
+ if (site)
81
+ return { host: site[1].toLowerCase(), secret: false };
82
+ const sec = REFUSED_SECRET_HOST.exec(line);
83
+ return sec ? { host: sec[1].toLowerCase(), secret: true } : null;
84
+ }
85
+ /** A host as the index may keep one: a DNS name or an address, nothing else. */
86
+ const HOST = /^[a-z0-9._:\[\]-]{1,253}$/;
87
+ /** What the index row of a failed step keeps for explainFailure: figures and
88
+ * host names, never prose. */
89
+ export function failureFactsOf(step) {
90
+ const sites = refusedSites({ events: step.events }).filter((r) => HOST.test(r.host));
91
+ const hosts = [...new Set(sites.map((r) => r.host))].slice(-5);
92
+ const secretHosts = [...new Set(sites.filter((r) => r.secret).map((r) => r.host))].filter((h) => hosts.includes(h));
93
+ const facts = {
94
+ ...(step.size ? { size: step.size } : {}),
95
+ ...(step.reserved?.memGiB ? { memGiB: step.reserved.memGiB } : {}),
96
+ ...(step.reserved?.diskGiB ? { diskGiB: step.reserved.diskGiB } : {}),
97
+ ...(typeof step.actual?.peakMemBytes === "number" ? { peakMemBytes: step.actual.peakMemBytes } : {}),
98
+ ...(hosts.length ? { refusedHosts: hosts } : {}),
99
+ ...(secretHosts.length ? { secretHosts } : {}),
100
+ ...(step.events.some((e) => e.type === "error" && e.security === true) ? { security: true } : {}),
101
+ ...(step.events.filter((e) => e.type === "error").at(-1)?.check ? { check: true } : {}),
102
+ };
103
+ return Object.keys(facts).length ? facts : undefined;
104
+ }
105
+ const UPGRADE = "or a plan that allows more (Settings → Billing)";
106
+ const SCOPES = {
107
+ "this run's": "run",
108
+ "this workspace's": "workspace",
109
+ "this account's": "account",
110
+ "the install's": "install",
111
+ "the largest node's": "node",
112
+ };
113
+ /** The room gate's "never fits" sentences (platform pod-room.ts tooBig —
114
+ * its tests feed every one of them through here). */
115
+ function tooBig(reason) {
116
+ const kindOf = (unit) => (unit === "vCPU" ? "cpu" : unit === "GiB" ? "memory" : "disk");
117
+ const one = /this step holds ([\d.]+) (GiB of disk|GiB|vCPU) and one step on this account may hold ([\d.]+)/.exec(reason);
118
+ if (one) {
119
+ const need = Number(one[1]);
120
+ const cap = Number(one[3]);
121
+ const kind = kindOf(one[2]);
122
+ const what = kind === "memory" ? "GiB of memory" : one[2];
123
+ return {
124
+ class: "policy_denied",
125
+ kind,
126
+ message: `This step asks for ${fmt(need)} ${what}; one step on this account may hold ${fmt(cap)} ${kind === "cpu" ? "vCPU" : "GiB"}.`,
127
+ fix: `Ask for less with size: or resources: on the agent, ${UPGRADE}.`,
128
+ used: need,
129
+ allowed: cap,
130
+ unit: kind === "cpu" ? "vCPU" : "GiB",
131
+ scope: "step",
132
+ };
133
+ }
134
+ 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);
135
+ if (pool) {
136
+ const need = Number(pool[1]);
137
+ const cap = Number(pool[4]);
138
+ const kind = kindOf(pool[2]);
139
+ const scope = SCOPES[pool[3]];
140
+ const what = kind === "memory" ? "GiB of memory" : pool[2];
141
+ const fix = scope === "run" ? "Ask for less with size: or resources: on the agent, or raise the flow's compute:."
142
+ : scope === "workspace" ? "Ask for less with size: or resources: on the agent, or raise the workspace's compute: (its AGENTS.md)."
143
+ : scope === "account" ? `Ask for less with size: or resources: on the agent, raise the account's compute: (Settings → Governance), ${UPGRADE}.`
144
+ : "Ask for less with size: or resources: on the agent: no machine here can hold a step this big.";
145
+ return {
146
+ class: "policy_denied",
147
+ kind,
148
+ message: scope === "node"
149
+ ? `This step asks for ${fmt(need)} ${what}; the largest machine here holds ${fmt(cap)}.`
150
+ : `This step alone asks for ${fmt(need)} ${what}, more than ${pool[3]} ${fmt(cap)} for all its steps together.`,
151
+ fix,
152
+ used: need,
153
+ allowed: cap,
154
+ unit: kind === "cpu" ? "vCPU" : "GiB",
155
+ scope,
156
+ };
157
+ }
158
+ return null;
159
+ }
160
+ const MEMORY = /\bOOMKilled\b|JavaScript heap out of memory|out of memory|Cannot allocate memory|\bENOMEM\b/i;
161
+ const DISK = /no space left on device|\bENOSPC\b|\bEDQUOT\b|disk quota exceeded|ephemeral local storage usage exceeds/i;
162
+ /** The cluster evicting a step because the MACHINE ran short — not the
163
+ * step over its own limit. */
164
+ const NODE_PRESSURE = /\bEvicted\b[^\n]*\bThe node (was|had) (low on|condition)|\bnode (was )?low on resource\b/i;
165
+ /**
166
+ * Why this failed step failed, for the customer. `reason` is its last error
167
+ * (store.ts runFailure); the step gives the figures a limit's message says.
168
+ */
169
+ export function explainFailure(reason, step) {
170
+ const facts = step?.failureFacts;
171
+ const text = String(reason ?? "");
172
+ // A security control — only the flag a host-side writer sets
173
+ // (securityStopEvent), never words that could come from the step itself.
174
+ if (facts?.security || step?.events.some((e) => e.type === "error" && e.security === true)) {
175
+ return {
176
+ class: "policy_denied",
177
+ kind: "security",
178
+ message: "This step was stopped by a platform security control.",
179
+ fix: "If you think this is a mistake, write to hello@foldrun.io with the run's id.",
180
+ };
181
+ }
182
+ const big = tooBig(text);
183
+ if (big)
184
+ return big;
185
+ const memGiB = step?.reserved?.memGiB ?? facts?.memGiB;
186
+ const diskGiB = step?.reserved?.diskGiB ?? facts?.diskGiB;
187
+ const peak = typeof step?.actual?.peakMemBytes === "number" ? step.actual.peakMemBytes : facts?.peakMemBytes ?? null;
188
+ if (NODE_PRESSURE.test(text)) {
189
+ return {
190
+ class: /ephemeral|disk/i.test(text) ? "disk_full" : "oom",
191
+ kind: "platform",
192
+ message: `The machine the step ran on ran short of ${/ephemeral|disk/i.test(text) ? "disk" : "memory"} and the cluster evicted the step.`,
193
+ fix: "Rerun it; if it happens again, a smaller size: or resources: makes the step easier to place.",
194
+ };
195
+ }
196
+ if (DISK.test(text)) {
197
+ const limit = /total limit of containers ([\d.]+)Gi\b/.exec(text);
198
+ const allowed = diskGiB ?? (limit ? Number(limit[1]) : undefined);
199
+ return {
200
+ class: "disk_full",
201
+ kind: "disk",
202
+ message: allowed ? `The step ran out of disk. Disk limit: ${fmt(allowed)} GiB.` : "The step ran out of disk.",
203
+ 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.",
204
+ ...(allowed ? { used: null, allowed, unit: "GiB", scope: "step" } : {}),
205
+ };
206
+ }
207
+ if (MEMORY.test(text)) {
208
+ const used = peak !== null && peak / GIB > 0.05 ? Math.round((peak / GIB) * 10) / 10 : null;
209
+ return {
210
+ class: "oom",
211
+ kind: "memory",
212
+ message: memGiB
213
+ ? `The step ran out of memory. Memory limit: ${fmt(memGiB)} GiB${used !== null ? `; last recorded peak: ${fmt(used)} GiB` : ""}.`
214
+ : "The step ran out of memory.",
215
+ 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.`,
216
+ ...(memGiB ? { used, allowed: memGiB, unit: "GiB", scope: "step" } : {}),
217
+ };
218
+ }
219
+ const timedOut = /timed out after (\d+)s \(timeout: in the flow file\)/.exec(text);
220
+ if (timedOut) {
221
+ const secs = Number(timedOut[1]);
222
+ return {
223
+ class: "timeout",
224
+ kind: "timeout",
225
+ message: `The step ran past its timeout: ${secs} seconds.`,
226
+ fix: "Raise timeout: on the step (in seconds), or give it less to do in one step.",
227
+ used: null,
228
+ allowed: secs,
229
+ unit: "s",
230
+ scope: "step",
231
+ };
232
+ }
233
+ if (/\bDeadlineExceeded\b/.test(text)) {
234
+ 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:." };
235
+ }
236
+ // The error itself is the egress proxy's refusal.
237
+ const direct = refusedHost(text);
238
+ if (direct)
239
+ return networkRefusal(direct, false);
240
+ if (/^over budget|is at its budget/.test(text)) {
241
+ return { class: "policy_denied", kind: "budget", message: firstSentence(text), fix: "Raise the budget: it names, or wait for its period to reset." };
242
+ }
243
+ if (/^(run )?stopped by |stopped while waiting for room/.test(text)) {
244
+ return { class: "cancelled", kind: "stopped", message: firstSentence(text), fix: null };
245
+ }
246
+ const cause = platformCause(text);
247
+ if (cause) {
248
+ const kind = cause.key === "model-auth" ? "credential" : cause.key === "sandbox" || cause.key === "worker" ? "platform" : "model";
249
+ return {
250
+ class: kind === "platform" ? "platform_error" : kind === "credential" ? "policy_denied" : "model_error",
251
+ kind,
252
+ message: `${cause.label}.`,
253
+ fix: cause.fix.charAt(0).toUpperCase() + cause.fix.slice(1),
254
+ };
255
+ }
256
+ const lastError = step?.events.filter((e) => e.type === "error").at(-1);
257
+ if (lastError?.check || facts?.check || /^verify\b|^output: json|^schema:/.test(text)) {
258
+ 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." };
259
+ }
260
+ if (/\b(Claude Code process|model process|the model stream ended|api\.anthropic\.com)\b/.test(text)) {
261
+ 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." };
262
+ }
263
+ // The step's own program gave up, and the proxy had also refused it a
264
+ // site: both said, the failure first — the trail does not prove which
265
+ // came first, let alone that one caused the other.
266
+ const refused = step ? refusedSites(step).at(-1) : undefined;
267
+ if (refused)
268
+ return networkRefusal(refused, true, firstSentence(text));
269
+ 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)) {
270
+ 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." };
271
+ }
272
+ // A bucket, not a diagnosis: the ops log counts the unknown as ours.
273
+ return { class: "platform_error", kind: "other", message: firstSentence(text), fix: null };
274
+ }
275
+ /** A site the egress proxy refused, said with the site — the list is the
276
+ * customer's own. `onTrail`: the refusal is only on the trail and the
277
+ * step's error, `after`, is something else. */
278
+ function networkRefusal(r, onTrail, after = "") {
279
+ const why = r.secret ? "none of its secrets is bound to that site" : "it is not on this agent's network: list";
280
+ return {
281
+ class: "policy_denied",
282
+ kind: "network",
283
+ message: onTrail ? `${after.replace(/[.\s]+$/, "")}. A request to ${r.host} was also refused: ${why}.` : `The step was refused ${r.host}: ${why}.`,
284
+ fix: r.secret
285
+ ? `If a secret is meant for ${r.host}, bind it there: \`foldrun secrets sites NAME ${r.host}\`.`
286
+ : `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.`,
287
+ host: r.host,
288
+ };
289
+ }
290
+ /** The reason's first line, trimmed to a sentence a table cell can hold. */
291
+ function firstSentence(text) {
292
+ const line = (text.split("\n").find((l) => l.trim()) ?? "").trim();
293
+ return line.length > 300 ? `${line.slice(0, 297)}…` : line || "The step failed without saying why.";
294
+ }
@@ -130,7 +130,7 @@ const FLOW = [
130
130
  { key: "budget", type: ["number", "string"], help: "USD per run" },
131
131
  { 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" },
132
132
  { key: "live", type: "boolean", help: "true: steps may act for real in a test run" },
133
- { key: "a2a", type: "object", help: "serve this flow to outside agents over A2A 1.0 — {publish: true, name?, description?, examples?, public_card?, input?}; changing it needs workspace:manage" },
133
+ { 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" },
134
134
  ];
135
135
  const TOOL = [
136
136
  { key: "name", type: "string", help: "defaults to the file or folder name" },
@@ -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): the
10
- // account's .deb cache and snapshots, so a package anyone installed before is
11
- // restored in about a second. Requests are served one at a time; the process
12
- // dies with the container.
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
  import fs from "node:fs";
@@ -38,7 +41,9 @@ export function refuse(req) {
38
41
  export function installApt(packages, cacheDir) {
39
42
  const logDir = fs.mkdtempSync(path.join(os.tmpdir(), "foldrun-install-"));
40
43
  return new Promise((resolve) => {
41
- const child = spawn("sh", ["-c", systemInstallSh(cacheDir, logDir)], {
44
+ // The environment the start-up gave this process (rootStartSh: the
45
+ // step's own reset away, the snapshot key's path in), plus the names.
46
+ const child = spawn("sh", ["-c", systemInstallSh(cacheDir, logDir, { save: false })], {
42
47
  env: { ...process.env, FOLDRUN_SYSTEM_PACKAGES: packages.join(" ") },
43
48
  stdio: "ignore",
44
49
  });
package/dist/src/mail.js CHANGED
@@ -23,6 +23,7 @@
23
23
  // The preference is asked at send time, here, through platform.mailPreference
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
+ import { opsError } from "./ops-log.js";
26
27
  import crypto from "node:crypto";
27
28
  import { platform } from "./platform.js";
28
29
  import { installKey, publicUrl } from "./webhook.js";
@@ -178,7 +179,7 @@ export async function mailWanted(tenant, email, category, workspace = null) {
178
179
  catch (err) {
179
180
  // A preferences store that cannot be read sends: a missed alert is
180
181
  // worse than one unwanted mail, and the next send asks again.
181
- console.error(`[foldrun] mail: preference for ${category} unreadable, sending:`, err instanceof Error ? err.message : err);
182
+ opsError("mail.preference_unreadable", err, { tenant, kind: category, outcome: "sent" }, "warn");
182
183
  return true;
183
184
  }
184
185
  }
@@ -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 and nothing else, so a program that ignores the proxy
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
  /** How wide a step's network is. */
@@ -30,6 +30,7 @@
30
30
  // Defaults: failed and awaiting-approval. Completed is opt-in — a schedule
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
+ import { opsLog, opsError } from "./ops-log.js";
33
34
  import crypto from "node:crypto";
34
35
  import { readAgentsMd } from "./runner.js";
35
36
  import { accountDir, workspaceDir, runCost, readFlow, runVerdict } from "./store.js";
@@ -159,7 +160,7 @@ export function signatureHeaders(tenant, workspace, config, body) {
159
160
  return {};
160
161
  const secret = getSecret(tenant, config.signingSecret, workspace);
161
162
  if (!secret) {
162
- console.error(`[foldrun] notify: signing_secret names ${signingSecretShown(config.signingSecret)}, which is not in the vault for ${tenant}/${workspace} — sending unsigned`);
163
+ opsLog("warn", "notify.signing_secret_missing", { tenant, workspace, outcome: "sent_unsigned" });
163
164
  return {};
164
165
  }
165
166
  const timestamp = Math.floor(Date.now() / 1000).toString();
@@ -437,7 +438,7 @@ export async function sendPlainNotificationOutcome(tenant, workspace, msg) {
437
438
  return { ok: r.ok, retrying: r.retrying === true };
438
439
  }
439
440
  catch (err) {
440
- console.error(`[foldrun] notify (${msg.event}): ${tenant}/${workspace} →`, err instanceof Error ? err.message : err);
441
+ opsError("notify.event_failed", err, { tenant, workspace, kind: msg.event });
441
442
  return no;
442
443
  }
443
444
  }
@@ -594,7 +595,9 @@ export async function sendRunNotification(tenant, workspace, run) {
594
595
  if (config.email) {
595
596
  const mail = notifyMail(tenant, workspace);
596
597
  if (!mail) {
597
- console.error(`[foldrun] notify: email configured but no mail credential — set RESEND_API_KEY (and EMAIL_FROM) on the account ${tenant}, or FOLDRUN_RESEND_API_KEY on the platform`);
598
+ // RESEND_API_KEY (and EMAIL_FROM) on the account, or
599
+ // FOLDRUN_RESEND_API_KEY on the platform.
600
+ opsLog("error", "notify.no_mail_credential", { tenant, workspace });
598
601
  return false;
599
602
  }
600
603
  // A gate is its own category: a person may want failures and not
@@ -629,7 +632,9 @@ export async function sendRunNotification(tenant, workspace, run) {
629
632
  // Resend's body says WHY — "domain not verified", "can only send to
630
633
  // your own address" — and a status alone sent someone to the wrong
631
634
  // dashboard for twenty minutes on 2026-09-06.
632
- console.error(`[foldrun] notify email: ${tenant}/${workspace} → ${r.status ? `HTTP ${r.status} ` : ""}${r.error ?? ""}`);
635
+ // The provider's words stay out of our log (they quote what was
636
+ // sent); the status is what an operator can act on.
637
+ opsLog("error", "notify.email_failed", { tenant, workspace, status: r.status });
633
638
  return false;
634
639
  }
635
640
  return true;
@@ -638,19 +643,19 @@ export async function sendRunNotification(tenant, workspace, run) {
638
643
  // vault instead of in a file that gets committed.
639
644
  const target = webhookTarget(tenant, workspace, config);
640
645
  if (!target.url) {
641
- console.error(`[foldrun] notify: ${target.refused ?? "secret in URL not set"} for ${tenant}/${workspace}`);
646
+ opsLog("error", "notify.no_webhook_url", { tenant, workspace, reason: target.refused ? "refused" : "secret_not_set" });
642
647
  return false;
643
648
  }
644
649
  const event = blocked ? "blocked" : run.status;
645
650
  const r = await platform.deliverWebhook(tenant, workspace, { event, body: JSON.stringify(body), retry: true });
646
651
  if (!r.ok) {
647
- console.error(`[foldrun] notify: ${tenant}/${workspace} → ${r.statusCode ? `HTTP ${r.statusCode}` : r.detail}${r.retrying ? " (will retry)" : ""}`);
652
+ opsLog("error", "notify.webhook_failed", { tenant, workspace, status: r.statusCode, retrying: r.retrying === true });
648
653
  return false;
649
654
  }
650
655
  return true;
651
656
  }
652
657
  catch (err) {
653
- console.error(`[foldrun] notify: ${tenant}/${workspace} →`, err instanceof Error ? err.message : err);
658
+ opsError("notify.failed", err, { tenant, workspace });
654
659
  return false;
655
660
  }
656
661
  }