@parcha/agentrun-computer 0.1.0-beta.40 → 0.1.0-beta.41

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 (48) hide show
  1. package/README.md +31 -14
  2. package/box/Dockerfile +6 -4
  3. package/box/README.md +8 -0
  4. package/box/build-daytona.py +3 -1
  5. package/box/install.sh +68 -7
  6. package/dist/attach.d.ts +46 -1
  7. package/dist/attach.js +48 -4
  8. package/dist/box-image.d.ts +2 -0
  9. package/dist/box-image.js +10 -0
  10. package/dist/computerd-linux-amd64 +0 -0
  11. package/dist/computerd-linux-arm64 +0 -0
  12. package/dist/computerd.json +2 -2
  13. package/dist/conformance/cases/provider.js +42 -26
  14. package/dist/conformance/cli.js +4 -1
  15. package/dist/conformance/daytona.d.ts +25 -0
  16. package/dist/conformance/daytona.js +26 -1
  17. package/dist/conformance/exec-stream.js +14 -6
  18. package/dist/conformance/runner.js +8 -4
  19. package/dist/conformance/sweep.d.ts +7 -2
  20. package/dist/conformance/sweep.js +17 -7
  21. package/dist/conformance/types.d.ts +21 -0
  22. package/dist/daytona.d.ts +8 -1
  23. package/dist/daytona.js +124 -101
  24. package/dist/descriptor.d.ts +22 -1
  25. package/dist/descriptor.js +18 -0
  26. package/dist/descriptors/daytona.d.ts +12 -3
  27. package/dist/descriptors/daytona.js +15 -7
  28. package/dist/descriptors/index.d.ts +8 -1
  29. package/dist/e2b.js +1 -1
  30. package/dist/host.d.ts +61 -37
  31. package/dist/hosted/framed-exec.d.ts +8 -19
  32. package/dist/hosted/framed-exec.js +21 -87
  33. package/dist/hosted/process.d.ts +2 -0
  34. package/dist/hosted/process.js +9 -2
  35. package/dist/hosted/provider.d.ts +41 -4
  36. package/dist/hosted/provider.js +289 -115
  37. package/dist/hosted/rest.d.ts +19 -0
  38. package/dist/hosted/rest.js +76 -0
  39. package/dist/hosted/scripts.d.ts +50 -0
  40. package/dist/hosted/scripts.js +116 -1
  41. package/dist/hosted/ssh-exec.d.ts +7 -6
  42. package/dist/hosted/ssh-exec.js +35 -52
  43. package/dist/index.d.ts +2 -2
  44. package/dist/index.js +2 -2
  45. package/dist/kinds.d.ts +2 -0
  46. package/dist/modal.js +21 -8
  47. package/dist/providers.d.ts +4 -2
  48. package/package.json +1 -1
@@ -11,6 +11,8 @@ import { readFileSync } from "node:fs";
11
11
  import { resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { isDeepStrictEqual } from "node:util";
14
+ import { ATTACH_PATH, DAEMON_PATH } from "../attach.js";
15
+ import { isBoxImage } from "../box-image.js";
14
16
  import { CreateRequests, endedWords, otherSpecWords, readBackDiffer } from "../create-requests.js";
15
17
  import { desktopOf, startDisplay } from "../desktop.js";
16
18
  import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, show, WORK } from "../drift.js";
@@ -25,10 +27,10 @@ import { failFor, ok } from "../result.js";
25
27
  import { daemonWatch } from "../screen-watch.js";
26
28
  import { countTested } from "../test-connection.js";
27
29
  import { waitUntil } from "../wait.js";
28
- import { bounded, CALL_SLACK_MS, hostCall, OUTPUT_MAX, openBridge, pause, rootOf, runToExit, seconds, uploadThroughExec } from "./process.js";
29
- import { isWhole, packLabels } from "./values.js";
30
+ import { bounded, CALL_SLACK_MS, hostCall, OUTPUT_MAX, openBridge, pause, rootOf, runToExit, seconds, uploadThroughExec, words } from "./process.js";
31
+ import { isWhole, PACKED_NAME, packLabels, unpackLabels } from "./values.js";
30
32
  import { EGRESS_POLICY, EGRESS_PROXY_USER, EGRESS_RELAY, HOSTED_ALLOW, NETWORK_LABEL, networkFormOf, networkOfForm, networkRefusal, throughProxy } from "./network.js";
31
- import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, installerOf, LABEL_FILE, labelsCommand } from "./scripts.js";
33
+ import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, initFlags, installerOf, LABEL_FILE, labelsCommand } from "./scripts.js";
32
34
  const VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
33
35
  export const NAME_LABEL = `${COMPUTER_LABEL}.name`;
34
36
  /** The image create was asked for: a vendor may report another name for it (a template's id). */
@@ -72,6 +74,15 @@ const START_POLL_MS = 500;
72
74
  * timeouts, and the vendor's clock against this one's.
73
75
  */
74
76
  const UNFILED_MARGIN_MS = 300_000;
77
+ /**
78
+ * The computerd build a hosted machine of arch runs: HostedProvider's default daemonPath, and the file serve's daemon
79
+ * route serves, so the sha256 a dial machine checks (AGENTRUN_DAEMON_SHA256) is this file's.
80
+ */
81
+ export function hostedDaemonPath(arch) {
82
+ return fileURLToPath(new URL(`../computerd-linux-${arch}`, import.meta.url));
83
+ }
84
+ /** The dial creates in flight per request name, keyed by the server's AttachHub (#inTurn). */
85
+ const DIAL_TURNS = new WeakMap();
75
86
  /** The longest a Node timer or AbortSignal.timeout holds. */
76
87
  const MAX_TIMER_MS = 2 ** 31 - 1;
77
88
  /** The longest timeout the adapter takes: the race of a call bounded by it must still fit a Node timer. */
@@ -164,6 +175,8 @@ export class HostedProvider {
164
175
  #uid;
165
176
  #gid;
166
177
  #timeouts;
178
+ /** What foundBy reads with: the timeouts, onNote, which hears of a machine a listing leaves out, and the image option. */
179
+ #finding;
167
180
  #probeTargets;
168
181
  #onNote;
169
182
  #archilEgress;
@@ -172,10 +185,10 @@ export class HostedProvider {
172
185
  #requests = new CreateRequests();
173
186
  /** Each computer's last extend, by machine id, while one runs: the next waits for it. */
174
187
  #extending = new Map();
175
- /** Each held computer's keepalive timer, by machine id (facts.idleMs). */
176
- #kept = new Map();
188
+ /** A dial host's server: what its machines reach, and what holds their tokens and sockets. */
189
+ #dial;
177
190
  constructor(host, options) {
178
- 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;
191
+ const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = hostedDaemonPath(host.facts.arch), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress, image, } = options;
179
192
  const { id, label, capabilities } = host.descriptor;
180
193
  if (kind !== "desktop" && kind !== "linux")
181
194
  throw new Error(`kind is desktop or linux, not ${String(kind)}`);
@@ -192,16 +205,22 @@ export class HostedProvider {
192
205
  if (!isWhole(maxLifetimeMs) || maxLifetimeMs <= 0 || maxLifetimeMs > host.facts.maxLifetimeMs) {
193
206
  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`);
194
207
  }
195
- const { idleMs } = host.facts;
196
- if (idleMs !== undefined && (!isWhole(idleMs) || idleMs <= 0 || idleMs > MAX_TIMER_MS))
197
- throw new Error(`facts.idleMs must be a whole number of ms above 0 and at most ${MAX_TIMER_MS}, not ${idleMs}`);
198
- if (idleMs !== undefined && !host.keepalive) {
199
- throw new Error(`${label} declares an idle timer (facts.idleMs ${idleMs}) and no keepalive, so a quiet computer would end under its run: give the host keepalive, the vendor's call that restarts the timer`);
208
+ if (host.facts.connect === "dial") {
209
+ // Every connection goes over the socket the machine dials: nothing reaches into it from here.
210
+ if (host.facts.labels === "machine")
211
+ throw new Error(`${label}'s machines dial this server (facts.connect "dial") and keep no labels (facts.labels "machine"), which are read through exec: keep its labels in vendor tags or packed`);
212
+ if (host.exec || host.upload)
213
+ throw new Error(`${label}'s machines dial this server (facts.connect "dial"), so its host has no exec and no upload: leave them out`);
214
+ if (kind === "desktop")
215
+ throw new Error(`${label}'s machines dial this server (facts.connect "dial"), and agentrun-dial starts init with no display: make it kind linux`);
200
216
  }
201
- // A machine whose create was cut off before its labels were written carries none the janitor lists: only a vendor's
202
- // timer ends it, at its deadline (lifetime vendor) or at the backstop.
203
- if (host.facts.labels === "machine" && host.facts.lifetime !== "vendor" && host.facts.backstop !== true) {
204
- throw new Error(`${label} keeps no labels (facts.labels "machine"), so a vendor timer must end its machines: a machine whose create stopped before its labels were written has none the janitor lists. Declare lifetime "vendor", or set the vendor's delete timer from req.backstopAt and declare backstop: true`);
217
+ // A machine whose create was cut off before its labels were written carries none the janitor lists: only the vendor's
218
+ // timer ends it. And the most a computer may live, which bounds an extend, would be read from inside the machine.
219
+ if (host.facts.labels === "machine" && host.facts.lifetime !== "vendor") {
220
+ throw new Error(`${label} keeps no labels (facts.labels "machine"), so its vendor's timer must end its machines: a machine whose create stopped before its labels were written has none the janitor lists. Declare lifetime "vendor"`);
221
+ }
222
+ if (host.facts.labels === "machine" && host.extend) {
223
+ throw new Error(`${label} keeps no labels (facts.labels "machine") and has extend: the most a computer may live, which bounds an extend, would be read from a file inside the machine. Leave extend out: its computers end at the deadline create gave them`);
205
224
  }
206
225
  const user = USER.exec(daemonUser);
207
226
  if (user === null || Number(user[1]) > MAX_ID || Number(user[2]) > MAX_ID)
@@ -227,7 +246,11 @@ export class HostedProvider {
227
246
  this.#maxLifetimeMs = maxLifetimeMs;
228
247
  [this.#uid, this.#gid] = [String(Number(user[1])), String(Number(user[2]))];
229
248
  this.#timeouts = merged;
249
+ if (image !== undefined && (typeof image !== "string" || image === ""))
250
+ throw new Error(`image names the image this provider's computers start from, not ${JSON.stringify(image)}`);
251
+ this.#finding = { ...merged, onNote, image };
230
252
  this.#probeTargets = [...probeTargets];
253
+ this.#dial = host.facts.connect === "dial" ? options.dial : undefined;
231
254
  // Extend only where the end can follow it: the host moves its timer or its deadline label.
232
255
  if (host.extend)
233
256
  this.extend = (ref, ttlMs, context) => this.#extendSerial(ref, ttlMs, context?.signal);
@@ -250,7 +273,7 @@ export class HostedProvider {
250
273
  groups: [...this.#configuration.groups],
251
274
  maxLifetimeMs: this.#maxLifetimeMs,
252
275
  release: ["delete"],
253
- mount: [...descriptor.mounts],
276
+ mount: descriptor.mounts.filter((kind) => !(this.#dialing && kind === "archil")),
254
277
  vendorAgentPorts: [...facts.vendorAgentPorts],
255
278
  ...(gpu === undefined ? {} : { gpu: structuredClone(gpu) }),
256
279
  ...(facts.user === undefined ? {} : { user: [...facts.user] }),
@@ -265,7 +288,9 @@ export class HostedProvider {
265
288
  const label = this.#label;
266
289
  // An Archil mount's own rules hold only where the provider takes one; elsewhere checkMount's refusal says why alone.
267
290
  const archil = mount?.kind === "archil" && (capabilities.mount ?? []).includes("archil");
268
- refusals.push(...checkMount(mount, capabilities.mount ?? [], this.host.descriptor.unmounted), ...(archil ? archilRefusals(given) : []));
291
+ // A machine that dials takes no Archil mount yet: its helper's steps run as root through exec, which it has none of.
292
+ const unmounted = this.#dialing ? { ...this.host.descriptor.unmounted, archil: `${label}'s machines dial this server, and a machine that dials takes no Archil mount yet` } : this.host.descriptor.unmounted;
293
+ refusals.push(...checkMount(mount, capabilities.mount ?? [], unmounted), ...(archil ? archilRefusals(given) : []));
269
294
  const daemonUser = `${this.#uid}:${this.#gid}`;
270
295
  const asked = this.#takesUser ? given.user : undefined;
271
296
  if (asked !== undefined) {
@@ -287,6 +312,10 @@ export class HostedProvider {
287
312
  }
288
313
  if (typeof image !== "string" || image === "" || image.includes("\0"))
289
314
  refuse("image", `an image is required: the name of ${a(label)} image`);
315
+ else if (this.#keeps && !ourImage({ image }, this.#finding.image)) {
316
+ // list reads labels only in a machine of our image, so a computer of another would never be found again.
317
+ refuse("image", `${a(label)} computer keeps its labels inside the machine, and list reads them only in one of this provider's image option or a box image, so ${image} is refused: ${this.#finding.image === undefined ? "ask for a box image" : `ask for ${this.#finding.image} or a box image`}`);
318
+ }
290
319
  refusals.push(...checkTenure(given, capabilities, label));
291
320
  // Only the forms the descriptor declares, each one this computer enforces; any other is refused, never widened.
292
321
  const networkProblem = networkRefusal(label, capabilities.network, network);
@@ -318,6 +347,59 @@ export class HostedProvider {
318
347
  refusals.push(...this.host.check(given));
319
348
  return refusals;
320
349
  }
350
+ /** Whether the host's machines dial this server (facts.connect "dial"): every connection goes over that socket. */
351
+ get #dialing() {
352
+ return this.host.facts.connect === "dial";
353
+ }
354
+ /**
355
+ * Where a dial host's machines reach this server: its attach route as ws(s) and its daemon route, from dial.url, an
356
+ * https address (http only on 127.0.0.1, for tests); or the refusal of a create, in words, where it has none or where
357
+ * the provider was given no dial (no hub, so no process to take the machine's socket).
358
+ */
359
+ #dialed() {
360
+ if (this.#dial === undefined) {
361
+ return { problem: `${this.#label} machines dial in to this server, and this process has no attach hub: start them from serve's own process` };
362
+ }
363
+ const url = this.#dial.url;
364
+ const at = URL.canParse(url ?? "") ? new URL(url) : undefined;
365
+ if (at === undefined || !(at.protocol === "https:" || (at.protocol === "http:" && at.hostname === "127.0.0.1"))) {
366
+ return {
367
+ problem: `${this.#label} machines dial this server, and it has no public https address: set AGENTRUN_PUBLIC_URL to one the internet reaches (a tunnel such as cloudflared or tailscale funnel works), or use a provider whose host has exec`,
368
+ };
369
+ }
370
+ // From the parsed address, whose scheme and host are lowercase: "HTTPS://Example.com/" is https://example.com.
371
+ const path = at.pathname.replace(/\/+$/, "");
372
+ return {
373
+ attach: `${at.protocol === "https:" ? "wss:" : "ws:"}//${at.host}${path}${ATTACH_PATH}`,
374
+ daemon: `${at.origin}${path}${DAEMON_PATH}?arch=${this.host.facts.arch}`,
375
+ dial: this.#dial,
376
+ };
377
+ }
378
+ /**
379
+ * A dial machine's token revoked, then its socket closed, best effort: the token first, so a redial while the revoke
380
+ * is written can't stay attached after the close. A token not revoked is refused past backstopAt.
381
+ */
382
+ async #revoke(name) {
383
+ const dial = this.#dial;
384
+ if (dial === undefined)
385
+ return;
386
+ const { requestMs } = this.#timeouts;
387
+ const said = (why) => this.#onNote?.({ computer: name, note: `its machine token could not be revoked (${why}): it is refused past the machine's backstop either way` });
388
+ let timer;
389
+ try {
390
+ // Bounded by requestMs: a store that never answers must not hold the socket open or the vendor's delete back.
391
+ const late = await Promise.race([dial.tokens.revoke(name).then(() => false), new Promise((done) => (timer = setTimeout(done, requestMs, true)))]);
392
+ if (late)
393
+ said(`the token store did not answer within ${requestMs / 1000} s`);
394
+ }
395
+ catch (error) {
396
+ said(words(error));
397
+ }
398
+ finally {
399
+ clearTimeout(timer);
400
+ dial.hub.revoke(name, `${name} was deleted`);
401
+ }
402
+ }
321
403
  /** Whether the host keeps no labels (facts.labels "machine"): the adapter keeps them in the machine, at LABEL_FILE. */
322
404
  get #keeps() {
323
405
  return this.host.facts.labels === "machine";
@@ -373,7 +455,7 @@ export class HostedProvider {
373
455
  const room = this.host.facts.labels ?? {};
374
456
  // Stand-ins as long as create's name and deadlines and as mixed, fixed so a spec's answer never changes (attach and a
375
457
  // retry check the spec again): a packed map deflates them as it does create's, give or take a byte, and create packs
376
- // its own before the host's call (#packedOver).
458
+ // its own before the host's call (#stored).
377
459
  const name = "computer-5f3a9c1e7b2d";
378
460
  const labels = this.#labelsOf(spec, name, "2026-11-16T04:15:29.481Z", "2026-11-17T04:05:29.481Z");
379
461
  if (room === "machine") {
@@ -383,8 +465,8 @@ export class HostedProvider {
383
465
  }
384
466
  const { count, bytes: max, packed } = room;
385
467
  if (packed) {
386
- const why = this.#packedOver(labels, name);
387
- return why === undefined ? undefined : { bytes: true, why };
468
+ const fit = this.#stored(labels, name);
469
+ return "problem" in fit ? { bytes: true, why: fit.problem } : undefined;
388
470
  }
389
471
  const keys = Object.keys(labels);
390
472
  if (count !== undefined && keys.length > count) {
@@ -400,11 +482,13 @@ export class HostedProvider {
400
482
  return undefined;
401
483
  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)}` };
402
484
  }
403
- /** Why labels don't fit packed (facts.labels.packed), in words; undefined when they fit or the host keeps them as they are. */
404
- #packedOver(labels, name) {
405
- const room = this.host.facts.labels;
406
- const fit = room !== "machine" && room?.packed ? packLabels(labels, name, room) : { labels };
407
- return "problem" in fit ? `${a(this.#label)} computer keeps its labels packed, and ${fit.problem}: ${shorterWords(labels)}` : undefined;
485
+ /** The labels as the host is given them: packed where it declares facts.labels.packed, else as they are; or why they don't fit packed, in words. */
486
+ #stored(labels, name) {
487
+ const room = packedRoom(this.host);
488
+ if (room === undefined)
489
+ return { labels };
490
+ const fit = packLabels(labels, name, room);
491
+ return "problem" in fit ? { problem: `${a(this.#label)} computer keeps its labels packed, and ${fit.problem}: ${shorterWords(labels)}` } : fit;
408
492
  }
409
493
  /** A host call bounded by ms, the caller's signal when given. */
410
494
  #call(what, run, ms, signal) {
@@ -418,6 +502,10 @@ export class HostedProvider {
418
502
  * for the first and answers what it does.
419
503
  */
420
504
  async create(spec, context) {
505
+ // Before any call to the vendor, so a machine that could never reach this server is never made or billed.
506
+ const dialed = this.#dialing ? this.#dialed() : undefined;
507
+ if (dialed !== undefined && "problem" in dialed)
508
+ return this.#fail("refused", dialed.problem);
421
509
  const refusals = this.check(spec);
422
510
  return this.#requests.create(spec, context, {
423
511
  refuse: (code, message) => this.#fail(code, message),
@@ -425,9 +513,37 @@ export class HostedProvider {
425
513
  // The checks #again makes of a computer listed already, made here of the spec in flight: what it gives is shared
426
514
  // only with a create that asks the same.
427
515
  userOf: (asked) => this.#userOf(asked),
428
- make: (name) => this.#createOnce(spec, name, context.signal),
516
+ make: (name) => (dialed === undefined ? this.#createOnce(spec, name, context.signal) : this.#inTurn(dialed.dial.hub, name, context.signal, () => this.#createOnce(spec, name, context.signal))),
429
517
  });
430
518
  }
519
+ /**
520
+ * A dial create of one request after any other of it on this server, whichever provider instance makes it. A
521
+ * machine's token and socket go by the request's name, so two machines of one request must never dial at once: the
522
+ * second create finds the first's computer instead (#createOnce). One server process is what dial asks for. A caller
523
+ * that aborts while it waits stops waiting; the turn after it still waits for the create before it.
524
+ */
525
+ async #inTurn(hub, name, signal, make) {
526
+ const turns = DIAL_TURNS.get(hub) ?? new Map();
527
+ DIAL_TURNS.set(hub, turns);
528
+ const before = turns.get(name) ?? Promise.resolve();
529
+ let done = () => { };
530
+ const mine = before.then(() => new Promise((resolve) => (done = resolve)));
531
+ turns.set(name, mine);
532
+ try {
533
+ if ((await untilAborted(before.then(() => true), [signal])) === undefined) {
534
+ return this.#fail("aborted", "create was aborted while another create of this request was in flight");
535
+ }
536
+ return await make();
537
+ }
538
+ finally {
539
+ // Once before has settled: a turn that stopped waiting holds the next one no longer than the create before it.
540
+ void before.then(() => done());
541
+ void mine.then(() => {
542
+ if (turns.get(name) === mine)
543
+ turns.delete(name);
544
+ });
545
+ }
546
+ }
431
547
  /** A request's computer given up on or deleted: its request is refused from now on. */
432
548
  #end(name) {
433
549
  this.#requests.end(name);
@@ -446,7 +562,7 @@ export class HostedProvider {
446
562
  }
447
563
  /** taken: the vendor refused this create's name as one a machine has (exists), so the name's machine is read once more. */
448
564
  async #createOnce(spec, name, signal, taken) {
449
- const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal);
565
+ const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#finding, signal);
450
566
  if (!listed.ok)
451
567
  return listed;
452
568
  // With labels kept in the machine, a young one of the name with none written yet is this request's still being made
@@ -465,7 +581,6 @@ export class HostedProvider {
465
581
  if (!launched.ok)
466
582
  return launched.error.code === "exists" ? this.#createOnce(spec, name, signal, launched) : launched;
467
583
  const { ref, made } = launched.value;
468
- this.#keepAlive(ref);
469
584
  // From here the machine exists: every step takes the caller's signal, and a failure or an abort deletes it.
470
585
  // Another provider instance's create of this request may have made one too (#converge): the oldest is kept.
471
586
  const first = await this.#converge(name, ref.id, signal);
@@ -501,7 +616,7 @@ export class HostedProvider {
501
616
  * same listing. Its value is the machine kept, or undefined when mine holds the name alone (or nothing is listed yet).
502
617
  */
503
618
  async #converge(name, mine, signal) {
504
- const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal);
619
+ const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#finding, signal);
505
620
  if (!listed.ok)
506
621
  return listed;
507
622
  const holders = listed.value.filter((machine) => ours(machine.labels, name) && alive(machine.state));
@@ -613,9 +728,9 @@ export class HostedProvider {
613
728
  const maxDeadline = new Date(now + this.#maxLifetimeMs).toISOString();
614
729
  const labels = this.#labelsOf(spec, name, deadline, maxDeadline);
615
730
  // check() packed stand-ins; these deflate a byte apart from them, so the host is never given labels that don't fit.
616
- const over = this.#packedOver(labels, name);
617
- if (over !== undefined)
618
- return this.#fail("refused", `labels: ${over}`);
731
+ const stored = this.#stored(labels, name);
732
+ if ("problem" in stored)
733
+ return this.#fail("refused", `labels: ${stored.problem}`);
619
734
  const archil = spec.mount?.kind === "archil";
620
735
  const user = this.#userOf(spec);
621
736
  const commands = hostedCommands({
@@ -633,17 +748,22 @@ export class HostedProvider {
633
748
  rootOnly: this.host.facts.rootOnly ?? [],
634
749
  network: formOf(spec.network),
635
750
  });
751
+ const backstopAt = new Date(now + this.#maxLifetimeMs + BACKSTOP_MARGIN_MS).toISOString();
752
+ const boot = this.#dialing ? await this.#boot(name, backstopAt, { deadline, user, maxDeadline, network: formOf(spec.network) }, sha256) : undefined;
753
+ if (boot !== undefined && !boot.ok)
754
+ return boot;
636
755
  const request = {
637
756
  name,
638
757
  image: spec.image,
639
- labels,
758
+ labels: stored.labels,
640
759
  lifetimeMs,
641
- backstopAt: new Date(now + this.#maxLifetimeMs + BACKSTOP_MARGIN_MS).toISOString(),
760
+ backstopAt,
642
761
  // The machine has egress where its tools' network is open or a list, which init's proxy holds to the public
643
762
  // internet (./network.ts), and where an Archil computer's root reaches Archil. Its tools' none is init's own
644
- // either way, read back by the probe from inside, as the tool user.
645
- egress: archil || throughProxy(spec.network),
646
- ...(this.host.facts.daemon === "pid1" ? { command: commands.entrypoint } : {}),
763
+ // either way, read back by the probe from inside, as the tool user. A dial machine's root reaches this server.
764
+ egress: archil || throughProxy(spec.network) || boot !== undefined,
765
+ ...(this.host.facts.daemon === "pid1" && boot === undefined ? { command: commands.entrypoint } : {}),
766
+ ...(boot === undefined ? {} : { boot: { env: boot.value } }),
647
767
  ...(spec.gpu === undefined ? {} : { gpu: spec.gpu }),
648
768
  ...(spec.cpus === undefined ? {} : { cpus: spec.cpus }),
649
769
  ...(spec.memoryMb === undefined ? {} : { memoryMb: spec.memoryMb }),
@@ -654,6 +774,8 @@ export class HostedProvider {
654
774
  // after this gave up is deleted by its id; one that fails after it, by its name where it may have made one.
655
775
  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);
656
776
  if (!created.ok) {
777
+ // A machine of this create's that lands after this never dials: its token goes with the create.
778
+ await this.#revoke(name);
657
779
  const { code, message } = created.error;
658
780
  if (code === "aborted" || code === "timeout") {
659
781
  this.#end(name);
@@ -668,6 +790,29 @@ export class HostedProvider {
668
790
  this.#requests.made(name);
669
791
  return ok({ ref: { id: created.value.id, name }, made: { deadline, maxDeadline, labels, daemon, sha256, commands, user } });
670
792
  }
793
+ /**
794
+ * A dial machine's environment (MachineRequest.boot.env, spec/computer/attach.md): its own token, minted here to stop
795
+ * at backstopAt, where it dials and fetches the daemon, the daemon's sha256, and init's flags as start gives them.
796
+ */
797
+ async #boot(name, backstopAt, init, sha256) {
798
+ const dialed = this.#dialed();
799
+ if ("problem" in dialed)
800
+ return this.#fail("refused", dialed.problem);
801
+ let token;
802
+ try {
803
+ token = await dialed.dial.tokens.mint(name, { kind: this.#kind, os: "linux", arch: this.host.facts.arch, expiresAt: new Date(backstopAt) });
804
+ }
805
+ catch (error) {
806
+ return this.#fail("refused", `minting ${name}'s machine token failed, so ${this.#label} was not called: ${words(error)}`);
807
+ }
808
+ return ok({
809
+ AGENTRUN_ATTACH_URL: dialed.attach,
810
+ AGENTRUN_ATTACH_TOKEN: token,
811
+ AGENTRUN_DAEMON_URL: dialed.daemon,
812
+ AGENTRUN_DAEMON_SHA256: sha256,
813
+ AGENTRUN_INIT_ARGS: initFlags(init).join(" "),
814
+ });
815
+ }
671
816
  /** Deletes a machine create gives up on, then waits, under the caller's signal, until get answers none for it. */
672
817
  async #abandon(ref, error, signal, mounted = false) {
673
818
  this.#end(ref.name);
@@ -694,7 +839,7 @@ export class HostedProvider {
694
839
  const until = Date.now() + listedMs;
695
840
  let named;
696
841
  for (let delay = Math.min(LISTED_POLL_MS, pollMs);; delay = Math.min(delay * 2, pollMs)) {
697
- const listed = await foundBy(this.host, "the listing by name", byName(name), this.#timeouts);
842
+ const listed = await foundBy(this.host, "the listing by name", byName(name), this.#finding);
698
843
  if (!listed.ok)
699
844
  return `; a machine named ${name} may be left (${listed.error.message}), which ends at its deadline`;
700
845
  named = listed.value.filter((machine) => ours(machine.labels, name) || this.#unfiled(machine, name) !== undefined);
@@ -716,47 +861,8 @@ export class HostedProvider {
716
861
  }
717
862
  return `; the machine named ${name} it made: ${said.join("; ")}${left}`;
718
863
  }
719
- /**
720
- * Calls the host's keepalive on the machine every idleMs / 3 (facts.idleMs), from create or attach until release or
721
- * the delete of a create that gave up, one call at a time: a tick while the host's last call has not settled, even
722
- * past its timeout, is skipped. One that fails is told through onNote and the next tries again; a machine the vendor
723
- * no longer has stops it. The timer holds no process open. An attach calls once at once too (now): a computer a
724
- * restarted server finds may have been quiet for most of its idle window already.
725
- */
726
- #keepAlive(ref, now = false) {
727
- const { idleMs } = this.host.facts;
728
- const keepalive = this.host.keepalive?.bind(this.host);
729
- if (idleMs === undefined || keepalive === undefined || this.#kept.has(ref.id))
730
- return;
731
- let calling = false;
732
- const keep = async () => {
733
- if (calling)
734
- return;
735
- calling = true;
736
- let call = Promise.resolve();
737
- const kept = await this.#call(`the keepalive of ${ref.name}`, (ctx) => (call = keepalive(ref.id, ctx)), this.#timeouts.requestMs);
738
- const free = () => (calling = false);
739
- call.then(free, free);
740
- if (kept.ok || this.#kept.get(ref.id) !== timer)
741
- return;
742
- if (kept.error.code === "not_found")
743
- this.#unkeep(ref.id);
744
- else
745
- this.#onNote?.({ computer: ref.name, note: `${kept.error.message}; the next keepalive tries again in ${seconds(idleMs / 3)}` });
746
- };
747
- const timer = setInterval(keep, idleMs / 3);
748
- timer.unref();
749
- this.#kept.set(ref.id, timer);
750
- if (now)
751
- void keep();
752
- }
753
- #unkeep(id) {
754
- clearInterval(this.#kept.get(id));
755
- this.#kept.delete(id);
756
- }
757
864
  /** The host's delete, never signalled: a delete that cleans up after an abort must outlive it. Not found is done. */
758
865
  async #kill(id) {
759
- this.#unkeep(id);
760
866
  const killed = await this.#call(`the delete of ${id}`, (ctx) => this.host.delete(id, ctx), this.#timeouts.requestMs);
761
867
  if (!killed.ok && killed.error.code !== "not_found")
762
868
  return killed;
@@ -769,11 +875,11 @@ export class HostedProvider {
769
875
  }
770
876
  /**
771
877
  * The host's get, bounded by requestMs; a machine the vendor reports as not found is none. Labels kept in the machine
772
- * are read from its file once and then as last read, or now with fresh.
878
+ * are read from its file once and then as last read.
773
879
  */
774
- async #get(id, signal, fresh = false) {
880
+ async #get(id, signal) {
775
881
  const read = await readMachine(this.host, id, this.#timeouts.requestMs, signal);
776
- return read.ok ? labelled(this.host, read.value, this.#timeouts.requestMs, signal, fresh) : read;
882
+ return read.ok ? labelled(this.host, read.value, this.#timeouts.requestMs, signal, false) : read;
777
883
  }
778
884
  /** The machine running, read while it starts (within createMs); gone or failed is refused in words. */
779
885
  async #running(ref, signal) {
@@ -827,6 +933,12 @@ export class HostedProvider {
827
933
  const drift = this.#machineDrift({ ...running.value, labels: kept.value }, labels);
828
934
  if (drift.length > 0)
829
935
  return this.#fail("refused", `it did not match its spec: ${drift.join("; ")}`);
936
+ const gpu = spec.gpu !== undefined;
937
+ const want = { user, isolation: (gpu ? this.#configuration.gpu?.isolation : undefined) ?? this.host.facts.isolation, gpu };
938
+ // A dial machine's agentrun-dial fetched the daemon, held it to AGENTRUN_DAEMON_SHA256 (this create's daemon's) and
939
+ // started init itself: the drift check holds by that sha, so nothing is installed or read back here.
940
+ if (this.#dialing)
941
+ return this.#start(spec, ref, commands, want, signal);
830
942
  // Before anything of this create's is in the machine: what root runs is root's alone (the Archil helper's sha256,
831
943
  // read at the mount's preflight, is read after this).
832
944
  if ((this.host.facts.rootOnly ?? []).length > 0) {
@@ -858,9 +970,7 @@ export class HostedProvider {
858
970
  // The run's folder, after the daemon is in place (serve runs it) and before init starts: no tool program runs before
859
971
  // it is mounted. A folder mounted for a computer create then gives up on is let go before the delete, never signalled.
860
972
  const started = async () => {
861
- const gpu = spec.gpu !== undefined;
862
- const isolation = (gpu ? this.#configuration.gpu?.isolation : undefined) ?? this.host.facts.isolation;
863
- const done = await this.#start(spec, ref, commands, { user, isolation, gpu }, signal);
973
+ const done = await this.#start(spec, ref, commands, want, signal);
864
974
  return done.ok && installer !== undefined ? ok([installer, ...done.value]) : done;
865
975
  };
866
976
  if (spec.mount?.kind !== "archil")
@@ -885,7 +995,7 @@ export class HostedProvider {
885
995
  /** The rest of #prepare from the daemon's install on: init started, its first connection checked, the listing waited for. */
886
996
  async #start(spec, ref, commands, want, signal) {
887
997
  const closed = [];
888
- if (this.host.facts.daemon === "child") {
998
+ if (this.host.facts.daemon === "child" && !this.#dialing) {
889
999
  // The session buses in /tmp, closed to the computer's user before any program of its runs.
890
1000
  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}` });
891
1001
  if (!shut.ok)
@@ -901,9 +1011,9 @@ export class HostedProvider {
901
1011
  if (init.value.exitCode !== 0)
902
1012
  return this.#fail("refused", `starting the daemon failed (exit ${init.value.exitCode}): ${`${init.value.stdout} ${init.value.stderr}`.trim().slice(0, 500)}`);
903
1013
  }
904
- const opened = await this.#openWhenListening(ref, signal);
1014
+ const opened = this.#dialing ? await this.#whenDialed(ref, signal) : await this.#openWhenListening(ref, signal);
905
1015
  if (!opened.ok) {
906
- if (opened.error.code === "aborted")
1016
+ if (opened.error.code === "aborted" || this.#dialing)
907
1017
  return opened;
908
1018
  const why = await this.#initWords(ref);
909
1019
  return this.#fail(opened.error.code, `the daemon did not answer: ${opened.error.message}${why ? `; init wrote: ${why}` : ""}`);
@@ -1003,6 +1113,14 @@ export class HostedProvider {
1003
1113
  /** One stdio bridge into the machine, after hello, unchecked; its client says so once the machine is deleted. */
1004
1114
  async #open(ref, signal, helloMs = this.#timeouts.helloMs) {
1005
1115
  const { requestMs } = this.#timeouts;
1116
+ if (this.#dialing) {
1117
+ // A dial machine's connection is over the socket it dialed, which the hub holds under its name: a drop fails the
1118
+ // calls in flight gone, and the first call after a redial is refused gone (attach.ts, AttachHub.connection).
1119
+ const connection = this.#dial?.hub.connection(ref.name);
1120
+ if (connection === undefined)
1121
+ return this.#fail("gone", `${ref.name} is not attached to this server now: its computerd dials back on its own, so try again shortly`);
1122
+ return ok(deletedSaid(this.host, ref, this.#label, requestMs, connection));
1123
+ }
1006
1124
  const opened = await openBridge(this.host, ref.id, { argv: hostedCommands().stdio, name: ref.name, version: VERSION, requestMs, helloMs, ...(signal ? { signal } : {}) });
1007
1125
  return opened.ok ? ok(deletedSaid(this.host, ref, this.#label, requestMs, opened.value)) : opened;
1008
1126
  }
@@ -1016,6 +1134,28 @@ export class HostedProvider {
1016
1134
  await pause(LISTEN_RETRY_MS, signal);
1017
1135
  }
1018
1136
  }
1137
+ /**
1138
+ * A dial machine's first connection: its socket waited for in the hub, from its start, within createMs. One that never
1139
+ * dials (a server it cannot reach, a daemon whose sha256 it refused, a hello the hub refused) fails timeout, naming the
1140
+ * address it was given; create then deletes it.
1141
+ */
1142
+ async #whenDialed(ref, signal) {
1143
+ const { createMs } = this.#timeouts;
1144
+ const until = Date.now() + createMs;
1145
+ for (;;) {
1146
+ const opened = await this.#open(ref, signal);
1147
+ if (opened.ok)
1148
+ return opened;
1149
+ if (Date.now() + this.#startPollMs() >= until) {
1150
+ const dialed = this.#dialed();
1151
+ const to = "problem" in dialed ? "this server" : dialed.attach;
1152
+ return this.#fail("timeout", `${ref.name} did not dial ${to} within ${seconds(createMs)}: the machine must reach that address, and run agentrun-dial (the box image's entrypoint while AGENTRUN_ATTACH_URL is set)`);
1153
+ }
1154
+ await pause(this.#startPollMs(), signal);
1155
+ if (signal?.aborted)
1156
+ return this.#fail("aborted", `create was aborted while it waited for ${ref.name} to dial`);
1157
+ }
1158
+ }
1019
1159
  /**
1020
1160
  * Its tools' network as they meet it, against the one create made: the probe, as the computer's own user. Under none,
1021
1161
  * no target answers. Under open or a list, still none answers directly (their own loopback alone), init's relay
@@ -1099,8 +1239,8 @@ export class HostedProvider {
1099
1239
  }
1100
1240
  }
1101
1241
  /** This provider's machine for ref, as the vendor reads it, or why not. */
1102
- async #own(ref, signal, fresh = false) {
1103
- const found = await this.#get(ref.id, signal, fresh);
1242
+ async #own(ref, signal) {
1243
+ const found = await this.#get(ref.id, signal);
1104
1244
  if (!found.ok)
1105
1245
  return found;
1106
1246
  if (found.value === undefined)
@@ -1228,7 +1368,6 @@ export class HostedProvider {
1228
1368
  found.push(`mount: ${name} is ${machine.state}, so its mount cannot be read back from inside`);
1229
1369
  if (found.length > 0)
1230
1370
  return this.#fail("refused", `the computer ${name} does not match this provider, so attach refuses it and it is left as it is: ${found.join("; ")}`);
1231
- this.#keepAlive(ref, true);
1232
1371
  return ok({
1233
1372
  ...ref,
1234
1373
  spec: {
@@ -1250,8 +1389,9 @@ export class HostedProvider {
1250
1389
  */
1251
1390
  async testConnection({ signal } = {}) {
1252
1391
  const listed = await listedBy(this.host, "the listing", { [COMPUTER_LABEL]: "1" }, this.#timeouts.listMs, signal);
1253
- // A host that keeps no labels lists them by their name alone.
1254
- const counted = (machine) => (this.#keeps ? NAME.test(machine.name ?? "") : ours(machine.labels)) && alive(machine.state);
1392
+ // A host that keeps no labels lists them by their image, and by their name where the vendor keeps one.
1393
+ const keptOurs = (machine) => ourImage(machine, this.#finding.image) && (machine.name === undefined || NAME.test(machine.name));
1394
+ const counted = (machine) => (this.#keeps ? keptOurs(machine) : ours(machine.labels)) && alive(machine.state);
1255
1395
  return countTested(this.#label, listed.ok ? ok({ count: listed.value.filter(counted).length }) : listed);
1256
1396
  }
1257
1397
  /**
@@ -1264,7 +1404,7 @@ export class HostedProvider {
1264
1404
  if (problem)
1265
1405
  return this.#fail("invalid", problem);
1266
1406
  const { listMs } = this.#timeouts;
1267
- const listed = await foundBy(this.host, "the listing", { ...labels, [COMPUTER_LABEL]: "1" }, this.#timeouts, signal);
1407
+ const listed = await foundBy(this.host, "the listing", { ...labels, [COMPUTER_LABEL]: "1" }, this.#finding, signal);
1268
1408
  if (!listed.ok)
1269
1409
  return listed.error.code === "timeout" ? this.#fail("timeout", `list did not finish within ${seconds(listMs)}: ${listed.error.message}`) : listed;
1270
1410
  const infos = [];
@@ -1346,12 +1486,12 @@ export class HostedProvider {
1346
1486
  }
1347
1487
  /**
1348
1488
  * Moves the deadline to now + ttlMs, refusing one earlier than it is (before any vendor call), never past create's time
1349
- * plus the cap (init's maximum): the host's extend first (its timer or its deadline label), and the label file where the
1350
- * labels are kept in the machine, then the end it reads back (get, deadlineOf), then init's own deadline, to that end. The deadline returned is the one init took.
1489
+ * plus the cap (init's maximum): the host's extend first (its timer or its deadline label), then the end it reads back
1490
+ * (get, deadlineOf), then init's own deadline, to that end. The deadline returned is the one init took. A host that
1491
+ * keeps labels in the machine has no extend (the constructor).
1351
1492
  */
1352
1493
  async #extend(ref, ttlMs, signal) {
1353
- // Labels kept in the machine are read now: another instance may have moved the deadline.
1354
- const found = await this.#own(ref, signal, true);
1494
+ const found = await this.#own(ref, signal);
1355
1495
  if (!found.ok)
1356
1496
  return found;
1357
1497
  const machine = found.value;
@@ -1377,11 +1517,6 @@ export class HostedProvider {
1377
1517
  const moved = await this.#call(`${this.#label}'s end of ${ref.name}`, (ctx) => extend(ref.id, new Date(target), ctx), this.#timeouts.requestMs, signal);
1378
1518
  if (!moved.ok)
1379
1519
  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}`);
1380
- if (this.#keeps) {
1381
- const kept = await this.#keep(ref, { ...machine.labels, [DEADLINE_LABEL]: new Date(target).toISOString() }, signal);
1382
- if (!kept.ok)
1383
- return this.#fail(kept.error.code, `${ref.name}'s deadline label did not move, nor did init's deadline: ${kept.error.message}`);
1384
- }
1385
1520
  const after = await this.#get(ref.id, signal);
1386
1521
  const end = after.ok && after.value !== undefined ? deadlineOf(after.value) : undefined;
1387
1522
  if (end === undefined) {
@@ -1428,7 +1563,8 @@ export class HostedProvider {
1428
1563
  if (!found.ok)
1429
1564
  return found;
1430
1565
  if (found.value === undefined) {
1431
- this.#unkeep(ref.id);
1566
+ // Gone already (deleted by hand, or the vendor's timer): its token and socket still go.
1567
+ await this.#revoke(ref.name);
1432
1568
  return ok(undefined);
1433
1569
  }
1434
1570
  if (!ours(found.value.labels, ref.name))
@@ -1448,6 +1584,7 @@ export class HostedProvider {
1448
1584
  */
1449
1585
  async #remove(ref, machine, signal) {
1450
1586
  const letGo = await this.#letGoOf(ref, machine, signal);
1587
+ await this.#revoke(ref.name);
1451
1588
  const killed = await this.#kill(ref.id);
1452
1589
  return { letGo, gone: killed.ok ? await this.#settle(ref, signal) : killed };
1453
1590
  }
@@ -1473,17 +1610,28 @@ export class HostedProvider {
1473
1610
  }
1474
1611
  /** The labels a listing by one computer's name asks for. */
1475
1612
  const byName = (name) => ({ [COMPUTER_LABEL]: "1", [NAME_LABEL]: name });
1613
+ /** The room of a host that keeps its labels packed (facts.labels.packed), or undefined. */
1614
+ function packedRoom(host) {
1615
+ const room = host.facts.labels;
1616
+ return room !== "machine" && room?.packed ? room : undefined;
1617
+ }
1618
+ /** A machine as the host read it, with a packed host's labels unpacked: none where it holds no packed map (not the adapter's). */
1619
+ const unpacked = (host, machine) => (packedRoom(host) === undefined ? machine : { ...machine, labels: unpackLabels(machine.labels) ?? {} });
1476
1620
  /**
1477
1621
  * The host's listing by labels, bounded by ms: only the machines that carry every one of them, since a vendor's listing
1478
- * may answer more (MachineHost.list). A host that keeps labels in the machine lists none: its machines of another name
1479
- * are left out, and the rest kept for foundBy to read.
1622
+ * may answer more (MachineHost.list). A packed host is asked for PACKED_NAME alone, the name's where one is asked, and
1623
+ * its machines' labels unpacked. A host that keeps labels in the machine lists none: its machines of another name are
1624
+ * left out, and the rest kept for foundBy to read.
1480
1625
  */
1481
1626
  export async function listedBy(host, what, labels, ms, signal) {
1482
- const listed = await hostCall(host, what, (ctx) => host.list(labels, ctx), ms, signal);
1483
1627
  const name = labels[NAME_LABEL];
1628
+ const asked = packedRoom(host) === undefined ? labels : name === undefined ? {} : { [PACKED_NAME]: name };
1629
+ const listed = await hostCall(host, what, (ctx) => host.list(asked, ctx), ms, signal);
1484
1630
  const keeps = (machine) => (host.facts.labels === "machine" ? name === undefined || machine.name === undefined || machine.name === name : carries(machine, labels));
1485
- return listed.ok ? ok(listed.value.filter(keeps)) : listed;
1631
+ return listed.ok ? ok(listed.value.map((machine) => unpacked(host, machine)).filter(keeps)) : listed;
1486
1632
  }
1633
+ /** Whether a machine's image is ours: the provider's image option, or a box image by its name rule (isBoxImage). */
1634
+ const ourImage = (machine, image) => machine.image !== undefined && (machine.image === image || isBoxImage(machine.image));
1487
1635
  /** With labels kept in the machine: each machine's label map as its file was last read, by host and machine id. */
1488
1636
  const filed = new WeakMap();
1489
1637
  function filedOf(host) {
@@ -1504,8 +1652,9 @@ function labelMapOf(text) {
1504
1652
  }
1505
1653
  /**
1506
1654
  * A machine of a host that keeps labels in the machine, with the labels its file holds: read through exec while it runs
1507
- * (fresh), else as last read, or none. No file (exit 3) is none; a read that fails otherwise is an error, never none, so
1508
- * a listing never leaves out a computer it could not read. Another host's machine is as read.
1655
+ * (fresh), within ms, else as last read, or none. No file (exit 3) is none; a read that fails otherwise, or does not end
1656
+ * within ms, is an error, never none (foundBy leaves the machine out of its listing, in words). Another host's machine is
1657
+ * as read.
1509
1658
  */
1510
1659
  async function labelled(host, machine, ms, signal, fresh) {
1511
1660
  if (host.facts.labels !== "machine" || machine === undefined)
@@ -1533,18 +1682,38 @@ const carries = (machine, labels) => Object.entries(labels).every(([key, value])
1533
1682
  * The listing finds, get answers (MachineHost.list): the machines the host's listing by labels names, each read now by
1534
1683
  * readMachine, within requestMs, and its label file where the host keeps labels in the machine. One the vendor no longer
1535
1684
  * has (not found) is dropped, and so is one whose get carries not every label, but a machine of the name asked for whose
1536
- * labels are not written yet. A read that fails otherwise fails the whole.
1685
+ * labels are not written yet. A label file's read that fails or does not end within requestMs leaves its machine out of
1686
+ * this listing alone, told through onNote by its id: one wedged machine never holds up the rest. A listing by a
1687
+ * request's name is the exception: what is left of it may be the request's own, so such a read fails it, as a get that
1688
+ * fails fails the whole. The label file is read only in a machine whose listed image is ours (ourImage): another's is
1689
+ * left out unread, and one that shows no image is left out in words.
1537
1690
  */
1538
- export async function foundBy(host, what, labels, { listMs, requestMs }, signal) {
1691
+ export async function foundBy(host, what, labels, { listMs, requestMs, onNote, image }, signal) {
1539
1692
  const listed = await listedBy(host, what, labels, listMs, signal);
1540
1693
  if (!listed.ok)
1541
1694
  return listed;
1542
- const reads = await Promise.all(listed.value.map(async ({ id }) => {
1695
+ const name = labels[NAME_LABEL];
1696
+ // With labels in the machine, the label read runs only in a machine of our image: never in another's.
1697
+ const readable = (machine) => {
1698
+ if (host.facts.labels !== "machine")
1699
+ return true;
1700
+ if (machine.image === undefined)
1701
+ onNote?.({ computer: machine.id, note: "its vendor record shows no image, so its labels are not read: this listing leaves it out" });
1702
+ return ourImage(machine, image);
1703
+ };
1704
+ const reads = await Promise.all(listed.value.filter(readable).map(async ({ id }) => {
1543
1705
  const read = await readMachine(host, id, requestMs, signal);
1544
- return read.ok ? labelled(host, read.value, requestMs, signal, true) : read;
1706
+ if (!read.ok)
1707
+ return read;
1708
+ const inside = await labelled(host, read.value, requestMs, signal, true);
1709
+ // A listing by a request's name is left with machines of that name or of none (listedBy), and either may be the
1710
+ // request's own: one that can't be read fails the listing, so its create never makes a second.
1711
+ if (inside.ok || inside.error.code === "aborted" || name !== undefined)
1712
+ return inside;
1713
+ onNote?.({ computer: id, note: `${inside.error.message}; this listing leaves it out, and the next one reads it again` });
1714
+ return ok(undefined);
1545
1715
  }));
1546
1716
  // With labels in the machine, one of the name asked for with none written yet is kept too, for the caller to judge.
1547
- const name = labels[NAME_LABEL];
1548
1717
  const unfiled = (machine) => host.facts.labels === "machine" && name !== undefined && machine.name === name && machine.labels[COMPUTER_LABEL] === undefined;
1549
1718
  const found = [];
1550
1719
  for (const read of reads) {
@@ -1555,10 +1724,15 @@ export async function foundBy(host, what, labels, { listMs, requestMs }, signal)
1555
1724
  }
1556
1725
  return ok(found);
1557
1726
  }
1558
- /** The host's get of one machine, bounded by ms: a machine the vendor reports as not found is none, never an error. */
1727
+ /**
1728
+ * The host's get of one machine, bounded by ms, a packed host's labels unpacked: a machine the vendor reports as not
1729
+ * found is none, never an error.
1730
+ */
1559
1731
  async function readMachine(host, id, ms, signal) {
1560
1732
  const read = await hostCall(host, `the read of ${id}`, (ctx) => host.get(id, ctx), ms, signal);
1561
- return !read.ok && read.error.code === "not_found" ? ok(undefined) : read;
1733
+ if (!read.ok)
1734
+ return read.error.code === "not_found" ? ok(undefined) : read;
1735
+ return ok(read.value === undefined ? undefined : unpacked(host, read.value));
1562
1736
  }
1563
1737
  /** What reading answers, or undefined once a signal aborts first: a caller that stopped waiting never waits on a read. */
1564
1738
  function untilAborted(reading, signals) {