@parcha/agentrun-computer 0.1.0-beta.67 → 0.1.0-beta.69
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 +243 -9
- package/box/README.md +8 -0
- package/box/install.sh +60 -6
- package/dist/boxd.js +43 -8
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +1 -1
- package/dist/conformance/cli.d.ts +6 -0
- package/dist/conformance/cli.js +14 -3
- package/dist/conformance/instabox.d.ts +36 -0
- package/dist/conformance/instabox.js +43 -0
- package/dist/conformance/northflank.d.ts +44 -0
- package/dist/conformance/northflank.js +50 -0
- package/dist/conformance/sprites.d.ts +32 -0
- package/dist/conformance/sprites.js +40 -0
- package/dist/conformance/vercel.d.ts +35 -0
- package/dist/conformance/vercel.js +43 -0
- package/dist/descriptor.d.ts +6 -0
- package/dist/descriptor.js +2 -0
- package/dist/descriptors/agent37.d.ts +1 -0
- package/dist/descriptors/agent37.js +2 -0
- package/dist/descriptors/daytona.d.ts +1 -0
- package/dist/descriptors/daytona.js +2 -0
- package/dist/descriptors/e2b.d.ts +14 -0
- package/dist/descriptors/e2b.js +20 -3
- package/dist/descriptors/fly.d.ts +1 -0
- package/dist/descriptors/fly.js +2 -0
- package/dist/descriptors/groundbox.d.ts +1 -0
- package/dist/descriptors/groundbox.js +2 -0
- package/dist/descriptors/index.d.ts +106 -1
- package/dist/descriptors/index.js +8 -2
- package/dist/descriptors/instabox.d.ts +20 -0
- package/dist/descriptors/instabox.js +22 -0
- package/dist/descriptors/modal.d.ts +1 -0
- package/dist/descriptors/modal.js +2 -0
- package/dist/descriptors/northflank.d.ts +24 -0
- package/dist/descriptors/northflank.js +30 -0
- package/dist/descriptors/orgo.d.ts +1 -0
- package/dist/descriptors/orgo.js +2 -0
- package/dist/descriptors/render.d.ts +1 -0
- package/dist/descriptors/render.js +2 -0
- package/dist/descriptors/sprites.d.ts +19 -0
- package/dist/descriptors/sprites.js +19 -0
- package/dist/descriptors/vercel.d.ts +23 -0
- package/dist/descriptors/vercel.js +24 -0
- package/dist/docker/egress-main.js +17 -10
- package/dist/docker/egress-proxy.d.ts +7 -0
- package/dist/docker/egress-proxy.js +12 -0
- package/dist/docker/egress.d.ts +3 -1
- package/dist/docker/egress.js +11 -4
- package/dist/docker/image.d.ts +8 -2
- package/dist/docker/image.js +24 -3
- package/dist/docker.d.ts +6 -0
- package/dist/docker.js +15 -5
- package/dist/e2b.d.ts +25 -10
- package/dist/e2b.js +36 -16
- package/dist/groundbox.js +15 -2
- package/dist/hosted/download.d.ts +16 -0
- package/dist/hosted/download.js +108 -2
- package/dist/hosted/provider.js +25 -12
- package/dist/hosted/rest.js +23 -1
- package/dist/hosted/scripts.d.ts +2 -0
- package/dist/hosted/scripts.js +29 -0
- package/dist/hosted/ssh-exec.d.ts +17 -2
- package/dist/hosted/ssh-exec.js +17 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/instabox.d.ts +30 -0
- package/dist/instabox.js +424 -0
- package/dist/northflank.d.ts +44 -0
- package/dist/northflank.js +448 -0
- package/dist/orgo-desktop.js +2 -2
- package/dist/orgo-names.d.ts +15 -1
- package/dist/orgo-names.js +13 -0
- package/dist/orgo.d.ts +10 -0
- package/dist/orgo.js +64 -4
- package/dist/providers.d.ts +10 -4
- package/dist/render.js +4 -3
- package/dist/sprites.d.ts +37 -0
- package/dist/sprites.js +309 -0
- package/dist/vercel.d.ts +26 -0
- package/dist/vercel.js +262 -0
- package/package.json +22 -2
package/dist/docker/image.d.ts
CHANGED
|
@@ -14,8 +14,14 @@ export declare const DOCKER_RECIPE_HAS = "python, git, curl, node, npm, rg";
|
|
|
14
14
|
* registry-1.docker.io/v2/library/python/manifests/3.12-slim accepting an OCI index or a manifest list: its
|
|
15
15
|
* `docker-content-digest`), and put it here. The recipe's hash changes with it, and so does DEFAULT_DOCKER_IMAGE. */
|
|
16
16
|
export declare const DOCKER_BASE = "python:3.12-slim@sha256:b18b261e1b4974b4f321451ad5251ded85abb22c2b8b262da527dda1d031ab30";
|
|
17
|
-
/** The
|
|
18
|
-
*
|
|
17
|
+
/** The Node release the default image runs, the server image's (packages/serve/docker/Dockerfile): Debian's nodejs
|
|
18
|
+
* comes with npm 9, older than the npm current packages are published for. */
|
|
19
|
+
export declare const DOCKER_NODE_VERSION = "24.22.3";
|
|
20
|
+
/** The sha256 of that release's Linux tarball for each Debian architecture, from its signed SHASUMS256.txt. */
|
|
21
|
+
export declare const DOCKER_NODE_SHA256: Readonly<Record<"amd64" | "arm64", string>>;
|
|
22
|
+
/** The default image's recipe: python with git, curl and rg for a model's tools, Node (node, npm and npx) from
|
|
23
|
+
* nodejs.org checked against its sha256 before it is unpacked, and socat, the relay to a computer's egress proxy when it
|
|
24
|
+
* has one. */
|
|
19
25
|
export declare const DOCKER_RECIPE: string;
|
|
20
26
|
/** Where an image comes from: a recipe, built here, or an image by name, pulled when Docker has none. */
|
|
21
27
|
export type ImageSource = {
|
package/dist/docker/image.js
CHANGED
|
@@ -36,13 +36,34 @@ export const DOCKER_RECIPE_HAS = "python, git, curl, node, npm, rg";
|
|
|
36
36
|
* registry-1.docker.io/v2/library/python/manifests/3.12-slim accepting an OCI index or a manifest list: its
|
|
37
37
|
* `docker-content-digest`), and put it here. The recipe's hash changes with it, and so does DEFAULT_DOCKER_IMAGE. */
|
|
38
38
|
export const DOCKER_BASE = "python:3.12-slim@sha256:b18b261e1b4974b4f321451ad5251ded85abb22c2b8b262da527dda1d031ab30";
|
|
39
|
-
/** The
|
|
40
|
-
*
|
|
39
|
+
/** The Node release the default image runs, the server image's (packages/serve/docker/Dockerfile): Debian's nodejs
|
|
40
|
+
* comes with npm 9, older than the npm current packages are published for. */
|
|
41
|
+
export const DOCKER_NODE_VERSION = "24.22.3";
|
|
42
|
+
/** The sha256 of that release's Linux tarball for each Debian architecture, from its signed SHASUMS256.txt. */
|
|
43
|
+
export const DOCKER_NODE_SHA256 = {
|
|
44
|
+
amd64: "4f2b175a6d53a5c617a80dba2676238a0688cef28c6da4eba35c7d844e66fcfb",
|
|
45
|
+
arm64: "6e51a2ada00f0011cc266f65d98922b403d7ad88f809ca2aa615a5fe1ce6e86c",
|
|
46
|
+
};
|
|
47
|
+
/** The default image's recipe: python with git, curl and rg for a model's tools, Node (node, npm and npx) from
|
|
48
|
+
* nodejs.org checked against its sha256 before it is unpacked, and socat, the relay to a computer's egress proxy when it
|
|
49
|
+
* has one. */
|
|
41
50
|
export const DOCKER_RECIPE = [
|
|
42
51
|
`FROM ${DOCKER_BASE}`,
|
|
43
52
|
"RUN apt-get update \\",
|
|
44
|
-
" && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git curl ca-certificates
|
|
53
|
+
" && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git curl ca-certificates xz-utils ripgrep socat \\",
|
|
45
54
|
" && rm -rf /var/lib/apt/lists/*",
|
|
55
|
+
"RUN set -eu; \\",
|
|
56
|
+
' case "$(dpkg --print-architecture)" in \\',
|
|
57
|
+
` amd64) arch=x64; sum=${DOCKER_NODE_SHA256.amd64} ;; \\`,
|
|
58
|
+
` arm64) arch=arm64; sum=${DOCKER_NODE_SHA256.arm64} ;; \\`,
|
|
59
|
+
' *) echo "no Node build for $(dpkg --print-architecture)" >&2; exit 1 ;; \\',
|
|
60
|
+
" esac; \\",
|
|
61
|
+
` file="node-v${DOCKER_NODE_VERSION}-linux-$arch.tar.xz"; \\`,
|
|
62
|
+
` curl -fsSLo "/tmp/$file" "https://nodejs.org/dist/v${DOCKER_NODE_VERSION}/$file"; \\`,
|
|
63
|
+
' echo "$sum /tmp/$file" | sha256sum -c -; \\',
|
|
64
|
+
' tar -xJf "/tmp/$file" -C /usr/local --strip-components=1 --no-same-owner; \\',
|
|
65
|
+
' rm -f "/tmp/$file" /usr/local/CHANGELOG.md /usr/local/README.md /usr/local/LICENSE; \\',
|
|
66
|
+
" node --version; npm --version",
|
|
46
67
|
"",
|
|
47
68
|
].join("\n");
|
|
48
69
|
export const recipeHash = (recipe) => createHash("sha256").update(recipe).digest("hex");
|
package/dist/docker.d.ts
CHANGED
|
@@ -31,6 +31,12 @@ export interface DockerEgressOptions {
|
|
|
31
31
|
* better; it never makes the refusal weaker than what that root shows.
|
|
32
32
|
*/
|
|
33
33
|
hostRoot?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The most connections one computer's proxy holds open at once (its tunnels and forwarded requests), past which a new
|
|
36
|
+
* one is refused with 429: a whole number from 1 to MAX_TUNNELS_CEILING (256). Default the proxy's, 64. A proxy keeps
|
|
37
|
+
* the cap it was made with.
|
|
38
|
+
*/
|
|
39
|
+
maxTunnels?: number;
|
|
34
40
|
}
|
|
35
41
|
export interface DockerProviderOptions {
|
|
36
42
|
/** The daemon binary on this machine, for the computer's architecture (dist/computerd-linux-<arch>). Any mode this
|
package/dist/docker.js
CHANGED
|
@@ -15,7 +15,7 @@ import { dockerEnv } from "./child-env.js";
|
|
|
15
15
|
import { DOCKER_RECIPE, ensureImage, imageSourceProblem } from "./docker/image.js";
|
|
16
16
|
import { ALLOW_PORTS, allowOf, containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_NETWORK, EGRESS_READY_MS, EGRESS_SOCKET, egressCode, egressCodeProblem, egressNameOf, egressNetworkArgs, egressNetworkProblem, egressRunArgs, egressVolumeArgs, hostAddresses, MAX_ALLOW, NO_CONFIG_PROXY, policyWords, RELAY_FLAG, } from "./docker/egress.js";
|
|
17
17
|
import { daemonStage, daemonVerified, egressStage, egressStaged } from "./docker/stage.js";
|
|
18
|
-
import { EGRESS_READY } from "./docker/egress-proxy.js";
|
|
18
|
+
import { EGRESS_READY, MAX_TUNNELS_CEILING } from "./docker/egress-proxy.js";
|
|
19
19
|
import { OLD_ENGINE, outsideWords, subpathOf, VOLUME_SUBPATH_ENGINE, volumeMount, volumeOf } from "./docker/volume.js";
|
|
20
20
|
import { addressBytes } from "./docker/egress-table.js";
|
|
21
21
|
import { checkMount, WORKSPACE } from "./mount.js";
|
|
@@ -733,8 +733,8 @@ export class DockerProvider {
|
|
|
733
733
|
return volume;
|
|
734
734
|
if (volume.value.exitCode !== 0)
|
|
735
735
|
return vendorFail("docker", `docker volume create ${proxy} failed: ${volume.value.stderr.trim()}`);
|
|
736
|
-
const { image, hint, readyMs } = this.#egress;
|
|
737
|
-
const args = egressRunArgs({ name, user, image, allow, local: this.#hostLocal(), deadline, code: this.#code, labels, ...(hint === undefined ? {} : { hint }) });
|
|
736
|
+
const { image, hint, readyMs, maxTunnels } = this.#egress;
|
|
737
|
+
const args = egressRunArgs({ name, user, image, allow, local: this.#hostLocal(), deadline, code: this.#code, labels, ...(hint === undefined ? {} : { hint }), ...(maxTunnels === undefined ? {} : { maxTunnels }) });
|
|
738
738
|
const ran = await this.#run(args, signal);
|
|
739
739
|
if (!ran.ok) {
|
|
740
740
|
// Cut off before its own exit: the daemon may still make the proxy after the caller's cleanup looked (#settle).
|
|
@@ -1594,7 +1594,7 @@ export function settleBoundsOf({ settleMs = SETTLE_MS, settleQuietMs = SETTLE_QU
|
|
|
1594
1594
|
return { settleMs, quietMs: settleQuietMs };
|
|
1595
1595
|
}
|
|
1596
1596
|
/** The egress options with their defaults, or a throw in words. */
|
|
1597
|
-
function egressOptionsOf({ image = EGRESS_IMAGE, hint, readyMs = EGRESS_READY_MS, hostAddresses: given, hostRoot = "/" }) {
|
|
1597
|
+
function egressOptionsOf({ image = EGRESS_IMAGE, hint, readyMs = EGRESS_READY_MS, hostAddresses: given, hostRoot = "/", maxTunnels }) {
|
|
1598
1598
|
if (typeof hostRoot !== "string" || !hostRoot.startsWith("/"))
|
|
1599
1599
|
throw new Error(`the egress proxy's hostRoot must be an absolute path, not ${JSON.stringify(hostRoot)}`);
|
|
1600
1600
|
if (typeof image !== "string" || image.trim() === "" || image.startsWith("-") || image.includes("\0")) {
|
|
@@ -1609,7 +1609,17 @@ function egressOptionsOf({ image = EGRESS_IMAGE, hint, readyMs = EGRESS_READY_MS
|
|
|
1609
1609
|
if (given !== undefined && !(Array.isArray(given) && given.every((address) => typeof address === "string" && addressBytes(address) !== undefined && !address.includes(",")))) {
|
|
1610
1610
|
throw new Error(`the egress proxy's hostAddresses must be a list of IP addresses, such as ["93.184.215.20"], not ${JSON.stringify(given)}`);
|
|
1611
1611
|
}
|
|
1612
|
-
|
|
1612
|
+
if (maxTunnels !== undefined && (!Number.isSafeInteger(maxTunnels) || maxTunnels < 1 || maxTunnels > MAX_TUNNELS_CEILING)) {
|
|
1613
|
+
throw new Error(`the egress proxy's maxTunnels must be a whole number from 1 to ${MAX_TUNNELS_CEILING}, not ${JSON.stringify(maxTunnels)}`);
|
|
1614
|
+
}
|
|
1615
|
+
return {
|
|
1616
|
+
image,
|
|
1617
|
+
readyMs,
|
|
1618
|
+
hostRoot,
|
|
1619
|
+
...(hint === undefined ? {} : { hint }),
|
|
1620
|
+
...(given === undefined ? {} : { hostAddresses: [...given] }),
|
|
1621
|
+
...(maxTunnels === undefined ? {} : { maxTunnels }),
|
|
1622
|
+
};
|
|
1613
1623
|
}
|
|
1614
1624
|
/**
|
|
1615
1625
|
* Why an allowlist is refused when this provider's own interfaces are not the Docker host's: the proxy refuses the host's
|
package/dist/e2b.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface E2BConnectionOptions {
|
|
|
14
14
|
domain: string;
|
|
15
15
|
apiUrl: string;
|
|
16
16
|
debug: false;
|
|
17
|
+
httpVersion: "1.1";
|
|
17
18
|
proxy?: string;
|
|
18
19
|
requestTimeoutMs?: number;
|
|
19
20
|
signal?: AbortSignal;
|
|
@@ -26,8 +27,15 @@ export interface E2BProviderOptions extends Omit<HostedOptions, "maxLifetimeMs">
|
|
|
26
27
|
apiKey: string;
|
|
27
28
|
/** The SDK's Sandbox class: the host's `e2b` package's. */
|
|
28
29
|
Sandbox: E2BSandboxClass;
|
|
29
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* E2B's domain, or that of a cloud that speaks E2B's API (serve's AGENTRUN_E2B_DOMAIN): each sandbox's envd is under it,
|
|
32
|
+
* and the API is https://api.<domain> unless apiUrl names another. Default e2b.app.
|
|
33
|
+
*/
|
|
30
34
|
domain?: string;
|
|
35
|
+
/** The API's URL, for a cloud whose API is not https://api.<domain> (serve's AGENTRUN_E2B_API_URL): https, no login, query or fragment. */
|
|
36
|
+
apiUrl?: string;
|
|
37
|
+
/** The template prepareImage() answers, in place of the box template (serve's AGENTRUN_E2B_TEMPLATE): an E2B template's name or id. */
|
|
38
|
+
template?: string;
|
|
31
39
|
/** desktop (default): a template with an X server, started through the daemon; linux: no screen. */
|
|
32
40
|
kind?: "desktop" | "linux";
|
|
33
41
|
/** The longest lifetime check takes: E2B Hobby's 1 h by default, Pro's 24 h at most. */
|
|
@@ -48,10 +56,15 @@ export interface E2BOptions extends Omit<E2BProviderOptions, "Sandbox"> {
|
|
|
48
56
|
/** The SDK's Sandbox class; the e2b package's by default. */
|
|
49
57
|
Sandbox?: E2BSandboxClass;
|
|
50
58
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The connection options every SDK call is given: the API at apiUrl when given, else https://api.<domain>. Exported for
|
|
61
|
+
* the test that hands them to the real SDK. The SDK sends every call through its one proxy, so it is given one unless
|
|
62
|
+
* NO_PROXY exempts the whole domain (proxyForDomain) and a given API URL's host too.
|
|
63
|
+
*/
|
|
64
|
+
export declare function connectionOptions({ apiKey, domain, apiUrl }: {
|
|
53
65
|
apiKey: string;
|
|
54
66
|
domain: string;
|
|
67
|
+
apiUrl?: string;
|
|
55
68
|
}, env?: ProxyEnv): E2BConnectionOptions;
|
|
56
69
|
/**
|
|
57
70
|
* An E2BProvider from its options alone; it reads no environment but the guard ambientProblem keeps. The key is
|
|
@@ -64,16 +77,18 @@ export declare function create(options: E2BOptions): Promise<E2BProvider>;
|
|
|
64
77
|
export declare const conformance: () => Promise<typeof import("./conformance/e2b.js")>;
|
|
65
78
|
/**
|
|
66
79
|
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id). A server
|
|
67
|
-
* starts every one, sandbox or desktop, from the
|
|
68
|
-
* with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
69
|
-
* computerd (desktop.ts). Any other template a spec
|
|
80
|
+
* starts every one, sandbox or desktop, from the template prepareImage() answers: by default the box template, the box
|
|
81
|
+
* image (box/Dockerfile) with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
82
|
+
* starts through computerd (desktop.ts). Any other template, options.template's or a spec's, must carry what the
|
|
83
|
+
* computer's kind needs.
|
|
70
84
|
*/
|
|
71
85
|
export declare class E2BProvider extends HostedProvider {
|
|
86
|
+
#private;
|
|
72
87
|
/**
|
|
73
|
-
* The provider contract's prepareImage (its descriptor declares it): the
|
|
74
|
-
* public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
75
|
-
* starts a
|
|
76
|
-
* from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
88
|
+
* The provider contract's prepareImage (its descriptor declares it): the template options.template names, else the
|
|
89
|
+
* box template the release publishes, public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
90
|
+
* starts by that name. No call: E2B starts a template at create with nothing to pull ahead of it, so onWait is never
|
|
91
|
+
* told. A desktop starts from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
77
92
|
*/
|
|
78
93
|
prepareImage(): Promise<Result<string>>;
|
|
79
94
|
constructor(options: E2BProviderOptions);
|
package/dist/e2b.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { boxE2bTemplate } from "./box-image.js";
|
|
2
2
|
import { E2B } from "./descriptors/e2b.js";
|
|
3
3
|
import { DEADLINE_LABEL, show } from "./drift.js";
|
|
4
|
-
import { installedProxy, proxyForDomain } from "./env-proxy.js";
|
|
4
|
+
import { installedProxy, proxyFor, proxyForDomain } from "./env-proxy.js";
|
|
5
5
|
import { HostError } from "./host.js";
|
|
6
6
|
import { deadlineOf, HostedProvider, isoOf, MAX_LABEL, timeoutsOf } from "./hosted/provider.js";
|
|
7
|
+
import { httpsBase } from "./hosted/rest.js";
|
|
7
8
|
import { dialLaunch } from "./hosted/scripts.js";
|
|
8
9
|
import { connectOf } from "./descriptor.js";
|
|
9
10
|
import { dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
|
|
@@ -11,10 +12,18 @@ import { PassThrough } from "node:stream";
|
|
|
11
12
|
import { ok } from "./result.js";
|
|
12
13
|
import { vendorSdk } from "./vendor-sdk.js";
|
|
13
14
|
const DEFAULT_DOMAIN = "e2b.app";
|
|
14
|
-
/** The
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** The server's name for the setting that fills `option` (its descriptor's key), for words that name what to fix. */
|
|
16
|
+
const settingName = (option) => E2B.keys.find((key) => key.option === option)?.name ?? option;
|
|
17
|
+
/**
|
|
18
|
+
* The connection options every SDK call is given: the API at apiUrl when given, else https://api.<domain>. Exported for
|
|
19
|
+
* the test that hands them to the real SDK. The SDK sends every call through its one proxy, so it is given one unless
|
|
20
|
+
* NO_PROXY exempts the whole domain (proxyForDomain) and a given API URL's host too.
|
|
21
|
+
*/
|
|
22
|
+
export function connectionOptions({ apiKey, domain, apiUrl }, env = installedProxy()) {
|
|
23
|
+
const proxy = proxyForDomain(domain, env) ?? (apiUrl === undefined ? undefined : proxyFor(new URL(apiUrl), env));
|
|
24
|
+
// HTTP/1.1 alone: when an idle HTTP/2 session times out, the SDK's undici client throws on a stream no one listens to,
|
|
25
|
+
// and that unhandled 'error' ends the whole process (index.mjs buildDispatchedFetch, allowH2 unless httpVersion "1.1").
|
|
26
|
+
return { apiKey, domain, apiUrl: apiUrl ?? `https://api.${domain}`, debug: false, httpVersion: "1.1", ...(proxy ? { proxy: proxy.href } : {}) };
|
|
18
27
|
}
|
|
19
28
|
/**
|
|
20
29
|
* The SDK takes sandboxUrl from E2B_SANDBOX_URL when it is given none (index.mjs:1152, 1183-1185), and no option can
|
|
@@ -378,25 +387,28 @@ class E2BHost {
|
|
|
378
387
|
}
|
|
379
388
|
/**
|
|
380
389
|
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id). A server
|
|
381
|
-
* starts every one, sandbox or desktop, from the
|
|
382
|
-
* with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
383
|
-
* computerd (desktop.ts). Any other template a spec
|
|
390
|
+
* starts every one, sandbox or desktop, from the template prepareImage() answers: by default the box template, the box
|
|
391
|
+
* image (box/Dockerfile) with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
392
|
+
* starts through computerd (desktop.ts). Any other template, options.template's or a spec's, must carry what the
|
|
393
|
+
* computer's kind needs.
|
|
384
394
|
*/
|
|
385
395
|
export class E2BProvider extends HostedProvider {
|
|
396
|
+
/** The template options.template names, or undefined for the box template. */
|
|
397
|
+
#template;
|
|
386
398
|
/**
|
|
387
|
-
* The provider contract's prepareImage (its descriptor declares it): the
|
|
388
|
-
* public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
389
|
-
* starts a
|
|
390
|
-
* from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
399
|
+
* The provider contract's prepareImage (its descriptor declares it): the template options.template names, else the
|
|
400
|
+
* box template the release publishes, public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
401
|
+
* starts by that name. No call: E2B starts a template at create with nothing to pull ahead of it, so onWait is never
|
|
402
|
+
* told. A desktop starts from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
391
403
|
*/
|
|
392
404
|
async prepareImage() {
|
|
393
|
-
return ok(boxE2bTemplate());
|
|
405
|
+
return ok(this.#template ?? boxE2bTemplate());
|
|
394
406
|
}
|
|
395
407
|
constructor(options) {
|
|
396
408
|
// A caller who still names the option is told it is gone, whatever its value: it once let public traffic in.
|
|
397
409
|
if (typeof options === "object" && options !== null && Object.hasOwn(options, "publicStream"))
|
|
398
410
|
throw new Error(PUBLIC);
|
|
399
|
-
const { apiKey, Sandbox, domain = DEFAULT_DOMAIN, kind = "desktop", maxLifetimeMs = HOBBY_MAX_MS, connect, ...rest } = options;
|
|
411
|
+
const { apiKey, Sandbox, domain = DEFAULT_DOMAIN, apiUrl, template, kind = "desktop", maxLifetimeMs = HOBBY_MAX_MS, connect, ...rest } = options;
|
|
400
412
|
const via = connectOf(E2B, { connect });
|
|
401
413
|
if (typeof apiKey !== "string" || apiKey === "")
|
|
402
414
|
throw new Error("options.apiKey, the E2B API key, is required: the provider reads no environment, so the caller passes it");
|
|
@@ -407,7 +419,15 @@ export class E2BProvider extends HostedProvider {
|
|
|
407
419
|
if (ambient)
|
|
408
420
|
throw new Error(ambient);
|
|
409
421
|
if (typeof domain !== "string" || !DOMAIN.test(domain))
|
|
410
|
-
throw new Error(`the E2B domain must be a host name such as ${DEFAULT_DOMAIN}, not ${JSON.stringify(domain)}`);
|
|
411
|
-
|
|
422
|
+
throw new Error(`the E2B domain (${settingName("domain")}) must be a host name such as ${DEFAULT_DOMAIN}, not ${JSON.stringify(domain)}`);
|
|
423
|
+
// The key goes to the API URL: https alone, and words that give its origin alone (httpsBase).
|
|
424
|
+
const api = apiUrl === undefined ? undefined : httpsBase(String(apiUrl), `the E2B API URL (${settingName("apiUrl")})`);
|
|
425
|
+
// Trimmed, as serve reads the same setting to select it (resolve-computer.ts registryHere, computer-deps.ts computerSpecOf).
|
|
426
|
+
const named = typeof template === "string" ? template.trim() : template;
|
|
427
|
+
if (named !== undefined && (typeof named !== "string" || !TEMPLATE.test(named))) {
|
|
428
|
+
throw new Error(`the E2B template (${settingName("template")}) is the name or id of an E2B template, such as "${boxE2bTemplate()}" (the box template), not ${JSON.stringify(template)}`);
|
|
429
|
+
}
|
|
430
|
+
super(new E2BHost(Sandbox, connectionOptions({ apiKey, domain, ...(api === undefined ? {} : { apiUrl: api }) }), timeoutsOf(rest.timeouts).requestMs, via), { ...rest, kind, maxLifetimeMs });
|
|
431
|
+
this.#template = named;
|
|
412
432
|
}
|
|
413
433
|
}
|
package/dist/groundbox.js
CHANGED
|
@@ -183,7 +183,20 @@ const QUEUE_HIGH = 8 * 1024 * 1024;
|
|
|
183
183
|
const QUEUE_LOW = 2 * 1024 * 1024;
|
|
184
184
|
/** The bytes a chunk of base64 holds. */
|
|
185
185
|
const bytesOf = (base64) => Math.floor((base64.length * 3) / 4);
|
|
186
|
-
/** A
|
|
186
|
+
/** A figure of the answer's size: a whole number above 0, else none (never a guess). */
|
|
187
|
+
const sized = (value) => (isWhole(value) && value > 0 ? value : undefined);
|
|
188
|
+
/**
|
|
189
|
+
* The size Groundbox says a sandbox runs at (its cpus, memory_gb and disk_gb), read from its answer over anything the
|
|
190
|
+
* create asked: a spec that names no size gets Groundbox's own, which only the answer says. None where it says none.
|
|
191
|
+
*/
|
|
192
|
+
function resourcesOf(sandbox) {
|
|
193
|
+
const cpus = sized(sandbox.cpus);
|
|
194
|
+
const memoryGb = sized(sandbox.memory_gb);
|
|
195
|
+
const diskGb = sized(sandbox.disk_gb);
|
|
196
|
+
const resources = { ...(cpus === undefined ? {} : { cpus }), ...(memoryGb === undefined ? {} : { memoryMb: memoryGb * 1024 }), ...(diskGb === undefined ? {} : { diskGb }) };
|
|
197
|
+
return Object.keys(resources).length > 0 ? { resources } : {};
|
|
198
|
+
}
|
|
199
|
+
/** A sandbox as the adapter reads a machine, with the size it runs at; none for a record Groundbox keeps of one that has ended. */
|
|
187
200
|
function machineOf(sandbox) {
|
|
188
201
|
const labels = { ...(sandbox.metadata ?? {}) };
|
|
189
202
|
// A status this host does not know is a machine that is there and not running: the janitor still finds and ends it.
|
|
@@ -193,7 +206,7 @@ function machineOf(sandbox) {
|
|
|
193
206
|
if (state === undefined)
|
|
194
207
|
return undefined;
|
|
195
208
|
const created = dateOf(sandbox.created_at);
|
|
196
|
-
return { id: sandbox.id, labels, state, ...(created ? { createdAt: created } : {}) };
|
|
209
|
+
return { id: sandbox.id, labels, state, ...(created ? { createdAt: created } : {}), ...resourcesOf(sandbox) };
|
|
197
210
|
}
|
|
198
211
|
/** Why Groundbox's metadata can't hold these labels, in words; undefined when it can. */
|
|
199
212
|
function labelProblem(labels) {
|
|
@@ -6,6 +6,13 @@ export interface DownloadBounds {
|
|
|
6
6
|
/** The download of one copy. */
|
|
7
7
|
downloadMs: number;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* The most bytes the pulls' copies of one connection hold at once. A copy is made one at a time, with what the copies
|
|
11
|
+
* still held leave of this as its tar's file-size limit (tree-stage's, in 512-byte blocks): a tar past it is cut off,
|
|
12
|
+
* and its pull is the daemon's. A copy is held from its download until its pull's end, its last read, or the
|
|
13
|
+
* connection's close, so a pull read once and left holds its room until then.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TREE_COPY_BYTES: number;
|
|
9
16
|
/**
|
|
10
17
|
* connection, with every files.read past one chunk read from one downloaded copy after its first chunk. A first chunk
|
|
11
18
|
* (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
|
|
@@ -19,5 +26,14 @@ export interface DownloadBounds {
|
|
|
19
26
|
* host with no download. The copy in the machine is removed once it is downloaded, without holding up the read. A close
|
|
20
27
|
* 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
28
|
* daemon client's (gone).
|
|
29
|
+
*
|
|
30
|
+
* A tar.pull of an absolute path outside /proc is read from a copy too. The daemon begins it, so a path it refuses is
|
|
31
|
+
* never copied; at the pull's first read, tree-stage makes its tar as the daemon's user (one pull's at a time per
|
|
32
|
+
* connection, within the room the copies still held leave of TREE_COPY_BYTES), it is downloaded and removed from the
|
|
33
|
+
* machine, and the daemon's own pull is ended. Every read of the pull is then answered from the copy, as the daemon answers (maxBytes of it, fewer only at
|
|
34
|
+
* its end, which eof marks), and the copy goes at its end, at tar.pull.end, or at the connection's close. A copy that
|
|
35
|
+
* fails at any step (the daemon's user unread, tree-stage refused or cut off, the download) leaves the pull the
|
|
36
|
+
* daemon's, from its first byte, since nothing of the copy was answered yet. A call of another method does not let a
|
|
37
|
+
* pull's copy go: once read from, the daemon's pull is ended, and the copy is the one tar of the pull there is.
|
|
22
38
|
*/
|
|
23
39
|
export declare function downloadingConnection(host: MachineHost, download: NonNullable<MachineHost["download"]>, id: string, connection: ComputerConnection, bounds: DownloadBounds): ComputerConnection;
|
package/dist/hosted/download.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
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
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
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.
|
|
5
|
+
// user, holds what that user can read and nothing more, whatever the path names by the time it is copied. A tar.pull
|
|
6
|
+
// takes the same way out: once the daemon has begun it (its check), the tar is made as the daemon's user (tree-stage)
|
|
7
|
+
// and downloaded whole, and its reads are answered from that copy.
|
|
6
8
|
import { randomBytes } from "node:crypto";
|
|
7
9
|
import { posix } from "node:path";
|
|
8
10
|
import { MAX_CHUNK_BYTES } from "../protocol.js";
|
|
9
11
|
import { ok } from "../result.js";
|
|
10
12
|
import { MAX_READ_BYTES } from "../surface/core.js";
|
|
11
13
|
import { hostCall, runToExit, untilAborted } from "./process.js";
|
|
12
|
-
import { READ_COPIES, readStage, readUnstage } from "./scripts.js";
|
|
14
|
+
import { READ_COPIES, readStage, readUnstage, treeStage } from "./scripts.js";
|
|
13
15
|
/**
|
|
14
16
|
* An absolute path as computerd's files.read opens it: cleaned first (filepath.Clean, files.go cleanPath), so a ".."
|
|
15
17
|
* takes off the name before it, a symlinked directory's or not. read-stage's cat opens the path as given, where a ".."
|
|
@@ -20,6 +22,13 @@ const cleaned = (path) => posix.resolve(path);
|
|
|
20
22
|
const copyable = ({ path, length }) => path.startsWith("/") && !cleaned(path).startsWith("/proc/") && (length === undefined || length === MAX_CHUNK_BYTES);
|
|
21
23
|
/** The bytes one connection's copies may hold at once: two files at the read limit. */
|
|
22
24
|
const COPIES_BYTES = 2 * MAX_READ_BYTES;
|
|
25
|
+
/**
|
|
26
|
+
* The most bytes the pulls' copies of one connection hold at once. A copy is made one at a time, with what the copies
|
|
27
|
+
* still held leave of this as its tar's file-size limit (tree-stage's, in 512-byte blocks): a tar past it is cut off,
|
|
28
|
+
* and its pull is the daemon's. A copy is held from its download until its pull's end, its last read, or the
|
|
29
|
+
* connection's close, so a pull read once and left holds its room until then.
|
|
30
|
+
*/
|
|
31
|
+
export const TREE_COPY_BYTES = 256 * 1024 * 1024;
|
|
23
32
|
/**
|
|
24
33
|
* connection, with every files.read past one chunk read from one downloaded copy after its first chunk. A first chunk
|
|
25
34
|
* (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
|
|
@@ -33,10 +42,23 @@ const COPIES_BYTES = 2 * MAX_READ_BYTES;
|
|
|
33
42
|
* host with no download. The copy in the machine is removed once it is downloaded, without holding up the read. A close
|
|
34
43
|
* 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
44
|
* daemon client's (gone).
|
|
45
|
+
*
|
|
46
|
+
* A tar.pull of an absolute path outside /proc is read from a copy too. The daemon begins it, so a path it refuses is
|
|
47
|
+
* never copied; at the pull's first read, tree-stage makes its tar as the daemon's user (one pull's at a time per
|
|
48
|
+
* connection, within the room the copies still held leave of TREE_COPY_BYTES), it is downloaded and removed from the
|
|
49
|
+
* machine, and the daemon's own pull is ended. Every read of the pull is then answered from the copy, as the daemon answers (maxBytes of it, fewer only at
|
|
50
|
+
* its end, which eof marks), and the copy goes at its end, at tar.pull.end, or at the connection's close. A copy that
|
|
51
|
+
* fails at any step (the daemon's user unread, tree-stage refused or cut off, the download) leaves the pull the
|
|
52
|
+
* daemon's, from its first byte, since nothing of the copy was answered yet. A call of another method does not let a
|
|
53
|
+
* pull's copy go: once read from, the daemon's pull is ended, and the copy is the one tar of the pull there is.
|
|
36
54
|
*/
|
|
37
55
|
export function downloadingConnection(host, download, id, connection, bounds) {
|
|
38
56
|
const { client } = connection;
|
|
39
57
|
const copies = new Map();
|
|
58
|
+
/** Pulls the daemon began, by its id. */
|
|
59
|
+
const trees = new Map();
|
|
60
|
+
/** The last pull's copy, so the next starts after it: one at a time. */
|
|
61
|
+
let treeTurn = Promise.resolve();
|
|
40
62
|
let closed = false;
|
|
41
63
|
let user;
|
|
42
64
|
/** The daemon's uid and gid, from its own /proc/self/status: each of its four ids the same, else none. */
|
|
@@ -70,6 +92,49 @@ export function downloadingConnection(host, download, id, connection, bounds) {
|
|
|
70
92
|
unstage();
|
|
71
93
|
return got.ok && got.value.length === size ? got.value : undefined;
|
|
72
94
|
};
|
|
95
|
+
/** The tar of path's pull, made as the daemon's user within `blocks` 512-byte blocks and downloaded until signal
|
|
96
|
+
* aborts: its bytes, else undefined. */
|
|
97
|
+
const treeCopyOf = async (path, blocks, signal) => {
|
|
98
|
+
const who = await userOf();
|
|
99
|
+
if (who === undefined || signal.aborted)
|
|
100
|
+
return undefined;
|
|
101
|
+
const copy = `${READ_COPIES}/${randomBytes(16).toString("hex")}`;
|
|
102
|
+
const unstage = () => void runToExit(host, id, readUnstage(copy), { ms: bounds.execMs, what: `removing the tar of ${path}` });
|
|
103
|
+
const staged = await runToExit(host, id, treeStage(who[0], who[1], path, copy, blocks), { ms: bounds.execMs, signal, what: `making the tar of ${path} as the daemon's user` });
|
|
104
|
+
if (!staged.ok || staged.value.exitCode !== 0) {
|
|
105
|
+
if (!staged.ok)
|
|
106
|
+
unstage();
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const got = await hostCall(host, `downloading the tar of ${path}`, (ctx) => download(id, copy, ctx), bounds.downloadMs, signal);
|
|
110
|
+
unstage();
|
|
111
|
+
return got.ok ? got.value : undefined;
|
|
112
|
+
};
|
|
113
|
+
/** The 512-byte blocks the copies still held leave of TREE_COPY_BYTES. */
|
|
114
|
+
const roomBlocks = () => {
|
|
115
|
+
let held = 0;
|
|
116
|
+
for (const each of trees.values())
|
|
117
|
+
held += each.held ?? 0;
|
|
118
|
+
return Math.floor((TREE_COPY_BYTES - held) / 512);
|
|
119
|
+
};
|
|
120
|
+
/** pullId's copy, one at a time: made after the last pull's copy settles, within the room the copies still held leave;
|
|
121
|
+
* once it is held, the daemon's pull is ended. */
|
|
122
|
+
const treeBytes = (pullId, tree) => {
|
|
123
|
+
const made = treeTurn.then(() => {
|
|
124
|
+
const blocks = roomBlocks();
|
|
125
|
+
return tree.stop.signal.aborted || blocks < 1 ? undefined : treeCopyOf(tree.path, blocks, tree.stop.signal);
|
|
126
|
+
});
|
|
127
|
+
// The turn waits for the copy and keeps none of its bytes.
|
|
128
|
+
treeTurn = made.then(() => undefined, () => undefined);
|
|
129
|
+
return made.then(async (bytes) => {
|
|
130
|
+
if (bytes === undefined || tree.stop.signal.aborted)
|
|
131
|
+
return undefined;
|
|
132
|
+
tree.held = bytes.length;
|
|
133
|
+
// The daemon's tar is no longer read: its pull is ended, and frees its slot of the daemon's MaxPulls.
|
|
134
|
+
await client.call("tar.pull.end", { id: pullId }).catch(() => undefined);
|
|
135
|
+
return bytes;
|
|
136
|
+
}, () => undefined);
|
|
137
|
+
};
|
|
73
138
|
/** key's copy let go, and stopped if it is still coming. */
|
|
74
139
|
const letGo = (key) => {
|
|
75
140
|
copies.get(key)?.stop.abort();
|
|
@@ -82,9 +147,50 @@ export function downloadingConnection(host, download, id, connection, bounds) {
|
|
|
82
147
|
const drop = () => {
|
|
83
148
|
closed = true;
|
|
84
149
|
letAllGo();
|
|
150
|
+
for (const tree of trees.values())
|
|
151
|
+
tree.stop.abort();
|
|
152
|
+
trees.clear();
|
|
153
|
+
};
|
|
154
|
+
/** A tar.pull's call: begin noted for a copy, read answered from the copy where it is held, end lets it go. */
|
|
155
|
+
const pullCall = async (method, params, options) => {
|
|
156
|
+
if (method === "tar.pull.begin") {
|
|
157
|
+
const begun = await client.call(method, params, options);
|
|
158
|
+
const { path } = params;
|
|
159
|
+
if (begun.ok && !closed && path.startsWith("/") && !cleaned(path).startsWith("/proc/")) {
|
|
160
|
+
trees.set(begun.value.id, { path: cleaned(path), stop: new AbortController(), read: 0 });
|
|
161
|
+
}
|
|
162
|
+
return begun;
|
|
163
|
+
}
|
|
164
|
+
if (method === "tar.pull.end") {
|
|
165
|
+
const { id: pullId } = params;
|
|
166
|
+
trees.get(pullId)?.stop.abort();
|
|
167
|
+
trees.delete(pullId);
|
|
168
|
+
return client.call(method, params, options);
|
|
169
|
+
}
|
|
170
|
+
const { id: pullId, maxBytes } = params;
|
|
171
|
+
const tree = trees.get(pullId);
|
|
172
|
+
const size = maxBytes ?? MAX_CHUNK_BYTES;
|
|
173
|
+
if (tree === undefined || !Number.isSafeInteger(size) || size < 1 || size > MAX_CHUNK_BYTES)
|
|
174
|
+
return client.call(method, params, options);
|
|
175
|
+
tree.bytes ??= treeBytes(pullId, tree);
|
|
176
|
+
const bytes = await untilAborted(tree.bytes, [options?.signal, tree.stop.signal]);
|
|
177
|
+
if (bytes === undefined) {
|
|
178
|
+
// Nothing of the copy was answered (a copy is answered only once held), so the daemon's pull is read from its start.
|
|
179
|
+
if (!options?.signal?.aborted)
|
|
180
|
+
trees.delete(pullId);
|
|
181
|
+
return client.call(method, params, options);
|
|
182
|
+
}
|
|
183
|
+
const data = bytes.subarray(tree.read, tree.read + size);
|
|
184
|
+
tree.read += data.length;
|
|
185
|
+
const eof = data.length < size;
|
|
186
|
+
if (eof)
|
|
187
|
+
trees.delete(pullId);
|
|
188
|
+
return ok({ data: Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString("base64"), eof });
|
|
85
189
|
};
|
|
86
190
|
const reading = {
|
|
87
191
|
async call(method, params, options) {
|
|
192
|
+
if (!closed && (method === "tar.pull.begin" || method === "tar.pull.read" || method === "tar.pull.end"))
|
|
193
|
+
return pullCall(method, params, options);
|
|
88
194
|
if (method !== "files.read" || closed) {
|
|
89
195
|
letAllGo();
|
|
90
196
|
return client.call(method, params, options);
|
package/dist/hosted/provider.js
CHANGED
|
@@ -511,8 +511,12 @@ export class HostedProvider {
|
|
|
511
511
|
/**
|
|
512
512
|
* A dial create of one request after any other of it on this server, whichever provider instance makes it. A
|
|
513
513
|
* machine's token and socket go by the request's name, so two machines of one request must never dial at once: the
|
|
514
|
-
* second create finds the first's computer instead (#createOnce).
|
|
515
|
-
*
|
|
514
|
+
* second create finds the first's computer instead (#createOnce). The turns hold within one process alone: a dial
|
|
515
|
+
* request must be created by one process. Two processes sharing one MachineTokens that create one request's name
|
|
516
|
+
* cut each other's machine: the second mint replaces the first's token, and a converge delete revokes the name's
|
|
517
|
+
* token and drops the name's socket, which may be the kept machine's (#converge). Serve never does: its request
|
|
518
|
+
* carries the run's claim epoch, and each epoch is one claim's. A caller that aborts while it waits stops waiting;
|
|
519
|
+
* the turn after it still waits for the create before it.
|
|
516
520
|
*/
|
|
517
521
|
async #inTurn(hub, name, signal, make) {
|
|
518
522
|
const turns = DIAL_TURNS.get(hub) ?? new Map();
|
|
@@ -580,8 +584,11 @@ export class HostedProvider {
|
|
|
580
584
|
return launched.error.code === "exists" ? this.#createOnce(spec, name, signal, launched) : launched;
|
|
581
585
|
const { ref, made } = launched.value;
|
|
582
586
|
// From here the machine exists: every step takes the caller's signal, and a failure or an abort deletes it.
|
|
583
|
-
// Another provider instance's create of this request may have made one too (#converge): the oldest is kept.
|
|
584
|
-
|
|
587
|
+
// Another provider instance's create of this request may have made one too (#converge): the oldest is kept. This
|
|
588
|
+
// first look may narrow by this spec's run and epoch (nameAsk: Render's one page by the whole name, not every page of
|
|
589
|
+
// the workspace). It only stops a create early: a machine of the request under another run or epoch is settled by
|
|
590
|
+
// the reads below, which never narrow, as each racing create makes them.
|
|
591
|
+
const first = await this.#converge(name, ref.id, signal, nameAsk(this.host, spec));
|
|
585
592
|
if (first.ok && first.value !== undefined && first.value.id !== ref.id)
|
|
586
593
|
return this.#again(spec, name, first.value, signal);
|
|
587
594
|
const prepared = await this.#prepare(spec, ref, made, signal);
|
|
@@ -631,11 +638,15 @@ export class HostedProvider {
|
|
|
631
638
|
* more than one machine holds the name, the oldest (createdAt, or the lowest id where any has none) is kept, and every
|
|
632
639
|
* other is deleted and read back gone, its Archil folder let go first. Every instance picks the same one from the
|
|
633
640
|
* same listing. Its value is the machine kept, or undefined when mine holds the name alone (or nothing is listed yet).
|
|
634
|
-
* The listing
|
|
635
|
-
* must still see each other's machine, so one is
|
|
641
|
+
* The listing that settles a create (after a failed prepare, and the last) is by the name alone, never narrowed
|
|
642
|
+
* (nameAsk): two creates of one request that ask another run or epoch must still see each other's machine, so one is
|
|
643
|
+
* kept and the other answered exists. `also` narrows the first look after the vendor's answer alone (#createOnce).
|
|
644
|
+
* Across processes this settles the vendor's machines alone. A dial machine's token and hub socket go by the name,
|
|
645
|
+
* not the machine, so a delete here revokes the name's token and drops the name's socket in this process's hub, and
|
|
646
|
+
* either can be the kept machine's own. So a dial request must be created by one process (#inTurn).
|
|
636
647
|
*/
|
|
637
|
-
async #converge(name, mine, signal) {
|
|
638
|
-
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal);
|
|
648
|
+
async #converge(name, mine, signal, also) {
|
|
649
|
+
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal, also);
|
|
639
650
|
if (!listed.ok)
|
|
640
651
|
return listed;
|
|
641
652
|
const holders = listed.value.filter((machine) => ours(machine.labels, name) && alive(machine.state));
|
|
@@ -908,8 +919,8 @@ export class HostedProvider {
|
|
|
908
919
|
if (!read.ok)
|
|
909
920
|
return read;
|
|
910
921
|
const machine = read.value;
|
|
911
|
-
// A machine the vendor failed
|
|
912
|
-
if (machine?.why !== undefined && machine.state === "gone")
|
|
922
|
+
// A machine the vendor failed, gone or stopped in its words: the create stops in them, not at createMs.
|
|
923
|
+
if (machine?.why !== undefined && (machine.state === "gone" || machine.state === "stopped"))
|
|
913
924
|
return this.#fail("vendor", `${this.#label} could not start ${ref.name}: ${machine.why}`);
|
|
914
925
|
if (machine === undefined || machine.state === "gone")
|
|
915
926
|
return this.#fail("gone", `${ref.name} was gone before it ran`);
|
|
@@ -1776,8 +1787,10 @@ const byName = (name) => ({ [COMPUTER_LABEL]: "1", [NAME_LABEL]: name });
|
|
|
1776
1787
|
* What a listing by a create's name asks beside byName on a host whose names carry the run and epoch (facts.labels.named):
|
|
1777
1788
|
* the spec's run and epoch, where it has both, so the host can look up the whole name. Only asked, never required: a
|
|
1778
1789
|
* machine of the name is kept whatever its get says of them (a sandbox before its labels file, read by its name alone).
|
|
1779
|
-
* Only the sweeps for a machine this create made ask it (#waitListed, #deleteNamed)
|
|
1780
|
-
*
|
|
1790
|
+
* Only the sweeps for a machine this create made ask it (#waitListed, #deleteNamed), and the first look for a racing
|
|
1791
|
+
* create's machine right after the vendor's answer, which only stops a create early: that machine's name is the whole
|
|
1792
|
+
* name. The first check and the convergence that settles a create look for any machine of the request, whatever run or
|
|
1793
|
+
* epoch it was made with.
|
|
1781
1794
|
*/
|
|
1782
1795
|
function nameAsk(host, spec) {
|
|
1783
1796
|
const run = spec.labels?.[RUN_LABEL];
|