@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52
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/CHANGELOG.md +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
// opens for the claim (held.ts), never the key. The runner keeps the claim, its renewals, its commands and its end.
|
|
7
7
|
//
|
|
8
8
|
// Where the image's helper can switch (agentrun-runas, root:node 0750 with file capabilities), each of the runner's claim
|
|
9
|
-
// slots runs as a uid of its own (1001 + slot), in
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
9
|
+
// slots runs as a uid of its own (1001 + slot), in its own group alone. While a run holds its slot, its folders are the
|
|
10
|
+
// slot's uid's and the runner's group's (2770, setgid, the helper's `own <slot>`), which the server's user reads through
|
|
11
|
+
// that one group: the server's user is in no slot's group, and no slot is in the server's, so one run can read neither
|
|
12
|
+
// another run's folder nor, being another uid, its memory. A slot is reaped at each run's end (every process of its uid
|
|
13
|
+
// killed, its files in /tmp removed), and its folders are given back to the server's user (`own runner`), so the slot's
|
|
14
|
+
// next run reaches nothing of them.
|
|
13
15
|
import { execFile, spawn } from "node:child_process";
|
|
14
16
|
import { existsSync } from "node:fs";
|
|
15
|
-
import { chmod,
|
|
17
|
+
import { chmod, mkdir, rm } from "node:fs/promises";
|
|
16
18
|
import { dirname, join } from "node:path";
|
|
17
19
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
18
20
|
import { encode, SECRET_NAMES, SECRETS_FD_ENV, SECRETS_LEN_ENV, withoutSecrets } from "../secrets.js";
|
|
@@ -51,12 +53,12 @@ import { liveForRun, runnerLiveOf } from "../live-reach.js";
|
|
|
51
53
|
import { learningFolderOf, secretsShown } from "../learning.js";
|
|
52
54
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
53
55
|
import { messageText } from "../run-manifest.js";
|
|
54
|
-
import { placeRunInputs } from "../uploads.js";
|
|
56
|
+
import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
55
57
|
import { withAudit } from "./audit.js";
|
|
56
58
|
import { compareEndOfRun } from "./compare-end.js";
|
|
57
59
|
import { learnedFirst } from "./learned-first.js";
|
|
58
60
|
import { workflowsAt } from "./learning-seed.js";
|
|
59
|
-
import { heldMcpOf, mcpForClaim } from "./mcp-run.js";
|
|
61
|
+
import { heldMcpOf, mcpForClaim, mediaForClaim } from "./mcp-run.js";
|
|
60
62
|
import { learnedTiers, learnsWorkflows, mcpReachOf } from "./adapter-run-spec.js";
|
|
61
63
|
import { createDispatchLoop } from "./dispatch.js";
|
|
62
64
|
import { resolveRunnerLoop, withSavedGatewayDeps } from "./harness-loops.js";
|
|
@@ -69,7 +71,7 @@ import { registerRunErrors } from "./run-errors.js";
|
|
|
69
71
|
import { exposeSaveSlots } from "./save-slots.js";
|
|
70
72
|
import { runBigWrites } from "./big-writes.js";
|
|
71
73
|
import { SERVER_SLOTS } from "../web-save.js";
|
|
72
|
-
import { readLaunchBody } from "../run-launch.js";
|
|
74
|
+
import { launchOnItsDisk, readLaunchBody } from "../run-launch.js";
|
|
73
75
|
import { SUBAGENT_TOOL } from "./subagent.js";
|
|
74
76
|
/** The image's helper that starts a run's process as its slot's uid (packages/serve/runas). */
|
|
75
77
|
export const RUNAS_HELPER = "/usr/local/bin/agentrun-runas";
|
|
@@ -265,121 +267,51 @@ const runParents = (data, agentId, runId) => {
|
|
|
265
267
|
const scratch = scratchFolder(data, agentId, runId);
|
|
266
268
|
return [data, join(data, "disk"), join(data, "disk", "agents"), join(data, "disk", "agents", agentDirName(agentId)), dirname(top), join(data, "scratch"), dirname(scratch)];
|
|
267
269
|
};
|
|
268
|
-
/** Before the run's process starts on `slot`: its parents traverse-only, its
|
|
269
|
-
*
|
|
270
|
+
/** Before the run's process starts on `slot`: its parents traverse-only, the folders its process opens first made (its
|
|
271
|
+
* folder, its recordings and its temporary folder, its TMPDIR), and its top folders with everything in them given to the
|
|
272
|
+
* slot (the helper's `own <slot>`: the slot's uid, the runner's group, folders 2770). What an earlier claim's slot left,
|
|
273
|
+
* and what the server's user placed at this claim, is the slot's with the rest. */
|
|
270
274
|
async function layRunFolders(isolation, data, agentId, runId, slot) {
|
|
271
275
|
for (const parent of runParents(data, agentId, runId)) {
|
|
272
276
|
await mkdir(parent, { recursive: true });
|
|
273
277
|
await chmod(parent, 0o711);
|
|
274
278
|
}
|
|
275
|
-
const
|
|
276
|
-
for (const
|
|
277
|
-
await mkdir(top, { recursive: true });
|
|
278
|
-
await chown(top, process.getuid(), gid);
|
|
279
|
-
await chmod(top, 0o2770);
|
|
280
|
-
// An earlier claim of this run on another slot left its files that slot's: given to this one, so the run reads and
|
|
281
|
-
// writes what it wrote before.
|
|
282
|
-
for (const other of await slotsUnder(top, slot)) {
|
|
283
|
-
const moved = await execText(isolation.helper, ["reown", String(other), String(slot), top], 120_000);
|
|
284
|
-
if (moved.code !== 0)
|
|
285
|
-
throw new Error(`the run's folder could not be given to its slot: ${moved.stderr.trim()}`);
|
|
286
|
-
}
|
|
287
|
-
// What the server's user made there (a run's inputs placed at this claim, an earlier run's folders on a volume from
|
|
288
|
-
// before runs had slots of their own): the slot group's, so the run writes there too.
|
|
289
|
-
await toSlotGroup(top, gid);
|
|
290
|
-
}
|
|
291
|
-
// The folders the run's process opens first, made here in the slot's group (setgid): its folder, its recordings and its
|
|
292
|
-
// temporary folder (its TMPDIR), each one the server reads through the group as the run writes it.
|
|
293
|
-
for (const folder of [runFolder(data, agentId, runId), recordingsFolder(data, agentId, runId), join(scratchFolder(data, agentId, runId), "tmp")]) {
|
|
279
|
+
const tops = runTops(data, agentId, runId);
|
|
280
|
+
for (const folder of [...tops, runFolder(data, agentId, runId), recordingsFolder(data, agentId, runId), join(scratchFolder(data, agentId, runId), "tmp")])
|
|
294
281
|
await mkdir(folder, { recursive: true });
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
await chown(folder, process.getuid(), gid);
|
|
299
|
-
await chmod(folder, 0o2770);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
/** Every entry under `dir` the server's user owns, given to group `gid` as the helper's reown gives a slot's: a folder
|
|
303
|
-
* the group's to enter and write (2770), a file's owner bits copied to the group, none for others. The whole tree, a
|
|
304
|
-
* symlink never followed nor changed (an lstat's). Run while no process of the slot is alive (after its reap), so
|
|
305
|
-
* nothing it walks is swapped under it. */
|
|
306
|
-
export async function toSlotGroup(dir, gid) {
|
|
307
|
-
const me = process.getuid();
|
|
308
|
-
const walk = async (at) => {
|
|
309
|
-
let names;
|
|
310
|
-
try {
|
|
311
|
-
names = await readdir(at);
|
|
312
|
-
}
|
|
313
|
-
catch {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
for (const name of names) {
|
|
317
|
-
const path = join(at, name);
|
|
318
|
-
const stat = await lstat(path).catch(() => undefined);
|
|
319
|
-
if (!stat || stat.isSymbolicLink())
|
|
320
|
-
continue;
|
|
321
|
-
if (stat.uid === me) {
|
|
322
|
-
await lchown(path, me, gid);
|
|
323
|
-
const owner = stat.mode & 0o700;
|
|
324
|
-
await chmod(path, stat.isDirectory() ? 0o2770 : owner | (owner >> 3));
|
|
325
|
-
}
|
|
326
|
-
if (stat.isDirectory())
|
|
327
|
-
await walk(path);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
await walk(dir);
|
|
331
|
-
}
|
|
332
|
-
/** The other slots that own an entry anywhere under `dir`, as the helper's reown walks it: the whole tree, a symlink
|
|
333
|
-
* never followed (an lstat's, never a directory). `statOf`: the stat it reads (a test's). */
|
|
334
|
-
export async function slotsUnder(dir, slot, statOf = lstat) {
|
|
335
|
-
const found = new Set();
|
|
336
|
-
const look = async (at) => {
|
|
337
|
-
let names;
|
|
338
|
-
try {
|
|
339
|
-
names = await readdir(at);
|
|
340
|
-
}
|
|
341
|
-
catch {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
for (const name of names) {
|
|
345
|
-
const path = join(at, name);
|
|
346
|
-
const stat = await statOf(path).catch(() => undefined);
|
|
347
|
-
if (!stat)
|
|
348
|
-
continue;
|
|
349
|
-
const other = stat.uid - FIRST_RUN_ID;
|
|
350
|
-
if (other >= 0 && other < RUN_SLOTS && other !== slot)
|
|
351
|
-
found.add(other);
|
|
352
|
-
if (stat.isDirectory())
|
|
353
|
-
await look(path);
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
await look(dir);
|
|
357
|
-
return [...found];
|
|
282
|
+
const given = await execText(isolation.helper, ["own", String(slot), ...tops], 120_000);
|
|
283
|
+
if (given.code !== 0)
|
|
284
|
+
throw new Error(`the run's folders could not be given to its slot: ${given.stderr.trim() || `${isolation.helper} own exited ${given.code}`}`);
|
|
358
285
|
}
|
|
359
286
|
/** The host's shared folders a slot's uid can leave a file in, each swept at its reap (/var/lock is /run/lock's link on
|
|
360
287
|
* Debian, swept as itself where it is a folder of its own). SysV IPC is not swept. */
|
|
361
288
|
const SWEPT = ["/tmp", "/var/tmp", "/dev/shm", "/run/lock", "/var/lock", "/dev/mqueue"];
|
|
289
|
+
/** At a claim, before anything of the run is placed: its top folders and everything in them the server's user's again
|
|
290
|
+
* (the helper's `own runner`), whoever an earlier claim left them to. Throws, in words, when they could not be. */
|
|
291
|
+
export async function takeBackRunFolders(isolation, tops) {
|
|
292
|
+
const taken = await execText(isolation.helper, ["own", "runner", ...tops], 120_000);
|
|
293
|
+
if (taken.code !== 0)
|
|
294
|
+
throw new Error(`the run's folders could not be taken back from the slot an earlier claim left them to: ${taken.stderr.trim() || `${isolation.helper} own exited ${taken.code}`}`);
|
|
295
|
+
}
|
|
362
296
|
/** After the run's process ended: every process of the slot's uid killed, its files in the shared temporary folders
|
|
363
|
-
* removed,
|
|
364
|
-
*
|
|
365
|
-
* the uid is left, and says so
|
|
366
|
-
* again by this runner). */
|
|
297
|
+
* removed, and its top folders with everything in them given back to the server's user (the helper's `own runner`:
|
|
298
|
+
* the server's uid and group, folders 2770), which the slot's next run cannot enter. Whether the reap held: the helper
|
|
299
|
+
* kills until no process of the uid is left, and says so, and the folders were given back; false when a process still
|
|
300
|
+
* is, or either step could not run (the slot is then never run on again by this runner). */
|
|
367
301
|
export async function reapSlot(isolation, slot, tops, log) {
|
|
368
|
-
const
|
|
369
|
-
const reaped = await execText(isolation.helper, args, 120_000);
|
|
302
|
+
const reaped = await execText(isolation.helper, ["reap", String(slot), ...SWEPT.flatMap((dir) => ["--sweep", dir])], 120_000);
|
|
370
303
|
if (reaped.code !== 0)
|
|
371
304
|
log(`slot ${slot}'s reap said: ${reaped.stderr.trim()}`);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
log(`the run's folder ${top} was not given back to the server: ${error.message}`);
|
|
305
|
+
// Given back whether or not the reap held: a process of the slot's uid still alive then reaches its folders no more.
|
|
306
|
+
let back = true;
|
|
307
|
+
if (tops.length) {
|
|
308
|
+
const given = await execText(isolation.helper, ["own", "runner", ...tops], 120_000);
|
|
309
|
+
if (given.code !== 0) {
|
|
310
|
+
log(`slot ${slot}'s folders were not all given back to the server: ${given.stderr.trim()}`);
|
|
311
|
+
back = false;
|
|
380
312
|
}
|
|
381
313
|
}
|
|
382
|
-
return reaped.code === 0;
|
|
314
|
+
return reaped.code === 0 && back;
|
|
383
315
|
}
|
|
384
316
|
/** After a reap that held: the run's scratch folder as a claim's end in the runner's own process leaves it (cli-run-spec.ts
|
|
385
317
|
* sweepScratch), with the temporary folder the runner laid for its process (its TMPDIR) gone too. The agent's folder
|
|
@@ -686,7 +618,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
686
618
|
mcp: async (ask) => {
|
|
687
619
|
const reach = await mcpReachOf(deps);
|
|
688
620
|
const harness = { commit: (change) => change({ appendEntry: async (_conversation, entry) => void (await ask.appendRoot(dataOnly(entry))) }) };
|
|
689
|
-
const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach });
|
|
621
|
+
const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: () => launch.maxCostUsd !== undefined, media: mediaForClaim(deps.env, deps.evalFakes?.(run.agentId)?.web, deps.saveSlots) });
|
|
690
622
|
if (!made)
|
|
691
623
|
return undefined;
|
|
692
624
|
releases.push(() => made.release());
|
|
@@ -888,7 +820,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
888
820
|
? await openRunWorkspace({ mode: 1, agentId: run.agentId, runId: claim.runId, data: deps.data, log })
|
|
889
821
|
: await openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: made, log });
|
|
890
822
|
try {
|
|
891
|
-
await placeRunInputs(deps.data, claim.runId, ws.workspace, launch
|
|
823
|
+
await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
|
|
892
824
|
}
|
|
893
825
|
finally {
|
|
894
826
|
await ws.end();
|
|
@@ -951,9 +883,10 @@ export const childArgv = () => [process.execPath, "--import", new URL("../secret
|
|
|
951
883
|
* A built-in learning run (its launch names harness "learning"): its grade is one ask through the runner's model route,
|
|
952
884
|
* and its one write is the merge into the agent's learning folder, which no run's process may write. An SDK backend
|
|
953
885
|
* run (launch.sdk): its agent runs in the caller's application, and its loop here reads the evidence it posts and closes
|
|
954
|
-
* its inbox. A
|
|
886
|
+
* its inbox. A CLI capture (launch.cli_learning) likewise only receives source evidence and serves owner corrections.
|
|
887
|
+
* A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
|
|
955
888
|
* connectors, whose rows are the server's. */
|
|
956
|
-
export const runsInRunner = (harness, launch) => harness === "learning" || Boolean(launch.sdk) || Boolean(launch.native);
|
|
889
|
+
export const runsInRunner = (harness, launch) => harness === "learning" || Boolean(launch.sdk) || Boolean(launch.native) || Boolean(launch.cli_learning);
|
|
957
890
|
/** The words a run on Claude Code's login on this machine is refused in where each run is a user of its own. */
|
|
958
891
|
export const LOGIN_NEEDS_SERVER_USER = `A run on Claude Code's login on this machine needs runs under the server's own user, and this runner runs each run as a user of its own: set ${RUN_USER_ENV}=same, or give the run a model_key.`;
|
|
959
892
|
/** Whether run `runId` stays in its runner's process: runsInRunner's, and a workflow run on a server with a documents
|
|
@@ -1085,7 +1018,9 @@ function childLoop(options, slots, loopDeps) {
|
|
|
1085
1018
|
const runRow = await deps.store.runs.get(claim.runId);
|
|
1086
1019
|
if (!runRow)
|
|
1087
1020
|
throw new Error(`run ${claim.runId}: its row is gone from the store`);
|
|
1088
|
-
|
|
1021
|
+
// The launch as this run runs it: on a named disk, with nothing learned on another disk (launchOnItsDisk).
|
|
1022
|
+
const read = readLaunchBody((await deps.store.runs.launch(claim.runId)).body);
|
|
1023
|
+
const launch = read && launchOnItsDisk(read);
|
|
1089
1024
|
if (!launch)
|
|
1090
1025
|
throw new Error(`run ${claim.runId}: its launch record could not be read as a launch`);
|
|
1091
1026
|
const revisionRow = await deps.store.agents.revision(runRow.revisionId);
|
|
@@ -1141,6 +1076,11 @@ function childLoop(options, slots, loopDeps) {
|
|
|
1141
1076
|
try {
|
|
1142
1077
|
let extra = {};
|
|
1143
1078
|
let argv = [...(options.argv ?? childArgv())];
|
|
1079
|
+
// A claim that resumes a run whose last runner ended before giving its folders back finds them its last slot's,
|
|
1080
|
+
// perhaps shut (a run's own chmod 700): taken back first, so the inputs and folders below are laid as the
|
|
1081
|
+
// server's, then given to this slot.
|
|
1082
|
+
if (isolation.kind === "uid" && slot !== undefined)
|
|
1083
|
+
await takeBackRunFolders(isolation, tops);
|
|
1144
1084
|
// The run's uploads and opening message, placed by the runner before its process starts (their hold is the
|
|
1145
1085
|
// server's alone), then given to the slot with its folders.
|
|
1146
1086
|
await heldSide.inputs();
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { ConversationBusy, ConversationIdle, ReadAfterWrite, ReadOnlySession, SessionFailed, StorageRequestError } from "@earendil-works/pi-durable";
|
|
5
5
|
import { CommandTaken, Fenced, RunFinal, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreLaunchMissing, StoreWorkerLost } from "../store/store.js";
|
|
6
6
|
import { Unanswered } from "../store/postgres/connection.js";
|
|
7
|
+
import { WorkspaceError } from "../workspace/workspace.js";
|
|
7
8
|
import { LaunchUnreadable, UnknownHarness } from "./dispatch.js";
|
|
8
9
|
import { NeverFits } from "./harness-loops.js";
|
|
9
10
|
import { ClaimRefused } from "./loop-contract.js";
|
|
@@ -16,5 +17,6 @@ export function registerRunErrors() {
|
|
|
16
17
|
ClaimRefused, NeverFits, McpClaimRefused, ClaimLost, UnknownHarness, LaunchUnreadable,
|
|
17
18
|
Fenced, CommandTaken, RunFinal, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreLaunchMissing, StoreWorkerLost, Unanswered,
|
|
18
19
|
ConversationBusy, ConversationIdle, ReadAfterWrite, ReadOnlySession, SessionFailed, StorageRequestError,
|
|
20
|
+
WorkspaceError,
|
|
19
21
|
});
|
|
20
22
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Settings } from "../store/store.js";
|
|
2
|
+
/** The store.settings key a server keeps the names of its run-facing environment under at each start: `{ v: 1, names }`. */
|
|
3
|
+
export declare const RUN_ENV_KEY = "server.run_env";
|
|
4
|
+
export declare const STORE_URL_ENV = "AGENTRUN_STORE_URL";
|
|
5
|
+
/** Whether `name` is one a run's claim reads from its runner's environment (FIXED, or an upstream's address). */
|
|
6
|
+
export declare const runFacing: (name: string) => boolean;
|
|
7
|
+
/** The run-facing names `read` holds, sorted: of FIXED and of `listed` (the environment's own names, for its upstreams). */
|
|
8
|
+
export declare function runFacingNames(read: (name: string) => string | undefined, listed: Iterable<string>): string[];
|
|
9
|
+
/** The server's start: the names of its run-facing environment, replacing the last start's. Names only, never a value. */
|
|
10
|
+
export declare function recordRunEnv(store: {
|
|
11
|
+
settings: Pick<Settings, "put">;
|
|
12
|
+
}, names: readonly string[]): Promise<void>;
|
|
13
|
+
/** The names the server kept at its last start (recordRunEnv), or undefined when it kept none (a server older than this). */
|
|
14
|
+
export declare function serverRunEnv(store: {
|
|
15
|
+
settings: Pick<Settings, "get">;
|
|
16
|
+
}): Promise<string[] | undefined>;
|
|
17
|
+
/** One line of the check: a name (or what it checked, for the heartbeat) and its state, with why. Never a value. */
|
|
18
|
+
export type CheckRow = {
|
|
19
|
+
readonly state: "ok" | "missing" | "bad" | "skipped" | "warn";
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly why: string;
|
|
22
|
+
};
|
|
23
|
+
/** States that fail the check. */
|
|
24
|
+
export declare const failing: (row: CheckRow) => boolean;
|
|
25
|
+
export interface RunnerEnvCheckOptions {
|
|
26
|
+
/** --data, when given: a SQLite store and the seal key's file are read there when the environment names neither. */
|
|
27
|
+
readonly dataDir?: string;
|
|
28
|
+
/** The runner's environment (AGENTRUN_STORE_SCHEMA and every name it lists). */
|
|
29
|
+
readonly env: NodeJS.ProcessEnv;
|
|
30
|
+
/** A name's value as the runner would read it: its secret handed over by the launcher, else its environment's. */
|
|
31
|
+
readonly read: (name: string) => string | undefined;
|
|
32
|
+
/** Whether a TCP connect to `host`:`port` is answered within `ms` (a test's stand-in). */
|
|
33
|
+
readonly answers?: (host: string, port: number, ms: number) => Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
/** How long a forwarder has to answer the check's connect. */
|
|
36
|
+
export declare const FORWARDER_MS = 2000;
|
|
37
|
+
/** Whether `host`:`port` takes a TCP connection within `ms`. */
|
|
38
|
+
export declare function tcpAnswers(host: string, port: number, ms: number): Promise<boolean>;
|
|
39
|
+
/** `value`'s host and port when it is an http(s) URL on this machine's loopback, else undefined. */
|
|
40
|
+
export declare function loopbackTarget(value: string): {
|
|
41
|
+
host: string;
|
|
42
|
+
port: number;
|
|
43
|
+
} | undefined;
|
|
44
|
+
/** The runner's environment checked (the header's contract), one row per name. The store is opened as a runner, with a
|
|
45
|
+
* pool of one, and closed before this returns. */
|
|
46
|
+
export declare function checkRunnerEnv(options: RunnerEnvCheckOptions): Promise<CheckRow[]>;
|
|
47
|
+
/** The check's lines: one per row (its state, its name, why), then the outcome. */
|
|
48
|
+
export declare function checkLines(rows: readonly CheckRow[]): {
|
|
49
|
+
lines: string[];
|
|
50
|
+
ok: boolean;
|
|
51
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// `agentrun-serve runner --check`: the runner's environment contract, checked and printed by name, never by value. A
|
|
2
|
+
// runner on a disk of its own (disk-free.ts) gets everything it needs from its environment and its store, so a name its
|
|
3
|
+
// launcher dropped is a run that fails at its claim, or a model request that goes to the wrong place. The check says
|
|
4
|
+
// each gap before that, and fails closed: any gap exits 1. What it reads:
|
|
5
|
+
//
|
|
6
|
+
// - the store: AGENTRUN_STORE_URL opens, at a schema this runner knows (else a SQLite store in --data, the server's own);
|
|
7
|
+
// - the seal key: AGENTRUN_SEAL_KEY (else the key file in --data) is the one the store's secrets are sealed under;
|
|
8
|
+
// - the server's run-facing names: every one the server held at its last start (it keeps their names, never their values,
|
|
9
|
+
// in the store: RUN_ENV_KEY), the runner holds too. These are what a run's claim reads from its runner's environment:
|
|
10
|
+
// model, tool and box keys, the Archil settings, each box provider's settings, the tiers' models (AGENT_MODEL,
|
|
11
|
+
// AGENT_MODEL_FAST, AGENT_MODEL_STRONG), AGENTRUN_BOX_ALLOW and the upstreams a model or a tool is sent to
|
|
12
|
+
// (*_BASE_URL, *_API_URL). A server older than this release says none: then that part is skipped, said, and fails
|
|
13
|
+
// nothing;
|
|
14
|
+
// - forwarder targets: each upstream the runner holds that names this machine's loopback (a forwarder beside the runner,
|
|
15
|
+
// such as a model gateway's) answers a TCP connect.
|
|
16
|
+
//
|
|
17
|
+
// A runner that holds the server's own secrets (its API tokens and key) is warned: a runner never needs them.
|
|
18
|
+
import { connect } from "node:net";
|
|
19
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
20
|
+
import { ARCHIL_SETTINGS_ENV } from "../archil-settings.js";
|
|
21
|
+
import { BOX_ALLOW_ENV } from "../box-settings.js";
|
|
22
|
+
import { TOOL_KEY_ROWS } from "../key-words.js";
|
|
23
|
+
import { PRIVATE_HOSTS_ENV } from "../mcp-private-hosts.js";
|
|
24
|
+
import { HARNESS_MODULES_SETTING } from "../harness-table.js";
|
|
25
|
+
import { GATEWAY_IDS_ENV } from "../model-gateway.js";
|
|
26
|
+
import { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV, MCP_ALLOW_LOOPBACK_ENV } from "../start-switches.js";
|
|
27
|
+
import { DOCKER_IMAGE_ENV } from "../box-image.js";
|
|
28
|
+
import { bootSealKey } from "../seal-key.js";
|
|
29
|
+
import { SECRET_NAMES } from "../secrets.js";
|
|
30
|
+
import { SEAL_KEY_ENV } from "../tool-keys.js";
|
|
31
|
+
/** The store.settings key a server keeps the names of its run-facing environment under at each start: `{ v: 1, names }`. */
|
|
32
|
+
export const RUN_ENV_KEY = "server.run_env";
|
|
33
|
+
export const STORE_URL_ENV = "AGENTRUN_STORE_URL";
|
|
34
|
+
/** The most connections a Postgres store holds at once; its start refuses a value that is no size (store/open.ts). */
|
|
35
|
+
const POOL_SIZE_ENV = "AGENTRUN_STORE_POOL_SIZE";
|
|
36
|
+
/** The server's own secrets: never a runner's (runner/main.ts RUNNER_ONLY keeps them from its runs, too). */
|
|
37
|
+
const SERVER_ONLY = ["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY"];
|
|
38
|
+
/** Names that are neither the server's run-facing environment nor the runner's: its own store and key (checked on their
|
|
39
|
+
* own), the server's secrets, and a client's address of the server. */
|
|
40
|
+
const NOT_RUN_FACING = new Set([...SERVER_ONLY, STORE_URL_ENV, SEAL_KEY_ENV, "AGENTRUN_BASE_URL"]);
|
|
41
|
+
/** An upstream a model or a tool is sent to, by its name's end. */
|
|
42
|
+
const UPSTREAM = /_(?:BASE_URL|API_URL)$/;
|
|
43
|
+
/** The fixed run-facing names: every secret the launcher hands over but the server's own, each tool key, each box
|
|
44
|
+
* provider's keys and settings by their environment names, the Archil settings, the default model and the boxes'
|
|
45
|
+
* network allow-list, and the operator's bound on owners' private hosts (each dial reads it from the process that dials). */
|
|
46
|
+
const FIXED = new Set([
|
|
47
|
+
...SECRET_NAMES,
|
|
48
|
+
...TOOL_KEY_ROWS.flatMap((row) => row.fields),
|
|
49
|
+
...PROVIDERS.flatMap((provider) => provider.keys.map((key) => key.name)),
|
|
50
|
+
...Object.values(ARCHIL_SETTINGS_ENV),
|
|
51
|
+
// The model of each tier (model.ts TIER_ENV): the default, and the fast and strong ones a subagent may pick.
|
|
52
|
+
"AGENT_MODEL",
|
|
53
|
+
"AGENT_MODEL_FAST",
|
|
54
|
+
"AGENT_MODEL_STRONG",
|
|
55
|
+
BOX_ALLOW_ENV,
|
|
56
|
+
PRIVATE_HOSTS_ENV,
|
|
57
|
+
// How a gateway is sent a model id (model-gateway.ts), and whether runs may reach an MCP server on loopback: each read
|
|
58
|
+
// from the environment of the process that runs the run.
|
|
59
|
+
GATEWAY_IDS_ENV,
|
|
60
|
+
MCP_ALLOW_LOOPBACK_ENV,
|
|
61
|
+
// The harness modules a server loads (harness-table.ts): a runner without them claims their runs and has no harness to
|
|
62
|
+
// run them on.
|
|
63
|
+
HARNESS_MODULES_SETTING,
|
|
64
|
+
// A Docker computer's image and size (box-image.ts, workspace/computer-deps.ts dockerLimitsOf): read where the run's
|
|
65
|
+
// computer starts, the runner.
|
|
66
|
+
DOCKER_IMAGE_ENV,
|
|
67
|
+
BOX_CPUS_ENV,
|
|
68
|
+
BOX_MEMORY_ENV,
|
|
69
|
+
BOX_PIDS_ENV,
|
|
70
|
+
].filter((name) => !NOT_RUN_FACING.has(name)));
|
|
71
|
+
/** Whether `name` is one a run's claim reads from its runner's environment (FIXED, or an upstream's address). */
|
|
72
|
+
export const runFacing = (name) => !NOT_RUN_FACING.has(name) && (FIXED.has(name) || UPSTREAM.test(name));
|
|
73
|
+
/** The run-facing names `read` holds, sorted: of FIXED and of `listed` (the environment's own names, for its upstreams). */
|
|
74
|
+
export function runFacingNames(read, listed) {
|
|
75
|
+
const names = new Set([...FIXED, ...[...listed].filter(runFacing)]);
|
|
76
|
+
return [...names].filter((name) => Boolean(read(name)?.trim())).sort();
|
|
77
|
+
}
|
|
78
|
+
/** The server's start: the names of its run-facing environment, replacing the last start's. Names only, never a value. */
|
|
79
|
+
export async function recordRunEnv(store, names) {
|
|
80
|
+
await store.settings.put(RUN_ENV_KEY, { v: 1, names: [...names] });
|
|
81
|
+
}
|
|
82
|
+
/** The names the server kept at its last start (recordRunEnv), or undefined when it kept none (a server older than this). */
|
|
83
|
+
export async function serverRunEnv(store) {
|
|
84
|
+
const kept = await store.settings.get(RUN_ENV_KEY);
|
|
85
|
+
const names = typeof kept === "object" && kept !== null ? kept.names : undefined;
|
|
86
|
+
return Array.isArray(names) ? names.filter((name) => typeof name === "string") : undefined;
|
|
87
|
+
}
|
|
88
|
+
/** States that fail the check. */
|
|
89
|
+
export const failing = (row) => row.state === "missing" || row.state === "bad";
|
|
90
|
+
/** How long a forwarder has to answer the check's connect. */
|
|
91
|
+
export const FORWARDER_MS = 2_000;
|
|
92
|
+
/** Whether `host`:`port` takes a TCP connection within `ms`. */
|
|
93
|
+
export function tcpAnswers(host, port, ms) {
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
const socket = connect({ host, port });
|
|
96
|
+
const done = (ok) => {
|
|
97
|
+
socket.destroy();
|
|
98
|
+
resolve(ok);
|
|
99
|
+
};
|
|
100
|
+
socket.setTimeout(ms, () => done(false));
|
|
101
|
+
socket.once("connect", () => done(true));
|
|
102
|
+
socket.once("error", () => done(false));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const LOOPBACK_HOST = /^(?:localhost|127(?:\.\d{1,3}){3}|\[::1\])$/i;
|
|
106
|
+
/** `value`'s host and port when it is an http(s) URL on this machine's loopback, else undefined. */
|
|
107
|
+
export function loopbackTarget(value) {
|
|
108
|
+
const url = URL.parse(value.trim());
|
|
109
|
+
if (!url || (url.protocol !== "http:" && url.protocol !== "https:") || !LOOPBACK_HOST.test(url.hostname))
|
|
110
|
+
return undefined;
|
|
111
|
+
const port = url.port ? Number(url.port) : url.protocol === "https:" ? 443 : 80;
|
|
112
|
+
return { host: url.hostname.replace(/^\[|\]$/g, ""), port };
|
|
113
|
+
}
|
|
114
|
+
/** `text` with the store URL and its password taken out: a driver's error may quote what it was given. */
|
|
115
|
+
function withoutUrl(text, url) {
|
|
116
|
+
if (!url)
|
|
117
|
+
return text;
|
|
118
|
+
let out = text.split(url).join(`<${STORE_URL_ENV}>`);
|
|
119
|
+
const password = URL.parse(url)?.password;
|
|
120
|
+
if (password)
|
|
121
|
+
for (const form of new Set([password, decodeURIComponent(password)]))
|
|
122
|
+
if (form.length >= 4)
|
|
123
|
+
out = out.split(form).join("<password>");
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
/** The runner's environment checked (the header's contract), one row per name. The store is opened as a runner, with a
|
|
127
|
+
* pool of one, and closed before this returns. */
|
|
128
|
+
export async function checkRunnerEnv(options) {
|
|
129
|
+
const { env, read } = options;
|
|
130
|
+
const answers = options.answers ?? tcpAnswers;
|
|
131
|
+
const rows = [];
|
|
132
|
+
const url = read(STORE_URL_ENV)?.trim() || undefined;
|
|
133
|
+
const dataDir = options.dataDir ?? process.cwd();
|
|
134
|
+
let store;
|
|
135
|
+
if (!url && options.dataDir === undefined) {
|
|
136
|
+
rows.push({ state: "missing", name: STORE_URL_ENV, why: "the store's URL: unset, and no --data to find a SQLite store in" });
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// The check opens its store with a pool of one, so a pool size the runner's own start refuses (open.ts, on either
|
|
140
|
+
// store) is checked as given first: a runner whose start would fail never passes this check.
|
|
141
|
+
const { storePoolSize } = await import("../store/open.js");
|
|
142
|
+
try {
|
|
143
|
+
storePoolSize(env);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
rows.push({ state: "bad", name: POOL_SIZE_ENV, why: `the runner's store does not open with it: ${error?.message ?? String(error)}` });
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
// Read when the check runs: the server imports this module for its names alone, never the runner's start.
|
|
150
|
+
const { openRunnerStore } = await import("./main.js");
|
|
151
|
+
const opened = await openRunnerStore(dataDir, { ...env, [POOL_SIZE_ENV]: "1" }, () => { }, url);
|
|
152
|
+
store = opened.store;
|
|
153
|
+
rows.push({ state: "ok", name: STORE_URL_ENV, why: url ? `the store opens: ${opened.kind}, schema v${opened.schema}` : "unset: the store is SQLite in the data directory, which is the server's" });
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
const why = withoutUrl(error?.message ?? String(error), url);
|
|
157
|
+
rows.push({ state: url ? "bad" : "missing", name: STORE_URL_ENV, why: url ? `the store does not open: ${why}` : `unset, and the data directory holds no store a runner can open: ${why}` });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const given = read(SEAL_KEY_ENV)?.trim() || undefined;
|
|
162
|
+
if (store) {
|
|
163
|
+
try {
|
|
164
|
+
const seal = await bootSealKey(store, dataDir, { given, role: "runner", write: false, say: () => { } });
|
|
165
|
+
seal?.release();
|
|
166
|
+
rows.push(seal ? { state: "ok", name: SEAL_KEY_ENV, why: given ? "the store's seal key" : "unset: the store's seal key is the one in the data directory" } : { state: "missing", name: SEAL_KEY_ENV, why: "the seal key: unset, and none in the data directory" });
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
rows.push({ state: given ? "bad" : "missing", name: SEAL_KEY_ENV, why: error?.message ?? String(error) });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else
|
|
173
|
+
rows.push(given ? { state: "skipped", name: SEAL_KEY_ENV, why: "set, and not checked against the store, which did not open" } : { state: "missing", name: SEAL_KEY_ENV, why: "the seal key the store's secrets are sealed under: unset" });
|
|
174
|
+
const names = store ? await serverRunEnv(store) : undefined;
|
|
175
|
+
if (!store)
|
|
176
|
+
rows.push({ state: "skipped", name: RUN_ENV_KEY, why: "the server's run-facing names are read from the store, which did not open" });
|
|
177
|
+
else if (names === undefined)
|
|
178
|
+
rows.push({ state: "skipped", name: RUN_ENV_KEY, why: "the server has not said its run-facing names in this store (a server older than this runner): start the server of this release first" });
|
|
179
|
+
else
|
|
180
|
+
for (const name of names)
|
|
181
|
+
rows.push(read(name)?.trim() ? { state: "ok", name, why: "the server holds it, and so does this runner" } : { state: "missing", name, why: "the server holds it and a run's claim reads it here: hand it to this runner too" });
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
await store?.close().catch(() => undefined);
|
|
185
|
+
}
|
|
186
|
+
const listed = Object.keys(env);
|
|
187
|
+
for (const name of [...new Set(listed)].filter((one) => runFacing(one) && UPSTREAM.test(one)).sort()) {
|
|
188
|
+
const value = read(name);
|
|
189
|
+
const target = value ? loopbackTarget(value) : undefined;
|
|
190
|
+
if (!target)
|
|
191
|
+
continue;
|
|
192
|
+
rows.push((await answers(target.host, target.port, FORWARDER_MS)) ? { state: "ok", name, why: "on this machine's loopback, and a forwarder answers there" } : { state: "bad", name, why: `on this machine's loopback, and nothing answers there within ${FORWARDER_MS / 1000} s: start its forwarder` });
|
|
193
|
+
}
|
|
194
|
+
for (const name of SERVER_ONLY)
|
|
195
|
+
if (read(name)?.trim())
|
|
196
|
+
rows.push({ state: "warn", name, why: "the server's own secret: a runner never needs it, so leave it off the runner" });
|
|
197
|
+
return rows;
|
|
198
|
+
}
|
|
199
|
+
/** The check's lines: one per row (its state, its name, why), then the outcome. */
|
|
200
|
+
export function checkLines(rows) {
|
|
201
|
+
const width = Math.max(0, ...rows.map((row) => row.name.length));
|
|
202
|
+
const lines = rows.map((row) => `${row.state.padEnd(7)} ${row.name.padEnd(width)} ${row.why}`);
|
|
203
|
+
const gaps = rows.filter(failing);
|
|
204
|
+
lines.push(gaps.length === 0 ? `Runner environment: complete (${rows.filter((row) => row.state === "ok").length} ok)` : `Runner environment: ${gaps.length} gap${gaps.length === 1 ? "" : "s"}: ${gaps.map((row) => row.name).join(", ")}`);
|
|
205
|
+
return { lines, ok: gaps.length === 0 };
|
|
206
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RunnerEvent } from "./runner.js";
|
|
2
|
+
/** How often a runner says its gauge line. */
|
|
3
|
+
export declare const RUNNER_GAUGE_EVERY_MS = 60000;
|
|
4
|
+
/** The metric line of runner `runner`'s `event`, or undefined for an event that is none (a run's start and end have their
|
|
5
|
+
* own lines: print.ts runLine; an error is said as trouble: main.ts troubleLine). */
|
|
6
|
+
export declare function metricLine(runner: string, event: RunnerEvent): string | undefined;
|
|
7
|
+
/** The gauge line: `active` runs held of `slots`, and `rssBytes` as MiB. */
|
|
8
|
+
export declare const gaugeLine: (runner: string, active: number, slots: number, rssBytes: number) => string;
|
|
9
|
+
/** Says runner `runner`'s gauge line through `write` every `everyMs` (its timer never holds the process up) until stop(). */
|
|
10
|
+
export declare function startRunnerGauge({ runner, held, slots, write, everyMs, rssBytes }: {
|
|
11
|
+
runner: string;
|
|
12
|
+
held: () => number;
|
|
13
|
+
slots: number;
|
|
14
|
+
write: (line: string) => void;
|
|
15
|
+
everyMs?: number;
|
|
16
|
+
rssBytes?: () => number;
|
|
17
|
+
}): {
|
|
18
|
+
stop(): void;
|
|
19
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A runner's metrics as log lines, in the server's one log format (print.ts logLine: `at=<ISO> event=<name> key=value`),
|
|
2
|
+
// so a log-based metric counts them or reads a figure from them with no metrics server. Runner names, run ids, epochs,
|
|
3
|
+
// causes and numbers only: never a prompt, a key, a path or a customer's word. Five lines:
|
|
4
|
+
//
|
|
5
|
+
// - `runner_claimed runner run epoch from`, one per claim; `took_over=1` when it took the run over from a runner whose
|
|
6
|
+
// lease ran out (`lost_runner`, that runner): the run's earlier runner died or lost its claim.
|
|
7
|
+
// - `runner_hand_back runner run epoch cause`, one per run the runner gave back still running (runner.ts HandBackCause:
|
|
8
|
+
// drain, interrupted, end_retry, give_back), and `cause=claim_lost` with `why` (fenced, not_renewed) for a claim it lost.
|
|
9
|
+
// - `runner_drained runner ms held left`, once per close that held a run: how long the drain took, how many runs it began
|
|
10
|
+
// with and how many it handed back at its end.
|
|
11
|
+
// - `runner_gauge runner active slots rss_mib`, every RUNNER_GAUGE_EVERY_MS while the runner runs: the runs it holds, the
|
|
12
|
+
// most it holds at once, and its process's resident memory.
|
|
13
|
+
import { logLine } from "../print.js";
|
|
14
|
+
/** How often a runner says its gauge line. */
|
|
15
|
+
export const RUNNER_GAUGE_EVERY_MS = 60_000;
|
|
16
|
+
const MIB = 1024 * 1024;
|
|
17
|
+
/** The metric line of runner `runner`'s `event`, or undefined for an event that is none (a run's start and end have their
|
|
18
|
+
* own lines: print.ts runLine; an error is said as trouble: main.ts troubleLine). */
|
|
19
|
+
export function metricLine(runner, event) {
|
|
20
|
+
switch (event.type) {
|
|
21
|
+
case "claimed": {
|
|
22
|
+
const { claim } = event;
|
|
23
|
+
return logLine("runner_claimed", { runner, run: claim.runId, epoch: claim.epoch, from: claim.from, ...(claim.lost ? { took_over: 1, lost_runner: claim.lost.runner } : {}) });
|
|
24
|
+
}
|
|
25
|
+
case "handed-back":
|
|
26
|
+
return logLine("runner_hand_back", { runner, run: event.runId, epoch: event.epoch, cause: event.cause });
|
|
27
|
+
case "claim-lost":
|
|
28
|
+
return logLine("runner_hand_back", { runner, run: event.runId, epoch: event.epoch, cause: "claim_lost", why: event.why === "not-renewed" ? "not_renewed" : event.why });
|
|
29
|
+
case "drained":
|
|
30
|
+
return logLine("runner_drained", { runner, ms: event.ms, held: event.held, left: event.left });
|
|
31
|
+
default:
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The gauge line: `active` runs held of `slots`, and `rssBytes` as MiB. */
|
|
36
|
+
export const gaugeLine = (runner, active, slots, rssBytes) => logLine("runner_gauge", { runner, active, slots, rss_mib: Math.round(rssBytes / MIB) });
|
|
37
|
+
/** Says runner `runner`'s gauge line through `write` every `everyMs` (its timer never holds the process up) until stop(). */
|
|
38
|
+
export function startRunnerGauge({ runner, held, slots, write, everyMs = RUNNER_GAUGE_EVERY_MS, rssBytes = () => process.memoryUsage.rss() }) {
|
|
39
|
+
const timer = setInterval(() => {
|
|
40
|
+
try {
|
|
41
|
+
write(gaugeLine(runner, held(), slots, rssBytes()));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// A gauge it could not read or write never stops the runner.
|
|
45
|
+
}
|
|
46
|
+
}, everyMs);
|
|
47
|
+
timer.unref();
|
|
48
|
+
return { stop: () => clearInterval(timer) };
|
|
49
|
+
}
|