@parcha/agentrun-computer 0.1.0-beta.58 → 0.1.0-beta.60
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/README.md +285 -81
- package/box/Dockerfile +4 -3
- package/box/install.sh +57 -11
- package/dist/agent37.d.ts +11 -4
- package/dist/agent37.js +217 -19
- package/dist/attach.d.ts +24 -4
- package/dist/attach.js +50 -19
- package/dist/boxd.js +22 -9
- package/dist/browser.d.ts +56 -11
- package/dist/browser.js +76 -17
- package/dist/browserbase.d.ts +20 -5
- package/dist/browserbase.js +186 -21
- package/dist/child-env.d.ts +11 -0
- package/dist/child-env.js +22 -0
- package/dist/chrome.d.ts +5 -2
- package/dist/chrome.js +5 -2
- package/dist/cloudflare.d.ts +2 -0
- package/dist/cloudflare.js +5 -3
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +1 -1
- package/dist/conformance/agent37.d.ts +20 -40
- package/dist/conformance/agent37.js +31 -118
- package/dist/conformance/archil.d.ts +13 -3
- package/dist/conformance/archil.js +22 -17
- package/dist/conformance/boxd.d.ts +8 -31
- package/dist/conformance/boxd.js +19 -74
- package/dist/conformance/browserbase.d.ts +3 -6
- package/dist/conformance/browserbase.js +6 -17
- package/dist/conformance/cases/health.js +6 -3
- package/dist/conformance/cases/provider.js +4 -1
- package/dist/conformance/cli.d.ts +3 -1
- package/dist/conformance/cli.js +69 -9
- package/dist/conformance/cloudflare.d.ts +3 -6
- package/dist/conformance/cloudflare.js +7 -15
- package/dist/conformance/daytona.d.ts +6 -20
- package/dist/conformance/daytona.js +22 -57
- package/dist/conformance/dial-only.d.ts +4 -3
- package/dist/conformance/dial-only.js +3 -3
- package/dist/conformance/docker.d.ts +4 -5
- package/dist/conformance/docker.js +8 -14
- package/dist/conformance/e2b.d.ts +10 -36
- package/dist/conformance/e2b.js +27 -84
- package/dist/conformance/fly.d.ts +3 -6
- package/dist/conformance/fly.js +2 -6
- package/dist/conformance/groundbox.d.ts +7 -23
- package/dist/conformance/groundbox.js +16 -56
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +1 -0
- package/dist/conformance/kernel.d.ts +3 -6
- package/dist/conformance/kernel.js +5 -15
- package/dist/conformance/kind.d.ts +0 -6
- package/dist/conformance/kind.js +0 -4
- package/dist/conformance/local-chrome.d.ts +5 -7
- package/dist/conformance/local-chrome.js +7 -11
- package/dist/conformance/modal.d.ts +10 -38
- package/dist/conformance/modal.js +27 -74
- package/dist/conformance/module-kit.d.ts +87 -0
- package/dist/conformance/module-kit.js +88 -0
- package/dist/conformance/morph.d.ts +7 -23
- package/dist/conformance/morph.js +20 -66
- package/dist/conformance/orgo.d.ts +5 -10
- package/dist/conformance/orgo.js +15 -27
- package/dist/conformance/phone-harness.d.ts +3 -5
- package/dist/conformance/phone-harness.js +3 -11
- package/dist/conformance/runner.d.ts +13 -3
- package/dist/conformance/runner.js +32 -11
- package/dist/conformance/smolcloud.d.ts +7 -23
- package/dist/conformance/smolcloud.js +16 -49
- package/dist/conformance/sweep.d.ts +10 -5
- package/dist/conformance/sweep.js +91 -38
- package/dist/conformance/tti.d.ts +69 -0
- package/dist/conformance/tti.js +205 -0
- package/dist/conformance/types.d.ts +9 -2
- package/dist/daytona.js +60 -20
- package/dist/descriptor.d.ts +37 -0
- package/dist/descriptor.js +9 -0
- package/dist/descriptors/agent37.d.ts +4 -1
- package/dist/descriptors/agent37.js +5 -2
- package/dist/descriptors/browserbase.d.ts +3 -0
- package/dist/descriptors/browserbase.js +4 -0
- package/dist/descriptors/docker.d.ts +2 -0
- package/dist/descriptors/docker.js +5 -0
- package/dist/descriptors/env-names.d.ts +32 -0
- package/dist/descriptors/env-names.js +60 -0
- package/dist/descriptors/index.d.ts +14 -3
- package/dist/descriptors/kernel.d.ts +3 -0
- package/dist/descriptors/kernel.js +2 -0
- package/dist/descriptors/local-chrome.d.ts +1 -1
- package/dist/descriptors/local-chrome.js +5 -3
- package/dist/descriptors/phone-harness.d.ts +1 -1
- package/dist/descriptors/phone-harness.js +4 -2
- package/dist/docker/egress.d.ts +7 -0
- package/dist/docker/egress.js +8 -0
- package/dist/docker/image.d.ts +5 -1
- package/dist/docker/image.js +12 -8
- package/dist/docker.d.ts +52 -13
- package/dist/docker.js +166 -92
- package/dist/drift.js +6 -6
- package/dist/e2b.d.ts +2 -2
- package/dist/e2b.js +2 -3
- package/dist/groundbox.js +6 -6
- package/dist/host.d.ts +23 -0
- package/dist/hosted/download.d.ts +23 -0
- package/dist/hosted/download.js +144 -0
- package/dist/hosted/process.d.ts +5 -0
- package/dist/hosted/process.js +20 -0
- package/dist/hosted/provider.js +120 -48
- package/dist/hosted/rest.d.ts +19 -8
- package/dist/hosted/rest.js +47 -14
- package/dist/hosted/scripts.d.ts +10 -0
- package/dist/hosted/scripts.js +23 -2
- package/dist/hosted/ssh-exec.d.ts +7 -1
- package/dist/hosted/ssh-exec.js +19 -14
- package/dist/hosted/ssh-key.d.ts +18 -0
- package/dist/hosted/ssh-key.js +36 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/janitor.d.ts +7 -1
- package/dist/janitor.js +2 -2
- package/dist/kernel.d.ts +14 -4
- package/dist/kernel.js +141 -18
- package/dist/local-chrome.d.ts +12 -3
- package/dist/local-chrome.js +108 -10
- package/dist/local-supervisor.js +1 -0
- package/dist/modal.d.ts +6 -5
- package/dist/modal.js +7 -7
- package/dist/morph.js +5 -8
- package/dist/orgo-channel.d.ts +3 -2
- package/dist/orgo-channel.js +3 -3
- package/dist/orgo-desktop.js +2 -4
- package/dist/orgo.d.ts +6 -0
- package/dist/orgo.js +158 -15
- package/dist/phone-harness.d.ts +7 -5
- package/dist/phone-harness.js +60 -61
- package/dist/protocol.d.ts +10 -0
- package/dist/protocol.js +17 -0
- package/dist/provider.d.ts +6 -2
- package/dist/screen-watch.d.ts +6 -1
- package/dist/screen-watch.js +166 -12
- package/dist/vendor-sdk.d.ts +9 -0
- package/dist/vendor-sdk.js +26 -0
- package/package.json +8 -1
package/dist/drift.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The drift checks every provider shares: the daemon's hello against what the provider declares, and the report of
|
|
2
2
|
// computerd probe from inside a computer. Pure: no vendor call. Each mismatch is one sentence; none is an empty list.
|
|
3
3
|
// Docker's own read-back (docker info, docker inspect) is docker/inspect.ts's.
|
|
4
|
-
import {
|
|
4
|
+
import { helloProblem, NETWORK_FENCES } from "./protocol.js";
|
|
5
5
|
/** Where the daemon is mounted in each computer, read-only. */
|
|
6
6
|
export const DAEMON_IN_COMPUTER = "/opt/agentrun/computerd";
|
|
7
7
|
export const COMPUTER_LABEL = "agentrun.computer";
|
|
@@ -64,11 +64,11 @@ export function probeNotes(probe, network) {
|
|
|
64
64
|
/** Every way hello differs from what the provider expects. */
|
|
65
65
|
export function helloDrift(hello, expected) {
|
|
66
66
|
const found = [];
|
|
67
|
-
//
|
|
68
|
-
// daemon version,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
// spec/computer/README.md, "Versioning": a protocol helloProblem refuses is another wire, in its words, and the
|
|
68
|
+
// daemon's own version, which pins the build the provider ships, must match exactly.
|
|
69
|
+
const protocol = helloProblem(hello?.protocol, "provider");
|
|
70
|
+
if (protocol)
|
|
71
|
+
found.push(`hello: the daemon ${protocol}`);
|
|
72
72
|
if (hello?.version !== expected.version)
|
|
73
73
|
found.push(`hello: the daemon reports version ${text(hello?.version)}, expected ${expected.version}`);
|
|
74
74
|
if (hello?.os !== "linux")
|
package/dist/e2b.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type Result } from "./result.js";
|
|
|
7
7
|
* process-wide proxy doesn't reach, and it sends every call, the API's and each sandbox's envd's, through the one `proxy`
|
|
8
8
|
* it is given. So it is given that one unless its NO_PROXY exempts the whole domain (proxyForDomain).
|
|
9
9
|
* The SDK's types below are `import type`: erased at build, so nothing loads the SDK from here and the published types
|
|
10
|
-
* name none of it (
|
|
10
|
+
* name none of it (e2b is only an optional dependency).
|
|
11
11
|
*/
|
|
12
12
|
export interface E2BConnectionOptions {
|
|
13
13
|
apiKey: string;
|
|
@@ -45,7 +45,7 @@ export interface E2BProviderOptions extends Omit<HostedOptions, "maxLifetimeMs">
|
|
|
45
45
|
* Not SandboxOpts, which is the SDK's own Sandbox.create options.
|
|
46
46
|
*/
|
|
47
47
|
export interface E2BOptions extends Omit<E2BProviderOptions, "Sandbox"> {
|
|
48
|
-
/** The SDK's Sandbox class;
|
|
48
|
+
/** The SDK's Sandbox class; the e2b package's by default. */
|
|
49
49
|
Sandbox?: E2BSandboxClass;
|
|
50
50
|
}
|
|
51
51
|
/** The connection options every SDK call is given. Exported for the test that hands them to the real SDK. */
|
package/dist/e2b.js
CHANGED
|
@@ -9,8 +9,7 @@ import { connectOf } from "./descriptor.js";
|
|
|
9
9
|
import { dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
|
|
10
10
|
import { PassThrough } from "node:stream";
|
|
11
11
|
import { ok } from "./result.js";
|
|
12
|
-
|
|
13
|
-
const E2B_PACKAGE = "e2b";
|
|
12
|
+
import { vendorSdk } from "./vendor-sdk.js";
|
|
14
13
|
const DEFAULT_DOMAIN = "e2b.app";
|
|
15
14
|
/** The connection options every SDK call is given. Exported for the test that hands them to the real SDK. */
|
|
16
15
|
export function connectionOptions({ apiKey, domain }, env = installedProxy()) {
|
|
@@ -37,7 +36,7 @@ function ambientProblem() {
|
|
|
37
36
|
*/
|
|
38
37
|
export async function create(options) {
|
|
39
38
|
const { Sandbox: given, ...rest } = options ?? {};
|
|
40
|
-
const Sandbox = given ?? (await
|
|
39
|
+
const Sandbox = given ?? (await vendorSdk(E2B.label, "e2b")).Sandbox;
|
|
41
40
|
return new E2BProvider({ ...rest, Sandbox });
|
|
42
41
|
}
|
|
43
42
|
/** The conformance CLI's module for E2B: its live switch, the run's 30-minute cap, its template and the drifted twin. */
|
package/dist/groundbox.js
CHANGED
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
// it, so kill is the shared pid kill as root. Labels are the sandbox's metadata, which the listing filters by. The
|
|
11
11
|
// lifetime is the janitor's, by the deadline label, and Groundbox's own timer (timeout_minutes) is set to the request's
|
|
12
12
|
// backstop. Kind desktop is the box image's Xvfb and xfwm4, started through the daemon as on E2B and boxd. The rest of
|
|
13
|
-
// the computer is the shared machine-host adapter's (./hosted/provider.ts).
|
|
14
|
-
// the README's Groundbox section.
|
|
13
|
+
// the computer is the shared machine-host adapter's (./hosted/provider.ts).
|
|
15
14
|
import { randomBytes } from "node:crypto";
|
|
16
15
|
import { boxImageRef } from "./box-image.js";
|
|
17
16
|
import { GROUNDBOX, GROUNDBOX_OWN_IMAGE } from "./descriptors/groundbox.js";
|
|
@@ -21,7 +20,7 @@ import { framedExec } from "./hosted/framed-exec.js";
|
|
|
21
20
|
import { boundOf, orThrow, pause, seconds } from "./hosted/process.js";
|
|
22
21
|
import { HostedProvider } from "./hosted/provider.js";
|
|
23
22
|
import { allPages, httpsBase, jsonOf, rest } from "./hosted/rest.js";
|
|
24
|
-
import { PID_KILL } from "./hosted/scripts.js";
|
|
23
|
+
import { PID_ECHO, PID_KILL, ROOT } from "./hosted/scripts.js";
|
|
25
24
|
import { dateOf, isWhole } from "./hosted/values.js";
|
|
26
25
|
import { ok } from "./result.js";
|
|
27
26
|
export async function create(options) {
|
|
@@ -102,8 +101,9 @@ const DIR_PREFIX = "/tmp/.agentrun-exec-";
|
|
|
102
101
|
const START_SCRIPT = [
|
|
103
102
|
"d=$1; shift",
|
|
104
103
|
'mkdir -m 700 "$d" 2>/dev/null || { echo "agentrun: $d is already there, so it is not one this command made: the command did not start" >&2; exit 126; }',
|
|
105
|
-
|
|
106
|
-
'
|
|
104
|
+
// `command exec`: a failed redirection of a bare exec ends a non-interactive sh with status 2, past the refusal.
|
|
105
|
+
'mkfifo -m 600 "$d/in" && command exec 3<>"$d/in" || { rm -rf "$d"; exit 126; }',
|
|
106
|
+
`${PID_ECHO} >"$d/pid.new" && mv -f "$d/pid.new" "$d/pid" || { rm -rf "$d"; exit 126; }`,
|
|
107
107
|
'echo "agentrun-ready:${d##*-}" >&2',
|
|
108
108
|
'"$@" <&3 3<&-; c=$?',
|
|
109
109
|
'rm -rf "$d"; exit $c',
|
|
@@ -150,7 +150,7 @@ const KILL_SCRIPT = [
|
|
|
150
150
|
OWN_DIR,
|
|
151
151
|
ownFile("pid"),
|
|
152
152
|
"read -r pid start 2>/dev/null <pid || exit 0",
|
|
153
|
-
|
|
153
|
+
ROOT,
|
|
154
154
|
'$p sh -c "$2" sh "$pid" "$start"',
|
|
155
155
|
'cd / && rm -rf "$d"',
|
|
156
156
|
].join("\n");
|
package/dist/host.d.ts
CHANGED
|
@@ -83,6 +83,14 @@ export interface MachineHost {
|
|
|
83
83
|
* streams the file through exec's stdin as base64 text, which root decodes (`base64 -d`, in coreutils and busybox).
|
|
84
84
|
*/
|
|
85
85
|
upload?(id: string, path: string, bytes: Uint8Array, ctx: HostCall): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* The bytes of the file at path in the machine, whole, read as root. Optional, on an exec host alone: one whose exec
|
|
88
|
+
* output is slow has it (Daytona's: its toolbox's files/download, where exec's stdout is a log read at about 0.3 MB/s).
|
|
89
|
+
* A files.read past one chunk then takes its first chunk from the daemon and the rest from one copy of the file the
|
|
90
|
+
* adapter makes as the daemon's user (./hosted/download.ts), so root's read never shows what that user cannot read. A
|
|
91
|
+
* path that is not there throws.
|
|
92
|
+
*/
|
|
93
|
+
download?(id: string, path: string, ctx: HostCall): Promise<Uint8Array>;
|
|
86
94
|
/**
|
|
87
95
|
* What agentrun-dial wrote in a dial machine, for a create whose machine never dialed: the adapter adds its last lines
|
|
88
96
|
* to the timeout's words. undefined when agentrun-dial never started there. A host that started agentrun-dial itself
|
|
@@ -90,6 +98,21 @@ export interface MachineHost {
|
|
|
90
98
|
* words stay as they were.
|
|
91
99
|
*/
|
|
92
100
|
dialLog?(id: string, ctx: HostCall): Promise<string | undefined>;
|
|
101
|
+
/**
|
|
102
|
+
* agentrun-dial's exit code in a dial machine once it has exited; undefined while it runs, or where it never started.
|
|
103
|
+
* A host that started agentrun-dial itself and can read its exit has it (Daytona's: its session command's). The
|
|
104
|
+
* adapter reads it while it waits for the machine to dial: one that exited never dials, so create stops then, in
|
|
105
|
+
* dialLog's words, instead of at createMs, and while it runs and writes, the wait may go past createMs. A read that
|
|
106
|
+
* fails throws, and the wait goes on.
|
|
107
|
+
*/
|
|
108
|
+
dialExit?(id: string, ctx: HostCall): Promise<number | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Starts agentrun-dial once more in a dial machine whose agentrun-dial exited, as create started it: the same env and
|
|
111
|
+
* token, so the same machine dials. The adapter calls it at most once per machine, for an exit that leaves nothing of
|
|
112
|
+
* agentrun-dial running (its fetch failed, 3, or its init never listened and was ended, 5); after the start, dialLog
|
|
113
|
+
* and dialExit read the new one. A start the vendor refuses throws, and create fails in the first exit's words.
|
|
114
|
+
*/
|
|
115
|
+
redial?(id: string, ctx: HostCall): Promise<void>;
|
|
93
116
|
/**
|
|
94
117
|
* The code of an error the vendor's client threw: one of ComputerErrorCode. Optional: the adapter reads a HostError's
|
|
95
118
|
* own code, an AbortError as "aborted" and a TimeoutError as "timeout" itself, and anything else a host does not map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MachineHost } from "../host.js";
|
|
2
|
+
import type { ComputerConnection } from "../provider.js";
|
|
3
|
+
export interface DownloadBounds {
|
|
4
|
+
/** Each of read-stage and read-unstage, and the daemon's read of its own /proc/self/status. */
|
|
5
|
+
execMs: number;
|
|
6
|
+
/** The download of one copy. */
|
|
7
|
+
downloadMs: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* connection, with every files.read past one chunk read from one downloaded copy after its first chunk. A first chunk
|
|
11
|
+
* (offset 0, a whole chunk) whose file runs past it, and is at most the surface's read limit (MAX_READ_BYTES, all a copy
|
|
12
|
+
* holds in memory), makes its file one to copy; a larger file is the daemon's, chunk by chunk. The copy starts at the
|
|
13
|
+
* first read past that chunk, so a reader that stops at one chunk copies nothing. The reads after it, at the offsets the
|
|
14
|
+
* first's reader asks for, are answered from the copy, as the daemon answers (eof once a read reaches the copy's size),
|
|
15
|
+
* and the copy is let go at its end, at the next first chunk of its path, at any call of another method, which may change
|
|
16
|
+
* a file, or, the oldest first, once the files to copy pass COPIES_BYTES in all. A copy let go while it is still coming
|
|
17
|
+
* is stopped, and the reads waiting on it are the daemon's. A copy that fails at any step (the daemon's user unread,
|
|
18
|
+
* read-stage refused, the download, a size other than the daemon read) leaves the daemon to answer every read, as on a
|
|
19
|
+
* host with no download. The copy in the machine is removed once it is downloaded, without holding up the read. A close
|
|
20
|
+
* of the connection or of its client lets every copy go: each read after it, or still waiting on a copy, is the closed
|
|
21
|
+
* daemon client's (gone).
|
|
22
|
+
*/
|
|
23
|
+
export declare function downloadingConnection(host: MachineHost, download: NonNullable<MachineHost["download"]>, id: string, connection: ComputerConnection, bounds: DownloadBounds): ComputerConnection;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// A files.read past one chunk on a host with download (src/host.ts): the daemon answers the first chunk, as it answers
|
|
2
|
+
// every read, and the rest comes from one copy of the file, made as the daemon's user (read-stage) and downloaded whole.
|
|
3
|
+
// On Daytona the bridge is a session command's log, read at about 0.3 MB/s (the sandbox bench, 11-25); its toolbox's
|
|
4
|
+
// files/download is not. The daemon's read is the check: a file it refuses is never copied, and the copy, opened as its
|
|
5
|
+
// user, holds what that user can read and nothing more, whatever the path names by the time it is copied.
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
7
|
+
import { posix } from "node:path";
|
|
8
|
+
import { MAX_CHUNK_BYTES } from "../protocol.js";
|
|
9
|
+
import { ok } from "../result.js";
|
|
10
|
+
import { MAX_READ_BYTES } from "../surface/core.js";
|
|
11
|
+
import { hostCall, runToExit, untilAborted } from "./process.js";
|
|
12
|
+
import { READ_COPIES, readStage, readUnstage } from "./scripts.js";
|
|
13
|
+
/**
|
|
14
|
+
* An absolute path as computerd's files.read opens it: cleaned first (filepath.Clean, files.go cleanPath), so a ".."
|
|
15
|
+
* takes off the name before it, a symlinked directory's or not. read-stage's cat opens the path as given, where a ".."
|
|
16
|
+
* after a link leaves the link's target: it is given this one, the file the daemon read.
|
|
17
|
+
*/
|
|
18
|
+
const cleaned = (path) => posix.resolve(path);
|
|
19
|
+
/** A read the daemon may answer from a copy: an absolute path outside /proc (whose self is the reader's), a whole chunk. */
|
|
20
|
+
const copyable = ({ path, length }) => path.startsWith("/") && !cleaned(path).startsWith("/proc/") && (length === undefined || length === MAX_CHUNK_BYTES);
|
|
21
|
+
/** The bytes one connection's copies may hold at once: two files at the read limit. */
|
|
22
|
+
const COPIES_BYTES = 2 * MAX_READ_BYTES;
|
|
23
|
+
/**
|
|
24
|
+
* connection, with every files.read past one chunk read from one downloaded copy after its first chunk. A first chunk
|
|
25
|
+
* (offset 0, a whole chunk) whose file runs past it, and is at most the surface's read limit (MAX_READ_BYTES, all a copy
|
|
26
|
+
* holds in memory), makes its file one to copy; a larger file is the daemon's, chunk by chunk. The copy starts at the
|
|
27
|
+
* first read past that chunk, so a reader that stops at one chunk copies nothing. The reads after it, at the offsets the
|
|
28
|
+
* first's reader asks for, are answered from the copy, as the daemon answers (eof once a read reaches the copy's size),
|
|
29
|
+
* and the copy is let go at its end, at the next first chunk of its path, at any call of another method, which may change
|
|
30
|
+
* a file, or, the oldest first, once the files to copy pass COPIES_BYTES in all. A copy let go while it is still coming
|
|
31
|
+
* is stopped, and the reads waiting on it are the daemon's. A copy that fails at any step (the daemon's user unread,
|
|
32
|
+
* read-stage refused, the download, a size other than the daemon read) leaves the daemon to answer every read, as on a
|
|
33
|
+
* host with no download. The copy in the machine is removed once it is downloaded, without holding up the read. A close
|
|
34
|
+
* of the connection or of its client lets every copy go: each read after it, or still waiting on a copy, is the closed
|
|
35
|
+
* daemon client's (gone).
|
|
36
|
+
*/
|
|
37
|
+
export function downloadingConnection(host, download, id, connection, bounds) {
|
|
38
|
+
const { client } = connection;
|
|
39
|
+
const copies = new Map();
|
|
40
|
+
let closed = false;
|
|
41
|
+
let user;
|
|
42
|
+
/** The daemon's uid and gid, from its own /proc/self/status: each of its four ids the same, else none. */
|
|
43
|
+
const userOf = () => (user ??= (async () => {
|
|
44
|
+
const status = await client.call("files.read", { path: "/proc/self/status" }, { signal: AbortSignal.timeout(bounds.execMs) });
|
|
45
|
+
const text = status.ok ? Buffer.from(status.value.data, "base64").toString("utf8") : "";
|
|
46
|
+
const ids = (name) => new RegExp(`^${name}:\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*$`, "m").exec(text)?.slice(1) ?? [];
|
|
47
|
+
const [uids, gids] = [ids("Uid"), ids("Gid")];
|
|
48
|
+
const one = (found) => (found.length === 4 && found.every((each) => each === found[0]) ? found[0] : undefined);
|
|
49
|
+
const [uid, gid] = [one(uids), one(gids)];
|
|
50
|
+
if (uid !== undefined && gid !== undefined)
|
|
51
|
+
return [uid, gid];
|
|
52
|
+
user = undefined;
|
|
53
|
+
return undefined;
|
|
54
|
+
})());
|
|
55
|
+
/** path's copy, downloaded until signal aborts: its bytes when they are size long, else undefined. */
|
|
56
|
+
const copyOf = async (path, size, signal) => {
|
|
57
|
+
const who = await userOf();
|
|
58
|
+
if (who === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
const copy = `${READ_COPIES}/${randomBytes(16).toString("hex")}`;
|
|
61
|
+
const unstage = () => void runToExit(host, id, readUnstage(copy), { ms: bounds.execMs, what: `removing the copy of ${path}` });
|
|
62
|
+
const staged = await runToExit(host, id, readStage(who[0], who[1], path, copy), { ms: bounds.execMs, signal, what: `copying ${path} as the daemon's user` });
|
|
63
|
+
if (!staged.ok || staged.value.exitCode !== 0) {
|
|
64
|
+
// One that never answered may yet write its copy.
|
|
65
|
+
if (!staged.ok)
|
|
66
|
+
unstage();
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const got = await hostCall(host, `downloading the copy of ${path}`, (ctx) => download(id, copy, ctx), bounds.downloadMs, signal);
|
|
70
|
+
unstage();
|
|
71
|
+
return got.ok && got.value.length === size ? got.value : undefined;
|
|
72
|
+
};
|
|
73
|
+
/** key's copy let go, and stopped if it is still coming. */
|
|
74
|
+
const letGo = (key) => {
|
|
75
|
+
copies.get(key)?.stop.abort();
|
|
76
|
+
copies.delete(key);
|
|
77
|
+
};
|
|
78
|
+
const letAllGo = () => {
|
|
79
|
+
for (const key of copies.keys())
|
|
80
|
+
letGo(key);
|
|
81
|
+
};
|
|
82
|
+
const drop = () => {
|
|
83
|
+
closed = true;
|
|
84
|
+
letAllGo();
|
|
85
|
+
};
|
|
86
|
+
const reading = {
|
|
87
|
+
async call(method, params, options) {
|
|
88
|
+
if (method !== "files.read" || closed) {
|
|
89
|
+
letAllGo();
|
|
90
|
+
return client.call(method, params, options);
|
|
91
|
+
}
|
|
92
|
+
const read = params;
|
|
93
|
+
const offset = read.offset ?? 0;
|
|
94
|
+
if (offset === 0) {
|
|
95
|
+
letGo(read.path);
|
|
96
|
+
const first = await client.call(method, params, options);
|
|
97
|
+
const answer = first.ok ? first.value : undefined;
|
|
98
|
+
if (answer !== undefined && !answer.eof && answer.size > MAX_CHUNK_BYTES && answer.size <= MAX_READ_BYTES && copyable(read)) {
|
|
99
|
+
// Room for it within COPIES_BYTES: the oldest let go first.
|
|
100
|
+
let held = answer.size;
|
|
101
|
+
for (const each of copies.values())
|
|
102
|
+
held += each.size;
|
|
103
|
+
for (const [key, each] of copies) {
|
|
104
|
+
if (held <= COPIES_BYTES)
|
|
105
|
+
break;
|
|
106
|
+
held -= each.size;
|
|
107
|
+
letGo(key);
|
|
108
|
+
}
|
|
109
|
+
copies.set(read.path, { path: cleaned(read.path), size: answer.size, stop: new AbortController() });
|
|
110
|
+
}
|
|
111
|
+
return first;
|
|
112
|
+
}
|
|
113
|
+
const copy = copies.get(read.path);
|
|
114
|
+
const length = read.length ?? MAX_CHUNK_BYTES;
|
|
115
|
+
if (copy === undefined || !Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(length) || length < 1 || length > MAX_CHUNK_BYTES)
|
|
116
|
+
return client.call(method, params, options);
|
|
117
|
+
copy.bytes ??= copyOf(copy.path, copy.size, copy.stop.signal);
|
|
118
|
+
const bytes = await untilAborted(copy.bytes, [options?.signal, copy.stop.signal]);
|
|
119
|
+
if (bytes === undefined) {
|
|
120
|
+
if (!options?.signal?.aborted)
|
|
121
|
+
copies.delete(read.path);
|
|
122
|
+
return client.call(method, params, options);
|
|
123
|
+
}
|
|
124
|
+
const data = bytes.subarray(offset, offset + length);
|
|
125
|
+
const eof = data.length < length || offset + data.length >= bytes.length;
|
|
126
|
+
if (eof)
|
|
127
|
+
copies.delete(read.path);
|
|
128
|
+
const answer = { data: Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString("base64"), eof, size: bytes.length };
|
|
129
|
+
return ok(answer);
|
|
130
|
+
},
|
|
131
|
+
close() {
|
|
132
|
+
drop();
|
|
133
|
+
client.close();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
...connection,
|
|
138
|
+
client: reading,
|
|
139
|
+
close() {
|
|
140
|
+
drop();
|
|
141
|
+
return connection.close();
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
package/dist/hosted/process.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export declare const words: (error: unknown) => string;
|
|
|
13
13
|
export declare const redact: (text: string, secrets: readonly (string | undefined)[]) => string;
|
|
14
14
|
/** A pause that ends early when signal aborts; never rejects. */
|
|
15
15
|
export declare const pause: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* What reading answers, or undefined once a signal aborts first: a caller that stopped waiting never waits on a read.
|
|
18
|
+
* Its listener goes when either settles, so a signal given to many waits holds none of them.
|
|
19
|
+
*/
|
|
20
|
+
export declare function untilAborted<T>(reading: Promise<T>, signals: readonly (AbortSignal | undefined)[]): Promise<T | undefined>;
|
|
16
21
|
/**
|
|
17
22
|
* done() asked until it answers a value, pollMs apart: for an image build's waits (a build machine, a snapshot), all
|
|
18
23
|
* held to one end (epoch ms). Past the end is a timeout, the caller's abort aborted, each a HostError in words; an
|
package/dist/hosted/process.js
CHANGED
|
@@ -39,6 +39,26 @@ export const pause = (ms, signal) => new Promise((done) => {
|
|
|
39
39
|
else
|
|
40
40
|
signal?.addEventListener("abort", finish, { once: true });
|
|
41
41
|
});
|
|
42
|
+
/**
|
|
43
|
+
* What reading answers, or undefined once a signal aborts first: a caller that stopped waiting never waits on a read.
|
|
44
|
+
* Its listener goes when either settles, so a signal given to many waits holds none of them.
|
|
45
|
+
*/
|
|
46
|
+
export function untilAborted(reading, signals) {
|
|
47
|
+
const given = signals.filter((signal) => signal !== undefined);
|
|
48
|
+
if (given.length === 0)
|
|
49
|
+
return reading;
|
|
50
|
+
const signal = AbortSignal.any(given);
|
|
51
|
+
if (signal.aborted)
|
|
52
|
+
return Promise.resolve(undefined);
|
|
53
|
+
return new Promise((settle) => {
|
|
54
|
+
const onAbort = () => settle(undefined);
|
|
55
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
56
|
+
reading.then((value) => {
|
|
57
|
+
signal.removeEventListener("abort", onAbort);
|
|
58
|
+
settle(value);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
42
62
|
/**
|
|
43
63
|
* done() asked until it answers a value, pollMs apart: for an image build's waits (a build machine, a snapshot), all
|
|
44
64
|
* held to one end (epoch ms). Past the end is a timeout, the caller's abort aborted, each a HostError in words; an
|
package/dist/hosted/provider.js
CHANGED
|
@@ -27,7 +27,8 @@ import { failFor, ok } from "../result.js";
|
|
|
27
27
|
import { daemonWatch } from "../screen-watch.js";
|
|
28
28
|
import { countTested } from "../test-connection.js";
|
|
29
29
|
import { waitUntil } from "../wait.js";
|
|
30
|
-
import { bounded, CALL_SLACK_MS, hostCall, openBridge, pause, rootOf, runToExit, seconds, uploadThroughExec, words } from "./process.js";
|
|
30
|
+
import { bounded, CALL_SLACK_MS, hostCall, openBridge, pause, rootOf, runToExit, seconds, untilAborted, uploadThroughExec, words } from "./process.js";
|
|
31
|
+
import { downloadingConnection } from "./download.js";
|
|
31
32
|
import { isWhole, PACKED_NAME, packLabels, unpackLabels } from "./values.js";
|
|
32
33
|
import { EGRESS_POLICY, EGRESS_PROXY_USER, EGRESS_RELAY, HOSTED_ALLOW, NETWORK_LABEL, networkFormOf, networkOfForm, networkRefusal, throughProxy } from "./network.js";
|
|
33
34
|
import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, initFlags, installerOf } from "./scripts.js";
|
|
@@ -68,9 +69,18 @@ const LISTED_POLL_MS = 150;
|
|
|
68
69
|
const LISTED_ROUNDS = 2;
|
|
69
70
|
const LISTEN_RETRY_MS = 250;
|
|
70
71
|
const START_POLL_MS = 500;
|
|
71
|
-
/** How much of agentrun-dial's output a dial
|
|
72
|
+
/** How much of agentrun-dial's output a dial failure carries (MachineHost.dialLog): its last lines, cut to these characters. */
|
|
72
73
|
const DIAL_LOG_LINES = 10;
|
|
73
74
|
const DIAL_LOG_CHARS = 800;
|
|
75
|
+
/**
|
|
76
|
+
* agentrun-dial's exits after which it may be started once more in its machine (MachineHost.redial): its fetch failed
|
|
77
|
+
* (3), or its init never listened and was ended (5). Neither leaves anything of it running; any other exit is final.
|
|
78
|
+
*/
|
|
79
|
+
const DIAL_AGAIN = new Set([3, 5]);
|
|
80
|
+
/** The step by which a dial's wait goes past createMs while agentrun-dial runs and writes, up to twice createMs. */
|
|
81
|
+
const DIAL_STEP_MS = 30_000;
|
|
82
|
+
/** What a dial machine needs, after the cause of a dial failure. */
|
|
83
|
+
const DIAL_NEEDS = "the machine must reach that address, and run agentrun-dial (the box image's entrypoint while AGENTRUN_ATTACH_URL is set, or the provider's own start of it)";
|
|
74
84
|
/**
|
|
75
85
|
* A machine token anywhere in what agentrun-dial wrote, not the tail of a longer word (`restart_…`): a dial timeout's
|
|
76
86
|
* words carry `<token>` in its place.
|
|
@@ -359,10 +369,11 @@ export class HostedProvider {
|
|
|
359
369
|
*/
|
|
360
370
|
#dialed() {
|
|
361
371
|
if (this.#dial === undefined) {
|
|
362
|
-
// No dial: a runner in a process of its own (serve's runner subcommand, the image's server-and-runner)
|
|
363
|
-
// the
|
|
372
|
+
// No dial: a runner in a process of its own (serve's runner subcommand, the image's server-and-runner) that relays
|
|
373
|
+
// no socket. The fixes are the ones a paired computer's refusal names (serve's workspace/attached-computers.ts
|
|
374
|
+
// RELAY_FIX, then ONE_PROCESS_FIX).
|
|
364
375
|
return {
|
|
365
|
-
problem: `${this.#label} machines dial in to this server, and this runner runs in a process of its own
|
|
376
|
+
problem: `${this.#label} machines dial in to this server, and this runner runs in a process of its own and relays no machine's socket: give the runner AGENTRUN_PUBLIC_URL (this server's public address), or start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)`,
|
|
366
377
|
};
|
|
367
378
|
}
|
|
368
379
|
const url = this.#dial.url;
|
|
@@ -1011,7 +1022,8 @@ export class HostedProvider {
|
|
|
1011
1022
|
if (init.value.exitCode !== 0)
|
|
1012
1023
|
return this.#fail("refused", `starting the daemon failed (exit ${init.value.exitCode}): ${`${init.value.stdout} ${init.value.stderr}`.trim().slice(0, 500)}`);
|
|
1013
1024
|
}
|
|
1014
|
-
const
|
|
1025
|
+
const dialNotes = [];
|
|
1026
|
+
const opened = this.#dialing ? await this.#whenDialed(ref, dialNotes, signal) : await this.#openWhenListening(ref, signal);
|
|
1015
1027
|
if (!opened.ok) {
|
|
1016
1028
|
if (opened.error.code === "aborted" || this.#dialing)
|
|
1017
1029
|
return opened;
|
|
@@ -1031,7 +1043,7 @@ export class HostedProvider {
|
|
|
1031
1043
|
await opened.value.close();
|
|
1032
1044
|
}
|
|
1033
1045
|
const listed = await this.#waitListed(ref, signal);
|
|
1034
|
-
return listed.ok ? ok([...closed, ...notes, ...listed.value]) : listed;
|
|
1046
|
+
return listed.ok ? ok([...closed, ...dialNotes, ...notes, ...listed.value]) : listed;
|
|
1035
1047
|
}
|
|
1036
1048
|
/** What init wrote to its log (child) or the vendor's words of the machine (pid1): the end of it, or nothing. */
|
|
1037
1049
|
async #initWords(ref) {
|
|
@@ -1129,7 +1141,13 @@ export class HostedProvider {
|
|
|
1129
1141
|
return ok(deletedSaid(this.host, ref, this.#label, requestMs, { ...connection, hello: hello.value }));
|
|
1130
1142
|
}
|
|
1131
1143
|
const opened = await openBridge(this.host, ref.id, { argv: hostedCommands().stdio, name: ref.name, version: VERSION, requestMs, helloMs, ...(signal ? { signal } : {}) });
|
|
1132
|
-
|
|
1144
|
+
if (!opened.ok)
|
|
1145
|
+
return opened;
|
|
1146
|
+
// A host with download takes a read past one chunk out through it, not the bridge (./download.ts).
|
|
1147
|
+
const download = this.host.download?.bind(this.host);
|
|
1148
|
+
const { execMs, uploadMs } = this.#timeouts;
|
|
1149
|
+
const connection = download === undefined ? opened.value : downloadingConnection(this.host, download, ref.id, opened.value, { execMs, downloadMs: uploadMs });
|
|
1150
|
+
return ok(deletedSaid(this.host, ref, this.#label, requestMs, connection));
|
|
1133
1151
|
}
|
|
1134
1152
|
/** #open, tried again while the bridge finds no daemon listening, until hello or helloMs in all. */
|
|
1135
1153
|
async #openWhenListening(ref, signal) {
|
|
@@ -1148,52 +1166,123 @@ export class HostedProvider {
|
|
|
1148
1166
|
* refused) fails refused in those words as the read answers. The read, one at a time, bounded by requestMs, the time
|
|
1149
1167
|
* left and the signal, holds no poll of the hub back, and the hub is read once more before a timeout: a socket there
|
|
1150
1168
|
* wins. Create then deletes one that failed.
|
|
1169
|
+
*
|
|
1170
|
+
* Where the host reads agentrun-dial's exit (dialExit), it is read too, one at a time, every few polls: one that
|
|
1171
|
+
* exited before the socket came fails refused at once, its words first. An exit in DIAL_AGAIN starts it once more in
|
|
1172
|
+
* the same machine (redial), with a note, and the wait goes on, at least half of createMs from then. And one that runs
|
|
1173
|
+
* and writes is waited for past createMs: its log is read a step (DIAL_STEP_MS, at most a quarter of createMs) before
|
|
1174
|
+
* the deadline, beside the polls, and again at it, and a log that changed between them moves the deadline a step, up
|
|
1175
|
+
* to twice createMs. The hub is read once more after those reads, so a socket that came while they ran wins.
|
|
1151
1176
|
*/
|
|
1152
|
-
async #whenDialed(ref, signal) {
|
|
1177
|
+
async #whenDialed(ref, notes, signal) {
|
|
1153
1178
|
const { createMs, requestMs } = this.#timeouts;
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1179
|
+
const { dialExit, dialLog, redial } = this.host;
|
|
1180
|
+
const began = Date.now();
|
|
1181
|
+
const cap = began + 2 * createMs;
|
|
1182
|
+
const step = Math.min(DIAL_STEP_MS, createMs / 4);
|
|
1183
|
+
let until = began + createMs;
|
|
1184
|
+
// The log's reads for the wait past createMs: a host that cannot say agentrun-dial still runs has none.
|
|
1185
|
+
const readLog = dialExit === undefined || dialLog === undefined
|
|
1186
|
+
? undefined
|
|
1187
|
+
: () => this.#call(`the dial log of ${ref.name}`, (ctx) => dialLog.call(this.host, ref.id, ctx), requestMs, signal).then((read) => (read.ok ? read.value : undefined));
|
|
1188
|
+
let logAt = until - step;
|
|
1189
|
+
// The step's first read, from logAt on: running beside the polls, it holds none of them back.
|
|
1190
|
+
let logged;
|
|
1191
|
+
let refusing;
|
|
1192
|
+
let exiting;
|
|
1193
|
+
let exitAt = began;
|
|
1194
|
+
let first;
|
|
1156
1195
|
for (;;) {
|
|
1157
1196
|
const opened = await this.#open(ref, signal);
|
|
1158
1197
|
if (opened.ok)
|
|
1159
1198
|
return opened;
|
|
1199
|
+
if (readLog !== undefined && logged === undefined && Date.now() >= logAt)
|
|
1200
|
+
logged = readLog();
|
|
1160
1201
|
const left = until - Date.now();
|
|
1161
1202
|
if (left <= 0) {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1203
|
+
if (logged !== undefined) {
|
|
1204
|
+
const before = await logged;
|
|
1205
|
+
const now = await readLog?.();
|
|
1206
|
+
logged = undefined;
|
|
1207
|
+
if (before !== undefined && now !== undefined && now !== before && until + step <= cap) {
|
|
1208
|
+
until += step;
|
|
1209
|
+
// This read is the next step's first.
|
|
1210
|
+
logged = Promise.resolve(now);
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
// A socket that came while the log was read wins.
|
|
1215
|
+
const late = await this.#open(ref, signal);
|
|
1216
|
+
if (late.ok)
|
|
1217
|
+
return late;
|
|
1218
|
+
const said = await this.#dialSaid(ref, signal);
|
|
1219
|
+
return this.#fail("timeout", `${said === undefined ? "" : `${said}; `}${this.#notDialed(ref)} within ${seconds(until - began)}: ${DIAL_NEEDS}`);
|
|
1220
|
+
}
|
|
1221
|
+
const polled = pause(Math.min(this.#startPollMs(), left), signal).then(() => ({ polled: true }));
|
|
1222
|
+
refusing ??= this.#dialRefused(ref.name, Math.min(requestMs, left), signal).then((refused) => ({ refused }));
|
|
1223
|
+
if (exiting === undefined && dialExit !== undefined && Date.now() >= exitAt) {
|
|
1224
|
+
exiting = this.#call(`agentrun-dial's exit in ${ref.name}`, (ctx) => dialExit.call(this.host, ref.id, ctx), Math.min(requestMs, left), signal).then((read) => ({ exited: read.ok ? read.value : undefined }));
|
|
1166
1225
|
}
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
if (read !== undefined)
|
|
1173
|
-
return this.#fail("refused", `the server refused ${read}`);
|
|
1226
|
+
const read = await Promise.race([refusing, polled, ...(exiting === undefined ? [] : [exiting])]);
|
|
1227
|
+
if ("refused" in read) {
|
|
1228
|
+
refusing = undefined;
|
|
1229
|
+
if (read.refused !== undefined)
|
|
1230
|
+
return this.#fail("refused", `the server refused ${read.refused}`);
|
|
1174
1231
|
await polled;
|
|
1175
1232
|
}
|
|
1233
|
+
else if ("exited" in read) {
|
|
1234
|
+
exiting = undefined;
|
|
1235
|
+
exitAt = Date.now() + this.#startPollMs() * 4;
|
|
1236
|
+
if (read.exited === undefined)
|
|
1237
|
+
await polled;
|
|
1238
|
+
else {
|
|
1239
|
+
// A socket that came as it exited wins.
|
|
1240
|
+
const late = await this.#open(ref, signal);
|
|
1241
|
+
if (late.ok)
|
|
1242
|
+
return late;
|
|
1243
|
+
const said = await this.#dialSaid(ref, signal);
|
|
1244
|
+
const again = first === undefined && DIAL_AGAIN.has(read.exited) && redial !== undefined && !signal?.aborted ? await this.#call(`agentrun-dial's second start in ${ref.name}`, (ctx) => redial.call(this.host, ref.id, ctx), requestMs, signal) : undefined;
|
|
1245
|
+
if (again?.ok) {
|
|
1246
|
+
first = read.exited;
|
|
1247
|
+
notes.push(`agentrun-dial's first start in ${ref.name} exited ${read.exited}${said === undefined ? "" : ` (${said})`}, and it was started once more`);
|
|
1248
|
+
until = Math.min(cap, Math.max(until, Date.now() + createMs / 2));
|
|
1249
|
+
logged = undefined;
|
|
1250
|
+
logAt = until - step;
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
const restart = again === undefined || again.ok ? "" : `, and starting it once more failed (${again.error.message})`;
|
|
1254
|
+
const before = first === undefined ? "" : `, and its first start exited ${first} before it was started once more`;
|
|
1255
|
+
return this.#fail("refused", `${said === undefined ? "" : `${said}; `}${this.#notDialed(ref)}: agentrun-dial exited ${read.exited}${before}${restart}: ${DIAL_NEEDS}`);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1176
1258
|
if (signal?.aborted)
|
|
1177
1259
|
return this.#fail("aborted", `create was aborted while it waited for ${ref.name} to dial`);
|
|
1178
1260
|
}
|
|
1179
1261
|
}
|
|
1262
|
+
/** "<name> did not dial <attach URL>[ through <relay>]": a dial failure's words, after its cause. */
|
|
1263
|
+
#notDialed(ref) {
|
|
1264
|
+
const dialed = this.#dialed();
|
|
1265
|
+
const to = "problem" in dialed ? "this server" : dialed.attach;
|
|
1266
|
+
const through = this.#attachEgress === undefined ? "" : ` through ${this.#attachEgress}`;
|
|
1267
|
+
return `${ref.name} did not dial ${to}${through}`;
|
|
1268
|
+
}
|
|
1180
1269
|
/**
|
|
1181
|
-
*
|
|
1182
|
-
* `<token>`, its last DIAL_LOG_LINES lines within DIAL_LOG_CHARS characters, or that it never started
|
|
1183
|
-
* host without dialLog, or a read that fails, outlasts requestMs or is cut by the create's
|
|
1184
|
-
* waits on it.
|
|
1270
|
+
* What a dial failure's words lead with: what the host's dialLog read of agentrun-dial, every machine token replaced
|
|
1271
|
+
* by `<token>`, its last DIAL_LOG_LINES lines within DIAL_LOG_CHARS characters, or that it never started or wrote
|
|
1272
|
+
* nothing. undefined for a host without dialLog, or a read that fails, outlasts requestMs or is cut by the create's
|
|
1273
|
+
* signal, so a cancel never waits on it.
|
|
1185
1274
|
*/
|
|
1186
|
-
async #
|
|
1275
|
+
async #dialSaid(ref, signal) {
|
|
1187
1276
|
const { dialLog } = this.host;
|
|
1188
1277
|
if (dialLog === undefined)
|
|
1189
|
-
return
|
|
1278
|
+
return undefined;
|
|
1190
1279
|
const read = await this.#call(`the dial log of ${ref.name}`, (ctx) => dialLog.call(this.host, ref.id, ctx), this.#timeouts.requestMs, signal);
|
|
1191
1280
|
if (!read.ok)
|
|
1192
|
-
return
|
|
1281
|
+
return undefined;
|
|
1193
1282
|
if (read.value === undefined)
|
|
1194
|
-
return "
|
|
1283
|
+
return "agentrun-dial never started";
|
|
1195
1284
|
const lines = read.value.replaceAll(MACHINE_TOKEN, "<token>").split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "");
|
|
1196
|
-
return lines.length === 0 ? "
|
|
1285
|
+
return lines.length === 0 ? "agentrun-dial wrote nothing" : `agentrun-dial said: ${lines.slice(-DIAL_LOG_LINES).join(" | ").slice(-DIAL_LOG_CHARS)}`;
|
|
1197
1286
|
}
|
|
1198
1287
|
/**
|
|
1199
1288
|
* Its tools' network as they meet it, against the one create made: the probe, as the computer's own user. Under none,
|
|
@@ -1727,23 +1816,6 @@ async function readMachine(host, id, ms, signal) {
|
|
|
1727
1816
|
return read.error.code === "not_found" ? ok(undefined) : read;
|
|
1728
1817
|
return ok(read.value === undefined ? undefined : unpacked(host, read.value));
|
|
1729
1818
|
}
|
|
1730
|
-
/** What reading answers, or undefined once a signal aborts first: a caller that stopped waiting never waits on a read. */
|
|
1731
|
-
function untilAborted(reading, signals) {
|
|
1732
|
-
const given = signals.filter((signal) => signal !== undefined);
|
|
1733
|
-
if (given.length === 0)
|
|
1734
|
-
return reading;
|
|
1735
|
-
const signal = AbortSignal.any(given);
|
|
1736
|
-
if (signal.aborted)
|
|
1737
|
-
return Promise.resolve(undefined);
|
|
1738
|
-
return new Promise((settle) => {
|
|
1739
|
-
const onAbort = () => settle(undefined);
|
|
1740
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1741
|
-
reading.then((value) => {
|
|
1742
|
-
signal.removeEventListener("abort", onAbort);
|
|
1743
|
-
settle(value);
|
|
1744
|
-
});
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
1819
|
/**
|
|
1748
1820
|
* A connection that says its computer was deleted (the vendor's own API can delete it mid-run). Once its client answers
|
|
1749
1821
|
* gone (the stream ended or failed), the machine is read once, and that one read answers every call in flight at that
|