@parcha/agentrun-computer 0.1.0-beta.32 → 0.1.0-beta.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1366,8 +1366,12 @@ node packages/computer/dist/conformance/modal-sweep.js --after /tmp/modal-before
1366
1366
  sandbox in the app carrying `agentrun.computer=1` (`sandboxes.list({ appId, tags })`, which lists running sandboxes
1367
1367
  only, so a finished one needs no sweep). `--after` refuses, exit 2, before it lists anything, a file whose app or
1368
1368
  server is not the one the environment names now, or that names none: every computer of another app would read as
1369
- new. Otherwise it terminates every such sandbox not in that file, reads each back through `sandboxes.fromId` and `poll()` until it reports an exit code or Modal no
1370
- longer knows it (up to 60 s each), and prints one line, `{"swept":n,"gone":m,"stillThere":[ids]}`. It exits 0 when
1369
+ new. Otherwise it reads the tags (`getTags()`) of every such sandbox not in that file and terminates each that carries
1370
+ a conformance run's label (`agentrun.conformance`, which every computer of a run carries): one another user of the app
1371
+ made during the run, with no such label, is left alone, and so is one whose tags it cannot read (said on stderr). It
1372
+ reads each terminated sandbox back through `sandboxes.fromId` and `poll()` until it reports an exit code or Modal no
1373
+ longer knows it (up to 60 s each), and prints one line, `{"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}`, where
1374
+ `leftAlone` counts the new sandboxes it did not terminate. It exits 0 when
1371
1375
  every swept sandbox has finished, 1 when one still runs, and 2 on a usage error, an unreadable before file or one of
1372
1376
  another app or server, a missing token or app, or a listing Modal refused, having terminated nothing. A sandbox in the before file is never
1373
1377
  named by any call.
@@ -1606,13 +1610,16 @@ node packages/computer/dist/conformance/daytona-sweep.js --after /tmp/daytona-be
1606
1610
  ```
1607
1611
 
1608
1612
  `--before <file>` writes the id of every sandbox carrying `agentrun.computer=1`, whatever its name or state, into the
1609
- file. `--after <file>` lists them again and deletes (`release(ref, "delete")`) every one whose id is not in the file,
1610
- then reads each with `GET /sandbox/{id}` until Daytona answers 404, up to 60 s each, and prints one JSON line,
1611
- `{"swept":n,"notFound":m,"stillThere":[ids]}`, where `swept` counts the sandboxes not there before and `notFound` plus
1612
- `stillThere`'s length is `swept`. A sandbox in the file is never named by any call. A new sandbox without a computer's
1613
- name is not this provider's: release refuses it, and it is reported still there. Exit 0 when every swept sandbox reads
1614
- 404, 1 when one is still there, 2 on a usage error, a before file it cannot read, no key, or a listing Daytona refused
1615
- (nothing is deleted then). Anything else that creates a labelled sandbox between the two runs is swept too.
1613
+ file. `--after <file>` lists them again and deletes (`release(ref, "delete")`) every one whose id is not in the file
1614
+ and that carries a conformance run's label (`agentrun.conformance`, which every computer of a run carries), then reads
1615
+ each with `GET /sandbox/{id}` until Daytona answers 404, up to 60 s each, and prints one JSON line,
1616
+ `{"swept":n,"notFound":m,"stillThere":[ids],"leftAlone":k}`, where `swept` counts the conformance sandboxes not there
1617
+ before, `notFound` plus `stillThere`'s length is `swept`, and `leftAlone` counts the new labelled sandboxes with no
1618
+ conformance label: another user of the account (a server's computers) made them during the run, and no call names
1619
+ them. A sandbox in the file is never named by any call. A new conformance sandbox without a computer's name is not this
1620
+ provider's: release refuses it, and it is reported still there. Exit 0 when every swept sandbox reads 404, 1 when one
1621
+ is still there, 2 on a usage error, a before file it cannot read, no key, or a listing Daytona refused (nothing is
1622
+ deleted then).
1616
1623
 
1617
1624
  ### Not yet known
1618
1625
 
@@ -1904,8 +1911,11 @@ computer capped at 30 minutes, Hobby's plan for conformance
1904
1911
  switch and `COMPUTER_E2B_API_KEY` are both set; `E2B_API_KEY` never counts.
1905
1912
 
1906
1913
  `dist/conformance/e2b-sweep.js --before <file>` records every sandbox E2B lists with `agentrun.computer=1`; `--after
1907
- <file>` kills every one not in the file, reads each back until `getInfo` no longer finds it and the listing no longer
1908
- shows it, up to 60 s each, and prints `{"swept":n,"gone":m,"stillThere":[ids]}`. Exit 0 when every swept sandbox is
1914
+ <file>` kills every one not in the file whose metadata carries a conformance run's label (`agentrun.conformance`),
1915
+ leaving alone one another user of the account made during the run, reads each killed one back until `getInfo` no longer
1916
+ finds it and the listing no longer shows it, up to 60 s each, and prints
1917
+ `{"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}` (`leftAlone`: the new labelled sandboxes with no conformance
1918
+ label, which no call names). Exit 0 when every swept sandbox is
1909
1919
  gone, 1 when one is still there, 2 on a usage error, an unreadable before file, no key, or a refused listing (nothing is
1910
1920
  killed then). It reads `COMPUTER_E2B_API_KEY` and `COMPUTER_E2B_DOMAIN` as the conformance module does, and needs no
1911
1921
  live switch.
Binary file
Binary file
@@ -41,6 +41,12 @@ export async function assertIsolated(t, client) {
41
41
  t.observe(`quiet interfaces (down, no address) a program of the computer's user sees: ${quiet.join(", ")}`);
42
42
  const raised = Array.isArray(probe.raised) ? probe.raised.map(String) : [];
43
43
  t.assert(raised.length === 0, `a program of the computer's user brought up ${raised.join(", ")}, which no program of its own network may`);
44
+ // Every target's outcome, in one line of the report, before any is asserted: a passing run shows what was tried too.
45
+ const outcome = (target) => {
46
+ const result = probe.results?.find((one) => one.target === target);
47
+ return result === undefined ? "no result" : `${String(result.outcome)}${result.detail === undefined || result.detail === "" ? "" : ` (${String(result.detail)})`}`;
48
+ };
49
+ t.observe(`probe, as the computer's user: ${targets.map((target) => `${target} ${outcome(target)}`).join("; ")}`);
44
50
  for (const target of targets) {
45
51
  const result = probe.results?.find((one) => one.target === target);
46
52
  const what = agent.includes(target) ? "the vendor's agent" : "the outside";
@@ -4,20 +4,25 @@
4
4
  // node packages/computer/dist/conformance/daytona-sweep.js --after <file>
5
5
  //
6
6
  // --before records the id of every sandbox carrying agentrun.computer=1 into <file>. --after lists them again, deletes
7
- // (release delete) every one whose id is not in <file>, then reads each of those back with GET /sandbox/{id} until
8
- // Daytona answers 404, up to 60 s each, and prints one JSON line, {"swept":n,"notFound":m,"stillThere":[ids]}: swept is
9
- // every sandbox it found that was not there before, and notFound + stillThere.length = swept. A sandbox in <file> is
10
- // never touched: no call names it. Exit 0 when every swept sandbox reads back 404, 1 when one is still there, 2 on a
11
- // usage error, a before file it cannot read, a missing key or a listing Daytona refused (nothing is deleted then).
7
+ // (release delete) every one whose id is not in <file> and that carries a conformance run's label (agentrun.conformance,
8
+ // RUN_LABEL), then reads each of those back with GET /sandbox/{id} until Daytona answers 404, up to 60 s each, and
9
+ // prints one JSON line, {"swept":n,"notFound":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox
10
+ // it found that was not there before, notFound + stillThere.length = swept, and leftAlone counts the new labelled
11
+ // sandboxes with no conformance label, which another user of the account made during the run (a server's computers):
12
+ // never touched. A sandbox in <file> is never touched either: no call names it. Exit 0 when every swept sandbox reads
13
+ // back 404, 1 when one is still there, 2 on a usage error, a before file it cannot read, a missing key or a listing
14
+ // Daytona refused (nothing is deleted then).
12
15
  import { readFileSync, writeFileSync } from "node:fs";
13
16
  import { COMPUTER_LABEL } from "../drift.js";
14
17
  import { isCommand } from "../entry.js";
15
18
  import { waitUntil } from "../wait.js";
16
19
  import { createProvider } from "./daytona.js";
20
+ import { RUN_LABEL } from "./runner.js";
17
21
  const USAGE = `usage: node packages/computer/dist/conformance/daytona-sweep.js --before <file> | --after <file>
18
22
  --before <file> record the id of every sandbox carrying ${COMPUTER_LABEL}=1 into <file>
19
- --after <file> delete every sandbox carrying ${COMPUTER_LABEL}=1 whose id is not in <file>, read each back until
20
- Daytona answers 404 (up to 60 s each), and print {"swept":n,"notFound":m,"stillThere":[ids]}
23
+ --after <file> delete every sandbox carrying ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
24
+ each back until Daytona answers 404 (up to 60 s each), and print
25
+ {"swept":n,"notFound":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
21
26
  settings: COMPUTER_DAYTONA_API_KEY (required) and COMPUTER_DAYTONA_API_URL, as the conformance module reads them
22
27
  exit: 0 every swept sandbox is gone, 1 one is still there, 2 usage error, unreadable before file, no key, or a refused listing`;
23
28
  class Usage extends Error {
@@ -89,7 +94,10 @@ export async function main(argv, io = {}) {
89
94
  return 0;
90
95
  }
91
96
  const known = before;
92
- const fresh = [...new Map(listed.value.filter((sb) => !known.has(sb.id)).map((sb) => [sb.id, sb])).values()];
97
+ const added = [...new Map(listed.value.filter((sb) => !known.has(sb.id)).map((sb) => [sb.id, sb])).values()];
98
+ // Only a conformance run's computers: one another user of the account made during the run is not this sweep's.
99
+ const fresh = added.filter((sb) => Object.hasOwn(sb.labels, RUN_LABEL));
100
+ const leftAlone = added.length - fresh.length;
93
101
  for (const sb of fresh) {
94
102
  const released = await provider.release({ id: sb.id, name: sb.name ?? "" }, "delete");
95
103
  if (!released.ok)
@@ -110,7 +118,7 @@ export async function main(argv, io = {}) {
110
118
  return waited.ok;
111
119
  }));
112
120
  const stillThere = fresh.filter((_, i) => !gone[i]).map((sb) => sb.id);
113
- await write(stdout, `${JSON.stringify({ swept: fresh.length, notFound: fresh.length - stillThere.length, stillThere })}\n`);
121
+ await write(stdout, `${JSON.stringify({ swept: fresh.length, notFound: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
114
122
  return stillThere.length === 0 ? 0 : 1;
115
123
  }
116
124
  if (isCommand(import.meta)) {
@@ -5,12 +5,14 @@
5
5
  //
6
6
  // --before records into <file> the id of every sandbox E2B lists with the provider's label agentrun.computer=1
7
7
  // (Sandbox.list with that metadata, running and paused ones: e2b@2.63.0 dist/index.mjs:5974-5986, 5793-5835). --after
8
- // lists them again, kills (Sandbox.kill) every one whose id is not in <file>, then reads each of those back with getInfo
9
- // until E2B no longer has it (SandboxNotFoundError, index.mjs:5431) and no longer lists it, up to 60 s each, and prints
10
- // one JSON line, {"swept":n,"gone":m,"stillThere":[ids]}: swept is every labelled sandbox it found that was not there
11
- // before, and gone + stillThere.length = swept. A sandbox in <file> is never touched: no call names it. Exit 0 when
12
- // every swept sandbox is gone, 1 when one is still there, 2 on a usage error, a before file it cannot read, a missing
13
- // key, or a listing E2B refused (nothing is killed then).
8
+ // lists them again, kills (Sandbox.kill) every one whose id is not in <file> and whose metadata carries a conformance
9
+ // run's label (agentrun.conformance, RUN_LABEL), then reads each of those back with getInfo until E2B no longer has it
10
+ // (SandboxNotFoundError, index.mjs:5431) and no longer lists it, up to 60 s each, and prints one JSON line,
11
+ // {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox it found that was not there
12
+ // before, gone + stillThere.length = swept, and leftAlone counts the new labelled sandboxes with no conformance label,
13
+ // which another user of the account made during the run: never touched. A sandbox in <file> is never touched either:
14
+ // no call names it. Exit 0 when every swept sandbox is gone, 1 when one is still there, 2 on a usage error, a before
15
+ // file it cannot read, a missing key, or a listing E2B refused (nothing is killed then).
14
16
  //
15
17
  // It reads COMPUTER_E2B_API_KEY and COMPUTER_E2B_DOMAIN as the conformance module does (settingsFromEnv in ./e2b.ts)
16
18
  // and builds the provider with create(): the key passed to every SDK call explicitly, an ambient E2B_SANDBOX_URL
@@ -20,11 +22,13 @@ import { COMPUTER_LABEL } from "../drift.js";
20
22
  import { create } from "../e2b.js";
21
23
  import { isCommand } from "../entry.js";
22
24
  import { E2B_ENV as ENV, settingsFromEnv } from "./e2b.js";
25
+ import { RUN_LABEL } from "./runner.js";
23
26
  import { waitUntil } from "../wait.js";
24
27
  const USAGE = `usage: node packages/computer/dist/conformance/e2b-sweep.js --before <file> | --after <file>
25
28
  --before <file> record the id of every sandbox E2B lists with ${COMPUTER_LABEL}=1 into <file>
26
- --after <file> kill every sandbox listed with ${COMPUTER_LABEL}=1 whose id is not in <file>, read each back until
27
- E2B no longer has it (up to 60 s each), and print {"swept":n,"gone":m,"stillThere":[ids]}
29
+ --after <file> kill every sandbox listed with ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
30
+ each back until E2B no longer has it (up to 60 s each), and print
31
+ {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
28
32
  settings: ${ENV.key} (required) and ${ENV.domain}, as the conformance module reads them; never E2B_API_KEY
29
33
  exit: 0 every swept sandbox is gone, 1 one is still there, 2 usage error, unreadable before file, no key, or a refused listing`;
30
34
  class Usage extends Error {
@@ -95,7 +99,10 @@ export async function main(argv, io = {}) {
95
99
  return 0;
96
100
  }
97
101
  const known = before;
98
- const fresh = listed.value.filter((sb) => !known.has(sb.id)).map((sb) => sb.id);
102
+ const added = listed.value.filter((sb) => !known.has(sb.id));
103
+ // Only a conformance run's computers: one another user of the account made during the run is not this sweep's.
104
+ const fresh = added.filter((sb) => Object.hasOwn(sb.labels, RUN_LABEL)).map((sb) => sb.id);
105
+ const leftAlone = added.length - fresh.length;
99
106
  for (const id of fresh) {
100
107
  const killed = await provider.killById(id);
101
108
  if (!killed.ok)
@@ -117,7 +124,7 @@ export async function main(argv, io = {}) {
117
124
  return waited.ok;
118
125
  }));
119
126
  const stillThere = fresh.filter((_, i) => !gone[i]);
120
- await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere })}\n`);
127
+ await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
121
128
  return stillThere.length === 0 ? 0 : 1;
122
129
  }
123
130
  if (isCommand(import.meta)) {
@@ -8,11 +8,15 @@
8
8
  // agentrun.computer=1: sandboxes.list({ appId, tags }) returns those with at least those tags, and running ones only
9
9
  // (modal-client@64880502:js/src/sandbox.ts:1116-1159, includeFinished: false), so a finished sandbox is in neither list
10
10
  // and needs no sweep. --after refuses a file whose app or server is not the one the environment names now, or that
11
- // names none, before it lists anything: another app's computers would all read as new. Otherwise it lists them again, terminates every one whose id is not in <file>, then reads each of those
12
- // back with sandboxes.fromId and poll (sandbox.ts:960-962, 2766-2772; poll is null while it runs) until it reports an
13
- // exit code, or Modal no longer knows it, up to 60 s each, and prints one JSON line, {"swept":n,"gone":m,"stillThere":
14
- // [ids]}: swept is every tagged sandbox it found that was not there before, and gone + stillThere.length = swept. A
15
- // sandbox in <file> is never touched: no call names it. Exit 0 when every swept sandbox has finished, 1 when one still
11
+ // names none, before it lists anything: another app's computers would all read as new. Otherwise it lists them again,
12
+ // reads the tags of every one whose id is not in <file> (getTags: a list filters by exact tag values, and a run's label
13
+ // differs per run), terminates each that carries a conformance run's label (agentrun.conformance, RUN_LABEL), then
14
+ // reads each of those back with sandboxes.fromId and poll (sandbox.ts:960-962, 2766-2772; poll is null while it runs)
15
+ // until it reports an exit code, or Modal no longer knows it, up to 60 s each, and prints one JSON line,
16
+ // {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox it found that was not there
17
+ // before, gone + stillThere.length = swept, and leftAlone counts the new tagged sandboxes it did not terminate: no
18
+ // conformance label (another user of the app made them during the run), or tags it could not read (said on stderr).
19
+ // A sandbox in <file> is never touched: no call names it. Exit 0 when every swept sandbox has finished, 1 when one still
16
20
  // runs, 2 on a usage error, a before file it cannot read or of another app or server, a missing token or app, or a
17
21
  // listing Modal refused (nothing is terminated then).
18
22
  //
@@ -25,12 +29,14 @@ import { COMPUTER_LABEL } from "../drift.js";
25
29
  import { isCommand } from "../entry.js";
26
30
  import { MODAL_DEFAULT_SERVER_URL, modalClient, untilFinished } from "../modal.js";
27
31
  import { MODAL_ENV, settingsFromEnv } from "./modal.js";
32
+ import { RUN_LABEL } from "./runner.js";
28
33
  const TAG = { [COMPUTER_LABEL]: "1" };
29
34
  const USAGE = `usage: node packages/computer/dist/conformance/modal-sweep.js --before <file> | --after <file>
30
35
  --before <file> record the app, the server and the id of every running sandbox carrying ${COMPUTER_LABEL}=1 in the app into <file>
31
36
  --after <file> refuse a <file> of another app or server; else terminate every running sandbox carrying ${COMPUTER_LABEL}=1
32
- in the app whose id is not in <file>,
33
- read each back until it has finished (up to 60 s each), and print {"swept":n,"gone":m,"stillThere":[ids]}
37
+ and ${RUN_LABEL} in the app whose id is not in <file>, read each back until it has finished (up to 60 s
38
+ each), and print {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no
39
+ ${RUN_LABEL} (or tags it cannot read) is left alone
34
40
  settings: ${MODAL_ENV.tokenId} and ${MODAL_ENV.tokenSecret} (required), ${MODAL_ENV.app} (required) and
35
41
  ${MODAL_ENV.serverUrl}, as the conformance module reads them; never MODAL_TOKEN_ID or MODAL_TOKEN_SECRET
36
42
  exit: 0 every swept sandbox has finished, 1 one still runs, 2 usage error, unreadable before file or one of another app
@@ -167,7 +173,24 @@ export async function main(argv, io = {}) {
167
173
  return 0;
168
174
  }
169
175
  const known = before;
170
- const fresh = listed.value.filter((sandbox) => !known.has(sandbox.sandboxId));
176
+ const added = listed.value.filter((sandbox) => !known.has(sandbox.sandboxId));
177
+ // Only a conformance run's computers: one another user of the app made during the run is not this sweep's. Tags it
178
+ // cannot read leave the sandbox alone, said in words; one Modal no longer knows has finished already.
179
+ const fresh = [];
180
+ let leftAlone = 0;
181
+ for (const sandbox of added) {
182
+ const tags = await bounded(`getTags of ${sandbox.sandboxId}`, () => sandbox.getTags(), callMs);
183
+ if (!tags.ok) {
184
+ if (notFound(tags.error))
185
+ continue;
186
+ await write(stderr, `${sandbox.sandboxId} was left alone: its tags could not be read: ${words(tags.error)}\n`);
187
+ leftAlone += 1;
188
+ }
189
+ else if (Object.hasOwn(tags.value, RUN_LABEL))
190
+ fresh.push(sandbox);
191
+ else
192
+ leftAlone += 1;
193
+ }
171
194
  for (const sandbox of fresh) {
172
195
  const ended = await bounded(`terminate of ${sandbox.sandboxId}`, () => sandbox.terminate(), callMs);
173
196
  if (!ended.ok && !notFound(ended.error))
@@ -182,7 +205,7 @@ export async function main(argv, io = {}) {
182
205
  return waited.ok;
183
206
  }));
184
207
  const stillThere = fresh.filter((_, i) => !gone[i]).map((sandbox) => sandbox.sandboxId);
185
- await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere })}\n`);
208
+ await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
186
209
  return stillThere.length === 0 ? 0 : 1;
187
210
  }
188
211
  if (isCommand(import.meta)) {
package/dist/daytona.d.ts CHANGED
@@ -148,12 +148,14 @@ export declare class DaytonaProvider implements ComputerProvider {
148
148
  }, { signal }?: CallContext): Promise<Result<AttachedComputer>>;
149
149
  /**
150
150
  * For the sweep after a live run: every sandbox Daytona lists with agentrun.computer=1, whatever its name or state, as
151
- * Daytona reports it. list() keeps only this provider's computers; this keeps everything the label query returns.
151
+ * Daytona reports it, with its labels (the sweep deletes only a conformance run's). list() keeps only this provider's
152
+ * computers; this keeps everything the label query returns.
152
153
  */
153
154
  listLabelled({ signal }?: CallContext): Promise<Result<Array<{
154
155
  id: string;
155
156
  name?: string;
156
157
  state?: string;
158
+ labels: Record<string, string>;
157
159
  }>>>;
158
160
  /** For the sweep: GET /sandbox/{id} once, retried as every read is, and the status Daytona answered (404: none). */
159
161
  probe(id: string, { signal }?: CallContext): Promise<Result<{
package/dist/daytona.js CHANGED
@@ -975,7 +975,18 @@ export class DaytonaProvider {
975
975
  })());
976
976
  const bound = AbortSignal.timeout(this.#timeouts.helloMs);
977
977
  const either = signal ? AbortSignal.any([signal, bound]) : bound;
978
- const opened = await Promise.race([stream.open, new Promise((done) => either.addEventListener("abort", () => done(fail("aborted", "")), { once: true }))]);
978
+ // The stream's open raced against the bound; the abort listener is removed once the race is decided, so no connect
979
+ // leaves one behind on its signal.
980
+ let onAbort = () => { };
981
+ const aborted = new Promise((done) => {
982
+ onAbort = () => done(fail("aborted", ""));
983
+ if (either.aborted)
984
+ onAbort();
985
+ else
986
+ either.addEventListener("abort", onAbort, { once: true });
987
+ });
988
+ const opened = await Promise.race([stream.open, aborted]);
989
+ either.removeEventListener("abort", onAbort);
979
990
  const timedOut = () => fail("timeout", `the daemon in ${sb.name ?? sb.id} did not answer hello within ${this.#timeouts.helloMs / 1000} s`);
980
991
  if (!opened.ok) {
981
992
  await close();
@@ -1179,13 +1190,16 @@ export class DaytonaProvider {
1179
1190
  }
1180
1191
  /**
1181
1192
  * For the sweep after a live run: every sandbox Daytona lists with agentrun.computer=1, whatever its name or state, as
1182
- * Daytona reports it. list() keeps only this provider's computers; this keeps everything the label query returns.
1193
+ * Daytona reports it, with its labels (the sweep deletes only a conformance run's). list() keeps only this provider's
1194
+ * computers; this keeps everything the label query returns.
1183
1195
  */
1184
1196
  async listLabelled({ signal } = {}) {
1185
1197
  const listed = await this.#listOwn(signal);
1186
1198
  if (!listed.ok)
1187
1199
  return listed;
1188
- return ok(listed.value.filter((sb) => typeof sb?.id === "string").map((sb) => ({ id: sb.id, ...(typeof sb.name === "string" ? { name: sb.name } : {}), ...(typeof sb.state === "string" ? { state: sb.state } : {}) })));
1200
+ return ok(listed.value
1201
+ .filter((sb) => typeof sb?.id === "string")
1202
+ .map((sb) => ({ id: sb.id, ...(typeof sb.name === "string" ? { name: sb.name } : {}), ...(typeof sb.state === "string" ? { state: sb.state } : {}), labels: { ...(sb.labels ?? {}) } })));
1189
1203
  }
1190
1204
  /** For the sweep: GET /sandbox/{id} once, retried as every read is, and the status Daytona answered (404: none). */
1191
1205
  async probe(id, { signal } = {}) {
package/dist/docker.d.ts CHANGED
@@ -90,6 +90,12 @@ export declare function dockerArch({ docker, timeoutMs }?: Pick<DockerCreateOpti
90
90
  export declare function create(options?: DockerCreateOptions): Promise<DockerProvider>;
91
91
  /** The conformance CLI's module for Docker: the drifted twin. */
92
92
  export declare const conformance: () => Promise<typeof import("./conformance/docker.js")>;
93
+ /**
94
+ * Why #settle could not show its leftovers gone within SETTLE_MS, in words that always name them: `there`, what its
95
+ * last look still found; or, when the last look found none but the quiet window was not complete, every name it
96
+ * checked (`checked`), which could not be confirmed gone. Exported for its test.
97
+ */
98
+ export declare function settleWords(checked: readonly string[], there: readonly string[]): string;
93
99
  export declare class DockerProvider implements ComputerProvider {
94
100
  #private;
95
101
  readonly id = "docker";
package/dist/docker.js CHANGED
@@ -94,6 +94,22 @@ const FIXED = "a Docker computer's network is fixed at create; create a new comp
94
94
  const NETWORKS = 'network is required: "none", "open" or { allow: [names or CIDRs] }';
95
95
  /** How often create asks whether the egress proxy is ready. */
96
96
  const EGRESS_POLL_MS = 100;
97
+ /** After a docker run cut off before its own exit: how long, at most, the leftovers are removed and looked for again,
98
+ * how often, and for how long in a row the looks must find none of them before they count as gone (#settle). */
99
+ const SETTLE_MS = 10_000;
100
+ const SETTLE_EVERY_MS = 500;
101
+ const SETTLE_QUIET_MS = 3_000;
102
+ /**
103
+ * Why #settle could not show its leftovers gone within SETTLE_MS, in words that always name them: `there`, what its
104
+ * last look still found; or, when the last look found none but the quiet window was not complete, every name it
105
+ * checked (`checked`), which could not be confirmed gone. Exported for its test.
106
+ */
107
+ export function settleWords(checked, there) {
108
+ if (there.length > 0)
109
+ return `${there.join(" and ")} ${there.length === 1 ? "was" : "were"} still there ${SETTLE_MS / 1000} s after docker run was cut off`;
110
+ const named = checked.length > 0 ? checked.join(" and ") : "what docker run may have made";
111
+ return `${named} could not be confirmed gone within ${SETTLE_MS / 1000} s after docker run was cut off: the last look found none, but not for ${SETTLE_QUIET_MS / 1000} s in a row`;
112
+ }
97
113
  /** Only the fields hostOf reads, as JSON. */
98
114
  const INFO_FORMAT = '{"Architecture":{{json .Architecture}},"SecurityOptions":{{json .SecurityOptions}},"MemoryLimit":{{json .MemoryLimit}},' +
99
115
  '"SwapLimit":{{json .SwapLimit}},"PidsLimit":{{json .PidsLimit}},"CPUCfsQuota":{{json .CPUCfsQuota}},"CPUCfsPeriod":{{json .CPUCfsPeriod}},' +
@@ -398,8 +414,16 @@ export class DockerProvider {
398
414
  const ranMs = Date.now() - lifetimeFrom;
399
415
  if (!started.ok || started.value.exitCode !== 0) {
400
416
  // A run that failed or was aborted may still have made the container; an allowlist's proxy and volume go with it.
401
- await this.release({ id: name, name }, "delete");
402
- return started.ok ? fail("docker", `docker run failed: ${started.value.stderr.trim()}`) : started;
417
+ const released = await this.release({ id: name, name }, "delete");
418
+ if (started.ok)
419
+ return fail("docker", `docker run failed: ${started.value.stderr.trim()}`);
420
+ // Cut off before its own exit: the daemon may still make the computer after release looked, and then its egress
421
+ // volume with it (#settle).
422
+ const left = await this.#settle([name], allow === undefined ? [] : [egressNameOf(name)]);
423
+ const what = allow === undefined ? `the computer ${name}` : `the computer ${name}, its proxy and its volume`;
424
+ const removed = allow === undefined ? "was removed, if Docker made it after" : "were removed, if Docker made them after";
425
+ const words = !released.ok ? `${what} could not all be removed: ${released.error.message}` : left === undefined ? `${what} ${removed}` : `${what} could not all be removed: ${left}`;
426
+ return fail(started.error.code, `${started.error.message === "docker run was aborted" ? "create was aborted during docker run" : started.error.message}; ${words}`);
403
427
  }
404
428
  const ref = { id: started.value.stdout.trim(), name };
405
429
  // From here the computer exists: every step takes the caller's signal, and an abort deletes the computer.
@@ -453,6 +477,55 @@ export class DockerProvider {
453
477
  return fail("docker", `docker pull ${image} failed, so nothing was made: ${pulled.value.stderr.trim()}`);
454
478
  return ok(undefined);
455
479
  }
480
+ /**
481
+ * After a `docker run` that did not end with an exit of the CLI's own (it was aborted, or the CLI could not be run):
482
+ * the CLI client is gone, but the Docker daemon may still finish making the container a moment later, after a single
483
+ * `docker rm` found nothing, and leave it Created. So the containers and volumes named are removed by name, then
484
+ * inspected, again and again SETTLE_EVERY_MS apart, until the looks have found none of them for SETTLE_QUIET_MS in a
485
+ * row (a create that lands a second after the abort is still seen), on a bound of their own (SETTLE_MS), never the
486
+ * caller's signal, which has already ended. Undefined when they are gone; else what is still there, or could not be
487
+ * confirmed gone, in words (settleWords). A create later than that is the janitor's: sweepLeftovers takes it at the
488
+ * next sweep, past #leftoverGraceMs, which stays the backstop.
489
+ */
490
+ async #settle(containers, volumes) {
491
+ const bound = AbortSignal.timeout(SETTLE_MS);
492
+ // When the looks first found none of them in the current run of empty looks; there, what the last look found.
493
+ let quietSince;
494
+ // Each named as what it is: a container and a volume may share a name (the egress proxy's).
495
+ const containerWords = (name) => `the container ${name}`;
496
+ const volumeWords = (name) => `the volume ${name}`;
497
+ const checked = [...containers.map(containerWords), ...volumes.map(volumeWords)];
498
+ let there = checked;
499
+ while (!bound.aborted) {
500
+ // --volumes, as release removes a computer: a late container of an image that declares a VOLUME has its own.
501
+ for (const container of containers)
502
+ await this.#run(["rm", "--force", "--volumes", container], bound);
503
+ for (const volume of volumes)
504
+ await this.#run(["volume", "rm", "--force", volume], bound);
505
+ const found = containers.length === 0 ? ok([]) : await this.#inspect(containers, bound, "{{json .Name}}");
506
+ const listed = volumes.length === 0 ? undefined : await this.#run(["volume", "inspect", "--format", "{{.Name}}", ...volumes], bound);
507
+ // A look the bound cut off says nothing: what the last whole look found stands.
508
+ if (bound.aborted)
509
+ break;
510
+ // A read that fails for any reason but "no such" counts as all still there.
511
+ const unread = (ran) => ran.exitCode !== 0 && ran.stderr.split("\n").some((line) => line.trim() !== "" && !/no such volume/i.test(line));
512
+ const foundNames = found.ok ? found.value.map((name) => String(name).replace(/^\//, "")) : containers;
513
+ const listedText = listed === undefined ? "" : listed.ok && !unread(listed.value) ? listed.value.stdout : undefined;
514
+ there = [
515
+ ...containers.filter((name) => foundNames.includes(name)).map(containerWords),
516
+ ...volumes.filter((name) => listedText === undefined || listedText.split("\n").some((line) => line.includes(name))).map(volumeWords),
517
+ ];
518
+ if (there.length > 0)
519
+ quietSince = undefined;
520
+ else {
521
+ quietSince ??= Date.now();
522
+ if (Date.now() - quietSince >= SETTLE_QUIET_MS)
523
+ return undefined;
524
+ }
525
+ await sleep(SETTLE_EVERY_MS, undefined, { signal: bound }).catch(() => undefined);
526
+ }
527
+ return settleWords(checked, there);
528
+ }
456
529
  /** Deletes a computer whose create was aborted after docker run; the delete itself is not signalled. */
457
530
  async #abandon(ref) {
458
531
  const removed = await this.release(ref, "delete");
@@ -474,8 +547,12 @@ export class DockerProvider {
474
547
  const { image, hint, readyMs } = this.#egress;
475
548
  const args = egressRunArgs({ name, user, image, allow, local: this.#hostLocal(), deadline, code: this.#code, labels, ...(hint === undefined ? {} : { hint }) });
476
549
  const ran = await this.#run(args, signal);
477
- if (!ran.ok)
478
- return ran;
550
+ if (!ran.ok) {
551
+ // Cut off before its own exit: the daemon may still make the proxy after the caller's cleanup looked (#settle).
552
+ const left = await this.#settle([proxy], [proxy]);
553
+ const words = left === undefined ? "the proxy and its volume, if Docker made them after, were removed" : `the proxy and its volume could not all be removed: ${left}`;
554
+ return fail(ran.error.code, `${ran.error.message === "docker run was aborted" ? "create was aborted during docker run of the egress proxy" : ran.error.message}; ${words}`);
555
+ }
479
556
  if (ran.value.exitCode !== 0)
480
557
  return fail("docker", `docker run of the egress proxy ${proxy} failed: ${ran.value.stderr.trim()}`);
481
558
  // Every call of the poll ends at the readiness bound, so a docker that stops answering cannot hold create past it: a
package/dist/e2b.d.ts CHANGED
@@ -298,10 +298,12 @@ export declare class E2BProvider implements ComputerProvider {
298
298
  * page and every read-back.
299
299
  */
300
300
  list(labels: Record<string, string>, { signal }?: CallContext): Promise<Result<ComputerInfo[]>>;
301
- /** For the sweep: every sandbox E2B lists with agentrun.computer=1, whatever its name, as E2B reports it. */
301
+ /** For the sweep: every sandbox E2B lists with agentrun.computer=1, whatever its name, as E2B reports it, with its
302
+ * metadata as its labels (the sweep kills only a conformance run's). */
302
303
  listLabelled({ signal }?: CallContext): Promise<Result<Array<{
303
304
  id: string;
304
305
  state: string;
306
+ labels: Record<string, string>;
305
307
  }>>>;
306
308
  /** For the sweep: whether E2B still has a sandbox, read once by getInfo; not_found is gone. */
307
309
  probeGone(id: string, { signal }?: CallContext): Promise<Result<{
package/dist/e2b.js CHANGED
@@ -1244,10 +1244,11 @@ export class E2BProvider {
1244
1244
  }
1245
1245
  return ok(infos);
1246
1246
  }
1247
- /** For the sweep: every sandbox E2B lists with agentrun.computer=1, whatever its name, as E2B reports it. */
1247
+ /** For the sweep: every sandbox E2B lists with agentrun.computer=1, whatever its name, as E2B reports it, with its
1248
+ * metadata as its labels (the sweep kills only a conformance run's). */
1248
1249
  async listLabelled({ signal } = {}) {
1249
1250
  const listed = await this.#listPages({ [COMPUTER_LABEL]: "1" }, signal);
1250
- return listed.ok ? ok(listed.value.map((sb) => ({ id: sb.sandboxId, state: sb.state }))) : listed;
1251
+ return listed.ok ? ok(listed.value.map((sb) => ({ id: sb.sandboxId, state: sb.state, labels: { ...(sb.metadata ?? {}) } }))) : listed;
1251
1252
  }
1252
1253
  /** For the sweep: whether E2B still has a sandbox, read once by getInfo; not_found is gone. */
1253
1254
  async probeGone(id, { signal } = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-computer",
3
- "version": "0.1.0-beta.32",
3
+ "version": "0.1.0-beta.33",
4
4
  "description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
5
5
  "keywords": [
6
6
  "agentrun",