@parcha/agentrun-serve 0.1.0-beta.45 → 0.1.0-beta.47
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 +180 -0
- package/NOTICE +4 -0
- package/README.md +283 -47
- package/dist/acp-package.d.ts +35 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +5 -2
- package/dist/adapter-facts.js +6 -3
- package/dist/adapters.d.ts +7 -0
- package/dist/adapters.js +39 -0
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +7 -10
- package/dist/archil-routes.js +2 -1
- package/dist/cap.js +12 -2
- package/dist/chatgpt-plan.js +2 -1
- package/dist/cli.js +119 -44
- package/dist/composio-made.d.ts +19 -2
- package/dist/composio-made.js +17 -5
- package/dist/composio-preset.d.ts +42 -7
- package/dist/composio-preset.js +106 -70
- package/dist/composio-triggers.d.ts +9 -4
- package/dist/composio-triggers.js +20 -13
- package/dist/computer-attach.d.ts +11 -10
- package/dist/computer-attach.js +13 -14
- package/dist/computer-commands.d.ts +3 -0
- package/dist/computer-commands.js +3 -2
- package/dist/computer-lost.d.ts +4 -0
- package/dist/computer-lost.js +8 -3
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +9 -75
- package/dist/computers.js +20 -66
- package/dist/console/assets/index-BBFzAxLB.js +715 -0
- package/dist/console/assets/index-BRi-Rgq6.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/cost-heal.d.ts +13 -0
- package/dist/cost-heal.js +27 -0
- package/dist/dial-relay.d.ts +6 -2
- package/dist/dial-relay.js +9 -12
- package/dist/email/routes.js +2 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -0
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/faux-computers.d.ts +2 -3
- package/dist/faux-computers.js +9 -31
- package/dist/github-connection.js +2 -1
- package/dist/harness-archive.d.ts +19 -2
- package/dist/harness-archive.js +49 -15
- package/dist/harness-check.d.ts +73 -0
- package/dist/harness-check.js +489 -0
- package/dist/harness-cursor.d.ts +45 -0
- package/dist/harness-cursor.js +121 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +357 -0
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +62 -2
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +3 -2
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +14 -0
- package/dist/host.d.ts +10 -3
- package/dist/host.js +17 -3
- package/dist/import-sources.d.ts +2 -0
- package/dist/import-sources.js +2 -0
- package/dist/import-summary.d.ts +15 -5
- package/dist/import-summary.js +24 -8
- package/dist/import.d.ts +34 -4
- package/dist/import.js +134 -32
- package/dist/key-refusal.d.ts +1 -0
- package/dist/key-refusal.js +8 -3
- package/dist/key-words.d.ts +1 -1
- package/dist/key-words.js +4 -4
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +31 -20
- package/dist/learn/compile.js +11 -4
- package/dist/learn/promote.d.ts +77 -4
- package/dist/learn/promote.js +123 -2
- package/dist/learned-nodes.d.ts +4 -3
- package/dist/learned-workflow.js +4 -1
- package/dist/learning-cost.d.ts +6 -16
- package/dist/learning-cost.js +6 -12
- package/dist/learning-setting.d.ts +17 -6
- package/dist/learning-setting.js +41 -5
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +1 -1
- package/dist/listen-first.d.ts +10 -0
- package/dist/listen-first.js +25 -1
- package/dist/llms.txt +1 -1
- package/dist/mcp-gateway.d.ts +2 -1
- package/dist/mcp-gateway.js +31 -15
- package/dist/mcp-probe.d.ts +18 -6
- package/dist/mcp-probe.js +41 -8
- package/dist/mcp-secret-writes.d.ts +8 -0
- package/dist/mcp-secret-writes.js +104 -4
- package/dist/mcp-servers-store.d.ts +11 -5
- package/dist/mcp-servers-store.js +46 -20
- package/dist/model-form.d.ts +2 -1
- package/dist/model-form.js +22 -8
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +2 -1
- package/dist/model.js +9 -7
- package/dist/monid.js +1 -1
- package/dist/native/binding.d.ts +4 -0
- package/dist/native/binding.js +9 -0
- package/dist/native/cli.d.ts +3 -2
- package/dist/native/cli.js +6 -5
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +326 -41
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +8 -0
- package/dist/page.js +9 -1
- package/dist/port-models.js +17 -10
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +12 -3
- package/dist/public-address.d.ts +28 -0
- package/dist/public-address.js +62 -0
- package/dist/run-launch.d.ts +1 -1
- package/dist/run-launch.js +1 -1
- package/dist/run-secrets.d.ts +3 -2
- package/dist/run-secrets.js +6 -4
- package/dist/runner/adapter-loop.d.ts +10 -7
- package/dist/runner/adapter-loop.js +57 -22
- package/dist/runner/adapter-run-spec.d.ts +12 -0
- package/dist/runner/adapter-run-spec.js +40 -6
- package/dist/runner/adapters/index.js +16 -0
- package/dist/runner/adapters/pi.d.ts +5 -2
- package/dist/runner/adapters/pi.js +7 -4
- package/dist/runner/audit.d.ts +7 -0
- package/dist/runner/audit.js +24 -6
- package/dist/runner/claim-secrets.js +5 -1
- package/dist/runner/cli-run-spec.js +15 -7
- package/dist/runner/compare-end.d.ts +43 -0
- package/dist/runner/compare-end.js +95 -0
- package/dist/runner/computer-journal.d.ts +3 -0
- package/dist/runner/computer-journal.js +22 -2
- package/dist/runner/conformance/harness.js +19 -8
- package/dist/runner/conformance/subject.d.ts +6 -0
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +94 -54
- package/dist/runner/held.d.ts +5 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +3 -0
- package/dist/runner/loop-contract.d.ts +10 -0
- package/dist/runner/main.d.ts +5 -5
- package/dist/runner/main.js +81 -11
- package/dist/runner/mcp-claim.js +40 -12
- package/dist/runner/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +41 -0
- package/dist/runner/presence.js +89 -0
- package/dist/runner/promotion.d.ts +10 -3
- package/dist/runner/promotion.js +42 -21
- package/dist/runner/run-child-host.js +52 -14
- package/dist/runner/runner.d.ts +5 -0
- package/dist/runner/runner.js +8 -0
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +19 -7
- package/dist/runner/workflow-first.d.ts +5 -2
- package/dist/runner/workflow-first.js +6 -3
- package/dist/runs-over-store.d.ts +6 -2
- package/dist/runs-over-store.js +14 -4
- package/dist/sdk/runs.d.ts +1 -1
- package/dist/sdk/runs.js +6 -1
- package/dist/sdk/schema.js +1 -1
- package/dist/secret-writes.d.ts +16 -3
- package/dist/secret-writes.js +28 -3
- package/dist/server-secrets-store.js +5 -0
- package/dist/server.d.ts +31 -2
- package/dist/server.js +326 -53
- package/dist/sign-ins-secrets.js +4 -1
- package/dist/skills/agentrun-serve/SKILL.md +11 -0
- package/dist/slack-url.d.ts +5 -0
- package/dist/slack-url.js +11 -0
- package/dist/slack.d.ts +107 -0
- package/dist/slack.js +292 -0
- package/dist/start-switches.d.ts +28 -0
- package/dist/start-switches.js +37 -0
- package/dist/stats.d.ts +1 -1
- package/dist/stats.js +2 -1
- package/dist/stop-signals.d.ts +11 -0
- package/dist/stop-signals.js +22 -0
- package/dist/store/agent-body.d.ts +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0020_runners.sql +18 -0
- package/dist/store/postgres/store.d.ts +1 -1
- package/dist/store/postgres/store.js +4 -2
- package/dist/store/schema.d.ts +13 -5
- package/dist/store/schema.js +20 -11
- package/dist/store/seal.d.ts +16 -4
- package/dist/store/sqlite/store.d.ts +1 -1
- package/dist/store/sqlite/store.js +106 -27
- package/dist/store/store.d.ts +75 -23
- package/dist/store/store.js +11 -0
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +7 -0
- package/dist/store-reads/cap.js +11 -1
- package/dist/store-reads/journal.js +27 -1
- package/dist/store-reads/learning.d.ts +23 -2
- package/dist/store-reads/learning.js +29 -8
- package/dist/store-reads/runs.d.ts +9 -0
- package/dist/store-reads/runs.js +19 -6
- package/dist/store-reads/stats.d.ts +4 -1
- package/dist/store-reads/stats.js +15 -6
- package/dist/store-view.d.ts +123 -14
- package/dist/store-view.js +154 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/templates.d.ts +6 -3
- package/dist/templates.js +38 -3
- package/dist/timeline/timeline.js +18 -0
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.js +2 -2
- package/dist/trigger-adapter.d.ts +3 -4
- package/dist/trigger-adapter.js +2 -2
- package/dist/trigger-composio.js +3 -3
- package/dist/trigger-email.js +0 -2
- package/dist/trigger-feed.js +0 -2
- package/dist/trigger-schedule.js +3 -0
- package/dist/trigger-secrets-shown.d.ts +6 -3
- package/dist/trigger-secrets-shown.js +22 -13
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +19 -8
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +2 -1
- package/dist/webhooks.d.ts +85 -9
- package/dist/webhooks.js +129 -46
- package/dist/wires.d.ts +6 -1
- package/dist/wires.js +5 -0
- package/dist/workspace/attach.d.ts +3 -2
- package/dist/workspace/attach.js +2 -1
- package/dist/workspace/attached-computers.d.ts +6 -8
- package/dist/workspace/attached-computers.js +27 -24
- package/dist/workspace/computer-deps.d.ts +2 -3
- package/dist/workspace/computer-deps.js +3 -6
- package/dist/workspace/computer-for-claim.js +72 -96
- package/dist/workspace/computer-kept.d.ts +0 -7
- package/dist/workspace/computer-kept.js +0 -17
- package/dist/workspace/resolve-computer.d.ts +18 -14
- package/dist/workspace/resolve-computer.js +47 -60
- package/dist/workspace/synced-folder.d.ts +20 -15
- package/dist/workspace/synced-folder.js +33 -43
- package/launcher/agentrun-serve +4 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/templates/inbound-lead/agent.md +2 -1
- package/templates/kyb/agent.md +2 -1
- package/dist/console/assets/index-3O2Yl6hZ.js +0 -701
- package/dist/console/assets/index-DaFsZuzQ.css +0 -1
|
@@ -209,6 +209,10 @@ async function world(subject, t, timing = STEADY) {
|
|
|
209
209
|
const handed = new Set();
|
|
210
210
|
/** The command rows a loop's command() has answered: a steer it took is with the session by then (a CLI's has it). */
|
|
211
211
|
const answered = new Set();
|
|
212
|
+
/** What each command row's command() said, in order (taken, later or refused with its reason, or what it threw): for a
|
|
213
|
+
* case's failure message to name the branch a command took, never asserted on. */
|
|
214
|
+
const outcomes = new Map();
|
|
215
|
+
const outcomeSaid = (id, said) => outcomes.set(id, [...(outcomes.get(id) ?? []), said]);
|
|
212
216
|
/** Each runner's claims in flight (store.runs.claimMany), by its name: what claimsSettled waits for. */
|
|
213
217
|
const claiming = new Map();
|
|
214
218
|
/** `store` as runner `name` is handed it: the same store, its claims in flight counted (claiming). */
|
|
@@ -282,7 +286,10 @@ async function world(subject, t, timing = STEADY) {
|
|
|
282
286
|
command: (command) => {
|
|
283
287
|
handed.add(command.id);
|
|
284
288
|
const outcome = loop.command(command);
|
|
285
|
-
void Promise.resolve(outcome).then(() =>
|
|
289
|
+
void Promise.resolve(outcome).then((said) => {
|
|
290
|
+
outcomeSaid(command.id, said === null || typeof said !== "object" ? String(said) : "taken" in said ? "taken" : "later" in said ? `later: ${said.later}` : `refused: ${said.refused}`);
|
|
291
|
+
answered.add(command.id);
|
|
292
|
+
}, (error) => outcomeSaid(command.id, `threw ${error?.name ?? String(error)}`));
|
|
286
293
|
return outcome;
|
|
287
294
|
},
|
|
288
295
|
};
|
|
@@ -382,7 +389,7 @@ async function world(subject, t, timing = STEADY) {
|
|
|
382
389
|
assert.ok(ask, "the run wrote its ask");
|
|
383
390
|
return String(ask.data.callId);
|
|
384
391
|
};
|
|
385
|
-
return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), answered: (id) => answered.has(id), liveRows, servedRows };
|
|
392
|
+
return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), answered: (id) => answered.has(id), outcomeOf: (id) => (outcomes.get(id) ?? ["not answered"]).join(", then "), liveRows, servedRows };
|
|
386
393
|
}
|
|
387
394
|
/** What the process wrote after it said it stops at the point, in its file's order (each line is appended synchronously),
|
|
388
395
|
* or everything when it never said so. One millisecond of the clock can hold the loop's last write before the stop and
|
|
@@ -708,9 +715,13 @@ const CASES = [
|
|
|
708
715
|
async body(subject, t) {
|
|
709
716
|
const w = await world(subject, t);
|
|
710
717
|
const { tools, letSlowGo, slowStarted } = suiteTools();
|
|
711
|
-
|
|
718
|
+
// What the subject's model was handed, and at what priority, when it can say: a failure names it with the loop's
|
|
719
|
+
// outcome for the steer, so the branch that placed it is on the record (a CLI's own turn after the call reads `echo:`).
|
|
720
|
+
const received = [];
|
|
721
|
+
await w.start("runner-a", { script: [{ call: "slow" }, { sayLastSteer: true }], tools, hooks: quiet, received: (message) => void received.push({ ...message }) });
|
|
712
722
|
await w.began(slowStarted, "the slow tool to start");
|
|
713
723
|
const steer = await sendCommand(w.server, RUN, { kind: "steer", body: { text: "check the totals" } });
|
|
724
|
+
const why = () => `the loop's outcome for the steer: ${w.outcomeOf(steer.id)}; the model was handed: ${JSON.stringify(received)}`;
|
|
714
725
|
// The tool goes on once the loop has answered the steer: the turn in flight has it, never a timer (as in
|
|
715
726
|
// message-mid-turn-kept). A steer that reaches a CLI only after the tool's end is the next turn by its facts.
|
|
716
727
|
await until(() => w.answered(steer.id), "the steer placed by the loop mid-turn");
|
|
@@ -723,11 +734,11 @@ const CASES = [
|
|
|
723
734
|
// Everything the model said once the call started. What it said with the call, before the call's row (a CLI's
|
|
724
735
|
// "Calling slow."), is that step's, as deny-note reads it; the step after the call said only the steer.
|
|
725
736
|
const said = messages.filter((message) => message.role === "model" && message.entry > slow.startEntry);
|
|
726
|
-
assert.equal(steered?.text, "check the totals", `the steer is in the journal: ${JSON.stringify(messages)}`);
|
|
727
|
-
assert.ok(steered.entry > slow.endEntry,
|
|
728
|
-
assert.deepEqual(said.map((message) => message.text), ["check the totals"], `the next step saw it: ${JSON.stringify(messages)}`);
|
|
729
|
-
assert.ok(said[0].entry > steered.entry);
|
|
730
|
-
assert.ok((await w.commandRow(steer.id)).takenAt !== null,
|
|
737
|
+
assert.equal(steered?.text, "check the totals", `the steer is in the journal: ${JSON.stringify(messages)}; ${why()}`);
|
|
738
|
+
assert.ok(steered.entry > slow.endEntry, `after the tool's end: mid-turn, not lost; ${why()}`);
|
|
739
|
+
assert.deepEqual(said.map((message) => message.text), ["check the totals"], `the next step saw it: ${JSON.stringify(messages)}; ${why()}`);
|
|
740
|
+
assert.ok(said[0].entry > steered.entry, why());
|
|
741
|
+
assert.ok((await w.commandRow(steer.id)).takenAt !== null, `the steer row is taken; ${why()}`);
|
|
731
742
|
},
|
|
732
743
|
},
|
|
733
744
|
{
|
|
@@ -61,6 +61,12 @@ export interface ConformanceSetup {
|
|
|
61
61
|
readonly hooks: KernelHooks;
|
|
62
62
|
/** The run's agent, for the subject's spec to name (AdapterRunSpec.agentId): the end-of-run step is asked with it. */
|
|
63
63
|
readonly agentId?: string;
|
|
64
|
+
/** Called with each message the subject's model is handed, when the subject can see it (a stand-in's fake reports what
|
|
65
|
+
* it consumed and at what priority): for a case's failure message to name, never asserted on. */
|
|
66
|
+
readonly received?: (message: {
|
|
67
|
+
readonly text: string;
|
|
68
|
+
readonly priority?: string;
|
|
69
|
+
}) => void;
|
|
64
70
|
}
|
|
65
71
|
export type ConformanceCase = "crash-before-intent" | "crash-after-intent" | "crash-before-intent-process" | "crash-after-intent-process" | "stalled-past-lease-process" | "replay-safe-rerun" | "steer-mid-turn" | "message-mid-turn-kept" | "message-resent-after-crash" | "steer-placed-crash" | "cancel-ends-for-good" | "cancel-parked" | "deny-note" | "steer-origin" | "stop-ends-turn" | "park-on-ask" | "approval-names-its-call" | "approval-double-click" | "approval-race" | "message-never-answers" | "end-of-run-answer" | "fault-effects-once" | "fault-restarts-bounded" | "length-ends-failed" | "length-mid-run" | "meta-search" | "meta-call-park" | "meta-call-deny" | "meta-codemode-park" | "meta-codemode-stop" | "meta-codemode-crash";
|
|
66
72
|
export interface ConformanceSubject {
|
|
@@ -8,8 +8,13 @@ export declare class NeverFits extends ClaimRefused {
|
|
|
8
8
|
}
|
|
9
9
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
10
10
|
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
|
|
11
|
-
export declare function resolveRunnerLoop(
|
|
11
|
+
export declare function resolveRunnerLoop(given: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
|
|
12
12
|
/** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
|
|
13
13
|
* dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
|
|
14
14
|
* start and the test server pass this to startRunner. */
|
|
15
15
|
export declare function dispatchRunner(deps: AdapterSpecDeps): LoopFactory;
|
|
16
|
+
/** `deps` with the model gateway saved in the console laid over its run environment (model-gateway.ts withSavedGateway),
|
|
17
|
+
* read from the store now; `deps` itself where none is saved or the runner's environment names its own. A run's own
|
|
18
|
+
* process (no seal key) reads nothing of it: its runner laid it over the claim (run-child-host.ts) and marked it
|
|
19
|
+
* (SAVED_GATEWAY_ENV), and only that mark is read here. */
|
|
20
|
+
export declare function withSavedGatewayDeps(deps: AdapterSpecDeps): Promise<AdapterSpecDeps>;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { envGatewayInForce, readSavedGateway, savedGatewayIn, savedGatewayMarked, SAVED_GATEWAY_ENV, withSavedGateway } from "../model-gateway.js";
|
|
2
|
+
import { GATEWAY_KEY_ENV } from "../model.js";
|
|
3
|
+
import { heldRedactor } from "./redact.js";
|
|
4
|
+
import { envValue } from "../key-meta.js";
|
|
1
5
|
import { createSdkLoop } from "./sdk-loop.js";
|
|
2
6
|
import { createNativeLoop } from "./native-loop.js";
|
|
3
7
|
// The runner's dispatch switch (design 2.1: "the runner takes every run"): which loop a claimed run runs, by its revision
|
|
@@ -29,63 +33,86 @@ export class NeverFits extends ClaimRefused {
|
|
|
29
33
|
}
|
|
30
34
|
/** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
|
|
31
35
|
* returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
|
|
32
|
-
export function resolveRunnerLoop(
|
|
36
|
+
export function resolveRunnerLoop(given) {
|
|
33
37
|
return async (harness, launch, runId) => {
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// the runner resolves any (routeProviderOf over the route, the default when no providerOf is given).
|
|
41
|
-
// The runner's seal key and data directory go with it: a claim's sealed secrets are read with them (claim-secrets.ts,
|
|
42
|
-
// store-secrets.ts), and every one the server keeps is held by the run's one redactor.
|
|
43
|
-
return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}) }));
|
|
44
|
-
}
|
|
45
|
-
// A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
|
|
46
|
-
// start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
|
|
47
|
-
if (launch.sdk)
|
|
48
|
-
return createSdkLoop(launch, deps, async () => {
|
|
49
|
-
const base = deps.env ?? process.env;
|
|
50
|
-
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
51
|
-
// It runs after its backend reported the run complete, on no run's key: on a server that holds no gateway key it is
|
|
52
|
-
// skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
|
|
53
|
-
const off = noServerKeyFor(env, "An SDK run's compile turn");
|
|
54
|
-
if (off) {
|
|
55
|
-
deps.log?.(off);
|
|
56
|
-
throw new Error(off);
|
|
57
|
-
}
|
|
58
|
-
return askRouteOf(launch.learning.model, env, (model) => deps.routeOf(model, env, "default", PI_WIRES));
|
|
59
|
-
});
|
|
60
|
-
if (launch.native)
|
|
61
|
-
return createNativeLoop(launch, deps);
|
|
62
|
-
// The harness's own entry decides which spec builds the run, by what the entry gives and never the harness's name: an
|
|
63
|
-
// entry with an adapter's facts and serve's own adapter for it (the CLI harnesses) runs the CLI spec (cli-run-spec.ts);
|
|
64
|
-
// any other (pi, or a harness module's entry that gives only the required members) runs the run spec
|
|
65
|
-
// (adapterRunSpecFromLaunch), whose adapter is its runner's (resolveHarness), with the record mode that runner names.
|
|
66
|
-
// A harness with no entry is unknown here: the dispatch fails it in words.
|
|
67
|
-
const env = deps.env ?? process.env;
|
|
68
|
-
const runner = resolveHarness(harness, env);
|
|
69
|
-
if (runner) {
|
|
70
|
-
// A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
|
|
71
|
-
// fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
|
|
72
|
-
// started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
|
|
73
|
-
// the host's memory and its OOM kill would take every run on it.
|
|
74
|
-
const tooBig = neverFits(harness, hostMemory(), env);
|
|
75
|
-
if (tooBig)
|
|
76
|
-
throw new NeverFits(tooBig);
|
|
77
|
-
const entry = harnessOf(env, harness);
|
|
78
|
-
// A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
|
|
79
|
-
// where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
|
|
80
|
-
// path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
|
|
81
|
-
// run that does not learn supplies none. The same for the pi and the CLI spec.
|
|
82
|
-
return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
|
|
83
|
-
? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
|
|
84
|
-
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), deps.modelRetry ?? {});
|
|
85
|
-
}
|
|
86
|
-
return undefined;
|
|
38
|
+
// The model gateway saved in the console (model-gateway.ts), read from the store at each claim and laid over the run
|
|
39
|
+
// environment as its variables would be, so a gateway saved or removed since reaches the next run with no restart. A
|
|
40
|
+
// gateway the runner's environment names wins, and nothing saved is read over it.
|
|
41
|
+
const deps = await withSavedGatewayDeps(given);
|
|
42
|
+
const made = await loopOn(deps, harness, launch, runId);
|
|
43
|
+
return made && holdingGatewayKey(made, deps.env);
|
|
87
44
|
};
|
|
88
45
|
}
|
|
46
|
+
/** `made` with the saved gateway's key, as this claim read it, held by the run's one redactor before the loop starts: the
|
|
47
|
+
* key stays off the claim's tool keys (claimSecrets), and a later scan of the store (holdStored) would find only a key
|
|
48
|
+
* saved since, so a gateway reply that echoes this one is cut in the run's records and logs all the same. `made` itself
|
|
49
|
+
* where the gateway is not the saved one. */
|
|
50
|
+
function holdingGatewayKey(made, env) {
|
|
51
|
+
const key = env && savedGatewayIn(env) ? env[GATEWAY_KEY_ENV] : undefined;
|
|
52
|
+
if (!key)
|
|
53
|
+
return made;
|
|
54
|
+
return (loopDeps) => {
|
|
55
|
+
if (loopDeps.redact)
|
|
56
|
+
heldRedactor(loopDeps.redact).hold([key]);
|
|
57
|
+
return made(loopDeps);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** The loop a claimed run runs on, over `deps` (the saved gateway laid over its environment). */
|
|
61
|
+
async function loopOn(deps, harness, launch, runId) {
|
|
62
|
+
// A workflow revision runs on the workflow loop whatever the harness its body names (its default is pi): read the
|
|
63
|
+
// revision to tell it apart from an agentic pi run.
|
|
64
|
+
const run = await deps.store.runs.get(runId);
|
|
65
|
+
const revision = run ? await deps.store.agents.revision(run.revisionId) : undefined;
|
|
66
|
+
if (revision && isWorkflowRevision(revision)) {
|
|
67
|
+
// A workflow run on the workflow loop: its claim-time spec (workflow-spec.ts) resolves each tier's model the one way
|
|
68
|
+
// the runner resolves any (routeProviderOf over the route, the default when no providerOf is given).
|
|
69
|
+
// The runner's seal key and data directory go with it: a claim's sealed secrets are read with them (claim-secrets.ts,
|
|
70
|
+
// store-secrets.ts), and every one the server keeps is held by the run's one redactor.
|
|
71
|
+
return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}) }));
|
|
72
|
+
}
|
|
73
|
+
// A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
|
|
74
|
+
// start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
|
|
75
|
+
if (launch.sdk)
|
|
76
|
+
return createSdkLoop(launch, deps, async () => {
|
|
77
|
+
const base = deps.env ?? process.env;
|
|
78
|
+
const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
|
|
79
|
+
// It runs after its backend reported the run complete, on no run's key: on a server that holds no gateway key it is
|
|
80
|
+
// skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
|
|
81
|
+
const off = noServerKeyFor(env, "An SDK run's compile turn");
|
|
82
|
+
if (off) {
|
|
83
|
+
deps.log?.(off);
|
|
84
|
+
throw new Error(off);
|
|
85
|
+
}
|
|
86
|
+
return askRouteOf(launch.learning.model, env, (model) => deps.routeOf(model, env, "default", PI_WIRES));
|
|
87
|
+
});
|
|
88
|
+
if (launch.native)
|
|
89
|
+
return createNativeLoop(launch, deps);
|
|
90
|
+
// The harness's own entry decides which spec builds the run, by what the entry gives and never the harness's name: an
|
|
91
|
+
// entry with an adapter's facts and serve's own adapter for it (the CLI harnesses) runs the CLI spec (cli-run-spec.ts);
|
|
92
|
+
// any other (pi, or a harness module's entry that gives only the required members) runs the run spec
|
|
93
|
+
// (adapterRunSpecFromLaunch), whose adapter is its runner's (resolveHarness), with the record mode that runner names.
|
|
94
|
+
// A harness with no entry is unknown here: the dispatch fails it in words.
|
|
95
|
+
const env = deps.env ?? process.env;
|
|
96
|
+
const runner = resolveHarness(harness, env);
|
|
97
|
+
if (runner) {
|
|
98
|
+
// A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
|
|
99
|
+
// fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
|
|
100
|
+
// started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
|
|
101
|
+
// the host's memory and its OOM kill would take every run on it.
|
|
102
|
+
const tooBig = neverFits(harness, hostMemory(), env);
|
|
103
|
+
if (tooBig)
|
|
104
|
+
throw new NeverFits(tooBig);
|
|
105
|
+
const entry = harnessOf(env, harness);
|
|
106
|
+
// A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
|
|
107
|
+
// where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
|
|
108
|
+
// path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
|
|
109
|
+
// run that does not learn supplies none. The same for the pi and the CLI spec.
|
|
110
|
+
return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
|
|
111
|
+
? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
|
|
112
|
+
: adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), deps.modelRetry ?? {});
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
89
116
|
/** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
|
|
90
117
|
* dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
|
|
91
118
|
* start and the test server pass this to startRunner. */
|
|
@@ -95,3 +122,16 @@ export function dispatchRunner(deps) {
|
|
|
95
122
|
resolve: resolveRunnerLoop(deps),
|
|
96
123
|
});
|
|
97
124
|
}
|
|
125
|
+
/** `deps` with the model gateway saved in the console laid over its run environment (model-gateway.ts withSavedGateway),
|
|
126
|
+
* read from the store now; `deps` itself where none is saved or the runner's environment names its own. A run's own
|
|
127
|
+
* process (no seal key) reads nothing of it: its runner laid it over the claim (run-child-host.ts) and marked it
|
|
128
|
+
* (SAVED_GATEWAY_ENV), and only that mark is read here. */
|
|
129
|
+
export async function withSavedGatewayDeps(deps) {
|
|
130
|
+
const base = deps.env ?? process.env;
|
|
131
|
+
if (envValue(base, SAVED_GATEWAY_ENV) === "1")
|
|
132
|
+
return { ...deps, env: savedGatewayMarked(base) };
|
|
133
|
+
if (envGatewayInForce(base) || !deps.sealKey)
|
|
134
|
+
return deps;
|
|
135
|
+
const saved = await readSavedGateway(deps.store, deps.sealKey);
|
|
136
|
+
return saved ? { ...deps, env: withSavedGateway(base, saved) } : deps;
|
|
137
|
+
}
|
package/dist/runner/held.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import type { PlanReader } from "../chatgpt-plan.js";
|
|
|
2
2
|
import type { Tier } from "../model.js";
|
|
3
3
|
import type { RunSignIn } from "../sign-ins-store.js";
|
|
4
4
|
import type { LiveHandover } from "../browser-live.js";
|
|
5
|
+
import type { ComputerHoldChange } from "./computer-journal.js";
|
|
5
6
|
import type { ApprovalPrice, ToolEffect } from "../tool-gate.js";
|
|
6
7
|
import type { OpenedAccount } from "../email/account.js";
|
|
7
8
|
import type { SavedCalendar } from "../calendar/address.js";
|
|
8
9
|
import type { Workspace } from "../workspace/workspace.js";
|
|
9
10
|
import type { GithubAppAccessAt } from "./github-app.js";
|
|
10
11
|
import type { HarnessInstallEntry, HarnessPins } from "../harness-install.js";
|
|
11
|
-
import type { AlsoRow } from "../store/store.js";
|
|
12
12
|
import type { RunModelKey } from "../store/seal.js";
|
|
13
13
|
import type { EndOfRunKept, EndOfRunTurn } from "./loop-contract.js";
|
|
14
14
|
import type { LearnedFirst } from "./learned-first.js";
|
|
@@ -90,6 +90,9 @@ export interface Held {
|
|
|
90
90
|
/** A browser session's viewer handed over, and taken back (browser-live.ts). */
|
|
91
91
|
liveViewerPut(handover: LiveHandover): Promise<boolean>;
|
|
92
92
|
liveViewerDrop(tag?: string): Promise<void>;
|
|
93
|
+
/** A change of the claim's computer's hold, committed to the run's journal here: signalled on the runner, whose live
|
|
94
|
+
* view of the computer tells its open viewer (computer-journal.ts heardComputerHold). */
|
|
95
|
+
computerHold(change: ComputerHoldChange): Promise<void>;
|
|
93
96
|
/** The MCP credentials run `from` was handed, sealed again for run `id`, a run this one starts (promotion.ts,
|
|
94
97
|
* audit.ts): none unless `from` is the claim's own run. */
|
|
95
98
|
handOn(from: string, id: string): Promise<Uint8Array | undefined>;
|
|
@@ -119,9 +122,7 @@ export interface Held {
|
|
|
119
122
|
* what the run's learning must never keep is every secret the runner holds, which no run's process is given. Its
|
|
120
123
|
* turns are asked through `input.ask`, the run's own session; `input.keptOf` is read once, for the round the runner
|
|
121
124
|
* reads. */
|
|
122
|
-
endOfRun(input: HeldEndOfRunInput): Promise<
|
|
123
|
-
readonly also: readonly AlsoRow[];
|
|
124
|
-
} | undefined>;
|
|
125
|
+
endOfRun(input: HeldEndOfRunInput): Promise<Awaited<ReturnType<EndOfRunTurn>>>;
|
|
125
126
|
/** The claim's learned first choice (learned-first.ts learnedFirst), run by the runner over the workflows it reads at the
|
|
126
127
|
* claim's seed: `laid` says only whether the process's seed lay laid any (false: none is laid). Its audits, promotion
|
|
127
128
|
* and replay reads are the runner's. */
|
|
@@ -74,6 +74,9 @@ export declare const KINDS: {
|
|
|
74
74
|
* later claim that asks the same turn again reads the first ask's (the commit of main a compile turn was asked at among
|
|
75
75
|
* them), never its own. Neither a call nor a message: the reader passes over it. */
|
|
76
76
|
readonly endOfRunKept: "agentrun.end-of-run.kept";
|
|
77
|
+
/** A replay run's or an audit shadow's grader verdict (learn/promote.ts Compared), from its end-of-run step, written on
|
|
78
|
+
* the root before its end: its metrics carry it (`replay.compared`, `audit.compared`). Neither a call nor a message. */
|
|
79
|
+
readonly compared: "agentrun.learning.compared";
|
|
77
80
|
/** How the run's job's own turn ended (JobEndData: the end it gives the run, a CLI's error answer), as the claim that
|
|
78
81
|
* read it decided, written on the root before the end-of-run step asks its first turn. A claim that finds that turn
|
|
79
82
|
* open ends the run on the newest one, never working the job's end out again. Neither a call nor a message. */
|
|
@@ -208,7 +211,7 @@ export interface CallEndData {
|
|
|
208
211
|
readonly callId: string;
|
|
209
212
|
readonly status: CallStatus;
|
|
210
213
|
readonly output?: unknown;
|
|
211
|
-
/** On an `interrupted` end the run's own end wrote (a call
|
|
214
|
+
/** On an `interrupted` end the run's own end wrote (a CLI's call still open: adapter-loop.ts openCalls):
|
|
212
215
|
* nothing ended it, so it has no outcome. Its row reads interrupted, never failed (CALL_ENDED_WITH_RUN). */
|
|
213
216
|
readonly withRun?: true;
|
|
214
217
|
/** When it was written (ms, the loop's clock): the Timeline dates the result's row by it. */
|
|
@@ -74,6 +74,9 @@ export const KINDS = {
|
|
|
74
74
|
* later claim that asks the same turn again reads the first ask's (the commit of main a compile turn was asked at among
|
|
75
75
|
* them), never its own. Neither a call nor a message: the reader passes over it. */
|
|
76
76
|
endOfRunKept: "agentrun.end-of-run.kept",
|
|
77
|
+
/** A replay run's or an audit shadow's grader verdict (learn/promote.ts Compared), from its end-of-run step, written on
|
|
78
|
+
* the root before its end: its metrics carry it (`replay.compared`, `audit.compared`). Neither a call nor a message. */
|
|
79
|
+
compared: "agentrun.learning.compared",
|
|
77
80
|
/** How the run's job's own turn ended (JobEndData: the end it gives the run, a CLI's error answer), as the claim that
|
|
78
81
|
* read it decided, written on the root before the end-of-run step asks its first turn. A claim that finds that turn
|
|
79
82
|
* open ends the run on the newest one, never working the job's end out again. Neither a call nor a message. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AlsoRow, Claim, Command, Journal } from "../store/store.js";
|
|
2
2
|
import type { Redact } from "./redact.js";
|
|
3
|
+
import type { Compared, GraderReply } from "../learn/promote.js";
|
|
3
4
|
export type { AlsoRow, Claim, Command, Journal };
|
|
4
5
|
/** Why a run ends failed when the answer it would end on was cut at the model's output limit (stopReason "length"): the
|
|
5
6
|
* answer is unfinished, so the run never reads ended. `tokens`: what the cut answer used, when its harness says. */
|
|
@@ -64,9 +65,18 @@ export type EndOfRunTurn = (input: {
|
|
|
64
65
|
* earlier claim (or this one) started, readable before `ask`, so a step that skips or is cut never asks, and still
|
|
65
66
|
* closes that look-back with its first ask's figures. Undefined when none asked it, or the loop keeps no record (pi's). */
|
|
66
67
|
keptOf?(round: number): EndOfRunKept | undefined;
|
|
68
|
+
/** A replay run's or an audit shadow's grader (learn/promote.ts): its fast model's name (`grader`), and one request to
|
|
69
|
+
* it (`grade`), sent through the run's own session on its one cap, booked as the run's spend; a refusal of that cap
|
|
70
|
+
* never parks the run (`refused`). Absent when the run has no grader route (no fast model, or agree_on named). */
|
|
71
|
+
readonly grader?: string;
|
|
72
|
+
grade?(request: {
|
|
73
|
+
readonly system: string;
|
|
74
|
+
readonly user: string;
|
|
75
|
+
}): Promise<GraderReply>;
|
|
67
76
|
readonly signal: AbortSignal;
|
|
68
77
|
}) => Promise<{
|
|
69
78
|
readonly also: readonly AlsoRow[];
|
|
79
|
+
readonly compared?: Compared;
|
|
70
80
|
} | undefined>;
|
|
71
81
|
/** How a loop's start() ended. The run's own outcome (state, cost) is already in the journal's last commit. */
|
|
72
82
|
export type LoopEnd = {
|
package/dist/runner/main.d.ts
CHANGED
|
@@ -56,8 +56,8 @@ export declare class RunnerRefused extends Error {
|
|
|
56
56
|
name: string;
|
|
57
57
|
}
|
|
58
58
|
/** The store, opened as a runner, its kind and its schema version: refused when its schema is one this build does not
|
|
59
|
-
* know,
|
|
60
|
-
* names one, else SQLite in the data directory). */
|
|
59
|
+
* know, not set up yet, or not yet upgraded by its server. The one place the runner opens its store (store/open.ts:
|
|
60
|
+
* Postgres when AGENTRUN_STORE_URL names one, else SQLite in the data directory). */
|
|
61
61
|
export declare function openRunnerStore(dataDir: string, env: NodeJS.ProcessEnv, warn: (message: string) => void, url: string | undefined): Promise<{
|
|
62
62
|
store: Store;
|
|
63
63
|
kind: string;
|
|
@@ -174,9 +174,9 @@ export declare function lastResort(name: string, write?: (line: string) => void,
|
|
|
174
174
|
* goes to stderr. Undefined for any other event. The runner beside a server says them the same way (beside.ts), so a
|
|
175
175
|
* lapse of every claim at once shows its cause. */
|
|
176
176
|
export declare function troubleLine(name: string, event: RunnerEvent): string | undefined;
|
|
177
|
-
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store
|
|
178
|
-
* set up yet); 1: anything else; 0: closed on a signal, or --check found
|
|
179
|
-
* it when --name does not. */
|
|
177
|
+
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store this runner cannot open (a schema it does not
|
|
178
|
+
* know, none set up yet, or one its server has yet to upgrade); 1: anything else; 0: closed on a signal, or --check found
|
|
179
|
+
* a fresh heartbeat. AGENTRUN_RUNNER_NAME names it when --name does not. */
|
|
180
180
|
export declare function runnerMain(argv: readonly string[], given?: NodeJS.ProcessEnv, hooks?: RunnerMainHooks): Promise<number>;
|
|
181
181
|
/** A test's hooks into runnerMain: `started`, awaited once the runner has started claiming and before its stop handlers
|
|
182
182
|
* take over from the ones its start listened on (the window a stop must not fall through). */
|
package/dist/runner/main.js
CHANGED
|
@@ -8,10 +8,13 @@
|
|
|
8
8
|
// memory holds: the server's --max-runs default, host.ts maxRunsOf). SIGTERM or SIGINT closes it: each busy run finishes
|
|
9
9
|
// its turn for up to --drain-timeout (default AGENTRUN_DRAIN_TIMEOUT, else RUNNER_DRAIN_TIMEOUT), then every loop left is stopped where it can resume
|
|
10
10
|
// and its run handed back for another runner (a loop that never stops is given up when its claim would run out, and its
|
|
11
|
-
// run is claimable when its lease lapses); then 0. Bad arguments exit 2, a store
|
|
11
|
+
// run is claimable when its lease lapses); then 0. Bad arguments exit 2, a store it cannot open (yet) 3, anything else 1.
|
|
12
|
+
// A run isolation it cannot give (run-child-host.ts runIsolationOf) is said, and it stays up claiming nothing until a stop: 0.
|
|
12
13
|
// An error nothing handles exits 1 at once, said with its stack (lastResort).
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
13
15
|
import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
14
16
|
import { join, resolve } from "node:path";
|
|
17
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
15
18
|
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
16
19
|
import { startRunnerRelay } from "../dial-relay.js";
|
|
17
20
|
import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
@@ -26,7 +29,7 @@ import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
|
|
|
26
29
|
import { durationMs, runLine } from "../print.js";
|
|
27
30
|
import { bootSealKey } from "../seal-key.js";
|
|
28
31
|
import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
|
|
29
|
-
import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
|
|
32
|
+
import { migrationsIn, openStore, SchemaVersionUnknown, StoreAwaitsServer, storePlace, storeTarget } from "../store/index.js";
|
|
30
33
|
import { SCHEMA_VERSION } from "../store/schema.js";
|
|
31
34
|
import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
|
|
32
35
|
import { FAUX_BROWSER_ENV } from "../tools.js";
|
|
@@ -47,14 +50,15 @@ import { RUN_PROCESS_MIB, runnerMemory } from "./memory-claim.js";
|
|
|
47
50
|
import { childLoops, isolationLoops, RunIsolationRefused, runIsolationOf } from "./run-child-host.js";
|
|
48
51
|
import { sweepEndedScratch } from "./scratch-sweep.js";
|
|
49
52
|
import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
|
|
53
|
+
import { keepPresence } from "./presence.js";
|
|
50
54
|
export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
|
|
51
55
|
/** A store this runner cannot use, or arguments it cannot take, in words a person starting it can act on. */
|
|
52
56
|
export class RunnerRefused extends Error {
|
|
53
57
|
name = "RunnerRefused";
|
|
54
58
|
}
|
|
55
59
|
/** The store, opened as a runner, its kind and its schema version: refused when its schema is one this build does not
|
|
56
|
-
* know,
|
|
57
|
-
* names one, else SQLite in the data directory). */
|
|
60
|
+
* know, not set up yet, or not yet upgraded by its server. The one place the runner opens its store (store/open.ts:
|
|
61
|
+
* Postgres when AGENTRUN_STORE_URL names one, else SQLite in the data directory). */
|
|
58
62
|
export async function openRunnerStore(dataDir, env, warn, url) {
|
|
59
63
|
// The store module owns where the store is (design: only the store adapter knows a file or a schema). The URL is this
|
|
60
64
|
// process's secret (as the launcher handed it over), unless a test hands one.
|
|
@@ -67,6 +71,8 @@ export async function openRunnerStore(dataDir, env, warn, url) {
|
|
|
67
71
|
return { store, kind: target.kind, schema: target.kind === "sqlite" ? SCHEMA_VERSION : migrationsIn().at(-1).version };
|
|
68
72
|
}
|
|
69
73
|
catch (error) {
|
|
74
|
+
if (error instanceof StoreAwaitsServer)
|
|
75
|
+
throw new RunnerRefused(`The store in ${where} is behind this runner: start the server first, which upgrades the store in place, then the runner.`, { cause: error });
|
|
70
76
|
if (!(error instanceof SchemaVersionUnknown))
|
|
71
77
|
throw error;
|
|
72
78
|
const { found, known } = error;
|
|
@@ -217,6 +223,7 @@ export async function startRunnerProcess(options) {
|
|
|
217
223
|
let seal;
|
|
218
224
|
let janitor;
|
|
219
225
|
let relay;
|
|
226
|
+
let presence;
|
|
220
227
|
try {
|
|
221
228
|
// The server's seal key, booted the one way the server boots it (seal-key.ts): the one handed over, else the one in
|
|
222
229
|
// this data directory, checked against what the store records. A runner on a store whose secrets another key sealed
|
|
@@ -224,9 +231,13 @@ export async function startRunnerProcess(options) {
|
|
|
224
231
|
// or records a key.
|
|
225
232
|
seal = await bootSealKey(store, options.dataDir, { given: handedSecret(SEAL_KEY_ENV) ?? env[SEAL_KEY_ENV], role: "runner" });
|
|
226
233
|
const name = options.name ?? runnerName();
|
|
234
|
+
// One incarnation for this process: its word in the store that it is there (presence.ts) and its relay's minted
|
|
235
|
+
// tokens and proofs name the same one, so the server's "restarted since" and the runner's row speak of one process.
|
|
236
|
+
// The presence first, then the relay says where it answers on the presence's row.
|
|
237
|
+
presence = keepPresence(store.runners, name, null, { warn, incarnation: randomUUID() });
|
|
227
238
|
// Its relay (dial-relay.ts), where its environment names the server's public address: a machine that dials the
|
|
228
239
|
// server lands in this runner's hub, through the server. Its log lines are the runner's warnings.
|
|
229
|
-
relay = await startRunnerRelay({ store, sealKey: seal.key, runner: name, env, log: warn });
|
|
240
|
+
relay = await startRunnerRelay({ store, sealKey: seal.key, runner: name, presence, env, log: warn });
|
|
230
241
|
const made = options.createLoop ?? ofStore((opened, sealKey, dial) => runnerLoop(opened, options.dataDir, undefined, sealKey, undefined, dial));
|
|
231
242
|
// A factory of the store (marked by ofStore) is given the store; a loop factory is used as is.
|
|
232
243
|
const parts = isStoreFactory(made) ? made(store, seal.key, relay?.dial) : made;
|
|
@@ -243,6 +254,7 @@ export async function startRunnerProcess(options) {
|
|
|
243
254
|
store,
|
|
244
255
|
createLoop,
|
|
245
256
|
name,
|
|
257
|
+
presence,
|
|
246
258
|
...(options.loops ? { loops: options.loops } : {}),
|
|
247
259
|
...(options.drainMs ? { drainMs: options.drainMs } : {}),
|
|
248
260
|
memory,
|
|
@@ -254,6 +266,7 @@ export async function startRunnerProcess(options) {
|
|
|
254
266
|
catch (error) {
|
|
255
267
|
await janitor?.close();
|
|
256
268
|
await relay?.close();
|
|
269
|
+
await presence?.close();
|
|
257
270
|
seal?.release();
|
|
258
271
|
await store.close();
|
|
259
272
|
throw error;
|
|
@@ -261,6 +274,7 @@ export async function startRunnerProcess(options) {
|
|
|
261
274
|
let closing;
|
|
262
275
|
const held = seal;
|
|
263
276
|
const relayed = relay;
|
|
277
|
+
const kept = presence;
|
|
264
278
|
return {
|
|
265
279
|
runner,
|
|
266
280
|
store: { kind, schema },
|
|
@@ -268,8 +282,10 @@ export async function startRunnerProcess(options) {
|
|
|
268
282
|
close: () => (closing ??= (async () => {
|
|
269
283
|
// The janitor's sweep is cut and waited for on its own bound, beside the runner's close, never before it.
|
|
270
284
|
await Promise.all([janitor?.close(), runner.close()]);
|
|
271
|
-
// Its relay after its runs: a run's release revokes its machine's token through it.
|
|
285
|
+
// Its relay after its runs: a run's release revokes its machine's token through it. Then its word that it is
|
|
286
|
+
// there: it claims no more.
|
|
272
287
|
await relayed?.close();
|
|
288
|
+
await kept.close();
|
|
273
289
|
// A first-use install its claims started, stopped as they let go: its npm ends before this process can.
|
|
274
290
|
await claimInstallsStopped();
|
|
275
291
|
await store.close();
|
|
@@ -430,9 +446,9 @@ export function troubleLine(name, event) {
|
|
|
430
446
|
return `Runner ${name}: ${event.step}${event.runId ? ` ${event.runId}` : ""}: ${event.message}`;
|
|
431
447
|
return undefined;
|
|
432
448
|
}
|
|
433
|
-
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store
|
|
434
|
-
* set up yet); 1: anything else; 0: closed on a signal, or --check found
|
|
435
|
-
* it when --name does not. */
|
|
449
|
+
/** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store this runner cannot open (a schema it does not
|
|
450
|
+
* know, none set up yet, or one its server has yet to upgrade); 1: anything else; 0: closed on a signal, or --check found
|
|
451
|
+
* a fresh heartbeat. AGENTRUN_RUNNER_NAME names it when --name does not. */
|
|
436
452
|
export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
437
453
|
let args;
|
|
438
454
|
try {
|
|
@@ -502,8 +518,14 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
502
518
|
catch (error) {
|
|
503
519
|
if (!(error instanceof RunIsolationRefused))
|
|
504
520
|
throw error;
|
|
521
|
+
// Said, then up and claiming nothing until a stop: in the image's server-and-runner either process's exit stops the
|
|
522
|
+
// container, which a platform that restarts it (Render, Railway) would loop on, the refusal lost in the restarts.
|
|
505
523
|
console.error(`agentrun-serve runner: ${error.message}`);
|
|
506
|
-
|
|
524
|
+
// And said in the store until the stop (presence.ts), so the server, in its own process or on another host, refuses a
|
|
525
|
+
// launch in these words and fails the runs left queued while no runner that claims is there.
|
|
526
|
+
const stop = untilSignalled(RUNNER_SIGNALS);
|
|
527
|
+
await refusedInStore(args.dataDir, env, name ?? runnerName(), error.message, stop);
|
|
528
|
+
return 0;
|
|
507
529
|
}
|
|
508
530
|
if (isolation.kind === "uid" && holds.loops > isolation.slots)
|
|
509
531
|
console.error(`agentrun-serve runner: each run runs as a user of its own, and the helper reaches ${isolation.slots} slots from slot ${isolation.first}: this runner holds at most ${isolation.slots} runs at once`);
|
|
@@ -553,7 +575,7 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
553
575
|
catch (error) {
|
|
554
576
|
unlisten();
|
|
555
577
|
console.error(`agentrun-serve runner: ${error?.message ?? String(error)}`);
|
|
556
|
-
return error instanceof RunnerRefused && error.cause instanceof SchemaVersionUnknown ? 3 : 1;
|
|
578
|
+
return error instanceof RunnerRefused && (error.cause instanceof SchemaVersionUnknown || error.cause instanceof StoreAwaitsServer) ? 3 : 1;
|
|
557
579
|
}
|
|
558
580
|
await hooks.started?.(started);
|
|
559
581
|
// From here the handlers below take the stop, with nothing awaited between: no signal falls in a gap.
|
|
@@ -574,3 +596,51 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
|
|
|
574
596
|
}
|
|
575
597
|
/** The signals that stop a runner process. */
|
|
576
598
|
const RUNNER_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
599
|
+
/** How long a refusing runner waits before it tries its store again (refusedInStore). */
|
|
600
|
+
const REFUSED_STORE_RETRY_MS = 5_000;
|
|
601
|
+
/** A runner whose run isolation was refused: its `words` kept in its store (presence.ts) until `stopped`, then its row
|
|
602
|
+
* removed and the store closed. A store that does not open (not set up yet, one its server has yet to upgrade, a
|
|
603
|
+
* connection down) is said, once for each reason, and tried again every REFUSED_STORE_RETRY_MS until it opens or the
|
|
604
|
+
* stop: a runner that starts before its server still tells that server, once it is there. */
|
|
605
|
+
async function refusedInStore(dataDir, env, name, words, stopped) {
|
|
606
|
+
const warn = (line) => void console.error(`agentrun-serve runner: ${line}`);
|
|
607
|
+
let stop = false;
|
|
608
|
+
void stopped.then(() => void (stop = true));
|
|
609
|
+
let said;
|
|
610
|
+
while (!stop) {
|
|
611
|
+
let store;
|
|
612
|
+
try {
|
|
613
|
+
({ store } = await openRunnerStore(dataDir, env, warn, undefined));
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
const why = error?.message ?? String(error);
|
|
617
|
+
if (why !== said)
|
|
618
|
+
warn(`the server is not told yet that this runner claims nothing, since its store did not open (tried again every ${REFUSED_STORE_RETRY_MS / 1000} s): ${why}`);
|
|
619
|
+
said = why;
|
|
620
|
+
await Promise.race([sleep(REFUSED_STORE_RETRY_MS, undefined, { ref: false }), stopped]);
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (said !== undefined)
|
|
624
|
+
warn("its store opened: the server is told that this runner claims nothing");
|
|
625
|
+
const presence = keepPresence(store.runners, name, words, { warn });
|
|
626
|
+
await stopped;
|
|
627
|
+
await presence.close();
|
|
628
|
+
await store.close();
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
/** Holds the process up, with nothing else to do, until one of `signals`. */
|
|
633
|
+
function untilSignalled(signals) {
|
|
634
|
+
return new Promise((resolve) => {
|
|
635
|
+
// A signal's listener alone does not keep Node's loop alive.
|
|
636
|
+
const alive = setInterval(() => { }, 2 ** 30);
|
|
637
|
+
const onSignal = () => {
|
|
638
|
+
for (const signal of signals)
|
|
639
|
+
process.off(signal, onSignal);
|
|
640
|
+
clearInterval(alive);
|
|
641
|
+
resolve();
|
|
642
|
+
};
|
|
643
|
+
for (const signal of signals)
|
|
644
|
+
process.on(signal, onSignal);
|
|
645
|
+
});
|
|
646
|
+
}
|