@parcha/agentrun-computer 0.1.0-beta.38 → 0.1.0-beta.39

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.
Files changed (85) hide show
  1. package/README.md +101 -76
  2. package/box/README.md +2 -1
  3. package/box/recipe.d.mts +5 -0
  4. package/dist/agent37.d.ts +17 -4
  5. package/dist/agent37.js +96 -16
  6. package/dist/box-image.d.ts +14 -0
  7. package/dist/box-image.js +24 -0
  8. package/dist/computerd-linux-amd64 +0 -0
  9. package/dist/computerd-linux-arm64 +0 -0
  10. package/dist/computerd.json +2 -2
  11. package/dist/conformance/agent37.d.ts +9 -4
  12. package/dist/conformance/agent37.js +23 -11
  13. package/dist/conformance/browserbase.js +3 -3
  14. package/dist/conformance/cases/apps.d.ts +1 -1
  15. package/dist/conformance/cases/apps.js +1 -1
  16. package/dist/conformance/cases/isolation.d.ts +18 -3
  17. package/dist/conformance/cases/isolation.js +57 -6
  18. package/dist/conformance/cases/mount.js +4 -2
  19. package/dist/conformance/cases/provider.js +41 -0
  20. package/dist/conformance/cli.js +6 -5
  21. package/dist/conformance/e2b.js +9 -4
  22. package/dist/conformance/exec-stream.d.ts +7 -0
  23. package/dist/conformance/exec-stream.js +8 -1
  24. package/dist/conformance/kernel.js +2 -2
  25. package/dist/conformance/modal.js +1 -1
  26. package/dist/conformance/orgo.js +2 -2
  27. package/dist/daytona.d.ts +0 -5
  28. package/dist/daytona.js +16 -27
  29. package/dist/descriptor.d.ts +5 -3
  30. package/dist/descriptors/agent37.d.ts +3 -11
  31. package/dist/descriptors/agent37.js +9 -10
  32. package/dist/descriptors/daytona.d.ts +1 -1
  33. package/dist/descriptors/daytona.js +5 -2
  34. package/dist/descriptors/docker.d.ts +13 -1
  35. package/dist/descriptors/docker.js +3 -1
  36. package/dist/descriptors/e2b.d.ts +2 -9
  37. package/dist/descriptors/e2b.js +8 -8
  38. package/dist/descriptors/index.d.ts +21 -19
  39. package/dist/descriptors/index.js +1 -3
  40. package/dist/descriptors/modal.d.ts +2 -6
  41. package/dist/descriptors/modal.js +8 -6
  42. package/dist/descriptors/orgo.js +2 -1
  43. package/dist/docker/egress-main.js +23 -15
  44. package/dist/docker/egress.d.ts +6 -4
  45. package/dist/docker/egress.js +24 -16
  46. package/dist/docker/inspect.d.ts +2 -2
  47. package/dist/docker/inspect.js +5 -5
  48. package/dist/docker.d.ts +6 -5
  49. package/dist/docker.js +12 -11
  50. package/dist/e2b.d.ts +12 -2
  51. package/dist/e2b.js +42 -19
  52. package/dist/host.d.ts +54 -41
  53. package/dist/hosted/network.d.ts +23 -0
  54. package/dist/hosted/network.js +77 -0
  55. package/dist/hosted/process.d.ts +2 -0
  56. package/dist/hosted/process.js +5 -0
  57. package/dist/hosted/provider.d.ts +6 -4
  58. package/dist/hosted/provider.js +244 -136
  59. package/dist/hosted/rest.d.ts +10 -2
  60. package/dist/hosted/rest.js +9 -4
  61. package/dist/hosted/scripts.d.ts +19 -7
  62. package/dist/hosted/scripts.js +55 -18
  63. package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
  64. package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
  65. package/dist/hosted/values.d.ts +21 -0
  66. package/dist/hosted/values.js +55 -0
  67. package/dist/index.d.ts +1 -1
  68. package/dist/index.js +1 -1
  69. package/dist/isolation.d.ts +0 -2
  70. package/dist/isolation.js +3 -4
  71. package/dist/modal.d.ts +8 -2
  72. package/dist/modal.js +21 -15
  73. package/dist/mount-archil.d.ts +5 -4
  74. package/dist/mount-archil.js +5 -6
  75. package/dist/orgo.js +6 -4
  76. package/dist/providers.d.ts +4 -1
  77. package/dist/surface/api.d.ts +0 -9
  78. package/dist/surface/core.d.ts +7 -2
  79. package/dist/surface/core.js +12 -4
  80. package/dist/surface/index.d.ts +1 -1
  81. package/dist/surface/index.js +1 -1
  82. package/dist/surface/script.d.ts +4 -0
  83. package/dist/surface/script.js +9 -3
  84. package/package.json +1 -1
  85. package/box/build-agent37.mjs +0 -158
@@ -10,10 +10,11 @@ import { createHash, randomBytes } from "node:crypto";
10
10
  import { readFileSync } from "node:fs";
11
11
  import { resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
+ import { isDeepStrictEqual } from "node:util";
13
14
  import { CreateRequests, endedWords, otherSpecWords, readBackDiffer } from "../create-requests.js";
14
- import { DESKTOP_GROUPS, desktopOf, startDisplay } from "../desktop.js";
15
+ import { desktopOf, startDisplay } from "../desktop.js";
15
16
  import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, show, WORK } from "../drift.js";
16
- import { OWN_NETWORK_ONLY, readOwnNetwork, TOOL_USER } from "../isolation.js";
17
+ import { readOwnNetwork, TOOL_USER } from "../isolation.js";
17
18
  import { releaseOlder } from "../janitor.js";
18
19
  import { RUN_LABEL } from "../labels.js";
19
20
  import { checkMount, readBackOf } from "../mount.js";
@@ -24,7 +25,8 @@ import { daemonWatch } from "../screen-watch.js";
24
25
  import { countTested } from "../test-connection.js";
25
26
  import { waitUntil } from "../wait.js";
26
27
  import { bounded, CALL_SLACK_MS, hostCall, openBridge, pause, rootOf, runToExit, seconds, uploadThroughExec } from "./process.js";
27
- import { isWhole } from "./values.js";
28
+ import { isWhole, packLabels } from "./values.js";
29
+ import { EGRESS_POLICY, EGRESS_PROXY_USER, EGRESS_RELAY, HOSTED_ALLOW, NETWORK_LABEL, networkFormOf, networkOfForm, networkRefusal, throughProxy } from "./network.js";
28
30
  import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, installerOf } from "./scripts.js";
29
31
  const VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
30
32
  export const NAME_LABEL = `${COMPUTER_LABEL}.name`;
@@ -32,6 +34,8 @@ export const NAME_LABEL = `${COMPUTER_LABEL}.name`;
32
34
  export const IMAGE_LABEL = `${COMPUTER_LABEL}.image`;
33
35
  /** The most extend may move the deadline to: create's time plus the cap, by this machine's clock, as init was given. */
34
36
  export const MAX_LABEL = `${COMPUTER_LABEL}.max-deadline`;
37
+ /** A GPU computer's GPUs, type:count: a retry and attach read them here, so no vendor need read them back. */
38
+ export const GPU_LABEL = `${COMPUTER_LABEL}.gpu`;
35
39
  const NAME = /^computer-[0-9a-f]{12}$/;
36
40
  const MACHINE_ID = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/;
37
41
  const USER = /^(\d+):(\d+)$/;
@@ -74,9 +78,20 @@ const STAGING = "/tmp/agentrun-computerd-";
74
78
  const DEFAULT_PROBE_TARGETS = ["1.1.1.1:443", "8.8.8.8:443", "[2606:4700:4700::1111]:443", "1.1.1.1:53/udp", "[2606:4700:4700::1111]:53/udp"];
75
79
  /** A probe target: host:port, over TCP, or host:port/udp, a DNS query over UDP. */
76
80
  const TARGET = /^(?:\[[0-9A-Fa-f:.]+\]|[A-Za-z0-9.-]+):[0-9]{1,5}(?:\/udp)?$/;
77
- const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "mount", "gpu", "owner"]);
81
+ /** The spec's fields the adapter passes on or holds itself: a size goes in the request, for the host's check to refuse. */
82
+ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "mount", "gpu", "owner", "cpus", "memoryMb"]);
78
83
  const policyWords = (policy) => (typeof policy === "string" ? policy : "other" in policy ? policy.other : JSON.stringify(policy));
84
+ /** What makes a computer's labels smaller, in words: the list only where its network is one. */
85
+ const shorterWords = (labels) => `give a shorter image, mount folder${labels[NETWORK_LABEL]?.startsWith("allow:") ? ", network list" : ""} or labels`;
79
86
  const alive = (state) => state !== "gone";
87
+ /** The codes of a create the vendor refused, which made nothing. */
88
+ const REFUSED_CREATE = new Set(["invalid", "denied", "limit", "not_found", "refused", "unauthorized", "exists"]);
89
+ /**
90
+ * Whether a create that failed with code may have made a machine, so the request's name is swept. A refusal made
91
+ * nothing: a machine under the name then is another's (exists: another instance's create of the request), never
92
+ * deleted. Any other failure (the vendor's, a timeout) may have made one, answered in time or after create gave up.
93
+ */
94
+ const mayHaveMade = (code) => !REFUSED_CREATE.has(code);
80
95
  /** An ISO time a label holds, or undefined when it is missing or not the ISO time create writes. */
81
96
  export function isoOf(written) {
82
97
  const at = written === undefined ? Number.NaN : Date.parse(written);
@@ -115,6 +130,14 @@ function specUserOf(value) {
115
130
  const [uid, gid] = [Number(found[1]), Number(found[2] ?? found[1])];
116
131
  return uid <= MAX_ID && gid <= MAX_ID ? `${uid}:${gid}` : undefined;
117
132
  }
133
+ /** The GPUs a machine's GPU_LABEL records (type:count), as a spec's gpu field; none where it records none. */
134
+ function gpuOf(written) {
135
+ const at = written?.lastIndexOf(":") ?? -1;
136
+ if (written === undefined || at < 1)
137
+ return {};
138
+ const count = Number(written.slice(at + 1));
139
+ return isWhole(count) ? { gpu: { type: written.slice(0, at), count } } : {};
140
+ }
118
141
  /** The caller's labels of a machine: every one but the adapter's own namespace and the Archil mount's. */
119
142
  const callerLabels = (labels) => Object.fromEntries(Object.entries(labels).filter(([key]) => key !== COMPUTER_LABEL && !key.startsWith(`${COMPUTER_LABEL}.`) && key !== ARCHIL_MOUNT_LABEL));
120
143
  /** The shared adapter's provider: a ComputerProvider whose vendor is host. */
@@ -124,6 +147,8 @@ export class HostedProvider {
124
147
  /** The vendor's machines, for the live sweep (conformance/sweep.ts); nothing else reaches past the provider to them. */
125
148
  host;
126
149
  extend;
150
+ /** The host's descriptor's configuration of this provider's kind: its groups and GPUs. */
151
+ #configuration;
127
152
  #label;
128
153
  #fail;
129
154
  #daemonPath;
@@ -143,15 +168,19 @@ export class HostedProvider {
143
168
  #extending = new Map();
144
169
  constructor(host, options) {
145
170
  const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = fileURLToPath(new URL(`../computerd-linux-${host.facts.arch}`, import.meta.url)), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress, } = options;
146
- const { id, label } = host.descriptor;
171
+ const { id, label, capabilities } = host.descriptor;
172
+ if (kind !== "desktop" && kind !== "linux")
173
+ throw new Error(`kind is desktop or linux, not ${String(kind)}`);
174
+ const configuration = capabilities.find((one) => one.kind === kind);
175
+ if (configuration === undefined)
176
+ throw new Error(`${label} offers no ${kind} computer`);
147
177
  this.id = id;
148
178
  this.host = host;
179
+ this.#configuration = configuration;
149
180
  this.#label = label;
150
181
  this.#fail = failFor(id);
151
182
  this.#onNote = onNote;
152
183
  this.#archilEgress = archilEgress === undefined || archilEgress === "" ? undefined : archilEgressOf(archilEgress);
153
- if (kind !== "desktop" && kind !== "linux")
154
- throw new Error(`kind is desktop or linux, not ${String(kind)}`);
155
184
  if (!isWhole(maxLifetimeMs) || maxLifetimeMs <= 0 || maxLifetimeMs > host.facts.maxLifetimeMs) {
156
185
  throw new Error(`maxLifetimeMs must be a whole number of ms above 0 and at most ${host.facts.maxLifetimeMs} ms, the longest ${label} keeps a computer`);
157
186
  }
@@ -184,24 +213,27 @@ export class HostedProvider {
184
213
  if (host.extend)
185
214
  this.extend = (ref, ttlMs, context) => this.#extendSerial(ref, ttlMs, context?.signal);
186
215
  }
187
- /** The computer's facts, from the host's and the adapter's options alone. */
216
+ /** The computer's facts, from the descriptor, the host's facts and the adapter's options alone. */
188
217
  capabilities() {
189
218
  const { facts, descriptor } = this.host;
219
+ const { gpu } = this.#configuration;
190
220
  return {
191
221
  kind: this.#kind,
192
222
  lifetime: facts.lifetime,
193
223
  network: [...descriptor.network],
194
- // The probe from inside is the network's truth: no vendor's read of it is taken.
224
+ // A list is the egress proxy's, init's own (./network.ts): Docker's bounds and ports.
225
+ ...(descriptor.network.includes("allow") ? { allow: structuredClone(HOSTED_ALLOW) } : {}),
226
+ // The probe and the proxy's policy from inside are the network's truth: no vendor's read of it is taken.
195
227
  networkReadBack: false,
196
228
  isolation: facts.isolation,
197
229
  os: "linux",
198
230
  daemon: facts.daemon,
199
- groups: ["exec", "files", "processes", ...(this.#desktop ? DESKTOP_GROUPS : [])],
231
+ groups: [...this.#configuration.groups],
200
232
  maxLifetimeMs: this.#maxLifetimeMs,
201
233
  release: ["delete"],
202
234
  mount: [...descriptor.mounts],
203
235
  vendorAgentPorts: [...facts.vendorAgentPorts],
204
- ...(facts.gpu === undefined ? {} : { gpu: structuredClone(facts.gpu) }),
236
+ ...(gpu === undefined ? {} : { gpu: structuredClone(gpu) }),
205
237
  ...(facts.user === undefined ? {} : { user: [...facts.user] }),
206
238
  };
207
239
  }
@@ -216,7 +248,7 @@ export class HostedProvider {
216
248
  const archil = mount?.kind === "archil" && (capabilities.mount ?? []).includes("archil");
217
249
  refusals.push(...checkMount(mount, capabilities.mount ?? [], this.host.descriptor.unmounted), ...(archil ? archilRefusals(given) : []));
218
250
  const daemonUser = `${this.#uid}:${this.#gid}`;
219
- const asked = this.#takesUser() ? given.user : undefined;
251
+ const asked = this.#takesUser ? given.user : undefined;
220
252
  if (asked !== undefined) {
221
253
  const user = specUserOf(asked);
222
254
  if (user === undefined)
@@ -227,6 +259,9 @@ export class HostedProvider {
227
259
  else if (archil && user !== ARCHIL_USER) {
228
260
  refuse("user", `a computer with an Archil mount runs its tools as agentrun-tool, ${ARCHIL_USER}, the user its image makes with no way to root; leave user unset or ask for ${ARCHIL_USER}`);
229
261
  }
262
+ else if (throughProxy(network) && user.split(":").includes(String(EGRESS_PROXY_USER))) {
263
+ refuse("user", `the egress proxy of a network open or a list runs as uid and gid ${EGRESS_PROXY_USER} (nobody), so its programs' user may be neither; ask for another uid, such as 1000:1000`);
264
+ }
230
265
  }
231
266
  else if (archil && daemonUser !== ARCHIL_USER) {
232
267
  refuse("mount", `a computer with an Archil mount runs its tools as agentrun-tool, ${ARCHIL_USER}, the user its image makes with no way to root; this provider's daemon user is ${daemonUser}: make it with daemonUser ${ARCHIL_USER}`);
@@ -234,25 +269,24 @@ export class HostedProvider {
234
269
  if (typeof image !== "string" || image === "" || image.includes("\0"))
235
270
  refuse("image", `an image is required: the name of ${a(label)} image`);
236
271
  refusals.push(...checkTenure(given, capabilities, label));
237
- if (network === "open" || (typeof network === "object" && network !== null && "allow" in network))
238
- refuse("network", OWN_NETWORK_ONLY);
239
- else if (network !== "none")
240
- refuse("network", 'network is required: "none"');
272
+ // Only the forms the descriptor declares, each one this computer enforces; any other is refused, never widened.
273
+ const networkProblem = networkRefusal(label, capabilities.network, network);
274
+ if (networkProblem)
275
+ refuse("network", networkProblem);
241
276
  const entries = labels === undefined ? [] : typeof labels === "object" && labels !== null && !Array.isArray(labels) ? Object.entries(labels) : undefined;
242
- const bad = entries === undefined ? "labels must map names to strings" : (entries.map(([key, value]) => labelProblem(key, value)).find(Boolean) ?? this.#labelCount(entries.length, given));
277
+ const bad = entries === undefined ? "labels must map names to strings" : entries.map(([key, value]) => labelProblem(key, value)).find(Boolean);
243
278
  if (bad)
244
279
  refuse("labels", bad);
245
280
  else if (typeof image === "string" && (!archil || ["disk", "region", "folder"].every((key) => typeof mount[key] === "string"))) {
246
- const over = this.#labelBytes(given);
281
+ const over = this.#labelsOver(given);
247
282
  if (over)
248
- refuse(archil ? "mount" : "labels", over);
283
+ refuse(archil && over.bytes ? "mount" : "labels", over.why);
249
284
  }
250
285
  refusals.push(...checkGpu(given.gpu, capabilities, mount));
251
- const taken = new Set(this.host.facts.specFields ?? []);
252
286
  for (const [field, value] of Object.entries(given)) {
253
- if (SPEC_FIELDS.has(field) || taken.has(field) || value === undefined)
287
+ if (SPEC_FIELDS.has(field) || (field === "user" && this.#takesUser) || value === undefined)
254
288
  continue;
255
- if (field === "cpus" || field === "memoryMb" || field === "pids")
289
+ if (field === "pids")
256
290
  refuse(field, `${a(label)} computer has the size of its image: name an image of the size you need, not ${field}`);
257
291
  else if (field === "user")
258
292
  refuse(field, `${a(label)} computer's daemon runs as the provider's daemon user (${daemonUser}), never as one a spec names`);
@@ -265,39 +299,48 @@ export class HostedProvider {
265
299
  refusals.push(...this.host.check(given));
266
300
  return refusals;
267
301
  }
268
- /** Whether the host takes a spec's user (facts.specFields): then a computer's daemon runs as the one a spec names. */
269
- #takesUser() {
270
- return (this.host.facts.specFields ?? []).includes("user");
302
+ /** Whether the host takes a spec's user (facts.user): then a computer's daemon runs as the one a spec names. */
303
+ get #takesUser() {
304
+ return this.host.facts.user !== undefined;
271
305
  }
272
306
  /** Who one create's daemon runs as, uid:gid: the spec's user where the host takes one, else the provider's daemon user. */
273
307
  #userOf(spec) {
274
- return (this.#takesUser() ? specUserOf(spec.user) : undefined) ?? `${this.#uid}:${this.#gid}`;
275
- }
276
- /** The labels create would give a spec's computer, the adapter's own at their longest (#labelsOf). */
277
- #longestLabels(spec, caller) {
278
- const at = new Date(0).toISOString();
279
- return this.#labelsOf({ ...spec, labels: caller ? spec.labels : {} }, "computer-000000000000", at, at);
308
+ return (this.#takesUser ? specUserOf(spec.user) : undefined) ?? `${this.#uid}:${this.#gid}`;
280
309
  }
281
- /** Why a spec's labels, with the adapter's own, are more than the vendor takes; undefined when they fit. */
282
- #labelCount(count, spec) {
283
- const max = this.host.facts.labelRules?.max;
310
+ /**
311
+ * Why a spec's labels, with the adapter's own (#labelsOf, as create gives them, each deadline an ISO time at its
312
+ * longest), are more, or come to more bytes, or pack into more, than the vendor takes (facts.labels); undefined when
313
+ * they fit.
314
+ */
315
+ #labelsOver(spec) {
316
+ const { count, bytes: max, packed } = this.host.facts.labels ?? {};
317
+ // Stand-ins as long as create's name and deadlines and as mixed, fixed so a spec's answer never changes (attach and a
318
+ // retry check the spec again): a packed map deflates them as it does create's, give or take a byte, and create packs
319
+ // its own before the host's call (#packedOver).
320
+ const name = "computer-5f3a9c1e7b2d";
321
+ const labels = this.#labelsOf(spec, name, "2026-11-16T04:15:29.481Z", "2026-11-17T04:05:29.481Z");
322
+ if (packed) {
323
+ const why = this.#packedOver(labels, name);
324
+ return why === undefined ? undefined : { bytes: true, why };
325
+ }
326
+ const keys = Object.keys(labels);
327
+ if (count !== undefined && keys.length > count) {
328
+ // labelProblem refuses a caller's label of the adapter's names, so the two never overlap.
329
+ const own = keys.length - Object.keys(spec.labels ?? {}).length;
330
+ return { bytes: false, why: `${a(this.#label)} computer carries at most ${count} labels, the adapter's own among them, and this one's would carry ${keys.length}, ${own} of them the adapter's: give at most ${count - own} labels` };
331
+ }
284
332
  if (max === undefined)
285
333
  return undefined;
286
- const own = Object.keys(this.#longestLabels(spec, false)).length;
287
- return count + own > max ? `${a(this.#label)} computer takes ${max} labels, ${own} of them the provider's own: ${count} is ${count + own - max} too many` : undefined;
288
- }
289
- /** Why a spec's labels, with the adapter's own at their longest, come to more bytes than the vendor takes; undefined when they fit. */
290
- #labelBytes(spec) {
291
- const { maxBytes, measure = "pairs" } = this.host.facts.labelRules ?? {};
292
- if (maxBytes === undefined)
293
- return undefined;
294
- const labels = this.#longestLabels(spec, true);
295
334
  const sizes = Object.entries(labels).map(([key, value]) => [key, Buffer.byteLength(key) + Buffer.byteLength(value)]);
296
- const bytes = measure === "json" ? Buffer.byteLength(JSON.stringify(labels)) : sizes.reduce((sum, [, size]) => sum + size, 0);
297
- if (bytes <= maxBytes)
335
+ const bytes = sizes.reduce((sum, [, size]) => sum + size, 0);
336
+ if (bytes <= max)
298
337
  return undefined;
299
- const how = measure === "json" ? "as JSON" : "names and values together";
300
- return `${a(this.#label)} computer's labels come to at most ${maxBytes} bytes, ${how}, and this computer's would come to ${bytes} (${sizes.map(([key, size]) => `${key} ${size}`).join(", ")}): give a shorter image, mount folder or labels`;
338
+ return { bytes: true, why: `${a(this.#label)} computer's labels come to at most ${max} bytes, names and values together, and this computer's would come to ${bytes} (${sizes.map(([key, size]) => `${key} ${size}`).join(", ")}): ${shorterWords(labels)}` };
339
+ }
340
+ /** Why labels don't fit packed (facts.labels.packed), in words; undefined when they fit or the host keeps them as they are. */
341
+ #packedOver(labels, name) {
342
+ const fit = this.host.facts.labels?.packed ? packLabels(labels, name, this.host.facts.labels) : { labels };
343
+ return "problem" in fit ? `${a(this.#label)} computer keeps its labels packed, and ${fit.problem}: ${shorterWords(labels)}` : undefined;
301
344
  }
302
345
  /** A host call bounded by ms, the caller's signal when given. */
303
346
  #call(what, run, ms, signal) {
@@ -329,14 +372,16 @@ export class HostedProvider {
329
372
  #labelDiffer(spec, name, labels, seen) {
330
373
  const asked = this.#labelsOf(spec, name, labels[DEADLINE_LABEL] ?? "", labels[MAX_LABEL] ?? "");
331
374
  const differ = Object.entries(asked)
332
- .filter(([key, value]) => key !== DEADLINE_LABEL && key !== MAX_LABEL && labels[key] !== value)
375
+ // The GPUs' label is read back as the spec's gpu, held where the user and network are (#again).
376
+ .filter(([key, value]) => key !== DEADLINE_LABEL && key !== MAX_LABEL && key !== GPU_LABEL && labels[key] !== value)
333
377
  .map(([key, value]) => `label ${key}: asked ${show(value)}, ${seen} ${show(labels[key])}`);
334
378
  const extra = Object.keys(callerLabels(labels)).filter((key) => !Object.hasOwn(asked, key));
335
379
  if (extra.length > 0)
336
380
  differ.push(`labels ${extra.join(", ")}: ${seen}, never asked for`);
337
381
  return differ;
338
382
  }
339
- async #createOnce(spec, name, signal) {
383
+ /** taken: the vendor refused this create's name as one a machine has (exists), so the name's machine is read once more. */
384
+ async #createOnce(spec, name, signal, taken) {
340
385
  const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal);
341
386
  if (!listed.ok)
342
387
  return listed;
@@ -345,9 +390,11 @@ export class HostedProvider {
345
390
  return this.#fail("exists", `${found.length} machines carry the name ${name} (${found.map((m) => m.id).join(", ")}): create with a new request id`);
346
391
  if (found.length === 1)
347
392
  return this.#again(spec, name, found[0], signal);
393
+ if (taken)
394
+ return taken;
348
395
  const launched = await this.#launch(spec, name, signal);
349
396
  if (!launched.ok)
350
- return launched;
397
+ return launched.error.code === "exists" ? this.#createOnce(spec, name, signal, launched) : launched;
351
398
  const { ref, made } = launched.value;
352
399
  // From here the machine exists: every step takes the caller's signal, and a failure or an abort deletes it.
353
400
  // Another provider instance's create of this request may have made one too (#converge): the oldest is kept.
@@ -427,10 +474,9 @@ export class HostedProvider {
427
474
  if (differ.length > 0)
428
475
  return this.#fail("exists", otherSpecWords(name, "was made", differ));
429
476
  const attached = await this.#attached(machine, signal);
430
- // The image and an Archil mount are in the labels; the user, the network, and the GPUs where the vendor reads them
431
- // back, are read back. A vendor that reads no GPU back (Modal) cannot show a drift in it, nor any vendor in a size.
432
- const gpu = this.host.facts.gpuReadBack ? ["gpu"] : [];
433
- const drift = attached.ok ? readBackDiffer({ ...spec, user: this.#userOf(spec) }, attached.value.spec, ["user", "network", ...gpu]) : [];
477
+ // The image, an Archil mount and the GPUs are in the labels; the user and the network are read back. No vendor
478
+ // shows a drift in a size.
479
+ const drift = attached.ok ? readBackDiffer({ ...spec, network: networkOfForm(formOf(spec.network)), user: this.#userOf(spec) }, attached.value.spec, ["user", "network", "gpu"]) : [];
434
480
  if (drift.length > 0)
435
481
  return this.#fail("exists", otherSpecWords(name, "was made", drift));
436
482
  if (attached.ok)
@@ -456,16 +502,23 @@ export class HostedProvider {
456
502
  machine = read.value;
457
503
  }
458
504
  }
459
- /** The labels create gives a computer: the caller's, the adapter's own, and an Archil mount's (never its token). */
505
+ /**
506
+ * The labels create gives a computer: the caller's, the adapter's own, and an Archil mount's (never its token). The
507
+ * most its deadline may reach only where the host can extend it, the label's one reader: a host with no extend (Modal,
508
+ * Daytona) spends none of its label bytes on it (Modal's 512 hold the box image's tag beside an Archil mount's label).
509
+ */
460
510
  #labelsOf(spec, name, deadline, maxDeadline) {
511
+ const network = formOf(spec.network);
461
512
  return {
462
513
  ...spec.labels,
463
514
  [COMPUTER_LABEL]: "1",
464
515
  [NAME_LABEL]: name,
465
516
  [DEADLINE_LABEL]: deadline,
466
517
  [IMAGE_LABEL]: spec.image,
467
- [MAX_LABEL]: maxDeadline,
518
+ ...(this.host.extend ? { [MAX_LABEL]: maxDeadline } : {}),
519
+ ...(network === "" ? {} : { [NETWORK_LABEL]: network }),
468
520
  ...(spec.mount?.kind === "archil" ? archilLabels(spec.mount) : {}),
521
+ ...(typeof spec.gpu?.type === "string" && typeof spec.gpu.count === "number" ? { [GPU_LABEL]: `${spec.gpu.type}:${spec.gpu.count}` } : {}),
469
522
  };
470
523
  }
471
524
  /** Everything create does up to the vendor's answer: the daemon read, the machine made, by its request. */
@@ -485,6 +538,10 @@ export class HostedProvider {
485
538
  const deadline = new Date(now + lifetimeMs).toISOString();
486
539
  const maxDeadline = new Date(now + this.#maxLifetimeMs).toISOString();
487
540
  const labels = this.#labelsOf(spec, name, deadline, maxDeadline);
541
+ // check() packed stand-ins; these deflate a byte apart from them, so the host is never given labels that don't fit.
542
+ const over = this.#packedOver(labels, name);
543
+ if (over !== undefined)
544
+ return this.#fail("refused", `labels: ${over}`);
488
545
  const archil = spec.mount?.kind === "archil";
489
546
  const user = this.#userOf(spec);
490
547
  const commands = hostedCommands({
@@ -499,44 +556,42 @@ export class HostedProvider {
499
556
  nonce: randomBytes(16).toString("hex"),
500
557
  waitS: Math.ceil((this.#timeouts.createMs + this.#timeouts.uploadMs + this.#timeouts.execMs + (archil ? this.#timeouts.mountMs * 3 : 0)) / 1000),
501
558
  ...(archil && this.host.facts.daemon === "pid1" ? { gate: ARCHIL_GATE } : {}),
502
- ...(this.host.facts.daemon === "child" && this.host.facts.vendorSockets !== undefined ? { vendorSockets: this.host.facts.vendorSockets } : {}),
559
+ rootOnly: this.host.facts.rootOnly ?? [],
560
+ network: formOf(spec.network),
503
561
  });
504
- const taken = new Set(this.host.facts.specFields ?? []);
505
562
  const request = {
506
563
  name,
507
564
  image: spec.image,
508
565
  labels,
509
- ...(this.host.facts.lifetime === "vendor" ? { lifetimeMs } : {}),
510
- // An Archil computer's root reaches Archil, so its vendor network is open: its tools' none is init's own, read
511
- // back by the probe from inside, as the tool user, like every network none here.
512
- network: archil ? "open" : "none",
566
+ lifetimeMs,
567
+ // The machine has egress where its tools' network is open or a list, which init's proxy holds to the public
568
+ // internet (./network.ts), and where an Archil computer's root reaches Archil. Its tools' none is init's own
569
+ // either way, read back by the probe from inside, as the tool user.
570
+ egress: archil || throughProxy(spec.network),
513
571
  ...(this.host.facts.daemon === "pid1" ? { command: commands.entrypoint } : {}),
514
572
  ...(spec.gpu === undefined ? {} : { gpu: spec.gpu }),
515
- ...(taken.has("cpus") && spec.cpus !== undefined ? { cpus: spec.cpus } : {}),
516
- ...(taken.has("memoryMb") && spec.memoryMb !== undefined ? { memoryMb: spec.memoryMb } : {}),
517
- ...(taken.has("workdir") && spec.workdir !== undefined ? { workdir: spec.workdir } : {}),
518
- ...(taken.has("user") && spec.user !== undefined ? { user } : {}),
573
+ ...(spec.cpus === undefined ? {} : { cpus: spec.cpus }),
574
+ ...(spec.memoryMb === undefined ? {} : { memoryMb: spec.memoryMb }),
575
+ ...(this.#takesUser && spec.user !== undefined ? { user } : {}),
519
576
  };
520
- const runtime = this.host.facts.runtime?.(request);
521
577
  const { createMs } = this.#timeouts;
522
578
  // Never signalled, only raced: an aborted call could leave a machine made whose id never came back. One that lands
523
- // after this gave up is deleted by its id; one whose answer never comes, by its name.
524
- const created = await hostCall(this.host, `${this.#label}'s create`, (ctx) => this.host.create(request, { timeoutMs: ctx.timeoutMs }), createMs, signal, (made) => made.ok ? this.#kill(made.value.id) : this.#deleteNamed(name));
579
+ // after this gave up is deleted by its id; one that fails after it, by its name where it may have made one.
580
+ const created = await hostCall(this.host, `${this.#label}'s create`, (ctx) => this.host.create(request, { timeoutMs: ctx.timeoutMs }), createMs, signal, (made) => made.ok ? this.#kill(made.value.id) : mayHaveMade(made.error.code) ? this.#deleteNamed(name) : undefined);
525
581
  if (!created.ok) {
526
582
  const { code, message } = created.error;
527
583
  if (code === "aborted" || code === "timeout") {
528
584
  this.#end(name);
529
585
  return this.#fail(code, `${message}; a machine it makes after this is deleted as it lands, and ${this.#label} ends it by ${deadline} either way`);
530
586
  }
531
- // A create the vendor refused made nothing. One that failed otherwise may have: it goes by its name.
532
- if (["invalid", "denied", "limit", "not_found", "refused", "unauthorized", "exists"].includes(code))
587
+ if (!mayHaveMade(code))
533
588
  return created;
534
589
  this.#end(name);
535
590
  const swept = await this.#deleteNamed(name);
536
591
  return this.#fail(code, `${this.#label} did not create the machine: ${message}${swept}`);
537
592
  }
538
593
  this.#requests.made(name);
539
- return ok({ ref: { id: created.value.id, name }, made: { deadline, maxDeadline, labels, daemon, sha256, commands, user, ...(runtime === undefined ? {} : { runtime }) } });
594
+ return ok({ ref: { id: created.value.id, name }, made: { deadline, maxDeadline, labels, daemon, sha256, commands, user } });
540
595
  }
541
596
  /** Deletes a machine create gives up on, then waits, under the caller's signal, until get answers none for it. */
542
597
  async #abandon(ref, error, signal, mounted = false) {
@@ -553,7 +608,8 @@ export class HostedProvider {
553
608
  return this.#fail(error.code, `the computer ${ref.name} ${after}: ${error.message}`);
554
609
  }
555
610
  /**
556
- * Every machine carrying a name create gave, deleted and read back gone: for a create whose answer never came. The
611
+ * Every machine carrying a name create gave, deleted and read back gone: for a create that may have made one whose
612
+ * id never came (mayHaveMade), never after a refusal, where a machine under the name is another's. The
557
613
  * listing shows a new machine a moment after the vendor makes it, so it is read for the name until one shows or
558
614
  * listedMs passes. Best effort, in words.
559
615
  */
@@ -631,7 +687,7 @@ export class HostedProvider {
631
687
  * Everything between the vendor's answer and a computer that passed the read-back, whose value is what the read-back
632
688
  * recorded that does not refuse it (notes).
633
689
  */
634
- async #prepare(spec, ref, { labels, daemon, sha256, commands, user, runtime }, signal) {
690
+ async #prepare(spec, ref, { labels, daemon, sha256, commands, user }, signal) {
635
691
  const { uploadMs, execMs } = this.#timeouts;
636
692
  const running = await this.#running(ref, signal);
637
693
  if (!running.ok)
@@ -639,6 +695,15 @@ export class HostedProvider {
639
695
  const drift = this.#machineDrift(running.value, labels);
640
696
  if (drift.length > 0)
641
697
  return this.#fail("refused", `it did not match its spec: ${drift.join("; ")}`);
698
+ // Before anything of this create's is in the machine: what root runs is root's alone (the Archil helper's sha256,
699
+ // read at the mount's preflight, is read after this).
700
+ if ((this.host.facts.rootOnly ?? []).length > 0) {
701
+ const closed = await runToExit(this.host, ref.id, commands.rootOnly, { ms: execMs, ...(signal ? { signal } : {}), what: `making system paths root's alone in ${ref.name}` });
702
+ if (!closed.ok)
703
+ return closed;
704
+ if (closed.value.exitCode !== 0)
705
+ return this.#fail("refused", `making system paths root's alone failed (exit ${closed.value.exitCode}): ${`${closed.value.stdout} ${closed.value.stderr}`.trim().slice(0, 300)}`);
706
+ }
642
707
  const staging = commands.install[4];
643
708
  const bytes = new Uint8Array(daemon.buffer, daemon.byteOffset, daemon.byteLength);
644
709
  const upload = this.host.upload?.bind(this.host);
@@ -661,7 +726,9 @@ export class HostedProvider {
661
726
  // The run's folder, after the daemon is in place (serve runs it) and before init starts: no tool program runs before
662
727
  // it is mounted. A folder mounted for a computer create then gives up on is let go before the delete, never signalled.
663
728
  const started = async () => {
664
- const done = await this.#start(spec, ref, commands, { user, ...(runtime === undefined ? {} : { runtime }) }, signal);
729
+ const gpu = spec.gpu !== undefined;
730
+ const isolation = (gpu ? this.#configuration.gpu?.isolation : undefined) ?? this.host.facts.isolation;
731
+ const done = await this.#start(spec, ref, commands, { user, isolation, gpu }, signal);
665
732
  return done.ok && installer !== undefined ? ok([installer, ...done.value]) : done;
666
733
  };
667
734
  if (spec.mount?.kind !== "archil")
@@ -687,16 +754,15 @@ export class HostedProvider {
687
754
  async #start(spec, ref, commands, want, signal) {
688
755
  const closed = [];
689
756
  if (this.host.facts.daemon === "child") {
690
- // The vendor's own sockets outside /run, closed to the computer's user before any program of its runs.
691
- if (commands.sockets !== undefined) {
692
- const shut = await runToExit(this.host, ref.id, commands.sockets, { ms: this.#timeouts.execMs, ...(signal ? { signal } : {}), what: `closing ${this.#label}'s own sockets in ${ref.name}` });
693
- if (!shut.ok)
694
- return shut;
695
- if (shut.value.exitCode !== 0)
696
- return this.#fail("refused", `closing ${this.#label}'s own sockets to the computer's user failed (exit ${shut.value.exitCode}): ${`${shut.value.stdout} ${shut.value.stderr}`.trim().slice(0, 300)}`);
697
- const found = closedSocketsOf(shut.value.stdout);
698
- closed.push(`${this.#label}'s own sockets closed to the computer's user: ${found.join(", ") || `none found (${(this.host.facts.vendorSockets ?? []).join(", ")})`}`);
699
- }
757
+ // The session buses in /tmp, closed to the computer's user before any program of its runs.
758
+ const shut = await runToExit(this.host, ref.id, commands.sockets, { ms: this.#timeouts.execMs, ...(signal ? { signal } : {}), what: `closing the session buses in /tmp in ${ref.name}` });
759
+ if (!shut.ok)
760
+ return shut;
761
+ if (shut.value.exitCode !== 0)
762
+ return this.#fail("refused", `closing the session buses in /tmp to the computer's user failed (exit ${shut.value.exitCode}): ${`${shut.value.stdout} ${shut.value.stderr}`.trim().slice(0, 300)}`);
763
+ const found = closedSocketsOf(shut.value.stdout);
764
+ if (found.length > 0)
765
+ closed.push(`session buses in /tmp closed to the computer's user: ${found.join(", ")}`);
700
766
  const init = await runToExit(this.host, ref.id, commands.start, { ms: this.#timeouts.execMs, ...(signal ? { signal } : {}), what: `starting the daemon in ${ref.name}` });
701
767
  if (!init.ok)
702
768
  return init;
@@ -714,7 +780,7 @@ export class HostedProvider {
714
780
  try {
715
781
  const archil = spec.mount?.kind === "archil" ? { mount: { kind: "archil", disk: spec.mount.disk, region: spec.mount.region, folder: spec.mount.folder }, epoch: claimEpoch(spec.labels) } : undefined;
716
782
  const expected = archil === undefined ? undefined : { ...archil, expected: readBackOf({ ...archil.mount, token: "" }, archil.epoch) };
717
- const inside = await this.#checkInside(opened.value, ref.name, spec.network, true, want, signal, expected);
783
+ const inside = await this.#checkInside(opened.value, ref.name, networkOfForm(formOf(spec.network)), true, want, signal, expected);
718
784
  if (!inside.ok)
719
785
  return inside;
720
786
  notes = inside.value;
@@ -762,19 +828,17 @@ export class HostedProvider {
762
828
  const drift = [...found.value];
763
829
  const notes = [];
764
830
  let user;
765
- if (network === "none") {
766
- const probe = await this.#probe(current, name, signal);
767
- if (!probe.ok)
768
- return probe;
769
- user = `${probe.value.uid}:${probe.value.gid}`;
770
- drift.push(...probeNetworkDrift(probe.value));
771
- if (want.runtime !== undefined)
772
- drift.push(...runtimeDrift(want.runtime, probe.value.kernel));
773
- notes.push(...probeNotes(probe.value, network));
831
+ if (typeof network === "string" || !("other" in network)) {
832
+ const read = await this.#networkDrift(current, name, network, signal);
833
+ if (!read.ok)
834
+ return read;
835
+ user = `${read.value.probe.uid}:${read.value.probe.gid}`;
836
+ drift.push(...read.value.drift, ...runtimeDrift(want, read.value.probe.kernel));
837
+ notes.push(...probeNotes(read.value.probe, network));
774
838
  }
775
839
  // Which way init fenced its programs, as hello read it back: said once a way other than the plain one was taken.
776
840
  if (starting && current.hello.fence === "userns-netns") {
777
- notes.push(`fence: userns-netns: init made its programs' network namespace inside a user namespace of its own, as root on ${want.runtime ?? "this machine"} may not make one itself`);
841
+ notes.push(`fence: userns-netns: init made its programs' network namespace inside a user namespace of its own, as root on ${want.isolation ?? "this machine"} may not make one itself`);
778
842
  }
779
843
  const said = user === undefined ? {} : { user };
780
844
  if (archil === undefined)
@@ -820,10 +884,44 @@ export class HostedProvider {
820
884
  await pause(LISTEN_RETRY_MS, signal);
821
885
  }
822
886
  }
823
- /** `computerd probe` through the daemon, so it runs as the computer's own user. */
824
- async #probe(connection, name, signal) {
887
+ /**
888
+ * Its tools' network as they meet it, against the one create made: the probe, as the computer's own user. Under none,
889
+ * no target answers. Under open or a list, still none answers directly (their own loopback alone), init's relay
890
+ * answers (the one way out, to the proxy), and the proxy's policy beside its socket holds the form create asked for.
891
+ */
892
+ async #networkDrift(connection, name, network, signal) {
893
+ if (network === "none") {
894
+ const probe = await this.#probe(connection, name, signal);
895
+ return probe.ok ? ok({ drift: probeNetworkDrift(probe.value), probe: probe.value }) : probe;
896
+ }
897
+ const probe = await this.#probe(connection, name, signal, [...this.#probeTargets, EGRESS_RELAY]);
898
+ if (!probe.ok)
899
+ return probe;
900
+ const form = formOf(network);
901
+ const drift = [];
902
+ const direct = probe.value.reached.filter((target) => target !== EGRESS_RELAY);
903
+ if (direct.length > 0)
904
+ drift.push(`network: declared ${form} through the egress proxy alone, read back a direct answer from ${direct.join(", ")}`);
905
+ if (!probe.value.reached.includes(EGRESS_RELAY))
906
+ drift.push(`network: declared ${form} through the egress proxy, and init's relay at ${EGRESS_RELAY} did not answer from inside`);
907
+ const { helloMs } = this.#timeouts;
908
+ const policy = await connection.client.call("files.read", { path: EGRESS_POLICY }, { signal: bounded(helloMs, signal) });
909
+ if (!policy.ok) {
910
+ if (policy.error.code === "aborted")
911
+ return signal?.aborted ? this.#fail("aborted", `reading ${EGRESS_POLICY} in ${name} was aborted`) : this.#fail("timeout", `reading ${EGRESS_POLICY} in ${name} did not answer within ${seconds(helloMs)}`);
912
+ drift.push(`network: declared ${form}, and the egress proxy's policy ${EGRESS_POLICY} could not be read: ${policy.error.message}`);
913
+ }
914
+ else {
915
+ const served = Buffer.from(policy.value.data, "base64").toString("utf8");
916
+ if (served !== `${form}\n`)
917
+ drift.push(`network: declared ${form}, the egress proxy serves ${show(served.trim().slice(0, 300))}`);
918
+ }
919
+ return ok({ drift, probe: probe.value });
920
+ }
921
+ /** `computerd probe` through the daemon, so it runs as the computer's own user: to targets, the configured ones by default. */
922
+ async #probe(connection, name, signal, targets = this.#probeTargets) {
825
923
  const { probeMs } = this.#timeouts;
826
- const argv = [DAEMON_IN_COMPUTER, "probe", ...this.#probeTargets.flatMap((target) => ["--connect", target])];
924
+ const argv = [DAEMON_IN_COMPUTER, "probe", ...targets.flatMap((target) => ["--connect", target])];
827
925
  const ran = await connection.client.call("exec.run", { argv, timeoutMs: probeMs }, { signal: bounded(probeMs + CALL_SLACK_MS, signal) });
828
926
  if (!ran.ok) {
829
927
  if (signal?.aborted)
@@ -959,8 +1057,9 @@ export class HostedProvider {
959
1057
  if (deadline === undefined)
960
1058
  found.push(`deadline: the label ${DEADLINE_LABEL} reads ${show(machine.labels[DEADLINE_LABEL])}, not the ISO time create writes`);
961
1059
  const archil = recordedArchil(machine.labels);
962
- // Its tools' network is none, read from inside (#checkInside's probe): no vendor's read of it is taken.
963
- const network = "none";
1060
+ // Its tools' network as create recorded it, read from inside (#checkInside: the probe, and the proxy's policy):
1061
+ // no vendor's read of it is taken.
1062
+ const network = networkOfForm(machine.labels[NETWORK_LABEL]);
964
1063
  const image = machine.labels[IMAGE_LABEL] ?? "";
965
1064
  const spec = { image, lifetimeMs: 1, network, labels: callerLabels(machine.labels) };
966
1065
  found.push(...this.check(spec).map(({ field, message }) => `${field}: ${message}, read back from the computer`));
@@ -975,7 +1074,7 @@ export class HostedProvider {
975
1074
  try {
976
1075
  // A host that takes a spec's user made this computer's daemon run as the one its spec named: read back, never root
977
1076
  // (an Archil computer's is the tool user); every other runs as the provider's daemon user.
978
- const want = this.#takesUser() ? (archil === undefined ? {} : { user: ARCHIL_USER }) : { user: `${this.#uid}:${this.#gid}` };
1077
+ const want = this.#takesUser ? (archil === undefined ? {} : { user: ARCHIL_USER }) : { user: `${this.#uid}:${this.#gid}` };
979
1078
  const inside = await this.#checkInside(opened.value, name, network, false, want, signal, archil);
980
1079
  if (!inside.ok && inside.error.code !== "refused")
981
1080
  return inside;
@@ -1000,13 +1099,13 @@ export class HostedProvider {
1000
1099
  ...ref,
1001
1100
  spec: {
1002
1101
  image,
1003
- user: (this.#takesUser() ? user : undefined) ?? `${this.#uid}:${this.#gid}`,
1102
+ user: (this.#takesUser ? user : undefined) ?? `${this.#uid}:${this.#gid}`,
1004
1103
  network,
1005
1104
  workdir: WORK,
1006
1105
  ...(deadline === undefined ? {} : { deadline }),
1007
1106
  ...(kind === undefined ? {} : { kind }),
1008
1107
  ...(mount === undefined ? {} : { mount }),
1009
- ...(machine.gpu === undefined ? {} : { gpu: machine.gpu }),
1108
+ ...gpuOf(machine.labels[GPU_LABEL]),
1010
1109
  },
1011
1110
  ...(notes.length > 0 ? { notes } : {}),
1012
1111
  });
@@ -1021,8 +1120,8 @@ export class HostedProvider {
1021
1120
  }
1022
1121
  /**
1023
1122
  * Every computer this provider made that carries all of these labels, running or stopped: the listing finds them, and
1024
- * a get of each reads its state, labels and end (foundBy). Its network is none, as create made it and the probe reads
1025
- * it from inside.
1123
+ * a get of each reads its state, labels and end (foundBy). Its network is the one its label records, as create made
1124
+ * it (none without one); attach and network() read it from inside.
1026
1125
  */
1027
1126
  async list(labels, { signal } = {}) {
1028
1127
  const problem = filterProblem(labels);
@@ -1043,52 +1142,52 @@ export class HostedProvider {
1043
1142
  labels: { ...machine.labels },
1044
1143
  deadline: deadlineOf(machine),
1045
1144
  state: machine.state,
1046
- network: "none",
1145
+ network: networkOfForm(machine.labels[NETWORK_LABEL]),
1047
1146
  ...(archil === undefined ? {} : { mount: archil.expected }),
1048
1147
  });
1049
1148
  }
1050
1149
  return ok(infos);
1051
1150
  }
1052
- /** The probe reads the policy back from inside. A change is refused: the network is fixed at create. */
1151
+ /** The probe and the proxy's policy read the network back from inside. A change is refused: it is fixed at create. */
1053
1152
  async network(ref, policy, { signal } = {}) {
1054
1153
  const problem = this.#refProblem(ref);
1055
1154
  if (problem)
1056
1155
  return this.#fail("invalid", problem);
1057
1156
  const fixed = `${a(this.#label)} computer's network is fixed at create: create a new computer`;
1058
- if (policy !== undefined && policy !== "none") {
1059
- const wider = policy === "open" || (typeof policy === "object" && policy !== null && "allow" in policy);
1060
- return this.#fail("refused", wider ? `${OWN_NETWORK_ONLY}; ${fixed}` : `${fixed}; a network is "none"`);
1061
- }
1157
+ const refused = policy === undefined ? undefined : networkRefusal(this.#label, this.capabilities().network, policy);
1158
+ if (refused)
1159
+ return this.#fail("refused", `${refused}; ${fixed}`);
1062
1160
  const found = await this.#own(ref, signal);
1063
1161
  if (!found.ok)
1064
1162
  return found;
1065
- let read = "none";
1066
- // Its tools' none is read from inside, as the tool user, whatever the vendor's network is (an Archil computer's root
1067
- // reaches Archil): the daemon's own network namespace's live interfaces are lo alone, none can be raised (computerd
1068
- // probe), and no probe target answers.
1069
- if (found.value.state === "running") {
1163
+ const recorded = networkOfForm(found.value.labels[NETWORK_LABEL]);
1164
+ let read = recorded;
1165
+ // Its tools' network is read from inside, as the tool user, whatever the vendor's network is (an Archil computer's
1166
+ // root reaches Archil, an open one's proxy the internet): the daemon's own network namespace's live interfaces are
1167
+ // lo alone, none can be raised (computerd probe), no probe target answers directly, and an open or listed one's
1168
+ // relay and proxy serve what its label records.
1169
+ if (found.value.state === "running" && (typeof recorded === "string" || !("other" in recorded))) {
1070
1170
  const opened = await this.#open(ref, signal);
1071
1171
  if (!opened.ok)
1072
1172
  return opened;
1073
1173
  try {
1074
- const drift = await readOwnNetwork(opened.value.client, this.#timeouts.helloMs, bounded(this.#timeouts.helloMs, signal));
1174
+ const own = await readOwnNetwork(opened.value.client, this.#timeouts.helloMs, bounded(this.#timeouts.helloMs, signal));
1175
+ if (!own.ok)
1176
+ return this.#fail(own.error.code, `${ref.name}: ${own.error.message}`);
1177
+ const drift = await this.#networkDrift(opened.value, ref.name, recorded, signal);
1075
1178
  if (!drift.ok)
1076
- return this.#fail(drift.error.code, `${ref.name}: ${drift.error.message}`);
1077
- if (drift.value.length > 0)
1078
- read = { other: drift.value.join("; ") };
1079
- const probe = await this.#probe(opened.value, ref.name, signal);
1080
- if (!probe.ok)
1081
- return probe;
1082
- if (probe.value.reached.length > 0)
1083
- read = { other: `its tools' network was created none, yet from inside an answer came back from ${probe.value.reached.join(", ")}` };
1179
+ return drift;
1180
+ const found = [...own.value, ...drift.value.drift];
1181
+ if (found.length > 0)
1182
+ read = { other: `its tools' network was created ${policyWords(recorded)}, yet from inside: ${found.join("; ")}` };
1084
1183
  }
1085
1184
  finally {
1086
1185
  await opened.value.close();
1087
1186
  }
1088
1187
  }
1089
- if (policy === undefined || policy === read)
1188
+ if (policy === undefined || isDeepStrictEqual(networkOfForm(formOf(policy)), read))
1090
1189
  return ok(read);
1091
- return this.#fail("refused", `${fixed}: ${ref.name} reads back network ${policyWords(read)}, not ${policy}`);
1190
+ return this.#fail("refused", `${fixed}: ${ref.name} reads back network ${policyWords(read)}, not ${policyWords(policy)}`);
1092
1191
  }
1093
1192
  /** One extend of a computer at a time, each reading the deadline the one before it left. */
1094
1193
  async #extendSerial(ref, ttlMs, signal) {
@@ -1140,12 +1239,12 @@ export class HostedProvider {
1140
1239
  return this.#fail("unsupported", `${a(this.#label)} computer's deadline cannot move`);
1141
1240
  const moved = await this.#call(`${this.#label}'s end of ${ref.name}`, (ctx) => extend(ref.id, new Date(target), ctx), this.#timeouts.requestMs, signal);
1142
1241
  if (!moved.ok)
1143
- return moved.error.code === "limit" ? moved : this.#fail(moved.error.code, `${this.#label}'s end did not move, so nothing did: ${moved.error.message}`);
1242
+ return moved.error.code === "limit" ? moved : this.#fail(moved.error.code, `${this.#label} did not move ${ref.name}'s end, so nothing did: ${moved.error.message}`);
1144
1243
  const after = await this.#get(ref.id, signal);
1145
1244
  const end = after.ok && after.value !== undefined ? deadlineOf(after.value) : undefined;
1146
1245
  if (end === undefined) {
1147
- const why = after.ok ? `${ref.name} read back with no end` : after.error.message;
1148
- return this.#fail(after.ok ? "gone" : after.error.code, `${this.#label}'s end was asked to move, and reading it back failed: ${why}; init's deadline did not move`);
1246
+ const why = !after.ok ? after.error.message : after.value === undefined ? `${ref.name} is gone` : `${ref.name} reads back no deadline`;
1247
+ return this.#fail(!after.ok ? after.error.code : after.value === undefined ? "gone" : "refused", `${this.#label} was asked to move ${ref.name}'s end, and reading it back failed: ${why}; init's deadline did not move`);
1149
1248
  }
1150
1249
  const opened = await this.#open(ref, signal);
1151
1250
  if (!opened.ok)
@@ -1387,13 +1486,13 @@ function oldestFirst(machines) {
1387
1486
  const byId = (a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
1388
1487
  return (a, b) => (dated && at(a) !== at(b) ? at(a) - at(b) : byId(a, b));
1389
1488
  }
1390
- /** The probe's kernel against the runtime declared: gVisor exactly where the host runs one (a pid1 host's GPU), a VM's elsewhere. */
1391
- function runtimeDrift(runtime, kernel) {
1489
+ /** The probe's kernel against the isolation declared: gVisor exactly where it says gvisor, never where it says vm. */
1490
+ function runtimeDrift({ isolation, gpu }, kernel) {
1392
1491
  const gvisor = /gvisor/i.test(kernel);
1393
- if (runtime === "vm" && gvisor)
1492
+ if (isolation === "vm" && gvisor)
1394
1493
  return [`runtime: declared vm, read back gVisor (the kernel reports ${JSON.stringify(kernel)})`];
1395
- if (runtime === "gvisor" && !gvisor)
1396
- return [`runtime: declared gVisor (a GPU computer), read back another kernel (${JSON.stringify(kernel)})`];
1494
+ if (isolation === "gvisor" && !gvisor)
1495
+ return [`runtime: declared gVisor${gpu ? " (a GPU computer)" : ""}, read back another kernel (${JSON.stringify(kernel)})`];
1397
1496
  return [];
1398
1497
  }
1399
1498
  function labelProblem(key, value) {
@@ -1413,3 +1512,12 @@ function labelProblem(key, value) {
1413
1512
  function a(label) {
1414
1513
  return `${/^[AEIOU]/i.test(label) ? "an" : "a"} ${label}`;
1415
1514
  }
1515
+ /** A spec's network as init's form (networkFormOf): "" for none, and for a network check() refuses. */
1516
+ function formOf(network) {
1517
+ try {
1518
+ return networkFormOf(network);
1519
+ }
1520
+ catch {
1521
+ return "";
1522
+ }
1523
+ }