@parcha/agentrun-computer 0.1.0-beta.61 → 0.1.0-beta.63

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
@@ -615,10 +615,18 @@ by its rectangle), so a longer one ends the connection before anything is alloca
615
615
  desktop files of `$XDG_DATA_HOME/applications` and each of `$XDG_DATA_DIRS` (default `~/.local/share`, then
616
616
  `/usr/local/share` and `/usr/share`), as the Desktop Entry spec says: the apps there are, by their desktop file ids
617
617
  (`org.xfce.mousepad`), with their names; hidden and `NoDisplay` entries, and a `TryExec` that is not there, are left
618
- out. Its `foreground` is the app of the window manager's active window, else of the top window. `apps.launch({ id,
619
- url? })` takes an id, a name (`Mousepad`) or a program (`mousepad`), starts the entry's `Exec` (`url` in its `%u`/`%f`
620
- field; an entry with none refuses a `url` as `invalid`) as `process.start` does with orphans `keep`, with `DISPLAY`,
621
- and answers `{}` once a new window of the app shows, raised and focused (through the window manager's
618
+ out. So is an app whose desktop file computerd's own user could change: on the way to it from `/`, every symbolic
619
+ link followed, the user owns a folder, a link or the file, or the mode bits let it write the file or a folder holding
620
+ one of them (a sticky folder only where it owns what is in it), or computerd runs as root. The entry is read from the
621
+ file that walk checked, opened without following a link and refused if another took its place, and read again for
622
+ each launch. An app runs what its desktop file says, so such a file, written through `files`, would run any command
623
+ with exec off: `apps.launch` and `apps.terminate` refuse such an app as `denied`, naming the file and why. Its `foreground` is the
624
+ app of the window manager's active window, else of the top window. `apps.launch({ id, url? })` takes an id, a name
625
+ (`Mousepad`) or a program (`mousepad`), starts the entry's `Exec` (`url` in its `%u`/`%f` field; an entry with none
626
+ refuses a `url` as `invalid`; a `url` is an absolute URL with a scheme, `https://…` or `file:///…`, or an absolute
627
+ path, `/…`, and anything else, such as a leading `-` or a relative path, is refused `invalid` and nothing starts; the
628
+ surface refuses a leading `-` itself, before the call leaves it) as `process.start` does with orphans `keep`, with
629
+ `DISPLAY`, and answers `{}` once a new window of the app shows, raised and focused (through the window manager's
622
630
  `_NET_ACTIVE_WINDOW` when one runs, waiting up to 2 s for it to be the active window), so keys typed right after
623
631
  reach it; none within 10 s is `timeout`, "no window within 10 s", and the app runs on. An
624
632
  app already running with a window is brought to the front and answers at once, unless a `url` is given. A
@@ -1330,10 +1338,16 @@ runs on the VM runtime, or on gVisor for a GPU computer (below). Its unit tests
1330
1338
  them, its own at their longest, and refuses in words with no call where the packed tags pass either bound; create
1331
1339
  refuses the same words first. A sandbox made before the tags were packed carries its labels as tags, and reads as
1332
1340
  them (`labels.packed.unpacked`): a listing by name asks for the labels as given beside the packed name, within the
1333
- one bound, so a request that made one sandbox of each form across an upgrade has both seen and one kept. An Archil
1334
- computer's mount label records the folder's agent alone, as on every host: the folder's run is the `agentrun.run`
1335
- label's. `list` is `sandboxes.list({ appId, tags })` over the provider's app: running sandboxes only, and one Modal
1336
- still lists after its terminate is polled and left out once `poll()` reads it finished.
1341
+ one bound, so a request that made one sandbox of each form across an upgrade has both seen. The upgrade is one-way: a
1342
+ server from before the change asks for the labels as given alone, so its retry of a create can make a second sandbox
1343
+ beside a packed one. A newer server's create of that request keeps the older of the two only while the two creates
1344
+ race, its own reads of the name after its sandbox is made seeing both; a later create of that request that finds both
1345
+ already there refuses as `exists`, naming both ids, and keeps both. The extra sandbox then lasts until it is deleted
1346
+ or Modal ends it at its lifetime. Upgrade every server that shares a Modal app together to avoid it. A caller's label
1347
+ named `agentrun` or `agentrun-<n>` is refused in words, on every hosted computer: those names hold the packed labels.
1348
+ An Archil computer's mount label records the folder's agent alone, as on every host: the folder's run is the
1349
+ `agentrun.run` label's. `list` is `sandboxes.list({ appId, tags })` over the provider's app: running sandboxes only,
1350
+ and one Modal still lists after its terminate is polled and left out once `poll()` reads it finished.
1337
1351
  - **release** `delete` is `terminate()`, and the adapter waits until get answers none (`poll()` reads it finished).
1338
1352
  `stop` is refused as `unsupported`: terminate is a sandbox's only end.
1339
1353
  - **GPU.** `capabilities().gpu` declares Modal's GPU types by its own names (guide/gpu): `T4`, `L4`, `A10`, `L40S`,
@@ -2480,7 +2494,9 @@ both find nothing make two computers, so after Orgo's answer, and again once its
2480
2494
  workspace once more: where an older computer of the request is there (by `created_at`, then id), it deletes its own
2481
2495
  and answers the older, and the oldest keeps its own. A caller's signal that aborts one of those reads deletes the
2482
2496
  create's own computer (not under that signal) and the create is `aborted`. A name Orgo already holds (two creates in the same second) is
2483
- answered the same way. The parked desktops name each computer at random, so a create retried there makes a second
2497
+ answered the same way. A create whose POST got no answer deletes the computer by that exact name, which can be the
2498
+ computer another process's create answered through that 409: not covered, and tracked separately (see the browser
2499
+ providers' gaps below). The parked desktops name each computer at random, so a create retried there makes a second
2484
2500
  computer.
2485
2501
 
2486
2502
  - **What each offers.** The protocol groups, by Orgo's calls:
@@ -2652,14 +2668,40 @@ vendor made with no usable CDP URL) is bounded by the
2652
2668
  provider's `cleanupMs` option (default `RECOVER_MS`, 30 s), never by the caller's signal: one that does not finish in
2653
2669
  time fails the create in words that say the browser may still be running, and a retry is answered as above, never
2654
2670
  stuck behind it. Another create's browser of the same request, even one another process answered, carries another attempt
2655
- label and is left running. A lost create's own browser is left running too, for another create's converge and to its
2656
- lifetime, when it is the oldest of the request's that runs and the request's browsers, ended ones included, hold a
2657
- newer one: only another create made that one, and its converge answers the older. Browserbase is asked status by
2658
- status in a session's own order (pending, then running, then the ended ones), so a session that moves on while a
2659
- list runs is found in a later answer, never missed; Kernel answers every state in one list. Where the lost create's browser is
2660
- the request's only one it is released, even when another process's create answered it by its lookup: nothing on the
2661
- vendor says so. A 4xx refusal made nothing, so nothing is looked for. Both labels are the provider's own:
2662
- `check()` refuses them in a spec, and no list or attach shows them.
2671
+ label and is left running. A lost create's own browser is left for another create's converge when it is the oldest of
2672
+ the request's that runs and the request's browsers, ended ones included, hold a newer one: only another create made
2673
+ that one, and its converge may answer the older. A converge that answers the older releases its own first, so once a
2674
+ newer browser has ended, the lost create's is left running for that create, at once when the first read shows it.
2675
+ Otherwise the request's browsers are read again, every 2 s for up to half of `cleanupMs` (once at least, and sooner
2676
+ when that half is under 2 s). While every newer one still runs, no converge has answered it (each such create kept its
2677
+ own), and at the end it is released. On the first read as on every later one, a newer one that has ended counts before
2678
+ an older one that runs, since a converge whose list missed the older may have answered it. That keeps one held by none
2679
+ too: where three creates of a request ran, the newest's converge may have answered the oldest and ended its own, and
2680
+ the lost create's, the middle one, then runs to the vendor's lifetime; its failure says that an older one still runs.
2681
+ A read that fails, or that misses the lost create's browser, or a read again that misses every newer one, says nothing
2682
+ of who holds it and leaves it running; a first read that fails or misses it is tried again within the same half before
2683
+ that. The search's own retries, for a vendor that lists a browser late, wait within that
2684
+ half too, so the release keeps the other half.
2685
+ Browserbase is asked status by status in a session's own order (pending, then running, then the ended ones), so a
2686
+ session that moves on while a list runs is found in a later answer, never missed, and one found in two answers reads as
2687
+ the later one says; Kernel answers every state in one paged list, and a browser listed twice reads as deleted once
2688
+ either row says so. A newer browser that ended for another reason reads the same as one a converge released: its create was aborted
2689
+ while it listed the request, or released its own and then failed (its release reported a failure, or its read of the
2690
+ older failed), or its own reply was lost too and its recovery released it. Nothing on the vendor tells those apart, so
2691
+ there the lost create's browser runs to the vendor's lifetime: on Browserbase its `timeout`, up to the run's lifetime
2692
+ and at most 6 h; on Kernel its idle timeout, at most 72 h. One kept because the request could not be read runs as long.
2693
+ The create's failure says so, and its labels let a sweep find it. This bound is not covered, and is tracked separately.
2694
+ Where a read shows the lost create's browser is the request's only one, it is released. A 4xx refusal made nothing, so nothing is looked for. Both labels are the provider's own: `check()` refuses
2695
+ them in a spec, and no list or attach shows them.
2696
+
2697
+ Two gaps are not covered, and are tracked separately. A lost create whose browser is the request's only one releases
2698
+ it even when another process's create answered it by its lookup, or when the lost create read the request before the
2699
+ other create's POST landed and that create's converge answered it: nothing on the vendor says so, and that create
2700
+ holds a browser that has ended. The same holds when a converge lists the lost create's browser running just before the
2701
+ lost create's last read again and ends its own just after: the lost create releases it, and that create's read of it
2702
+ most often finds it ended and fails the request. On Orgo, a create whose POST got no answer deletes the computer by its exact name; that
2703
+ name can be the computer another process's create answered through Orgo's 409 (name in use), which then holds a
2704
+ deleted computer.
2663
2705
 
2664
2706
  The conformance CLI runs the browser case set for a provider of kind browser: the health cases, then `browser.*`
2665
2707
  (check past the cap, attach by id and by labels, list, CDP `Browser.getVersion` and `Runtime.evaluate` on a `data:`
package/dist/browser.d.ts CHANGED
@@ -96,15 +96,28 @@ export declare function heldBrowser(asked: Record<string, string>, found: Readon
96
96
  * answers in place of its own once it has released its own. Every process picks the same one from the same listing.
97
97
  */
98
98
  export declare function convergedBrowser(listed: ReadonlyArray<HeldBrowser>, mine: HeldBrowser): "mine" | HeldBrowser;
99
+ /** A browser of a request as a lost create's recovery reads it, ended ones included: whether it still runs. */
100
+ export type MadeBrowser = HeldBrowser & {
101
+ live: boolean;
102
+ };
99
103
  /**
100
104
  * Whether a lost create's browser (`mine`) is left to another create of its request rather than released: it still runs,
101
105
  * no older browser of the request runs (so every converge keeps it), and the request's browsers, ended ones included,
102
- * hold a newer one, which only another create made: that create's converge answers mine. A lost create whose browser is
103
- * the request's only one releases it.
106
+ * hold a newer one, which only another create made: that create's converge may answer mine. A lost create whose browser
107
+ * is the request's only one releases it.
104
108
  */
105
- export declare function leftToConverge(mine: string, made: ReadonlyArray<HeldBrowser & {
106
- live: boolean;
107
- }>): boolean;
109
+ export declare function leftToConverge(mine: string, made: ReadonlyArray<MadeBrowser>): boolean;
110
+ /**
111
+ * Where a lost create's browser left to a converge (leftToConverge) stands when the request's browsers are read again:
112
+ * "unread" when the read lists neither mine nor any newer one (the first read did, so it says nothing); "release" once
113
+ * mine has ended; "answered" when a newer one has ended, since a converge that answers the older ends its own first;
114
+ * "answered-older" when an older one also runs, since that converge may have missed the older and answered mine, or
115
+ * answered the older and left mine held by none; "release" when an older one runs and every newer one runs too;
116
+ * "running" while every newer one still runs, so no converge has answered mine yet.
117
+ */
118
+ export declare function convergeSettled(mine: string, made: ReadonlyArray<MadeBrowser>): Settled;
119
+ /** What a read of a lost create's request says of its browser (convergeSettled). */
120
+ type Settled = "answered" | "answered-older" | "running" | "release" | "unread";
108
121
  /**
109
122
  * Whether a create that threw may still have made a browser: anything but the vendor's own 4xx answer (a refusal, which
110
123
  * makes nothing). A request not answered, aborted, cut short, or answered 5xx or with a body that is no browser may
@@ -118,11 +131,18 @@ export declare function createUncertain(error: unknown): boolean;
118
131
  export declare const RECOVER_MS = 30000;
119
132
  /**
120
133
  * After a create whose outcome is unknown: the browsers carrying its create label, found and released under a signal
121
- * of the recovery's own, `ms` in all (the caller's may be what ended the create), save one `leave` says another create
122
- * of the request answers (leftToConverge). The words say what became of them, for the create's failure; they never
123
- * carry a URL.
134
+ * of the recovery's own, `ms` in all (the caller's may be what ended the create). The search, its retries for a vendor
135
+ * that lists late and the reads below wait at most until half of `ms` has passed, each wait RECOVER_GAP_MS or what is
136
+ * left of that half, so the release keeps the other half. Where `made` reads the request's browsers (ended ones
137
+ * included), each found browser's request is read, again after a read that failed or did not list it, and one no read
138
+ * lists is kept: such a read says nothing of who holds it. One older than a browser of its request that has ended
139
+ * (convergeSettled) is kept at once, even when an older one runs, as a converge that answers it ends its own first and
140
+ * one whose list missed the older may have answered it; where an older one runs, the words say it may be held by none. One left to another create's converge (leftToConverge) is otherwise read again,
141
+ * every RECOVER_GAP_MS within that half (once at least), and kept once a newer one has ended or a read fails or misses
142
+ * a browser the first read listed. One whose newer browsers all still run at the end was answered by no converge (each
143
+ * kept its own) and is released. The words say what became of them, for the create's failure; they never carry a URL.
124
144
  */
125
- export declare function recoverCreate(what: string, find: (signal: AbortSignal) => Promise<Result<string[]>>, release: (id: string, signal: AbortSignal) => Promise<Result<void>>, sleep: (ms: number) => Promise<void>, ms?: number, leave?: (id: string, signal: AbortSignal) => Promise<boolean>): Promise<string>;
145
+ export declare function recoverCreate(what: string, find: (signal: AbortSignal) => Promise<Result<string[]>>, release: (id: string, signal: AbortSignal) => Promise<Result<void>>, sleep: (ms: number) => Promise<void>, ms?: number, made?: (signal: AbortSignal) => Promise<Result<MadeBrowser[]>>): Promise<string>;
126
146
  /**
127
147
  * The checks every browser provider makes before a vendor call: the image is chromium, the lifetime is within the
128
148
  * vendor's cap (and at least min), the network is open, the labels are ones the vendor's metadata holds, the session's
@@ -265,3 +285,4 @@ export declare const pointerOk: (pointer: unknown) => pointer is string;
265
285
  * carry a pointer.
266
286
  */
267
287
  export declare function browserSpecRefusals(session: unknown, features: BrowserFeatures, vendor: string): Refusal[];
288
+ export {};
package/dist/browser.js CHANGED
@@ -108,8 +108,8 @@ export function convergedBrowser(listed, mine) {
108
108
  /**
109
109
  * Whether a lost create's browser (`mine`) is left to another create of its request rather than released: it still runs,
110
110
  * no older browser of the request runs (so every converge keeps it), and the request's browsers, ended ones included,
111
- * hold a newer one, which only another create made: that create's converge answers mine. A lost create whose browser is
112
- * the request's only one releases it.
111
+ * hold a newer one, which only another create made: that create's converge may answer mine. A lost create whose browser
112
+ * is the request's only one releases it.
113
113
  */
114
114
  export function leftToConverge(mine, made) {
115
115
  const own = made.find((one) => one.id === mine);
@@ -119,6 +119,28 @@ export function leftToConverge(mine, made) {
119
119
  return false;
120
120
  return made.some((one) => one.id !== mine && oldestBrowserFirst(own, one) < 0);
121
121
  }
122
+ /**
123
+ * Where a lost create's browser left to a converge (leftToConverge) stands when the request's browsers are read again:
124
+ * "unread" when the read lists neither mine nor any newer one (the first read did, so it says nothing); "release" once
125
+ * mine has ended; "answered" when a newer one has ended, since a converge that answers the older ends its own first;
126
+ * "answered-older" when an older one also runs, since that converge may have missed the older and answered mine, or
127
+ * answered the older and left mine held by none; "release" when an older one runs and every newer one runs too;
128
+ * "running" while every newer one still runs, so no converge has answered mine yet.
129
+ */
130
+ export function convergeSettled(mine, made) {
131
+ const own = made.find((one) => one.id === mine);
132
+ if (own === undefined)
133
+ return "unread";
134
+ if (!own.live)
135
+ return "release";
136
+ const newer = made.filter((one) => one.id !== mine && oldestBrowserFirst(own, one) < 0);
137
+ if (newer.length === 0)
138
+ return "unread";
139
+ const olderRuns = made.some((one) => one.id !== mine && one.live && oldestBrowserFirst(one, own) < 0);
140
+ if (newer.some((one) => !one.live))
141
+ return olderRuns ? "answered-older" : "answered";
142
+ return olderRuns ? "release" : "running";
143
+ }
122
144
  /**
123
145
  * Whether a create that threw may still have made a browser: anything but the vendor's own 4xx answer (a refusal, which
124
146
  * makes nothing). A request not answered, aborted, cut short, or answered 5xx or with a body that is no browser may
@@ -137,16 +159,25 @@ const RECOVER_TRIES = 3;
137
159
  const RECOVER_GAP_MS = 2_000;
138
160
  /**
139
161
  * After a create whose outcome is unknown: the browsers carrying its create label, found and released under a signal
140
- * of the recovery's own, `ms` in all (the caller's may be what ended the create), save one `leave` says another create
141
- * of the request answers (leftToConverge). The words say what became of them, for the create's failure; they never
142
- * carry a URL.
162
+ * of the recovery's own, `ms` in all (the caller's may be what ended the create). The search, its retries for a vendor
163
+ * that lists late and the reads below wait at most until half of `ms` has passed, each wait RECOVER_GAP_MS or what is
164
+ * left of that half, so the release keeps the other half. Where `made` reads the request's browsers (ended ones
165
+ * included), each found browser's request is read, again after a read that failed or did not list it, and one no read
166
+ * lists is kept: such a read says nothing of who holds it. One older than a browser of its request that has ended
167
+ * (convergeSettled) is kept at once, even when an older one runs, as a converge that answers it ends its own first and
168
+ * one whose list missed the older may have answered it; where an older one runs, the words say it may be held by none. One left to another create's converge (leftToConverge) is otherwise read again,
169
+ * every RECOVER_GAP_MS within that half (once at least), and kept once a newer one has ended or a read fails or misses
170
+ * a browser the first read listed. One whose newer browsers all still run at the end was answered by no converge (each
171
+ * kept its own) and is released. The words say what became of them, for the create's failure; they never carry a URL.
143
172
  */
144
- export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS, leave) {
173
+ export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS, made) {
145
174
  const signal = AbortSignal.timeout(ms);
175
+ const settleBy = Date.now() + ms / 2;
176
+ const reads = Math.max(1, Math.floor(ms / 2 / RECOVER_GAP_MS));
146
177
  let found = ok([]);
147
178
  for (let tries = 0; tries < RECOVER_TRIES; tries++) {
148
- if (tries > 0)
149
- await sleep(RECOVER_GAP_MS);
179
+ if (tries > 0 && !(await waitWithin(sleep, settleBy, signal)))
180
+ break;
150
181
  found = await find(signal);
151
182
  if (!found.ok || found.value.length > 0 || signal.aborted)
152
183
  break;
@@ -157,13 +188,36 @@ export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS,
157
188
  return `no ${what} carries its create label, so none was made or the vendor does not list it yet; its labels let a sweep find it`;
158
189
  const words = [];
159
190
  for (const id of found.value) {
160
- if (leave !== undefined && (await leave(id, signal))) {
161
- words.push(`the ${what} it made (${id}) is its request's oldest, which another create of the request answers: it is left running for that create, to its lifetime`);
162
- continue;
191
+ let unanswered = false;
192
+ if (made !== undefined) {
193
+ const read = await firstRead(id, made, signal, sleep, settleBy, Math.max(1, Math.ceil(ms / 2 / RECOVER_GAP_MS)));
194
+ if (read === undefined) {
195
+ words.push(`the ${what} it made (${id}) may be one another create of its request answered, and the request's browsers could not be read, or did not list it, so nothing says who holds it: it is left running, at most to its lifetime, and its labels let a sweep find it`);
196
+ continue;
197
+ }
198
+ const first = convergeSettled(id, read);
199
+ const answered = first === "answered" || first === "answered-older";
200
+ if (answered || leftToConverge(id, read)) {
201
+ const settled = answered ? first : await settle(id, made, signal, sleep, settleBy, reads);
202
+ if (settled === "answered") {
203
+ words.push(`the ${what} it made (${id}) is older than one of its request that has ended, as a create's converge ends its own when it answers an older one: it is left running for that create, and if that create did not answer it (aborted, or failed once its own had ended, or its reply lost too) it runs to its lifetime, and its labels let a sweep find it`);
204
+ continue;
205
+ }
206
+ if (settled === "answered-older") {
207
+ words.push(`the ${what} it made (${id}) is older than one of its request that has ended, and an older one of its request still runs: the create whose own ended may have missed that one and answered this, so it is left running, and if that create answered the older instead it is held by none and runs to its lifetime; its labels let a sweep find it`);
208
+ continue;
209
+ }
210
+ if (settled === "unread") {
211
+ words.push(`the ${what} it made (${id}) is its request's oldest, which another create of the request may answer, and the request's browsers could not be read again: it is left running, at most to its lifetime, and its labels let a sweep find it`);
212
+ continue;
213
+ }
214
+ unanswered = settled === "running";
215
+ }
163
216
  }
164
217
  const released = await release(id, signal);
218
+ const why = unanswered ? `, since every newer ${what} of its request still runs and so no other create answered it` : "";
165
219
  if (released.ok)
166
- words.push(`the ${what} it made (${id}) was released`);
220
+ words.push(`the ${what} it made (${id}) was released${why}`);
167
221
  else if (signal.aborted)
168
222
  words.push(`the ${what} it made (${id}) may still be running: the search and its release did not finish within ${ms / 1000} s, and its labels let a sweep find it`);
169
223
  else
@@ -171,6 +225,61 @@ export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS,
171
225
  }
172
226
  return words.join("; ");
173
227
  }
228
+ /**
229
+ * One wait before a search or a read is tried again: RECOVER_GAP_MS, or what is left until `by` when that is less.
230
+ * False, with no wait, once nothing is left or the recovery's signal has ended.
231
+ */
232
+ async function waitWithin(sleep, by, signal) {
233
+ const left = by - Date.now();
234
+ if (left <= 0 || signal.aborted)
235
+ return false;
236
+ await sleep(Math.min(RECOVER_GAP_MS, left));
237
+ return true;
238
+ }
239
+ /**
240
+ * The request's browsers, read at once and then again after each read that failed or did not list `mine` (which the
241
+ * search found, so such a read says nothing of it), `retries` times at most, each after a wait that ends no later than
242
+ * `by` (waitWithin): so a window shorter than two gaps still tries again while time is left. Undefined when no read
243
+ * listed it.
244
+ */
245
+ async function firstRead(mine, made, signal, sleep, by, retries) {
246
+ for (let read = 0; read <= retries; read++) {
247
+ if (read > 0 && !(await waitWithin(sleep, by, signal)))
248
+ break;
249
+ const got = await made(signal);
250
+ if (got.ok && got.value.some((one) => one.id === mine))
251
+ return got.value;
252
+ }
253
+ return undefined;
254
+ }
255
+ /**
256
+ * A left browser's request read again (convergeSettled) after each RECOVER_GAP_MS, until it is answered or released,
257
+ * `reads` times at most and not past `by` (one read at least): "running" when the last read still found every newer
258
+ * browser running, "unread" when the last read failed or missed a browser the first read listed. No wait runs past
259
+ * `by`, so a bound shorter than the gap still reads once within it, and the read and the release keep the time after
260
+ * `by`.
261
+ */
262
+ async function settle(mine, made, signal, sleep, by, reads) {
263
+ let last = "unread";
264
+ for (let read = 0; read < reads; read++) {
265
+ const left = by - Date.now();
266
+ if ((read > 0 && left < RECOVER_GAP_MS) || signal.aborted)
267
+ break;
268
+ await sleep(Math.max(0, Math.min(RECOVER_GAP_MS, left)));
269
+ const again = await made(signal);
270
+ if (!again.ok) {
271
+ last = "unread";
272
+ continue;
273
+ }
274
+ const now = convergeSettled(mine, again.value);
275
+ if (now === "unread" || now === "running") {
276
+ last = now;
277
+ continue;
278
+ }
279
+ return now;
280
+ }
281
+ return last;
282
+ }
174
283
  const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "gpu", "browser"]);
175
284
  /**
176
285
  * The checks every browser provider makes before a vendor call: the image is chromium, the lifetime is within the
@@ -21,9 +21,9 @@
21
21
  import { readFileSync } from "node:fs";
22
22
  import { BROWSERBASE } from "./descriptors/browserbase.js";
23
23
  import { BROWSER_IMAGE } from "./descriptors/shared.js";
24
- import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, limitedBytes, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, leftToConverge, releaseConfirmed, boundedRelease, restBytes, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
24
+ import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, limitedBytes, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, releaseConfirmed, boundedRelease, restBytes, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
25
25
  import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
26
- import { httpsBase } from "./hosted/rest.js";
26
+ import { httpsBase, keyBase } from "./hosted/rest.js";
27
27
  import { runLifetimeMs, } from "./provider.js";
28
28
  import { failFor, ok, vendorFail } from "./result.js";
29
29
  import { connectionError } from "./test-connection.js";
@@ -40,7 +40,7 @@ export const BROWSERBASE_MAX_LIFETIME_MS = 6 * 60 * 60_000;
40
40
  /** Browserbase's shortest session timeout: 60 s. */
41
41
  export const BROWSERBASE_MIN_LIFETIME_MS = 60_000;
42
42
  const LIVE = new Set(["RUNNING", "PENDING"]);
43
- /** Every status a session reads as, ended ones included: a request's whole record (#leftToConverge). */
43
+ /** Every status a session reads as, ended ones included: a request's whole record (#requestBrowsers). */
44
44
  const EVER = new Set([...LIVE, "COMPLETED", "ERROR", "TIMED_OUT"]);
45
45
  /**
46
46
  * The order #sessions asks for the statuses, a session's own: it is PENDING, then RUNNING, then ended, and never goes
@@ -181,23 +181,12 @@ export function throughGateway(connectUrl, connectBase) {
181
181
  }
182
182
  }
183
183
  /**
184
- * The gateway that fronts the sessions' sockets (BROWSERBASE_CONNECT_BASE_URL), held to wss: or https: as httpsBase holds
185
- * an API URL, since every session's signed CDP URL rides it; throws in words on another, loopback included. One that is
186
- * no URL is not echoed: it may carry the gateway's own token.
184
+ * The gateway that fronts the sessions' sockets (BROWSERBASE_CONNECT_BASE_URL), held to the rule of a URL a key goes to
185
+ * over wss: or https: (keyBase), since every session's signed CDP URL rides it: another scheme, loopback included, a user
186
+ * or password, a query or a fragment throws in keyBase's words, which name the origin at most.
187
187
  */
188
188
  function connectBaseOf(url) {
189
- if (url === undefined)
190
- return undefined;
191
- let parsed;
192
- try {
193
- parsed = new URL(url);
194
- }
195
- catch {
196
- throw new Error("BROWSERBASE_CONNECT_BASE_URL is not a URL");
197
- }
198
- if (parsed.protocol !== "wss:" && parsed.protocol !== "https:")
199
- throw new Error(`BROWSERBASE_CONNECT_BASE_URL must be wss or https, so a session's signed URL never crosses in the clear: ${parsed.protocol}`);
200
- return url;
189
+ return url === undefined ? undefined : keyBase(url, "BROWSERBASE_CONNECT_BASE_URL", ["wss:", "https:"]);
201
190
  }
202
191
  const refOf = (s) => ({ id: s.id, name: s.id });
203
192
  const deadlineOf = (s) => {
@@ -540,13 +529,13 @@ export class BrowserbaseProvider {
540
529
  const found = await this.#sessions(labels, signal);
541
530
  return found.ok ? ok(found.value.map((s) => s.id)) : found;
542
531
  };
543
- const leave = (id, signal) => this.#leftToConverge(request, id, signal);
544
- return recoverCreate("session", find, (id, signal) => this.release({ id, name: id }, "delete", { signal }), this.#sleep, this.#cleanupMs, leave);
532
+ const made = (signal) => this.#requestBrowsers(request, signal);
533
+ return recoverCreate("session", find, (id, signal) => this.release({ id, name: id }, "delete", { signal }), this.#sleep, this.#cleanupMs, made);
545
534
  }
546
- /** Whether a lost create's session is left to another create of its request (leftToConverge); a listing that fails releases it. */
547
- async #leftToConverge(request, id, signal) {
535
+ /** The request's sessions, ended ones included, for a lost create's recovery (recoverCreate, leftToConverge). */
536
+ async #requestBrowsers(request, signal) {
548
537
  const made = await this.#sessions({ [CREATE_LABEL]: request }, signal, EVER);
549
- return made.ok && leftToConverge(id, made.value.map((s) => ({ ...heldOf(s), live: LIVE.has(s.status) })));
538
+ return made.ok ? ok(made.value.map((s) => ({ ...heldOf(s), live: LIVE.has(s.status) }))) : made;
550
539
  }
551
540
  /**
552
541
  * Settings' test: one read of the project's running sessions (GET /v1/sessions?status=RUNNING), which makes nothing.
@@ -618,7 +607,8 @@ export class BrowserbaseProvider {
618
607
  * The running and pending sessions with all of these labels. Browserbase is asked by status and by the first label a
619
608
  * query carries as it is; the match is the provider's own, so a lane that drops the query never hands back another's.
620
609
  * Both statuses must answer: a release trusts this list. `statuses` widens it, to the ended ones too (EVER). The
621
- * statuses are asked in a session's own order (LIFECYCLE), so every session there when the read starts is found.
610
+ * statuses are asked in a session's own order (LIFECYCLE), so every session there when the read starts is found, and a
611
+ * session found in two answers reads as the later one says.
622
612
  */
623
613
  async #sessions(labels, signal, statuses = LIVE) {
624
614
  const problem = browserbaseLabelsProblem(labels);
@@ -636,7 +626,8 @@ export class BrowserbaseProvider {
636
626
  continue;
637
627
  const pages = await Promise.all(asked.map((status) => this.#api.list({ status, ...(q === undefined ? {} : { q }) }, signal)));
638
628
  for (const s of pages.flat()) {
639
- if (typeof s?.id === "string" && statuses.has(s.status) && carries(metadataLabels(s.userMetadata), labels) && !found.has(s.id))
629
+ // A later group's row wins: a session only moves forward, so one answered RUNNING and then COMPLETED has ended.
630
+ if (typeof s?.id === "string" && statuses.has(s.status) && carries(metadataLabels(s.userMetadata), labels))
640
631
  found.set(s.id, s);
641
632
  }
642
633
  }
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.61",
3
- "source": "sha256:724f889fc95233b98e71e6ff4456498fb220f704db4ca2caed5772e3984ba4de"
2
+ "version": "0.1.0-beta.63",
3
+ "source": "sha256:87bae6cf24a8e902d2e9e0727e778cc283e1c62d03f6a54f4c6f78557ad5a632"
4
4
  }
@@ -0,0 +1,50 @@
1
+ import type { MachineHost } from "../host.js";
2
+ import type { HostedDial } from "../hosted/provider.js";
3
+ import type { ProviderNote } from "../mount-archil.js";
4
+ import { type RenderProvider } from "../render.js";
5
+ import { CONFORMANCE_MAX_LIFETIME_MS, type Env } from "./module-kit.js";
6
+ export { CONFORMANCE_MAX_LIFETIME_MS };
7
+ export declare const RENDER_ENV: {
8
+ /** apiKey, required: a Render API key that may make sandboxes in the workspace. */
9
+ readonly key: "COMPUTER_RENDER_API_KEY";
10
+ /** ownerId, required: the workspace the run's sandboxes are made in (tea-… or usr-…). */
11
+ readonly workspace: "COMPUTER_RENDER_WORKSPACE_ID";
12
+ /** The build the run's computers start from; default the box build prepareImage() finds or imports. */
13
+ readonly image: "COMPUTER_RENDER_IMAGE";
14
+ };
15
+ export declare const ENV: {
16
+ /** apiKey, required: a Render API key that may make sandboxes in the workspace. */
17
+ readonly key: "COMPUTER_RENDER_API_KEY";
18
+ /** ownerId, required: the workspace the run's sandboxes are made in (tea-… or usr-…). */
19
+ readonly workspace: "COMPUTER_RENDER_WORKSPACE_ID";
20
+ /** The build the run's computers start from; default the box build prepareImage() finds or imports. */
21
+ readonly image: "COMPUTER_RENDER_IMAGE";
22
+ };
23
+ /** The provider's options this module reads from env; throws in words without the key or the workspace, never echoing one. */
24
+ export declare function settingsFromEnv(env?: Env): {
25
+ apiKey: string;
26
+ ownerId: string;
27
+ };
28
+ export interface RenderModuleOptions {
29
+ /** The environment to read; process.env by default. */
30
+ env?: Record<string, string | undefined>;
31
+ /** The server the machines dial: dial-conformance.mjs gives its own. Without it every create is refused in words. */
32
+ dial?: HostedDial;
33
+ /** The daemon the server serves (its sha256 is what a machine checks); default this package's dist/computerd-linux-amd64. */
34
+ daemonPath?: string;
35
+ /** The fetch Render's calls go through; default the global one. */
36
+ fetch?: typeof fetch;
37
+ /** What the provider says that is no failure: the CLI gives it and puts it in the report. */
38
+ onNote?: ProviderNote;
39
+ }
40
+ /** The provider the run makes computers with, dialing the server options.dial names. */
41
+ export declare function createProvider({ env, dial, daemonPath, fetch, onNote }?: RenderModuleOptions): RenderProvider;
42
+ /** The run's image: COMPUTER_RENDER_IMAGE's build, else the box build the workspace has or imports (prepareImage). */
43
+ export declare function conformanceImage(options?: RenderModuleOptions, { signal }?: {
44
+ signal?: AbortSignal;
45
+ }): Promise<string>;
46
+ /** The server the run's machines dial, for provider.dial-token, as the CLI asks for it: refused in words (dial-only.ts). */
47
+ export declare const dialKit: () => import("./types.js").DialKit;
48
+ export declare function createHost({ env, fetch }?: Pick<RenderModuleOptions, "env" | "fetch">): MachineHost;
49
+ /** Where the sweep lists, in words: the workspace the settings name. */
50
+ export declare function sweepScope({ env }?: Pick<RenderModuleOptions, "env">): string;
@@ -0,0 +1,55 @@
1
+ // Render Sandboxes for the conformance run. Its machines dial the server that minted their tokens (facts.connect
2
+ // "dial"), so a Core run has to happen inside that server's own process, behind its public address: serve's
3
+ // packages/serve/scripts/dial-conformance.mjs --provider render does it: it gives createProvider() its dial (the public
4
+ // URL, the minted tokens and the attach hub) and the run a DialKit over the same server. From a laptop's CLI there is no
5
+ // such server: dialKit() refuses in words, and the provider refuses every create before Render is called. The key is
6
+ // read from COMPUTER_RENDER_API_KEY alone (never RENDER_API_KEY, which may hold a production key).
7
+ import { RENDER } from "../descriptors/render.js";
8
+ import { create } from "../render.js";
9
+ import { dialOnlyFromServer } from "./dial-only.js";
10
+ import { CONFORMANCE_MAX_LIFETIME_MS, preparedImage } from "./module-kit.js";
11
+ export { CONFORMANCE_MAX_LIFETIME_MS };
12
+ export const RENDER_ENV = {
13
+ /** apiKey, required: a Render API key that may make sandboxes in the workspace. */
14
+ key: "COMPUTER_RENDER_API_KEY",
15
+ /** ownerId, required: the workspace the run's sandboxes are made in (tea-… or usr-…). */
16
+ workspace: "COMPUTER_RENDER_WORKSPACE_ID",
17
+ /** The build the run's computers start from; default the box build prepareImage() finds or imports. */
18
+ image: "COMPUTER_RENDER_IMAGE",
19
+ };
20
+ export const ENV = RENDER_ENV;
21
+ /** The provider's options this module reads from env; throws in words without the key or the workspace, never echoing one. */
22
+ export function settingsFromEnv(env = process.env) {
23
+ const apiKey = env[RENDER_ENV.key];
24
+ const ownerId = env[RENDER_ENV.workspace];
25
+ if (!apiKey || !ownerId)
26
+ throw new Error(`the Render conformance module needs ${RENDER_ENV.key} and ${RENDER_ENV.workspace}: it takes a key from that name only, never RENDER_API_KEY`);
27
+ return { apiKey, ownerId };
28
+ }
29
+ /** The provider the run makes computers with, dialing the server options.dial names. */
30
+ export function createProvider({ env = process.env, dial, daemonPath, fetch, onNote } = {}) {
31
+ return create({
32
+ ...settingsFromEnv(env),
33
+ ...(dial ? { dial } : {}),
34
+ ...(daemonPath === undefined ? {} : { daemonPath }),
35
+ ...(fetch ? { fetch } : {}),
36
+ ...(onNote ? { onNote } : {}),
37
+ maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS,
38
+ });
39
+ }
40
+ /** The run's image: COMPUTER_RENDER_IMAGE's build, else the box build the workspace has or imports (prepareImage). */
41
+ export async function conformanceImage(options = {}, { signal } = {}) {
42
+ const named = (options.env ?? process.env)[RENDER_ENV.image];
43
+ if (named)
44
+ return named;
45
+ return preparedImage(createProvider(options), signal);
46
+ }
47
+ /** The server the run's machines dial, for provider.dial-token, as the CLI asks for it: refused in words (dial-only.ts). */
48
+ export const dialKit = dialOnlyFromServer(RENDER);
49
+ export function createHost({ env = process.env, fetch } = {}) {
50
+ return create({ ...settingsFromEnv(env), ...(fetch ? { fetch } : {}) }).host;
51
+ }
52
+ /** Where the sweep lists, in words: the workspace the settings name. */
53
+ export function sweepScope({ env = process.env } = {}) {
54
+ return `the Render workspace ${settingsFromEnv(env).ownerId}`;
55
+ }
@@ -13,6 +13,7 @@ import { MODAL } from "./modal.js";
13
13
  import { MORPH } from "./morph.js";
14
14
  import { ORGO } from "./orgo.js";
15
15
  import { PHONE_HARNESS } from "./phone-harness.js";
16
+ import { RENDER } from "./render.js";
16
17
  import { SMOLCLOUD } from "./smolcloud.js";
17
18
  export declare const DESCRIPTORS: readonly [{
18
19
  readonly id: "docker";
@@ -288,6 +289,25 @@ export declare const DESCRIPTORS: readonly [{
288
289
  }];
289
290
  readonly prepareImage: true;
290
291
  readonly load: () => Promise<typeof import("../fly.js")>;
292
+ }, {
293
+ readonly id: "render";
294
+ readonly label: "Render";
295
+ readonly keys: readonly [{
296
+ readonly name: "RENDER_API_KEY";
297
+ readonly option: "apiKey";
298
+ readonly required: true;
299
+ }, {
300
+ readonly name: "RENDER_WORKSPACE_ID";
301
+ readonly option: "ownerId";
302
+ readonly required: true;
303
+ }];
304
+ readonly metered: true;
305
+ readonly connect: "dial";
306
+ readonly mounts: readonly [];
307
+ readonly network: readonly ["none", "open", "allow"];
308
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities];
309
+ readonly prepareImage: true;
310
+ readonly load: () => Promise<typeof import("../render.js")>;
291
311
  }, {
292
312
  readonly id: "orgo";
293
313
  readonly label: "Orgo";
@@ -529,7 +549,7 @@ export declare const DESCRIPTORS: readonly [{
529
549
  readonly prepareImage: true;
530
550
  readonly load: () => Promise<typeof import("../groundbox.js")>;
531
551
  }];
532
- export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, GROUNDBOX, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, SMOLCLOUD };
552
+ export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, GROUNDBOX, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, RENDER, SMOLCLOUD };
533
553
  export { AGENT37_BASE_TEMPLATE } from "./agent37.js";
534
554
  export { BOXD_DEFAULT_IMAGE } from "./boxd.js";
535
555
  export { GROUNDBOX_OWN_IMAGE } from "./groundbox.js";
@@ -15,9 +15,10 @@ import { MODAL } from "./modal.js";
15
15
  import { MORPH } from "./morph.js";
16
16
  import { ORGO } from "./orgo.js";
17
17
  import { PHONE_HARNESS } from "./phone-harness.js";
18
+ import { RENDER } from "./render.js";
18
19
  import { SMOLCLOUD } from "./smolcloud.js";
19
- export const DESCRIPTORS = [DOCKER, DAYTONA, MODAL, E2B, AGENT37, MORPH, CLOUDFLARE, FLY, ORGO, PHONE_HARNESS, BROWSERBASE, KERNEL, LOCAL, BOXD, SMOLCLOUD, GROUNDBOX];
20
- export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, GROUNDBOX, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, SMOLCLOUD };
20
+ export const DESCRIPTORS = [DOCKER, DAYTONA, MODAL, E2B, AGENT37, MORPH, CLOUDFLARE, FLY, RENDER, ORGO, PHONE_HARNESS, BROWSERBASE, KERNEL, LOCAL, BOXD, SMOLCLOUD, GROUNDBOX];
21
+ export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, GROUNDBOX, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, RENDER, SMOLCLOUD };
21
22
  export { AGENT37_BASE_TEMPLATE } from "./agent37.js";
22
23
  export { BOXD_DEFAULT_IMAGE } from "./boxd.js";
23
24
  export { GROUNDBOX_OWN_IMAGE } from "./groundbox.js";