@parcha/agentrun-computer 0.1.0-beta.43 → 0.1.0-beta.45
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 +98 -12
- package/box/Dockerfile +2 -1
- package/box/build-daytona.py +12 -2
- package/box/install.sh +19 -5
- package/box/recipe.mjs +1 -1
- package/dist/attach.d.ts +13 -3
- package/dist/attach.js +182 -15
- package/dist/cloudflare.d.ts +4 -2
- package/dist/cloudflare.js +7 -3
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/cases/files.js +7 -1
- package/dist/conformance/cases/isolation.js +4 -0
- package/dist/conformance/cases/mount.js +155 -2
- package/dist/conformance/cases/provider.js +3 -1
- package/dist/conformance/daytona.d.ts +15 -1
- package/dist/conformance/daytona.js +19 -4
- package/dist/conformance/types.d.ts +1 -1
- package/dist/daytona.d.ts +11 -2
- package/dist/daytona.js +47 -15
- package/dist/descriptor.d.ts +34 -4
- package/dist/descriptor.js +40 -6
- package/dist/descriptors/cloudflare.d.ts +14 -1
- package/dist/descriptors/cloudflare.js +7 -3
- package/dist/descriptors/daytona.d.ts +21 -3
- package/dist/descriptors/daytona.js +15 -8
- package/dist/descriptors/e2b.d.ts +1 -0
- package/dist/descriptors/e2b.js +2 -1
- package/dist/descriptors/fly.d.ts +14 -1
- package/dist/descriptors/fly.js +6 -3
- package/dist/descriptors/index.d.ts +64 -2
- package/dist/descriptors/modal.d.ts +16 -2
- package/dist/descriptors/modal.js +10 -6
- package/dist/descriptors/orgo.d.ts +3 -0
- package/dist/descriptors/orgo.js +3 -1
- package/dist/e2b.d.ts +9 -4
- package/dist/e2b.js +8 -8
- package/dist/env-proxy.d.ts +26 -0
- package/dist/env-proxy.js +97 -0
- package/dist/fly.d.ts +4 -3
- package/dist/fly.js +7 -4
- package/dist/hosted/provider.d.ts +2 -1
- package/dist/hosted/provider.js +133 -54
- package/dist/hosted/scripts.d.ts +3 -2
- package/dist/hosted/scripts.js +12 -7
- package/dist/hosted/values.d.ts +2 -5
- package/dist/hosted/values.js +2 -9
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/kinds.d.ts +4 -2
- package/dist/kinds.js +10 -1
- package/dist/modal.d.ts +5 -2
- package/dist/modal.js +8 -2
- package/dist/morph.js +15 -7
- package/dist/mount-archil.d.ts +33 -17
- package/dist/mount-archil.js +83 -36
- package/dist/mount.d.ts +16 -7
- package/dist/mount.js +13 -8
- package/dist/orgo.js +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/sync-folder.d.ts +82 -0
- package/dist/sync-folder.js +494 -0
- package/dist/tar.d.ts +34 -0
- package/dist/tar.js +203 -0
- package/package.json +1 -1
- package/dist/conformance/tar.d.ts +0 -13
- package/dist/conformance/tar.js +0 -105
package/dist/kinds.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// The kind registry: the computer an agent is given, its setting kind, and the providers Settings offers for it. Two
|
|
2
|
+
// axes: the machine kind is the protocol's (capabilities().kind, KIND_SHAPES); the setting kind is what an agent is
|
|
3
|
+
// given in Settings, `computer: { kind, provider? }`, as machine kinds and capability groups. Whether a provider serves
|
|
4
|
+
// a setting kind is computed from its capabilities alone (serves), never kept beside them: a provider that drops a
|
|
5
|
+
// group stops serving the kind. The model's tools are not here: they live in the kernel's tool registry, keyed by
|
|
6
|
+
// these groups.
|
|
7
|
+
// The providers Settings offers (PROVIDERS) are derived from the providers' descriptors (descriptor.ts), each declared
|
|
8
|
+
// once in its descriptor module: loading this loads descriptors (data) alone, never a provider module or a vendor SDK.
|
|
9
|
+
import { derivedMounts } from "./descriptor.js";
|
|
1
10
|
import { DESCRIPTORS } from "./descriptors/index.js";
|
|
2
11
|
export const SETTING_KINDS = {
|
|
3
12
|
none: { machineKinds: [], required: [], optional: [] },
|
|
@@ -65,7 +74,7 @@ export function configurationOf(serving, image, defaultImage) {
|
|
|
65
74
|
/** A descriptor as Settings shows it: its data, and the setting kinds its capabilities serve, derived by serves(). */
|
|
66
75
|
export function entryOf(descriptor) {
|
|
67
76
|
const { load: _load, ...data } = descriptor;
|
|
68
|
-
return { ...data, kinds: SETTING_KIND_NAMES.filter((kind) => descriptor.capabilities.some((one) => serves(one, kind))) };
|
|
77
|
+
return { ...data, mounts: derivedMounts(descriptor), kinds: SETTING_KIND_NAMES.filter((kind) => descriptor.capabilities.some((one) => serves(one, kind))) };
|
|
69
78
|
}
|
|
70
79
|
/** Every provider Settings offers: each built-in descriptor (descriptors/index.ts), as entryOf gives it. */
|
|
71
80
|
export const PROVIDERS = DESCRIPTORS.map(entryOf);
|
package/dist/modal.d.ts
CHANGED
|
@@ -5,8 +5,11 @@ import { type Result } from "./result.js";
|
|
|
5
5
|
* own client (or the constructor), which these name.
|
|
6
6
|
*/
|
|
7
7
|
export type ModalSdk = object;
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The Modal provider's options: the client and the app, then the shared adapter's (HostedOptions), kind among them: a
|
|
10
|
+
* desktop on connect dial alone.
|
|
11
|
+
*/
|
|
12
|
+
export interface ModalProviderOptions extends Omit<HostedOptions, "desktop" | "maxLifetimeMs"> {
|
|
10
13
|
/** The host's Modal client. */
|
|
11
14
|
sdk: ModalSdk;
|
|
12
15
|
/** The Modal App the sandboxes live in; made when missing. */
|
package/dist/modal.js
CHANGED
|
@@ -4,7 +4,8 @@ import { DEFAULT_CPUS, DEFAULT_MEMORY_MB, WORK } from "./drift.js";
|
|
|
4
4
|
import { HostError } from "./host.js";
|
|
5
5
|
import { HostedProvider } from "./hosted/provider.js";
|
|
6
6
|
import { AGENTRUN_DIAL, PID_WRAPPER, pidKill, pidStderr } from "./hosted/scripts.js";
|
|
7
|
-
import { connectOf
|
|
7
|
+
import { connectOf } from "./descriptor.js";
|
|
8
|
+
import { execDesktopRefusal, isWhole } from "./hosted/values.js";
|
|
8
9
|
import { ok } from "./result.js";
|
|
9
10
|
/** A GPU as the SDK takes it: the type, then :count past one ("T4", "H100:8"). */
|
|
10
11
|
const modalGpu = ({ type, count }) => (count === 1 ? type : `${type}:${count}`);
|
|
@@ -138,6 +139,8 @@ class ModalHost {
|
|
|
138
139
|
arch: "amd64",
|
|
139
140
|
// No listener of Modal's own inside a sandbox is documented, so none is declared.
|
|
140
141
|
vendorAgentPorts: [],
|
|
142
|
+
// The box image has xfwm4 (box/install.sh's desktop step), for a desktop (connect dial alone).
|
|
143
|
+
windowManager: true,
|
|
141
144
|
// Never root: each connection is Modal's exec of the stdio bridge, as Modal's root, outside the daemon.
|
|
142
145
|
user: ["uid"],
|
|
143
146
|
labels: { count: MAX_TAGS, bytes: MAX_TAG_BYTES },
|
|
@@ -359,6 +362,9 @@ export class ModalProvider extends HostedProvider {
|
|
|
359
362
|
throw new Error(`options.sdk must be a Modal client; it lacks ${lacks.map(([name]) => name).join(", ")}`);
|
|
360
363
|
if (typeof app !== "string" || app.trim() === "")
|
|
361
364
|
throw new Error("options.app, the Modal app's name, is required");
|
|
362
|
-
|
|
365
|
+
const via = connectOf(MODAL, { connect });
|
|
366
|
+
if (rest.kind === "desktop" && via === "exec")
|
|
367
|
+
throw new Error(execDesktopRefusal("Modal", "the box image"));
|
|
368
|
+
super(new ModalHost(sdk, app, via), { ...rest, timeouts: { ...MODAL_TIMEOUTS, ...timeouts } });
|
|
363
369
|
}
|
|
364
370
|
}
|
package/dist/morph.js
CHANGED
|
@@ -18,6 +18,7 @@ import { isIP, connect as tcp } from "node:net";
|
|
|
18
18
|
import { boxRecipeHash } from "./box-image.js";
|
|
19
19
|
import { MORPH } from "./descriptors/morph.js";
|
|
20
20
|
import { DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, show } from "./drift.js";
|
|
21
|
+
import { proxyFor, tunnelThrough } from "./env-proxy.js";
|
|
21
22
|
import { HostError } from "./host.js";
|
|
22
23
|
import { orThrow, pause, runToExit, uploadThroughExec } from "./hosted/process.js";
|
|
23
24
|
import { HostedProvider, isoOf, MAX_LABEL } from "./hosted/provider.js";
|
|
@@ -150,18 +151,25 @@ class MorphHost {
|
|
|
150
151
|
return codeOf(error);
|
|
151
152
|
}
|
|
152
153
|
/**
|
|
153
|
-
* A TCP connection to the gateway
|
|
154
|
-
*
|
|
154
|
+
* A TCP connection to the gateway, through the proxy's CONNECT tunnel when the proxy the process installed into Node
|
|
155
|
+
* applies to it (env-proxy.ts). No host key is pinned: Morph publishes none, and both SDKs take any (paramiko's AutoAddPolicy). The
|
|
156
|
+
* login is a public key, so a host posing as the gateway learns no credential.
|
|
155
157
|
*/
|
|
156
158
|
#tunnel() {
|
|
157
159
|
const host = `${this.#sshHost}:${this.#sshPort}`;
|
|
158
|
-
const
|
|
160
|
+
const name = isIP(this.#sshHost) === 6 ? `[${this.#sshHost}]` : this.#sshHost;
|
|
161
|
+
const proxy = proxyFor(new URL(`https://${name}:${this.#sshPort}`));
|
|
162
|
+
const through = proxy && tunnelThrough(proxy, name, this.#sshPort);
|
|
163
|
+
const socket = through ? through.socket : tcp(this.#sshPort, this.#sshHost);
|
|
159
164
|
// ssh2 reads the socket's errors once it has it; this keeps one before then from being thrown.
|
|
160
165
|
socket.on("error", () => { });
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
const failed = (error) => new SshTunnelError(`the SSH connection to ${host}${proxy ? ` through the proxy ${proxy.host}` : ""} failed to open: ${error.message}`);
|
|
167
|
+
const opened = through
|
|
168
|
+
? through.opened.catch((error) => Promise.reject(failed(error)))
|
|
169
|
+
: new Promise((resolve, reject) => {
|
|
170
|
+
socket.once("connect", resolve);
|
|
171
|
+
socket.once("error", (error) => reject(failed(error)));
|
|
172
|
+
});
|
|
165
173
|
opened.catch(() => { });
|
|
166
174
|
return { duplex: socket, opened, host };
|
|
167
175
|
}
|
package/dist/mount-archil.d.ts
CHANGED
|
@@ -13,12 +13,21 @@ export declare const ARCHIL_TOOL_UID = 2510;
|
|
|
13
13
|
export declare const ARCHIL_SYNC_SOCKET = "/run/agentrun-archil/archil.sock";
|
|
14
14
|
/** The archil client the image pins, the version the live checks ran. */
|
|
15
15
|
export declare const ARCHIL_VERSION = "0.10.1-1793222256";
|
|
16
|
-
/** The label (Daytona) or metadata (E2B) an Archil computer carries its mount in: never the token (archilLabels). */
|
|
17
|
-
export declare const ARCHIL_MOUNT_LABEL = "agentrun.mount";
|
|
18
16
|
/** An Archil mount, as a spec gives it. */
|
|
19
17
|
export type ArchilMount = Extract<MountSpec, {
|
|
20
18
|
kind: "archil";
|
|
21
19
|
}>;
|
|
20
|
+
/**
|
|
21
|
+
* The label a remote computer carries its mount in, as JSON and never a token, so a kept computer is reattached as what
|
|
22
|
+
* it records: an Archil mount's source (archilLabels), or a synced folder's kind alone (SYNC_LABELS).
|
|
23
|
+
*/
|
|
24
|
+
export declare const MOUNT_LABEL = "agentrun.mount";
|
|
25
|
+
/** A synced folder's labels: its kind alone, since the computer holds nothing else of it. */
|
|
26
|
+
export declare const SYNC_LABELS: Readonly<Record<string, string>>;
|
|
27
|
+
/** A mount as a computer's label records it (MOUNT_LABEL): an Archil mount's source, never the token, or a synced folder. */
|
|
28
|
+
export type RecordedSource = Omit<ArchilMount, "token"> | {
|
|
29
|
+
kind: "sync";
|
|
30
|
+
};
|
|
22
31
|
/**
|
|
23
32
|
* A provider's own root channel into one of its computers: Daytona's toolbox exec, Modal's exec, E2B's commands as
|
|
24
33
|
* root. run() runs argv as root, never through computerd, with `stdin` (one line, then closed) as its fd 0 when given,
|
|
@@ -112,26 +121,31 @@ export interface ArchilMountOptions {
|
|
|
112
121
|
* loopback alone (computerd init --own-network), so there is no firewall to set here.
|
|
113
122
|
*/
|
|
114
123
|
export declare function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, egress, signal }: ArchilMountOptions): Promise<Result<void>>;
|
|
124
|
+
/** An Archil computer's sync, for syncingClient: computerd's mount.sync, which asks the resident serve to sync. */
|
|
125
|
+
export declare function archilSync(client: ComputerClient): () => Promise<Result<void>>;
|
|
115
126
|
/**
|
|
116
127
|
* A computerd client whose every call that may change the folder (files.write, move, remove and mkdir; tar.push.begin,
|
|
117
128
|
* which makes the destination and the folders above it, so a push never ended leaves none unsynced; tar.push.end, and
|
|
118
129
|
* a tar.push.write that failed, which ends the push with no tar.push.end once its extraction stops; exec.run;
|
|
119
130
|
* process.start, which makes its log and the folders above it; process.write and signal; a process seen
|
|
120
|
-
* ended, by process.wait or a process.read that says so) syncs before it answers, through
|
|
121
|
-
* call during a sync in flight waits for it, then shares one more. A failed sync fails the call in words; a call that
|
|
131
|
+
* ended, by process.wait or a process.read that says so) syncs before it answers, through `sync` (an Archil computer's
|
|
132
|
+
* archilSync, a synced folder's delta), coalesced: a call during a sync in flight waits for it, then shares one more. A failed sync fails the call in words; a call that
|
|
122
133
|
* failed still syncs, and answers its own error (one the client timed out with no answer from the daemon does so at
|
|
123
134
|
* once, not waiting for the sync, which rides the same transport; a timeout the daemon answered waits). A caller whose signal fires stops waiting, answered "aborted" in words
|
|
124
135
|
* (or its own error), while the shared sync goes on for every other caller. A tar.push.begin answered with such an error
|
|
125
136
|
* instead of its id first ends the push it began, so no push slot is held by a push its caller cannot name.
|
|
126
137
|
*/
|
|
127
|
-
export declare function syncingClient(client: ComputerClient): ComputerClient;
|
|
138
|
+
export declare function syncingClient(client: ComputerClient, once: () => Promise<Result<void>>): ComputerClient;
|
|
128
139
|
/**
|
|
129
140
|
* The label an Archil computer carries its mount in: kind, disk, region and the folder's agent as JSON, never the token.
|
|
130
141
|
* The folder's run is the computer's agentrun.run label (check holds them equal), so the label does not repeat it.
|
|
131
142
|
*/
|
|
132
143
|
export declare function archilLabels(mount: ArchilMount): Record<string, string>;
|
|
133
|
-
/**
|
|
134
|
-
|
|
144
|
+
/**
|
|
145
|
+
* The mount a computer's labels record: a synced folder (SYNC_LABELS), or an Archil mount, its folder from the
|
|
146
|
+
* agent and agentrun.run; undefined when there is none, or it is not one.
|
|
147
|
+
*/
|
|
148
|
+
export declare function recordedMount(labels: Record<string, string> | undefined): RecordedSource | undefined;
|
|
135
149
|
/**
|
|
136
150
|
* What is mounted at /workspace, read back from the computer's mount table (`mounts`, its /proc/self/mounts): an Archil
|
|
137
151
|
* mount (fuse.archil, source `<disk>:/<folder>`, with `[<region>]` when the client shows it, else the recorded region)
|
|
@@ -156,33 +170,35 @@ export declare function archilRelease({ root, client, timeoutMs, signal }: {
|
|
|
156
170
|
timeoutMs: number;
|
|
157
171
|
signal?: AbortSignal;
|
|
158
172
|
}): Promise<Result<void>>;
|
|
159
|
-
/**
|
|
160
|
-
export interface
|
|
173
|
+
/** A mount a computer records (a label, a tag), and what it must read back as under its epoch label. */
|
|
174
|
+
export interface RecordedFolder {
|
|
161
175
|
/** The source as recorded; none when what is recorded is not a mount this provider makes. */
|
|
162
|
-
mount?:
|
|
176
|
+
mount?: RecordedSource;
|
|
163
177
|
/** The computer's agentrun.epoch label, when it reads as one. */
|
|
164
178
|
epoch?: number;
|
|
165
179
|
/** What the mount must read back as: readBackOf under the label's epoch, or a mount in words. */
|
|
166
180
|
expected: MountReadBack;
|
|
167
181
|
}
|
|
168
182
|
/**
|
|
169
|
-
* The
|
|
183
|
+
* The mount a computer records, from what its provider read of it (`recorded`: the mount, and words when what is
|
|
170
184
|
* recorded is not one this provider makes, or not under the label's epoch; undefined for none at all), under the epoch
|
|
171
185
|
* of its `labels`.
|
|
172
186
|
*/
|
|
173
|
-
export declare function
|
|
174
|
-
mount?:
|
|
187
|
+
export declare function recordedFolder(labels: Record<string, string> | undefined, recorded: {
|
|
188
|
+
mount?: RecordedSource;
|
|
175
189
|
other?: string;
|
|
176
|
-
} | undefined):
|
|
190
|
+
} | undefined): RecordedFolder | undefined;
|
|
177
191
|
/** A mount read-back in words. */
|
|
178
192
|
export declare function mountWords(mount: MountReadBack): string;
|
|
179
193
|
/** How the mount read back from inside (undefined: nothing at /workspace) differs from the one expected, in words. */
|
|
180
194
|
export declare function mountDrift(expected: MountReadBack, read: MountReadBack | undefined): string[];
|
|
181
195
|
/**
|
|
182
|
-
* What a computer
|
|
183
|
-
*
|
|
196
|
+
* What a computer holds at /workspace, read back through its computerd, under `epoch`, the computer's label, each call
|
|
197
|
+
* bounded by timeoutMs and the signal: its mount table first. For a recorded synced folder, nothing may be mounted
|
|
198
|
+
* there, and /workspace must be a directory (never a link) of the computer's user, the owner of its home (WORK); else
|
|
199
|
+
* it is one in words. For any other, whether the resident serve answers a sync (an Archil mount's exclusive).
|
|
184
200
|
*/
|
|
185
|
-
export declare function
|
|
201
|
+
export declare function readMount(client: ComputerClient, { mount, epoch }: Pick<RecordedFolder, "mount" | "epoch">, { name, timeoutMs, signal }: {
|
|
186
202
|
name: string;
|
|
187
203
|
timeoutMs: number;
|
|
188
204
|
signal?: AbortSignal;
|
package/dist/mount-archil.js
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
// root through its own exec (its ArchilRoot), never through computerd; computerd runs every tool as the tool user, which
|
|
4
4
|
// has no way to root and never holds the disk's token. What each provider shares lives here: the spec rule, the steps
|
|
5
5
|
// at create, the syncing client, the read-back, the mount's label and the release. Only the root channel is a
|
|
6
|
-
// provider's own.
|
|
6
|
+
// provider's own. A synced folder's record and read-back live here beside Archil's, as the syncing client does, which
|
|
7
|
+
// takes either kind's sync.
|
|
7
8
|
//
|
|
8
9
|
// The token reaches only the helper's fd 0 (ArchilRoot.run's stdin, for mount and revoke): never an argument, a label,
|
|
9
10
|
// a read-back or an error. Whatever a computer prints is scrubbed of it before it reaches an error's words.
|
|
10
11
|
import { createHash } from "node:crypto";
|
|
11
12
|
import { readFileSync } from "node:fs";
|
|
12
13
|
import { unanswered } from "./client.js";
|
|
14
|
+
import { WORK } from "./drift.js";
|
|
13
15
|
import { EPOCH_LABEL, epochOf, RUN_LABEL, runProblem } from "./labels.js";
|
|
14
16
|
import { readBackOf, WORKSPACE } from "./mount.js";
|
|
15
17
|
import { fail, failAs, ok } from "./result.js";
|
|
@@ -24,8 +26,13 @@ export const ARCHIL_TOOL_UID = 2510;
|
|
|
24
26
|
export const ARCHIL_SYNC_SOCKET = "/run/agentrun-archil/archil.sock";
|
|
25
27
|
/** The archil client the image pins, the version the live checks ran. */
|
|
26
28
|
export const ARCHIL_VERSION = "0.10.1-1793222256";
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The label a remote computer carries its mount in, as JSON and never a token, so a kept computer is reattached as what
|
|
31
|
+
* it records: an Archil mount's source (archilLabels), or a synced folder's kind alone (SYNC_LABELS).
|
|
32
|
+
*/
|
|
33
|
+
export const MOUNT_LABEL = "agentrun.mount";
|
|
34
|
+
/** A synced folder's labels: its kind alone, since the computer holds nothing else of it. */
|
|
35
|
+
export const SYNC_LABELS = Object.freeze({ [MOUNT_LABEL]: JSON.stringify({ kind: "sync" }) });
|
|
29
36
|
// The shapes the helper itself checks (box/agentrun-archil), so a spec it would refuse is refused before any vendor call.
|
|
30
37
|
const DISK = /^(?:dsk-[0-9a-f]{16}|[A-Za-z0-9][A-Za-z0-9._@+-]{0,127}\/[A-Za-z0-9][A-Za-z0-9._-]{0,127})$/;
|
|
31
38
|
/**
|
|
@@ -262,6 +269,22 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
|
|
|
262
269
|
return failed("serve", served.value);
|
|
263
270
|
return ok(undefined);
|
|
264
271
|
}
|
|
272
|
+
/** An Archil computer's sync, for syncingClient: computerd's mount.sync, which asks the resident serve to sync. */
|
|
273
|
+
export function archilSync(client) {
|
|
274
|
+
return async () => {
|
|
275
|
+
try {
|
|
276
|
+
const synced = await client.call("mount.sync", {});
|
|
277
|
+
if (!synced.ok)
|
|
278
|
+
return fail(synced.error.code, synced.error.message);
|
|
279
|
+
if (synced.value.exitCode !== 0)
|
|
280
|
+
return fail("refused", `archil sync exited ${synced.value.exitCode}`);
|
|
281
|
+
return ok(undefined);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
return fail("refused", `archil sync could not be asked: ${error instanceof Error ? error.message : String(error)}`);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
265
288
|
/** The computerd calls that may change the folder: each syncs before it answers. */
|
|
266
289
|
const MUTATING = new Set(["files.write", "files.move", "files.remove", "files.mkdir", "tar.push.begin", "tar.push.end", "exec.run", "process.start", "process.write", "process.signal", "process.wait"]);
|
|
267
290
|
/**
|
|
@@ -269,29 +292,21 @@ const MUTATING = new Set(["files.write", "files.move", "files.remove", "files.mk
|
|
|
269
292
|
* which makes the destination and the folders above it, so a push never ended leaves none unsynced; tar.push.end, and
|
|
270
293
|
* a tar.push.write that failed, which ends the push with no tar.push.end once its extraction stops; exec.run;
|
|
271
294
|
* process.start, which makes its log and the folders above it; process.write and signal; a process seen
|
|
272
|
-
* ended, by process.wait or a process.read that says so) syncs before it answers, through
|
|
273
|
-
* call during a sync in flight waits for it, then shares one more. A failed sync fails the call in words; a call that
|
|
295
|
+
* ended, by process.wait or a process.read that says so) syncs before it answers, through `sync` (an Archil computer's
|
|
296
|
+
* archilSync, a synced folder's delta), coalesced: a call during a sync in flight waits for it, then shares one more. A failed sync fails the call in words; a call that
|
|
274
297
|
* failed still syncs, and answers its own error (one the client timed out with no answer from the daemon does so at
|
|
275
298
|
* once, not waiting for the sync, which rides the same transport; a timeout the daemon answered waits). A caller whose signal fires stops waiting, answered "aborted" in words
|
|
276
299
|
* (or its own error), while the shared sync goes on for every other caller. A tar.push.begin answered with such an error
|
|
277
300
|
* instead of its id first ends the push it began, so no push slot is held by a push its caller cannot name.
|
|
278
301
|
*/
|
|
279
|
-
export function syncingClient(client) {
|
|
302
|
+
export function syncingClient(client, once) {
|
|
280
303
|
// At most one sync in flight, and at most one follower shared by every call that comes during it. The hand-over from a
|
|
281
304
|
// run to its follower happens in one step, inside the run's own settling, so no call can land between them.
|
|
282
305
|
let running;
|
|
283
306
|
let follower;
|
|
284
|
-
const once = async () => {
|
|
285
|
-
const synced = await client.call("mount.sync", {});
|
|
286
|
-
if (!synced.ok)
|
|
287
|
-
return fail(synced.error.code, synced.error.message);
|
|
288
|
-
if (synced.value.exitCode !== 0)
|
|
289
|
-
return fail("refused", `archil sync exited ${synced.value.exitCode}`);
|
|
290
|
-
return ok(undefined);
|
|
291
|
-
};
|
|
292
307
|
const start = () => {
|
|
293
308
|
const now = once()
|
|
294
|
-
.catch((error) => fail("refused", `
|
|
309
|
+
.catch((error) => fail("refused", `the run's folder's sync could not be asked: ${error instanceof Error ? error.message : String(error)}`))
|
|
295
310
|
.then((result) => {
|
|
296
311
|
const next = follower;
|
|
297
312
|
follower = undefined;
|
|
@@ -369,15 +384,20 @@ export function syncingClient(client) {
|
|
|
369
384
|
* The folder's run is the computer's agentrun.run label (check holds them equal), so the label does not repeat it.
|
|
370
385
|
*/
|
|
371
386
|
export function archilLabels(mount) {
|
|
372
|
-
return { [
|
|
387
|
+
return { [MOUNT_LABEL]: JSON.stringify({ kind: "archil", disk: mount.disk, region: mount.region, agent: FOLDER.exec(mount.folder)?.[1] ?? "" }) };
|
|
373
388
|
}
|
|
374
|
-
/**
|
|
389
|
+
/**
|
|
390
|
+
* The mount a computer's labels record: a synced folder (SYNC_LABELS), or an Archil mount, its folder from the
|
|
391
|
+
* agent and agentrun.run; undefined when there is none, or it is not one.
|
|
392
|
+
*/
|
|
375
393
|
export function recordedMount(labels) {
|
|
376
|
-
const text = labels?.[
|
|
394
|
+
const text = labels?.[MOUNT_LABEL];
|
|
377
395
|
if (text === undefined)
|
|
378
396
|
return undefined;
|
|
379
397
|
try {
|
|
380
398
|
const { kind, disk, region, agent, ...rest } = (JSON.parse(text) ?? {});
|
|
399
|
+
if (kind === "sync")
|
|
400
|
+
return disk === undefined && region === undefined && agent === undefined && Object.keys(rest).length === 0 ? { kind } : undefined;
|
|
381
401
|
const run = labels?.[RUN_LABEL];
|
|
382
402
|
const folder = `agents/${String(agent)}/runs/${String(run)}/work`;
|
|
383
403
|
if (kind !== "archil" || typeof disk !== "string" || typeof region !== "string" || typeof agent !== "string" || typeof run !== "string" || Object.keys(rest).length > 0 || !FOLDER.test(folder))
|
|
@@ -445,11 +465,11 @@ export async function archilRelease({ root, client, timeoutMs, signal }) {
|
|
|
445
465
|
return fail(checkin.ok ? "refused" : checkin.error.code, `the run's folder was not let go cleanly: ${words.join("; ")}`);
|
|
446
466
|
}
|
|
447
467
|
/**
|
|
448
|
-
* The
|
|
468
|
+
* The mount a computer records, from what its provider read of it (`recorded`: the mount, and words when what is
|
|
449
469
|
* recorded is not one this provider makes, or not under the label's epoch; undefined for none at all), under the epoch
|
|
450
470
|
* of its `labels`.
|
|
451
471
|
*/
|
|
452
|
-
export function
|
|
472
|
+
export function recordedFolder(labels, recorded) {
|
|
453
473
|
if (recorded === undefined)
|
|
454
474
|
return undefined;
|
|
455
475
|
const read = epochOf(labels);
|
|
@@ -457,7 +477,7 @@ export function recordedArchil(labels, recorded) {
|
|
|
457
477
|
const mount = recorded.mount === undefined ? {} : { mount: recorded.mount };
|
|
458
478
|
if (recorded.other !== undefined || recorded.mount === undefined)
|
|
459
479
|
return { ...mount, ...epoch, expected: { other: recorded.other ?? "a mount this provider never makes" } };
|
|
460
|
-
return { mount: recorded.mount, ...epoch, expected: readBackOf({ ...recorded.mount, token: "" }, epoch.epoch) };
|
|
480
|
+
return { mount: recorded.mount, ...epoch, expected: readBackOf(recorded.mount.kind === "sync" ? recorded.mount : { ...recorded.mount, token: "" }, epoch.epoch) };
|
|
461
481
|
}
|
|
462
482
|
/** A mount read-back in words. */
|
|
463
483
|
export function mountWords(mount) {
|
|
@@ -465,31 +485,40 @@ export function mountWords(mount) {
|
|
|
465
485
|
return mount.other;
|
|
466
486
|
if (mount.kind === "bind")
|
|
467
487
|
return `a bind of ${mount.path}`;
|
|
488
|
+
if (mount.kind === "sync")
|
|
489
|
+
return `a synced folder, epoch ${mount.epoch}`;
|
|
468
490
|
return `archil ${mount.disk}:/${mount.folder} in ${mount.region}, ${mount.exclusive ? "exclusive" : "not exclusive"}, epoch ${mount.epoch}`;
|
|
469
491
|
}
|
|
492
|
+
/** Whether two read-backs of a mount are the same mount. */
|
|
493
|
+
function sameMount(read, expected) {
|
|
494
|
+
if ("other" in read || "other" in expected || read.kind !== expected.kind)
|
|
495
|
+
return false;
|
|
496
|
+
if (read.kind === "bind")
|
|
497
|
+
return expected.kind === "bind" && read.path === expected.path;
|
|
498
|
+
if (read.kind === "sync")
|
|
499
|
+
return expected.kind === "sync" && read.epoch === expected.epoch;
|
|
500
|
+
return (expected.kind === "archil" &&
|
|
501
|
+
read.disk === expected.disk &&
|
|
502
|
+
read.region === expected.region &&
|
|
503
|
+
read.folder === expected.folder &&
|
|
504
|
+
read.exclusive === expected.exclusive &&
|
|
505
|
+
read.epoch === expected.epoch);
|
|
506
|
+
}
|
|
470
507
|
/** How the mount read back from inside (undefined: nothing at /workspace) differs from the one expected, in words. */
|
|
471
508
|
export function mountDrift(expected, read) {
|
|
472
509
|
if ("other" in expected)
|
|
473
510
|
return [`mount: ${expected.other}`];
|
|
474
511
|
if (read === undefined)
|
|
475
512
|
return [`mount: declared ${mountWords(expected)}, yet nothing is mounted at ${WORKSPACE}`];
|
|
476
|
-
|
|
477
|
-
read.kind === expected.kind &&
|
|
478
|
-
(read.kind === "bind"
|
|
479
|
-
? expected.kind === "bind" && read.path === expected.path
|
|
480
|
-
: expected.kind === "archil" &&
|
|
481
|
-
read.disk === expected.disk &&
|
|
482
|
-
read.region === expected.region &&
|
|
483
|
-
read.folder === expected.folder &&
|
|
484
|
-
read.exclusive === expected.exclusive &&
|
|
485
|
-
read.epoch === expected.epoch);
|
|
486
|
-
return same ? [] : [`mount: declared ${mountWords(expected)}, read back ${mountWords(read)}`];
|
|
513
|
+
return sameMount(read, expected) ? [] : [`mount: declared ${mountWords(expected)}, read back ${mountWords(read)}`];
|
|
487
514
|
}
|
|
488
515
|
/**
|
|
489
|
-
* What a computer
|
|
490
|
-
*
|
|
516
|
+
* What a computer holds at /workspace, read back through its computerd, under `epoch`, the computer's label, each call
|
|
517
|
+
* bounded by timeoutMs and the signal: its mount table first. For a recorded synced folder, nothing may be mounted
|
|
518
|
+
* there, and /workspace must be a directory (never a link) of the computer's user, the owner of its home (WORK); else
|
|
519
|
+
* it is one in words. For any other, whether the resident serve answers a sync (an Archil mount's exclusive).
|
|
491
520
|
*/
|
|
492
|
-
export async function
|
|
521
|
+
export async function readMount(client, { mount, epoch }, { name, timeoutMs, signal }) {
|
|
493
522
|
const bounded = () => (signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs));
|
|
494
523
|
const table = await client.call("files.read", { path: "/proc/self/mounts" }, { signal: bounded() });
|
|
495
524
|
if (!table.ok) {
|
|
@@ -497,10 +526,28 @@ export async function readArchilMount(client, { mount, epoch }, { name, timeoutM
|
|
|
497
526
|
return fail("aborted", `reading the mount table in ${name} was aborted`);
|
|
498
527
|
return fail(table.error.code === "aborted" ? "timeout" : table.error.code, `reading the mount table in ${name}: ${table.error.message}`);
|
|
499
528
|
}
|
|
529
|
+
const mounts = Buffer.from(table.value.data, "base64").toString("utf8");
|
|
530
|
+
if (mount?.kind === "sync") {
|
|
531
|
+
const mounted = archilReadBack({ mounts, epoch, served: false });
|
|
532
|
+
if (mounted !== undefined)
|
|
533
|
+
return ok({ other: `${mountWords(mounted)}, where a synced folder has nothing mounted` });
|
|
534
|
+
const [folder, home] = [await client.call("files.stat", { path: WORKSPACE }, { signal: bounded() }), await client.call("files.stat", { path: WORK }, { signal: bounded() })];
|
|
535
|
+
if (signal?.aborted)
|
|
536
|
+
return fail("aborted", `reading ${WORKSPACE} in ${name} was aborted`);
|
|
537
|
+
if (!home.ok)
|
|
538
|
+
return fail(home.error.code, `reading ${WORK} in ${name}: ${home.error.message}`);
|
|
539
|
+
if (!folder.ok)
|
|
540
|
+
return folder.error.code === "not_found" ? ok({ other: `no ${WORKSPACE} for a synced folder` }) : fail(folder.error.code, `reading ${WORKSPACE} in ${name}: ${folder.error.message}`);
|
|
541
|
+
if (folder.value.type !== "dir")
|
|
542
|
+
return ok({ other: `a ${folder.value.type} at ${WORKSPACE}, where a synced folder is a directory` });
|
|
543
|
+
const [owner, user] = [`${folder.value.uid}:${folder.value.gid}`, `${home.value.uid}:${home.value.gid}`];
|
|
544
|
+
if (owner !== user)
|
|
545
|
+
return ok({ other: `${WORKSPACE} owned by ${owner}, not by the computer's user ${user}` });
|
|
546
|
+
return ok(readBackOf(mount, epoch));
|
|
547
|
+
}
|
|
500
548
|
const synced = await client.call("mount.sync", {}, { signal: bounded() });
|
|
501
549
|
if (signal?.aborted)
|
|
502
550
|
return fail("aborted", `the sync in ${name} was aborted`);
|
|
503
|
-
const mounts = Buffer.from(table.value.data, "base64").toString("utf8");
|
|
504
551
|
return ok(archilReadBack({ mounts, epoch, served: synced.ok && synced.value.exitCode === 0, ...(mount === undefined ? {} : { recorded: mount }) }));
|
|
505
552
|
}
|
|
506
553
|
/** The claim epoch of labels check() has held to it (archilRefusals): a caller's mistake otherwise, so it throws. */
|
package/dist/mount.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ export declare function epochProblem(epoch: unknown): string | undefined;
|
|
|
7
7
|
/** Where the run's folder is mounted in every computer. HOME is elsewhere (a Docker computer's is /work). */
|
|
8
8
|
export declare const WORKSPACE = "/workspace";
|
|
9
9
|
/**
|
|
10
|
-
* The run's folder,
|
|
11
|
-
*
|
|
12
|
-
* computer).
|
|
10
|
+
* The run's folder, at WORKSPACE. bind: a folder on the provider's host, bound in (the local Docker computer). archil:
|
|
11
|
+
* the run's folder inside an Archil disk in its region, mounted in the computer with the disk's token (a remote
|
|
12
|
+
* computer). sync: a plain directory the computer's user owns, with nothing mounted there; the runner holds the folder
|
|
13
|
+
* and keeps a working copy there, pushed at claim and pulled back after every call that may change it, so the computer
|
|
14
|
+
* holds no disk, region or token.
|
|
13
15
|
*/
|
|
14
16
|
export type MountSpec = {
|
|
15
17
|
kind: "bind";
|
|
@@ -20,6 +22,8 @@ export type MountSpec = {
|
|
|
20
22
|
region: string;
|
|
21
23
|
folder: string;
|
|
22
24
|
token: string;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "sync";
|
|
23
27
|
};
|
|
24
28
|
export type MountKind = MountSpec["kind"];
|
|
25
29
|
export declare const MOUNT_KINDS: readonly MountKind[];
|
|
@@ -27,7 +31,8 @@ export declare const MOUNT_KINDS: readonly MountKind[];
|
|
|
27
31
|
* A computer's mount as read back from the computer itself: its kind and where it comes from, never the token. `other`
|
|
28
32
|
* is a mount at WORKSPACE the provider never makes (read-only, a volume), in words. An Archil mount also reads back
|
|
29
33
|
* whether it holds the folder exclusively (no other client writes it) and the claim epoch it was made under: the
|
|
30
|
-
* computer's agentrun.epoch label (labels.ts), since Archil's hold on a folder carries no epoch of its own.
|
|
34
|
+
* computer's agentrun.epoch label (labels.ts), since Archil's hold on a folder carries no epoch of its own. A synced
|
|
35
|
+
* folder reads back the claim epoch alone, the same label's, as nothing in the computer carries one.
|
|
31
36
|
*/
|
|
32
37
|
export type MountReadBack = {
|
|
33
38
|
kind: "bind";
|
|
@@ -39,6 +44,9 @@ export type MountReadBack = {
|
|
|
39
44
|
folder: string;
|
|
40
45
|
exclusive: boolean;
|
|
41
46
|
epoch: number;
|
|
47
|
+
} | {
|
|
48
|
+
kind: "sync";
|
|
49
|
+
epoch: number;
|
|
42
50
|
} | {
|
|
43
51
|
other: string;
|
|
44
52
|
};
|
|
@@ -52,12 +60,13 @@ export type Unmounted = Readonly<Partial<Record<MountKind, string>>>;
|
|
|
52
60
|
* words (the provider's own reason, `unmounted`, where it gives one); a bind's path is absolute, canonical (its own
|
|
53
61
|
* realpath: what a provider reads back is what is bound), an existing directory on the host, with no NUL; an Archil
|
|
54
62
|
* mount's disk, region, folder and token are non-empty strings with no NUL, the folder relative to the disk's root and
|
|
55
|
-
* never above it. Each refusal names a field, never an Archil value.
|
|
63
|
+
* never above it; a synced folder has no field but its kind. Each refusal names a field, never an Archil value.
|
|
56
64
|
*/
|
|
57
65
|
export declare function checkMount(mount: unknown, declared: readonly MountKind[] | undefined, unmounted?: Unmounted): Refusal[];
|
|
58
66
|
/**
|
|
59
67
|
* What a provider reads back of a mount it made as asked: its kind and source, never the token. An Archil mount is
|
|
60
|
-
* always exclusive, and
|
|
61
|
-
* one,
|
|
68
|
+
* always exclusive, and it and a synced folder are read back under `epoch`, the computer's claim epoch. With no epoch,
|
|
69
|
+
* or a value that is not one, either is `{ other }` in words: a folder under no claim, which no attach takes, never a
|
|
70
|
+
* guessed epoch. A bind takes none.
|
|
62
71
|
*/
|
|
63
72
|
export declare function readBackOf(mount: MountSpec, epoch?: number): MountReadBack;
|
package/dist/mount.js
CHANGED
|
@@ -12,9 +12,10 @@ export function epochProblem(epoch) {
|
|
|
12
12
|
}
|
|
13
13
|
/** Where the run's folder is mounted in every computer. HOME is elsewhere (a Docker computer's is /work). */
|
|
14
14
|
export const WORKSPACE = "/workspace";
|
|
15
|
-
export const MOUNT_KINDS = ["bind", "archil"];
|
|
16
|
-
const SHAPE = 'mount is { kind: "bind", path }
|
|
17
|
-
const FIELDS = { bind: ["kind", "path"], archil: ["kind", "disk", "region", "folder", "token"] };
|
|
15
|
+
export const MOUNT_KINDS = ["bind", "archil", "sync"];
|
|
16
|
+
const SHAPE = 'mount is { kind: "bind", path }, { kind: "archil", disk, region, folder, token } or { kind: "sync" }';
|
|
17
|
+
const FIELDS = { bind: ["kind", "path"], archil: ["kind", "disk", "region", "folder", "token"], sync: ["kind"] };
|
|
18
|
+
const NAMES = { bind: "a bind", archil: "an archil", sync: "a sync" };
|
|
18
19
|
const NUL = "a NUL byte cannot be passed to a mount";
|
|
19
20
|
const filled = (value) => typeof value === "string" && value !== "";
|
|
20
21
|
/**
|
|
@@ -22,7 +23,7 @@ const filled = (value) => typeof value === "string" && value !== "";
|
|
|
22
23
|
* words (the provider's own reason, `unmounted`, where it gives one); a bind's path is absolute, canonical (its own
|
|
23
24
|
* realpath: what a provider reads back is what is bound), an existing directory on the host, with no NUL; an Archil
|
|
24
25
|
* mount's disk, region, folder and token are non-empty strings with no NUL, the folder relative to the disk's root and
|
|
25
|
-
* never above it. Each refusal names a field, never an Archil value.
|
|
26
|
+
* never above it; a synced folder has no field but its kind. Each refusal names a field, never an Archil value.
|
|
26
27
|
*/
|
|
27
28
|
export function checkMount(mount, declared, unmounted = {}) {
|
|
28
29
|
if (mount === undefined)
|
|
@@ -43,8 +44,9 @@ export function checkMount(mount, declared, unmounted = {}) {
|
|
|
43
44
|
}
|
|
44
45
|
const extra = Object.keys(given).find((field) => !FIELDS[kind].includes(field) && given[field] !== undefined);
|
|
45
46
|
if (extra !== undefined)
|
|
46
|
-
return refuse(`mount.${extra} is not a field of ${kind
|
|
47
|
-
|
|
47
|
+
return refuse(`mount.${extra} is not a field of ${NAMES[kind]} mount`);
|
|
48
|
+
const found = kind === "bind" ? bindRefusals(given.path) : kind === "archil" ? archilRefusals(given) : [];
|
|
49
|
+
return found.map((message) => ({ field: "mount", message }));
|
|
48
50
|
}
|
|
49
51
|
function bindRefusals(path) {
|
|
50
52
|
if (!filled(path))
|
|
@@ -95,13 +97,16 @@ function archilRefusals({ disk, region, folder, token }) {
|
|
|
95
97
|
}
|
|
96
98
|
/**
|
|
97
99
|
* What a provider reads back of a mount it made as asked: its kind and source, never the token. An Archil mount is
|
|
98
|
-
* always exclusive, and
|
|
99
|
-
* one,
|
|
100
|
+
* always exclusive, and it and a synced folder are read back under `epoch`, the computer's claim epoch. With no epoch,
|
|
101
|
+
* or a value that is not one, either is `{ other }` in words: a folder under no claim, which no attach takes, never a
|
|
102
|
+
* guessed epoch. A bind takes none.
|
|
100
103
|
*/
|
|
101
104
|
export function readBackOf(mount, epoch) {
|
|
102
105
|
if (mount.kind === "bind")
|
|
103
106
|
return { kind: "bind", path: mount.path };
|
|
104
107
|
const problem = epochProblem(epoch);
|
|
108
|
+
if (mount.kind === "sync")
|
|
109
|
+
return problem === undefined ? { kind: "sync", epoch: epoch } : { other: `a synced folder with no epoch to read it back under (${problem})` };
|
|
105
110
|
if (problem !== undefined)
|
|
106
111
|
return { other: `an Archil mount of ${mount.disk}:/${mount.folder} with no epoch to read it back under (${problem})` };
|
|
107
112
|
return { kind: "archil", disk: mount.disk, region: mount.region, folder: mount.folder, exclusive: true, epoch: epoch };
|
package/dist/orgo.js
CHANGED
|
@@ -283,7 +283,7 @@ export class OrgoProvider {
|
|
|
283
283
|
if (bad)
|
|
284
284
|
refuse("labels", bad);
|
|
285
285
|
}
|
|
286
|
-
refusals.push(...checkMount(mount, ORGO.mounts));
|
|
286
|
+
refusals.push(...checkMount(mount, ORGO.mounts, ORGO.unmounted));
|
|
287
287
|
refusals.push(...checkGpu(given.gpu, this.capabilities()));
|
|
288
288
|
for (const [field, value] of Object.entries(given)) {
|
|
289
289
|
if (SPEC_FIELDS.has(field) || field === "mount" || field === "owner" || value === undefined)
|
package/dist/provider.d.ts
CHANGED
|
@@ -88,7 +88,7 @@ export interface GpuCapability {
|
|
|
88
88
|
memoryMb: number;
|
|
89
89
|
diskMb: number;
|
|
90
90
|
};
|
|
91
|
-
/** The mount kinds a GPU computer takes, where fewer than capabilities().mount:
|
|
91
|
+
/** The mount kinds a GPU computer takes, where fewer than capabilities().mount: a synced folder, which needs no FUSE. */
|
|
92
92
|
mounts?: MountKind[];
|
|
93
93
|
/**
|
|
94
94
|
* Why a GPU computer takes none of the other mounts, in words naming no field: a fact of the vendor's runtime, or
|