@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51
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 +173 -9
- package/README.md +246 -39
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/agents-store.js +7 -3
- package/dist/api-only.d.ts +8 -10
- package/dist/api-only.js +11 -12
- 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/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/index-Bt1B51b7.js +733 -0
- package/dist/console/assets/index-sVftE9Ht.css +1 -0
- 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/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- 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 +3 -2
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/secrets.js +14 -3
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +1 -1
- package/dist/mcp-pin-first.js +2 -1
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- 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 +113 -29
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +16 -2
- package/dist/run-launch.js +6 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +12 -7
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +44 -27
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +15 -8
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +16 -8
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +3 -1
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +1 -1
- package/dist/runner/learning-end.js +13 -4
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/run-child-host.d.ts +27 -17
- package/dist/runner/run-child-host.js +70 -116
- package/dist/runner/run-child.js +3 -0
- 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 +43 -3
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runner/sdk-loop.js +34 -22
- package/dist/runs-over-store.d.ts +8 -1
- package/dist/runs-over-store.js +57 -9
- package/dist/sdk/runs.d.ts +25 -6
- package/dist/sdk/runs.js +107 -35
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -0
- package/dist/server.js +151 -28
- 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 +13 -2
- package/dist/store/agent-body.js +19 -4
- 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/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/0023_computer_interval_resources.sql +14 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +26 -4
- package/dist/store/schema.js +45 -4
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +44 -0
- package/dist/store/sqlite/store.d.ts +19 -4
- package/dist/store/sqlite/store.js +180 -93
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +61 -2
- 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/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +9 -4
- package/dist/store-view.js +48 -25
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +4 -3
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- 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 +430 -0
- package/dist/uploads.d.ts +55 -1
- package/dist/uploads.js +185 -98
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +11 -1
- package/dist/workspace/archil-disk.js +43 -10
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +102 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
- package/dist/console/assets/index-CR2ZGei1.css +0 -1
|
@@ -46,7 +46,7 @@ import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
|
46
46
|
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
47
47
|
import { COMPUTER_ROOT, recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
|
|
48
48
|
import { runTools, withKindTools } from "../workspace/run-tools.js";
|
|
49
|
-
import { placeRunInputs } from "../uploads.js";
|
|
49
|
+
import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
50
50
|
import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
|
|
51
51
|
import { UNREADABLE_SIGN_IN } from "../run-view.js";
|
|
52
52
|
import { durableWait } from "../workflow/pi-versions.js";
|
|
@@ -293,10 +293,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
293
293
|
// a 24 h ttl as the safety net if revoke never comes (revoke normally runs at the run's end, below). A run with no
|
|
294
294
|
// mounting computer never mints one.
|
|
295
295
|
// The mint is lazy (archil-claim.ts token(), k2's run-tools.ts): only a mounting computer asks for it, so a Mode 2 run
|
|
296
|
-
// with no computer
|
|
297
|
-
//
|
|
298
|
-
// The disk is the run's (run-disk.ts): its launch record's, else its agent's, made on its first run that needs one
|
|
299
|
-
|
|
296
|
+
// with no computer mints nothing. mountControl (a test's loopback control-plane fake) is the claim's control, so no
|
|
297
|
+
// test reaches the real control plane. MOUNT_TTL_MS is the credential's safety net (its computer's 24 h bound), not its lifetime.
|
|
298
|
+
// The disk is the run's (run-disk.ts): its launch record's, else its agent's, made on its first run that needs one,
|
|
299
|
+
// and read at Archil at every claim.
|
|
300
|
+
: await archilWhereHeld({ settings: archilSettings, keys: deps.store.sealedKeys, sealKey: deps.sealKey, signal: run.signal ?? new AbortController().signal, env: deps.env, mount: { runId: claim.runId, epoch: claim.epoch, ttlMs: MOUNT_TTL_MS }, ...(deps.mountControl ? { control: deps.mountControl } : {}), run: { agentId: runRow.agentId, ...(launch.archilDisk ? { launch: launch.archilDisk } : {}), store: deps.store }, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) });
|
|
300
301
|
// Each resource is held the moment it exists (spec-holds.ts): a throw after it lets it go.
|
|
301
302
|
holds.hold({ archil });
|
|
302
303
|
// The run's Workspace at the claim: Mode 1 the run's local folder (made here, the server's start made it before); Mode 2
|
|
@@ -310,7 +311,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
310
311
|
// a copy that fails ends the run failed, saying why. A run's own process copies nothing: its runner placed them before
|
|
311
312
|
// the process started (run-child-host.ts), as the server's held uploads are never the run's to read.
|
|
312
313
|
if (!(deps.sealKey === undefined && runnerSeam()))
|
|
313
|
-
await placeRunInputs(deps.data, claim.runId, ws.workspace, launch
|
|
314
|
+
await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
|
|
314
315
|
// The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
|
|
315
316
|
// turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
|
|
316
317
|
// there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
|
|
@@ -359,7 +360,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
359
360
|
// claim's is a new one whatever ended the earlier claim (a lost runner, a server's stop, a park past its keep). The
|
|
360
361
|
// computer a park kept, attached again, brings its mount credential with it (inheritMount): none is minted. A
|
|
361
362
|
// recording of its screen (computer.record) goes in the run's recordings folder, beside its folder, said on its timeline.
|
|
362
|
-
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
363
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
363
364
|
// The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
|
|
364
365
|
// (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
|
|
365
366
|
// A desktop's or a phone's hold (the person's take-over) wraps its ports: a call made while the person holds it waits,
|
|
@@ -573,13 +574,18 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
573
574
|
// Harness is open before the session, and at the run's end (the browser tool's reconcile and release hang off these). The
|
|
574
575
|
// adapter loop runs them from the spec's `lifecycle` (adapter-loop.ts hostLifecycle).
|
|
575
576
|
const life = hostLifecycle();
|
|
577
|
+
// The claim's computers' time booked up to now before the run's end or park is written (compute-cost.ts), so the end's
|
|
578
|
+
// cost holds it: the release that deletes them comes after the end.
|
|
579
|
+
const settleComputers = computer.settle;
|
|
580
|
+
if (settleComputers)
|
|
581
|
+
life.register.beforeRelease(() => settleComputers());
|
|
576
582
|
// The ToolHost the non-hand tools (browser, web, MCP, decisions, monid) bind through (buildToolHost, the one the CLI
|
|
577
583
|
// spec builds too), on the claim's keys and the run's one ledger and redactor.
|
|
578
584
|
// An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
|
|
579
585
|
const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
|
|
580
586
|
const fakes = deps.evalFakes?.(runRow.agentId);
|
|
581
587
|
const liveAt = await claimLiveAt(deps, claim.runId);
|
|
582
|
-
const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}) }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
|
|
588
|
+
const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}), ...(deps.saveSlots ? { saveSlots: deps.saveSlots } : {}) }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
|
|
583
589
|
gate.askedOn(host);
|
|
584
590
|
// The run's tools. The hands (read/write/edit/bash and the background tools) are the kernel registry's over the run's
|
|
585
591
|
// Workspace and computer (runTools.hostTools); the gate is the adapter loop's own (spec.gate), so they run as asked.
|
|
@@ -938,6 +944,7 @@ export function buildToolHost(opts) {
|
|
|
938
944
|
...(email ? { emailFake: email } : {}),
|
|
939
945
|
...(opts.loopback ? { calendarLoopback: true } : {}),
|
|
940
946
|
...(opts.own ? { serverOwn: opts.own } : {}),
|
|
947
|
+
...(opts.saveSlots ? { saveSlots: opts.saveSlots } : {}),
|
|
941
948
|
// The run's directory and its per-claim environment: the hands come from runTools, so the non-hand tools get the run's
|
|
942
949
|
// environment only.
|
|
943
950
|
where: { root, work: root, ref: { id: claim.runId } },
|
package/dist/runner/beside.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RunnerEvent } from "./runner.js";
|
|
1
2
|
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
2
3
|
export declare const DRAIN_TIMEOUT = "30s";
|
|
3
4
|
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
@@ -51,6 +52,18 @@ export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainM
|
|
|
51
52
|
runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
|
|
52
53
|
close: () => Promise<void>;
|
|
53
54
|
}>;
|
|
55
|
+
/** The lines runner `name` beside a server says for `event`, in order, each with whether it goes to stderr (`error`): its
|
|
56
|
+
* metric line (runner-metrics.ts metricLine: a claim, a hand-back by cause, a lost claim, the drain), then its trouble
|
|
57
|
+
* (main.ts troubleLine: a lost claim, an error) or else its run's start or end (print.ts runLine). A lost claim says
|
|
58
|
+
* both its metric and its trouble. The three are handed in, as runnerBeside imports them on its start. */
|
|
59
|
+
export declare function besideLines(name: string, event: RunnerEvent, say: {
|
|
60
|
+
metricLine: (name: string, event: RunnerEvent) => string | undefined;
|
|
61
|
+
troubleLine: (name: string, event: RunnerEvent) => string | undefined;
|
|
62
|
+
runLine: (event: RunnerEvent) => string | undefined;
|
|
63
|
+
}): {
|
|
64
|
+
line: string;
|
|
65
|
+
error: boolean;
|
|
66
|
+
}[];
|
|
54
67
|
/** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
|
|
55
68
|
* what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
|
|
56
69
|
* server's runs reach its fakes. For a launcher that starts serve in-process (a demo, a smoke): a server alone leaves
|
package/dist/runner/beside.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// the template eval's in-process server (template-eval.ts), which would otherwise leave every run it starts queued.
|
|
3
3
|
import { maxRunsOf } from "../host.js";
|
|
4
4
|
import { durationMs } from "../print.js";
|
|
5
|
-
import { runnerCloseBoundMs } from "./runner.js";
|
|
5
|
+
import { RUNNER_LOOPS, runnerCloseBoundMs } from "./runner.js";
|
|
6
6
|
/** How long a busy run may finish its turn when the server stops, unless --drain-timeout says (cli.ts). */
|
|
7
7
|
export const DRAIN_TIMEOUT = "30s";
|
|
8
8
|
/** The runner beside a server holds what the server's own flags say (cli.ts): at most --max-runs runs at once (the same
|
|
@@ -107,14 +107,11 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
107
107
|
// are said in its name as the runner subcommand says them (main.ts troubleLine: a lost claim on stdout, an error on
|
|
108
108
|
// stderr), so a lapse of its claims shows its cause.
|
|
109
109
|
const { runLine } = await import("../print.js");
|
|
110
|
+
const { metricLine, startRunnerGauge } = await import("./runner-metrics.js");
|
|
110
111
|
const name = runnerName();
|
|
111
112
|
const said = (event) => {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
return void (onLine ?? (event.type === "error" ? console.error : console.log))(trouble);
|
|
115
|
-
const line = runLine(event);
|
|
116
|
-
if (line)
|
|
117
|
-
(onLine ?? console.log)(line);
|
|
113
|
+
for (const { line, error } of besideLines(name, event, { metricLine, troubleLine, runLine }))
|
|
114
|
+
(onLine ?? (error ? console.error : console.log))(line);
|
|
118
115
|
// The server's anonymous counts (telemetry.ts) hear a run's end: its state alone, never which run or agent.
|
|
119
116
|
if (event.type === "ended")
|
|
120
117
|
onRunEnded?.(event.status);
|
|
@@ -130,7 +127,29 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
|
|
|
130
127
|
// Its close waits for any first-use install its claims let go of to stop (its npm ended) before it lets go of the data.
|
|
131
128
|
const { claimInstallsStopped } = await import("../harness-install.js");
|
|
132
129
|
// The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
|
|
133
|
-
|
|
130
|
+
// Its gauge (runner-metrics.ts): the runs it holds of its loops, and the process's memory (the server's with it), every
|
|
131
|
+
// minute until its close.
|
|
132
|
+
const gauge = startRunnerGauge({ runner: name, held: () => runner.held().length, slots: held ?? RUNNER_LOOPS, write: (line) => (onLine ?? console.log)(line) });
|
|
133
|
+
return { runner, close: async () => { gauge.stop(); await Promise.all([swept?.close(), runner.close()]); await claimInstallsStopped(); await store.close(); seal.release(); } };
|
|
134
|
+
}
|
|
135
|
+
/** The lines runner `name` beside a server says for `event`, in order, each with whether it goes to stderr (`error`): its
|
|
136
|
+
* metric line (runner-metrics.ts metricLine: a claim, a hand-back by cause, a lost claim, the drain), then its trouble
|
|
137
|
+
* (main.ts troubleLine: a lost claim, an error) or else its run's start or end (print.ts runLine). A lost claim says
|
|
138
|
+
* both its metric and its trouble. The three are handed in, as runnerBeside imports them on its start. */
|
|
139
|
+
export function besideLines(name, event, say) {
|
|
140
|
+
const lines = [];
|
|
141
|
+
const metric = say.metricLine(name, event);
|
|
142
|
+
if (metric)
|
|
143
|
+
lines.push({ line: metric, error: false });
|
|
144
|
+
const trouble = say.troubleLine(name, event);
|
|
145
|
+
if (trouble)
|
|
146
|
+
lines.push({ line: trouble, error: event.type === "error" });
|
|
147
|
+
else {
|
|
148
|
+
const line = say.runLine(event);
|
|
149
|
+
if (line)
|
|
150
|
+
lines.push({ line, error: false });
|
|
151
|
+
}
|
|
152
|
+
return lines;
|
|
134
153
|
}
|
|
135
154
|
/** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
|
|
136
155
|
* what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type SaveSlots } from "../web-save.js";
|
|
2
|
+
import type { Pieces } from "../workspace/pieced.js";
|
|
3
|
+
import { type Workspace } from "../workspace/workspace.js";
|
|
4
|
+
export type { Pieces, PullPiece, WritePieces } from "../workspace/pieced.js";
|
|
5
|
+
export { piecedWorkspace } from "../workspace/pieced.js";
|
|
6
|
+
/** The most bytes one piece carries over the channel: well under its MAX_FRAME (32 MiB). A write of at most this many
|
|
7
|
+
* bytes crosses as one call, as before. */
|
|
8
|
+
export declare const PIECE_BYTES: number;
|
|
9
|
+
/** The most bytes one pieced write may have: web_save's cap. */
|
|
10
|
+
export declare const BIG_WRITE_MAX: number;
|
|
11
|
+
/** How long the runner waits for one piece before the write fails. */
|
|
12
|
+
export declare const PIECE_MS = 60000;
|
|
13
|
+
/** The most pieced writes a runner assembles at once, across its runs: with BIG_WRITE_MAX, what they hold in memory. */
|
|
14
|
+
export declare const BIG_WRITES = 4;
|
|
15
|
+
/** The most pieced writes one run may have held or waiting at once: its waiters live in the runner. */
|
|
16
|
+
export declare const BIG_WRITES_PER_RUN = 8;
|
|
17
|
+
/** The runner's one gate for pieced writes. */
|
|
18
|
+
export declare const BIG_WRITE_SLOTS: SaveSlots;
|
|
19
|
+
export type BigWritesOptions = {
|
|
20
|
+
/** Default BIG_WRITE_SLOTS. */
|
|
21
|
+
readonly gate?: SaveSlots;
|
|
22
|
+
/** Default PIECE_BYTES. */
|
|
23
|
+
readonly piece?: number;
|
|
24
|
+
/** Default PIECE_MS. */
|
|
25
|
+
readonly pieceMs?: number;
|
|
26
|
+
};
|
|
27
|
+
/** One run's pieced writes on its runner: `pieces(ws)` is what is handed beside `ws`; `close()`, called when the run's
|
|
28
|
+
* channel ends (or its claim is released), lets every wait and hold of the run go. */
|
|
29
|
+
export interface RunBigWrites {
|
|
30
|
+
pieces(ws: Workspace): Pieces;
|
|
31
|
+
close(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function runBigWrites(options?: BigWritesOptions): RunBigWrites;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// A Workspace write bigger than a channel frame, from a run's own process. In Mode 2 the run's process holds its runner's
|
|
2
|
+
// Workspace of the run's folder by handle (held.ts archil, archil-claim.ts archilWhereHeld), and a call carries all its
|
|
3
|
+
// arguments in one frame of the run's channel (run-channel.ts MAX_FRAME): a write of a file past that would fail after
|
|
4
|
+
// the bytes were made (web_save's download, up to SAVE_MAX_BYTES). So a write of more than one piece does not cross as one
|
|
5
|
+
// call: the runner, handed the length, pulls the bytes from the run's process a piece at a time, each piece of exactly
|
|
6
|
+
// the length it asked for, into one buffer allocated at that length, and makes the one atomic write itself, on the same
|
|
7
|
+
// Workspace the run's process would have written through. A piece that is not the length asked, a length past
|
|
8
|
+
// BIG_WRITE_MAX, the run's signal, a piece not answered in PIECE_MS, or the run's channel ending writes nothing.
|
|
9
|
+
//
|
|
10
|
+
// The runner holds each assembled file in memory until its write returns, so it bounds them: at most BIG_WRITES at once
|
|
11
|
+
// across its runs (BIG_WRITE_SLOTS, a gate of its own, never web_save's download slots, so a run that holds a download
|
|
12
|
+
// slot never waits on itself), the rest waiting under their call's signal, and at most BIG_WRITES_PER_RUN held or waiting
|
|
13
|
+
// per run. Every wait and hold of a run is let go when its channel ends (save-slots.ts does the same for its slots). The
|
|
14
|
+
// runner only copies bytes and calls the Workspace: it reads nothing of them and dials nothing.
|
|
15
|
+
import { ClaimRefused } from "./loop-contract.js";
|
|
16
|
+
import { ChannelClosed } from "./run-channel.js";
|
|
17
|
+
import { saveSlots, SAVE_MAX_BYTES } from "../web-save.js";
|
|
18
|
+
import { WorkspaceError } from "../workspace/workspace.js";
|
|
19
|
+
export { piecedWorkspace } from "../workspace/pieced.js";
|
|
20
|
+
const MIB = 1024 * 1024;
|
|
21
|
+
/** The most bytes one piece carries over the channel: well under its MAX_FRAME (32 MiB). A write of at most this many
|
|
22
|
+
* bytes crosses as one call, as before. */
|
|
23
|
+
export const PIECE_BYTES = 8 * MIB;
|
|
24
|
+
/** The most bytes one pieced write may have: web_save's cap. */
|
|
25
|
+
export const BIG_WRITE_MAX = SAVE_MAX_BYTES;
|
|
26
|
+
/** How long the runner waits for one piece before the write fails. */
|
|
27
|
+
export const PIECE_MS = 60_000;
|
|
28
|
+
/** The most pieced writes a runner assembles at once, across its runs: with BIG_WRITE_MAX, what they hold in memory. */
|
|
29
|
+
export const BIG_WRITES = 4;
|
|
30
|
+
/** The most pieced writes one run may have held or waiting at once: its waiters live in the runner. */
|
|
31
|
+
export const BIG_WRITES_PER_RUN = 8;
|
|
32
|
+
/** The runner's one gate for pieced writes. */
|
|
33
|
+
export const BIG_WRITE_SLOTS = saveSlots(BIG_WRITES);
|
|
34
|
+
/** `work`'s answer, or `signal`'s reason as soon as it aborts. */
|
|
35
|
+
function until(work, signal) {
|
|
36
|
+
if (signal.aborted)
|
|
37
|
+
return Promise.reject(signal.reason);
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const abort = () => reject(signal.reason);
|
|
40
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
41
|
+
work.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function runBigWrites(options = {}) {
|
|
45
|
+
const gate = options.gate ?? BIG_WRITE_SLOTS;
|
|
46
|
+
const piece = options.piece ?? PIECE_BYTES;
|
|
47
|
+
const pieceMs = options.pieceMs ?? PIECE_MS;
|
|
48
|
+
/** Each write of the run, waiting or held: aborted when the run's channel ends. */
|
|
49
|
+
const live = new Set();
|
|
50
|
+
let closed = false;
|
|
51
|
+
const writeOn = (ws) => async (path, size, pull, signal) => {
|
|
52
|
+
if (closed)
|
|
53
|
+
throw new ChannelClosed("the run's channel ended");
|
|
54
|
+
if (typeof path !== "string")
|
|
55
|
+
throw new TypeError("a pieced write names its path");
|
|
56
|
+
if (!Number.isSafeInteger(size) || size < 0)
|
|
57
|
+
throw new TypeError("a pieced write's size is a whole number of bytes");
|
|
58
|
+
// Before anything is taken or allocated.
|
|
59
|
+
if (size > BIG_WRITE_MAX)
|
|
60
|
+
throw new WorkspaceError("TOO_LARGE", `a write from a run's process is at most ${BIG_WRITE_MAX} bytes, not ${size}`, { path });
|
|
61
|
+
if (typeof pull !== "function")
|
|
62
|
+
throw new TypeError("a pieced write is pulled through a function");
|
|
63
|
+
if (signal !== undefined && !(signal instanceof AbortSignal))
|
|
64
|
+
throw new TypeError("a pieced write runs under the call's signal");
|
|
65
|
+
if (live.size >= BIG_WRITES_PER_RUN)
|
|
66
|
+
throw new ClaimRefused(`this run already has ${BIG_WRITES_PER_RUN} big writes held or waiting`);
|
|
67
|
+
const left = new AbortController();
|
|
68
|
+
live.add(left);
|
|
69
|
+
const under = signal ? AbortSignal.any([signal, left.signal]) : left.signal;
|
|
70
|
+
try {
|
|
71
|
+
const release = await gate.take(under);
|
|
72
|
+
try {
|
|
73
|
+
const bytes = new Uint8Array(size);
|
|
74
|
+
for (let at = 0; at < size;) {
|
|
75
|
+
const want = Math.min(piece, size - at);
|
|
76
|
+
const got = await until(Promise.resolve().then(() => pull(at, want)), AbortSignal.any([under, AbortSignal.timeout(pieceMs)]));
|
|
77
|
+
if (!(got instanceof Uint8Array) || got.length !== want) {
|
|
78
|
+
throw new WorkspaceError("REFUSED", `the piece at ${at} of a write is ${got instanceof Uint8Array ? `${got.length} bytes` : "not bytes"}, not the ${want} asked for: nothing was written`, { path });
|
|
79
|
+
}
|
|
80
|
+
bytes.set(got, at);
|
|
81
|
+
at += want;
|
|
82
|
+
}
|
|
83
|
+
// The run's end while the last piece came: nothing is written for it.
|
|
84
|
+
under.throwIfAborted();
|
|
85
|
+
await ws.write(path, bytes);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
release();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
live.delete(left);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
pieces: (ws) => ({ write: writeOn(ws), piece }),
|
|
97
|
+
close() {
|
|
98
|
+
if (closed)
|
|
99
|
+
return;
|
|
100
|
+
closed = true;
|
|
101
|
+
for (const write of live)
|
|
102
|
+
write.abort(new ChannelClosed("the run's channel ended"));
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -38,7 +38,7 @@ import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
|
|
|
38
38
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
39
39
|
import { readsFiles, systemOf } from "../skills.js";
|
|
40
40
|
import { DATA_ENV } from "../server-fs.js";
|
|
41
|
-
import { placeRunInputs } from "../uploads.js";
|
|
41
|
+
import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
42
42
|
import { recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
|
|
43
43
|
import { openRunWorkspace } from "../workspace/run-workspace.js";
|
|
44
44
|
import { layOwnSkills } from "../workspace/revision-skills.js";
|
|
@@ -342,10 +342,11 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
342
342
|
? undefined
|
|
343
343
|
// The run's mount credential, minted per run (account key from the server's environment first, then the sealed row),
|
|
344
344
|
// named for the run and this claim's epoch; revoke at the run's end (below). mountControl (a test's loopback control-plane
|
|
345
|
-
// fake) is
|
|
345
|
+
// fake) is the claim's control, so no test reaches the real control plane. TODO(k2 lazy mint): the mint moves into
|
|
346
346
|
// computerForClaim (a mounting computer only), with the ttl the run's lifetime bound (not this fixed figure). As pi does.
|
|
347
|
-
// The disk is the run's (run-disk.ts): its launch record's, else its agent's, made on its first run that needs one
|
|
348
|
-
|
|
347
|
+
// The disk is the run's (run-disk.ts): its launch record's, else its agent's, made on its first run that needs one,
|
|
348
|
+
// and read at Archil at every claim.
|
|
349
|
+
: await archilWhereHeld({ settings: archilSettings, keys: deps.store.sealedKeys, sealKey: deps.sealKey, signal: run.signal ?? new AbortController().signal, env: deps.env, mount: { runId: claim.runId, epoch: claim.epoch, ttlMs: MOUNT_TTL_MS }, ...(deps.mountControl ? { control: deps.mountControl } : {}), run: { agentId: runRow.agentId, ...(launch.archilDisk ? { launch: launch.archilDisk } : {}), store: deps.store }, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) });
|
|
349
350
|
// Each resource is held the moment it exists (spec-holds.ts): a throw after it lets it go. The claim's Archil keys go
|
|
350
351
|
// from memory last, once nothing more reads the disk.
|
|
351
352
|
holds.hold({ archil, keys: archil });
|
|
@@ -360,7 +361,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
360
361
|
holds.hold({ checkout });
|
|
361
362
|
// A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
|
|
362
363
|
if (!(deps.sealKey === undefined && runnerSeam()))
|
|
363
|
-
await placeRunInputs(deps.data, claim.runId, ws.workspace, launch
|
|
364
|
+
await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
|
|
364
365
|
// The run's skills and its learning seed laid before its computer exists, as the pi spec lays them (adapter-run-spec.ts):
|
|
365
366
|
// on Archil the computer's mount takes the disk's write delegation, and a lay over the disk's file API after it is
|
|
366
367
|
// refused (409) while the mount holds it.
|
|
@@ -389,7 +390,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
389
390
|
// Whether an earlier claim made the run a computer of its own is the run's journal's to say (hadComputer), as the pi
|
|
390
391
|
// spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount). Its
|
|
391
392
|
// screen's recording (computer.record) goes in the run's recordings folder, as the pi spec's does.
|
|
392
|
-
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
393
|
+
{ ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
|
|
393
394
|
holds.hold({ computer });
|
|
394
395
|
const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
|
|
395
396
|
const heldComputer = heldSpecOf(launch, loopComputer);
|
|
@@ -573,6 +574,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
573
574
|
let learnedTool;
|
|
574
575
|
let webTools = [];
|
|
575
576
|
let life;
|
|
577
|
+
// The claim's computers' time booked up to now before the run's end or park is written (compute-cost.ts), so the end's
|
|
578
|
+
// cost holds it: the release that deletes them comes after the end.
|
|
579
|
+
const settleComputers = computer.settle;
|
|
580
|
+
if (settleComputers) {
|
|
581
|
+
life = hostLifecycle();
|
|
582
|
+
life.register.beforeRelease(() => settleComputers());
|
|
583
|
+
}
|
|
576
584
|
// The keys the claim hands the run (its web tools and its learned workflow's call nodes run on them): never learned
|
|
577
585
|
// (learningEndOfRun).
|
|
578
586
|
let handedKeys = [];
|
|
@@ -620,9 +628,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
620
628
|
if (launch.plane && Object.keys(launch.plane).length)
|
|
621
629
|
toolEnv[TOOL_PLANE_ENV] = JSON.stringify(launch.plane);
|
|
622
630
|
if (webNames.length) {
|
|
623
|
-
life
|
|
631
|
+
life ??= hostLifecycle();
|
|
624
632
|
const liveAt = await claimLiveAt(deps, claim.runId);
|
|
625
|
-
const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}) });
|
|
633
|
+
const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}), ...(deps.saveSlots ? { saveSlots: deps.saveSlots } : {}) });
|
|
626
634
|
gate.askedOn(host);
|
|
627
635
|
webTools = await webHostTools(host, granted, ctx);
|
|
628
636
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { KeyEnv } from "../key-meta.js";
|
|
2
|
+
import type { Settings } from "../store/store.js";
|
|
3
|
+
/** The file in the server's data root that holds its id (made once, kept across starts). */
|
|
4
|
+
export declare const DATA_ROOT_FILE = "data-root.id";
|
|
5
|
+
/** The store.settings key a server keeps its data root's id under at each start: `{ v: 1, id }`. */
|
|
6
|
+
export declare const DATA_ROOT_KEY = "server.data_root";
|
|
7
|
+
/** The id in `dataDir`'s DATA_ROOT_FILE, or undefined when there is none (or it does not read as one). Never made here. */
|
|
8
|
+
export declare function dataRootIdIn(dataDir: string): string | undefined;
|
|
9
|
+
/** The server's start: its data root's id (the file's, else a new one written there, 0600), said in the store, replacing
|
|
10
|
+
* the last start's. Called once the server holds its data root (server-lock.ts), so no other server writes the file. */
|
|
11
|
+
export declare function recordDataRoot(store: {
|
|
12
|
+
settings: Pick<Settings, "put">;
|
|
13
|
+
}, dataDir: string): Promise<string>;
|
|
14
|
+
/** Whether a runner on `dataDir` shares its server's disk: true when its data directory holds the id the server said at its
|
|
15
|
+
* last start, false when it holds none or another, and undefined when the store holds none (a server older than this, or
|
|
16
|
+
* none started yet), which a caller takes as shared. */
|
|
17
|
+
export declare function sharesServerDisk(store: {
|
|
18
|
+
settings: Pick<Settings, "get">;
|
|
19
|
+
}, dataDir: string): Promise<boolean | undefined>;
|
|
20
|
+
/** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
|
|
21
|
+
* saved in the store, or set in the server's own environment, whose names (never values) it says at each start
|
|
22
|
+
* (runner-check.ts RUN_ENV_KEY). */
|
|
23
|
+
export declare function serverInArchilMode(store: {
|
|
24
|
+
settings: Pick<Settings, "get">;
|
|
25
|
+
}): Promise<boolean>;
|
|
26
|
+
/** Why a runner on `dataDir` can't serve the runs its store holds now, or undefined while it can. On Postgres, a runner
|
|
27
|
+
* whose `dataDir` is not the server's disk can't while the server keeps runs' folders on that disk (Mode 1: the server
|
|
28
|
+
* holds no Archil settings, saved or in its environment), whatever this runner's environment holds; nor while the server
|
|
29
|
+
* is in Mode 2 by its own environment and this runner holds no Archil settings, so its claim would keep the run's folder
|
|
30
|
+
* on its own disk. On SQLite always undefined: the store is in the data directory, so the runner's is the server's. */
|
|
31
|
+
export declare function diskFreeRefusal(store: {
|
|
32
|
+
settings: Pick<Settings, "get">;
|
|
33
|
+
}, dataDir: string, env: KeyEnv, storeKind: string): Promise<string | undefined>;
|
|
34
|
+
/** A disk-free runner's words while the server is in Mode 1: what the runner can't do, why, and the two ways out. */
|
|
35
|
+
export declare const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
|
|
36
|
+
/** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
|
|
37
|
+
export declare const DISK_FREE_NO_ARCHIL: string;
|
|
38
|
+
/** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
|
|
39
|
+
export declare const DISK_FREE_GATE_MS = 5000;
|
|
40
|
+
/** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
|
|
41
|
+
* DISK_FREE_GATE_MS between polls and read again when asked fresh. */
|
|
42
|
+
export declare function diskFreeGate(store: {
|
|
43
|
+
settings: Pick<Settings, "get">;
|
|
44
|
+
}, dataDir: string, env: KeyEnv, storeKind: string, now?: () => number): (fresh: boolean) => Promise<string | undefined>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// A runner on a disk of its own (a disk-free runner): `agentrun-serve runner --data D` where D is the runner's own local
|
|
2
|
+
// directory, not the server's, on the Postgres store AGENTRUN_STORE_URL names. Its data directory then holds only what
|
|
3
|
+
// is the runner's: its heartbeat, its runs' uid slots and their scratch, and the harnesses it installs at a claim. It never
|
|
4
|
+
// reads the server's: a run's folder is on Archil (Mode 2), which every machine reaches; Mode 1 keeps it on the server's
|
|
5
|
+
// own disk, which this runner can't see, so a disk-free runner claims nothing while the server is in Mode 1.
|
|
6
|
+
//
|
|
7
|
+
// Which disk is the server's: the server keeps an id of its data root in a file there (DATA_ROOT_FILE, made once) and
|
|
8
|
+
// says it in the store at each start (DATA_ROOT_KEY). A runner whose data directory holds the same id shares the server's
|
|
9
|
+
// disk (the image's server-and-runner, compose's runners on one /data volume); any other runner is disk-free. A store
|
|
10
|
+
// whose server has not said its data root yet (one older than this) is taken as shared, as every runner was before.
|
|
11
|
+
// SQLite is in the data directory, so a runner on it always shares the server's.
|
|
12
|
+
import { randomBytes } from "node:crypto";
|
|
13
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { ARCHIL_SETTINGS_ENV, loadArchilSettings } from "../archil-settings.js";
|
|
16
|
+
import { serverRunEnv } from "./runner-check.js";
|
|
17
|
+
/** The file in the server's data root that holds its id (made once, kept across starts). */
|
|
18
|
+
export const DATA_ROOT_FILE = "data-root.id";
|
|
19
|
+
/** The store.settings key a server keeps its data root's id under at each start: `{ v: 1, id }`. */
|
|
20
|
+
export const DATA_ROOT_KEY = "server.data_root";
|
|
21
|
+
const ID = /^[0-9a-f]{32}$/;
|
|
22
|
+
/** The id in `dataDir`'s DATA_ROOT_FILE, or undefined when there is none (or it does not read as one). Never made here. */
|
|
23
|
+
export function dataRootIdIn(dataDir) {
|
|
24
|
+
try {
|
|
25
|
+
const id = readFileSync(join(dataDir, DATA_ROOT_FILE), "utf8").trim();
|
|
26
|
+
return ID.test(id) ? id : undefined;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The server's start: its data root's id (the file's, else a new one written there, 0600), said in the store, replacing
|
|
33
|
+
* the last start's. Called once the server holds its data root (server-lock.ts), so no other server writes the file. */
|
|
34
|
+
export async function recordDataRoot(store, dataDir) {
|
|
35
|
+
let id = dataRootIdIn(dataDir);
|
|
36
|
+
if (id === undefined) {
|
|
37
|
+
id = randomBytes(16).toString("hex");
|
|
38
|
+
writeFileSync(join(dataDir, DATA_ROOT_FILE), `${id}\n`, { mode: 0o600 });
|
|
39
|
+
}
|
|
40
|
+
await store.settings.put(DATA_ROOT_KEY, { v: 1, id });
|
|
41
|
+
return id;
|
|
42
|
+
}
|
|
43
|
+
/** Whether a runner on `dataDir` shares its server's disk: true when its data directory holds the id the server said at its
|
|
44
|
+
* last start, false when it holds none or another, and undefined when the store holds none (a server older than this, or
|
|
45
|
+
* none started yet), which a caller takes as shared. */
|
|
46
|
+
export async function sharesServerDisk(store, dataDir) {
|
|
47
|
+
const said = await store.settings.get(DATA_ROOT_KEY);
|
|
48
|
+
const id = typeof said === "object" && said !== null ? said.id : undefined;
|
|
49
|
+
if (typeof id !== "string" || !ID.test(id))
|
|
50
|
+
return undefined;
|
|
51
|
+
return dataRootIdIn(dataDir) === id;
|
|
52
|
+
}
|
|
53
|
+
/** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
|
|
54
|
+
* saved in the store, or set in the server's own environment, whose names (never values) it says at each start
|
|
55
|
+
* (runner-check.ts RUN_ENV_KEY). */
|
|
56
|
+
export async function serverInArchilMode(store) {
|
|
57
|
+
if ((await loadArchilSettings(store)) !== undefined)
|
|
58
|
+
return true;
|
|
59
|
+
const names = await serverRunEnv(store);
|
|
60
|
+
return names !== undefined && [ARCHIL_SETTINGS_ENV.region, ARCHIL_SETTINGS_ENV.s3Url].every((name) => names.includes(name));
|
|
61
|
+
}
|
|
62
|
+
/** Why a runner on `dataDir` can't serve the runs its store holds now, or undefined while it can. On Postgres, a runner
|
|
63
|
+
* whose `dataDir` is not the server's disk can't while the server keeps runs' folders on that disk (Mode 1: the server
|
|
64
|
+
* holds no Archil settings, saved or in its environment), whatever this runner's environment holds; nor while the server
|
|
65
|
+
* is in Mode 2 by its own environment and this runner holds no Archil settings, so its claim would keep the run's folder
|
|
66
|
+
* on its own disk. On SQLite always undefined: the store is in the data directory, so the runner's is the server's. */
|
|
67
|
+
export async function diskFreeRefusal(store, dataDir, env, storeKind) {
|
|
68
|
+
if (storeKind === "sqlite")
|
|
69
|
+
return undefined;
|
|
70
|
+
if ((await sharesServerDisk(store, dataDir)) !== false)
|
|
71
|
+
return undefined;
|
|
72
|
+
if (!(await serverInArchilMode(store)))
|
|
73
|
+
return DISK_FREE_MODE_1;
|
|
74
|
+
if ((await loadArchilSettings(store, env)) === undefined)
|
|
75
|
+
return DISK_FREE_NO_ARCHIL;
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
/** A disk-free runner's words while the server is in Mode 1: what the runner can't do, why, and the two ways out. */
|
|
79
|
+
export const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
|
|
80
|
+
/** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
|
|
81
|
+
export const DISK_FREE_NO_ARCHIL = `this runner's data directory is not the server's, and the server keeps each run's folder on Archil (Mode 2) by the Archil settings in its environment, which this runner does not hold. Hand this runner the server's ${ARCHIL_SETTINGS_ENV.region} and ${ARCHIL_SETTINGS_ENV.s3Url} (and ${ARCHIL_SETTINGS_ENV.image} when the server has it), or save the Archil settings in the store.`;
|
|
82
|
+
/** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
|
|
83
|
+
export const DISK_FREE_GATE_MS = 5_000;
|
|
84
|
+
/** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
|
|
85
|
+
* DISK_FREE_GATE_MS between polls and read again when asked fresh. */
|
|
86
|
+
export function diskFreeGate(store, dataDir, env, storeKind, now = Date.now) {
|
|
87
|
+
let kept;
|
|
88
|
+
return async (fresh) => {
|
|
89
|
+
const at = now();
|
|
90
|
+
if (!fresh && kept && at - kept.at < DISK_FREE_GATE_MS)
|
|
91
|
+
return kept.words;
|
|
92
|
+
const words = await diskFreeRefusal(store, dataDir, env, storeKind);
|
|
93
|
+
kept = { at, words };
|
|
94
|
+
return words;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -15,13 +15,17 @@ export interface KeptEnd {
|
|
|
15
15
|
readonly outcome?: EndData["outcome"];
|
|
16
16
|
readonly endedAt: number;
|
|
17
17
|
}
|
|
18
|
-
/** A feedback round, as its
|
|
19
|
-
*
|
|
18
|
+
/** A feedback round, as its FEEDBACK entry keeps it: the round, whether the grade said right, and the grade's words
|
|
19
|
+
* (`text`). */
|
|
20
20
|
export interface FeedbackData {
|
|
21
21
|
readonly round: FeedbackRound;
|
|
22
22
|
readonly correct: boolean;
|
|
23
23
|
readonly text: string;
|
|
24
|
-
|
|
24
|
+
}
|
|
25
|
+
/** A feedback round as its steer's body carries it (`feedback`, beside the words): with the end the run had when the
|
|
26
|
+
* grade opened it again (`kept`), which the steer's taking keeps as the job's end (KINDS.jobEnd, beside FEEDBACK). */
|
|
27
|
+
export interface FeedbackSteer extends FeedbackData {
|
|
28
|
+
readonly kept: KeptEnd;
|
|
25
29
|
}
|
|
26
30
|
/** Whether the run's root `entries` hold a job's end kept for its look-back (KINDS.jobEnd) with no run end after it: the
|
|
27
31
|
* job ended and its look-back is under way, whether or not that look-back has asked anything yet. A follow-up's turn
|
|
@@ -31,8 +35,8 @@ export declare function jobEndOpen(entries: readonly {
|
|
|
31
35
|
}[]): boolean;
|
|
32
36
|
/** The end run's look-back keeps while it runs, from the run's root `entries` and its command rows, else undefined (no
|
|
33
37
|
* look-back under way, or one whose job's end was never kept):
|
|
34
|
-
* - the job's end
|
|
35
|
-
*
|
|
38
|
+
* - the job's end kept for it (KINDS.jobEnd, with its time), newer than the run's last end: by its claim before the
|
|
39
|
+
* end-of-run step, or for a grade's round by the steer's taking;
|
|
36
40
|
* - else from the round's steer the grade wrote, not taken yet (the run opened again, no runner on it yet).
|
|
37
41
|
* A follow-up's own turn keeps none until its job's end is kept: its run reads as going on, as main's does. */
|
|
38
42
|
export declare function keptEndOf(entries: readonly {
|
|
@@ -45,9 +49,9 @@ export declare function keptEndOf(entries: readonly {
|
|
|
45
49
|
export declare function feedbackRoundOf(grade: {
|
|
46
50
|
readonly path: RunPath;
|
|
47
51
|
}, label: string | undefined): FeedbackRound | undefined;
|
|
48
|
-
/** The feedback round a steer's body asks for (`body.feedback`, the server's own:
|
|
49
|
-
* message API never does), else undefined. */
|
|
50
|
-
export declare function feedbackOf(body: unknown):
|
|
52
|
+
/** The feedback round a steer's body asks for (`body.feedback`, the server's own: openFeedbackRound writes it with the
|
|
53
|
+
* end it kept, and the message API never does), else undefined. */
|
|
54
|
+
export declare function feedbackOf(body: unknown): FeedbackSteer | undefined;
|
|
51
55
|
/** The feedback round the run's root `entries` say its next end closes: its newest FEEDBACK entry when no end came after
|
|
52
56
|
* it, else undefined. */
|
|
53
57
|
export declare function pendingFeedbackOf(entries: readonly {
|