@parcha/agentrun-computer 0.1.0-beta.64 → 0.1.0-beta.66

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
@@ -1236,6 +1236,16 @@ as a caller's labels, with no code of its own: Docker writes them with `--label`
1236
1236
  cannot prove it is current (named in `unproven`, with why). It keeps the run's computers of this epoch. It holds
1237
1237
  each listed computer to the run's label again, so a computer of another run is never touched, whatever `list` gives.
1238
1238
  It returns `{ released, kept, unproven }`.
1239
+ - `releaseUnheld(provider, run, epoch, held, { signal? })` is the claim's own sweep, for when it lets the run go: it
1240
+ lists the run's computers by `agentrun.run` and deletes each of this epoch that `held(info)` refuses, keeping every
1241
+ one of another epoch, another run, or the agent's tenure. A browser one create of a request made and then lost, kept
1242
+ by its recovery, is one: nothing holds it, and the vendor alone would end it. It returns
1243
+ `{ released, held, failed }`, each released computer with its labels and, when the listing gives it, `createdAt`,
1244
+ from which its time is charged; a release that fails is named in `failed` and the rest go on. Its options may carry
1245
+ `releasing(computer)`, run before each release is sent (a host saves what it books the computer's time by, so a
1246
+ process that ends before the booking leaves a record a later one books from; one that throws holds that computer back,
1247
+ named in `failed`), and `released(computer)`, run as each release answers, before the next is sent (a host books it
1248
+ there, so a later release that hangs leaves it booked).
1239
1249
  - **Fenced.** A computer of the run with a higher epoch means a later claim holds the run: `releaseOlder` is refused
1240
1250
  (`refused`, `fenced: run "r1" has computer-… at epoch 4, above this claim's epoch 3; …`) before it releases
1241
1251
  anything.
@@ -2679,10 +2689,10 @@ when that half is under 2 s). While every newer one still runs, no converge has
2679
2689
  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
2680
2690
  an older one that runs, since a converge whose list missed the older may have answered it. That keeps one held by none
2681
2691
  too: where three creates of a request ran, the newest's converge may have answered the oldest and ended its own, and
2682
- the lost create's, the middle one, then runs to the vendor's lifetime; its failure says that an older one still runs.
2683
- A read that fails, or that misses the lost create's browser, or a read again that misses every newer one, says nothing
2684
- of who holds it and leaves it running; a first read that fails or misses it is tried again within the same half before
2685
- that. The search's own retries, for a vendor that lists a browser late, wait within that
2692
+ the lost create's, the middle one, is held by none; its failure says that an older one still runs.
2693
+ A first read that fails or misses the lost create's browser, or a last read again that fails or misses it or every
2694
+ newer one, says nothing of who holds it and leaves it running (a read again before the last is followed by the next,
2695
+ which decides); a first read that fails or misses it is tried again within the same half before that. The search's own retries, for a vendor that lists a browser late, wait within that
2686
2696
  half too, so the release keeps the other half.
2687
2697
  Browserbase is asked status by status in a session's own order (pending, then running, then the ended ones), so a
2688
2698
  session that moves on while a list runs is found in a later answer, never missed, and one found in two answers reads as
@@ -2692,16 +2702,22 @@ while it listed the request, or released its own and then failed (its release re
2692
2702
  older failed), or its own reply was lost too and its recovery released it. Nothing on the vendor tells those apart, so
2693
2703
  there the lost create's browser runs to the vendor's lifetime: on Browserbase its `timeout`, up to the run's lifetime
2694
2704
  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.
2695
- The create's failure says so, and its labels let a sweep find it. This bound is not covered, and is tracked separately.
2705
+ The create's failure says so. A browser that carries a run's labels (`runLabels`) is released sooner, when the run's
2706
+ claim lets the run go (`releaseUnheld`, which serve runs at a run's end, stop and park).
2696
2707
  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
2697
2708
  them in a spec, and no list or attach shows them.
2698
2709
 
2699
- Two gaps are not covered, and are tracked separately. A lost create whose browser is the request's only one releases
2710
+ Three gaps are not covered, and are tracked separately. A lost create whose browser is the request's only one releases
2700
2711
  it even when another process's create answered it by its lookup, or when the lost create read the request before the
2701
2712
  other create's POST landed and that create's converge answered it: nothing on the vendor says so, and that create
2702
2713
  holds a browser that has ended. The same holds when a converge lists the lost create's browser running just before the
2703
2714
  lost create's last read again and ends its own just after: the lost create releases it, and that create's read of it
2704
- 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
2715
+ most often finds it ended and fails the request. Nor does a newer browser that still runs prove that nothing answered
2716
+ the lost create's: another create's lookup answers the request's oldest without a converge and ends nothing, so a
2717
+ lookup that lists the lost create's browser while a newer one runs answers it, and the lost create's last read again
2718
+ still finds every newer one running and releases it; nothing on the vendor tells that lookup apart. The lookup's caller
2719
+ then holds a browser that has ended: a pi-browser host's next call finds it ended and opens a fresh session, losing one
2720
+ call and the page state, and a call with effects that was under way may report `possibly_effected`. On Orgo, a create whose POST got no answer deletes the computer by its exact name; that
2705
2721
  name can be the computer another process's create answered through Orgo's 409 (name in use), which then holds a
2706
2722
  deleted computer.
2707
2723
 
package/dist/browser.d.ts CHANGED
@@ -67,6 +67,11 @@ export declare const ATTEMPT_LABEL = "agentrun.attempt";
67
67
  export declare const newAttempt: () => string;
68
68
  /** Labels without the provider's own, the create and attempt labels. */
69
69
  export declare const withoutCreateLabel: (labels: Record<string, string>) => Record<string, string>;
70
+ /** A listed browser's createdAt (ComputerInfo), from the time its vendor says it made it: none where that is absent or
71
+ * is no time. */
72
+ export declare const createdOf: (at: string | undefined) => {
73
+ createdAt?: Date;
74
+ };
70
75
  /** A browser a create label found: its id, when the vendor made it (an ISO time, where it says), and its labels. */
71
76
  export interface HeldBrowser {
72
77
  id: string;
@@ -109,8 +114,8 @@ export type MadeBrowser = HeldBrowser & {
109
114
  export declare function leftToConverge(mine: string, made: ReadonlyArray<MadeBrowser>): boolean;
110
115
  /**
111
116
  * 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;
117
+ * "unread" when the read does not list mine, or lists no newer one (the first read did, so it says nothing); "release"
118
+ * once mine has ended; "answered" when a newer one has ended, since a converge that answers the older ends its own first;
114
119
  * "answered-older" when an older one also runs, since that converge may have missed the older and answered mine, or
115
120
  * answered the older and left mine held by none; "release" when an older one runs and every newer one runs too;
116
121
  * "running" while every newer one still runs, so no converge has answered mine yet.
@@ -129,6 +134,15 @@ export declare function createUncertain(error: unknown): boolean;
129
134
  * late. Also the default bound of every other release a create runs for itself (a provider's cleanupMs).
130
135
  */
131
136
  export declare const RECOVER_MS = 30000;
137
+ /** A recovery under way in this process (recoverCreate): `by`, when its own bound ends (ms since the epoch), and `done`,
138
+ * settled once it has ended, never rejected. */
139
+ export type RecoveryInFlight = {
140
+ readonly by: number;
141
+ readonly done: Promise<void>;
142
+ };
143
+ /** Every recovery under way in this process (recoverCreate), as it starts: what a process that is about to exit waits
144
+ * for, each to its own bound, so a browser a lost create made is released before the process goes. */
145
+ export declare function recoveriesInFlight(): readonly RecoveryInFlight[];
132
146
  /**
133
147
  * After a create whose outcome is unknown: the browsers carrying its create label, found and released under a signal
134
148
  * of the recovery's own, `ms` in all (the caller's may be what ended the create). The search, its retries for a vendor
@@ -137,9 +151,10 @@ export declare const RECOVER_MS = 30000;
137
151
  * included), each found browser's request is read, again after a read that failed or did not list it, and one no read
138
152
  * lists is kept: such a read says nothing of who holds it. One older than a browser of its request that has ended
139
153
  * (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
154
+ * one whose list missed the older may have answered it; where an older one runs, the words say it may be held by none.
155
+ * One left to another create's converge (leftToConverge) is otherwise read again, every RECOVER_GAP_MS within that half
156
+ * (once at least), and kept once a newer one has ended or the last read fails or misses a browser the first read
157
+ * listed. One whose newer browsers all still run at the end was answered by no converge (each
143
158
  * kept its own) and is released. The words say what became of them, for the create's failure; they never carry a URL.
144
159
  */
145
160
  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>;
package/dist/browser.js CHANGED
@@ -78,6 +78,12 @@ export const withoutCreateLabel = (labels) => {
78
78
  const { [CREATE_LABEL]: _, [ATTEMPT_LABEL]: __, ...rest } = labels;
79
79
  return rest;
80
80
  };
81
+ /** A listed browser's createdAt (ComputerInfo), from the time its vendor says it made it: none where that is absent or
82
+ * is no time. */
83
+ export const createdOf = (at) => {
84
+ const time = typeof at === "string" && at !== "" ? new Date(at) : undefined;
85
+ return time !== undefined && !Number.isNaN(time.getTime()) ? { createdAt: time } : {};
86
+ };
81
87
  /**
82
88
  * The order a request's browsers are read in (heldBrowser, a create's converge): the oldest first, by the time the
83
89
  * vendor made each, then by id. The same browsers give the same order in every process.
@@ -121,8 +127,8 @@ export function leftToConverge(mine, made) {
121
127
  }
122
128
  /**
123
129
  * 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;
130
+ * "unread" when the read does not list mine, or lists no newer one (the first read did, so it says nothing); "release"
131
+ * once mine has ended; "answered" when a newer one has ended, since a converge that answers the older ends its own first;
126
132
  * "answered-older" when an older one also runs, since that converge may have missed the older and answered mine, or
127
133
  * answered the older and left mine held by none; "release" when an older one runs and every newer one runs too;
128
134
  * "running" while every newer one still runs, so no converge has answered mine yet.
@@ -157,6 +163,12 @@ export function createUncertain(error) {
157
163
  export const RECOVER_MS = 30_000;
158
164
  const RECOVER_TRIES = 3;
159
165
  const RECOVER_GAP_MS = 2_000;
166
+ const recovering = new Set();
167
+ /** Every recovery under way in this process (recoverCreate), as it starts: what a process that is about to exit waits
168
+ * for, each to its own bound, so a browser a lost create made is released before the process goes. */
169
+ export function recoveriesInFlight() {
170
+ return [...recovering];
171
+ }
160
172
  /**
161
173
  * After a create whose outcome is unknown: the browsers carrying its create label, found and released under a signal
162
174
  * of the recovery's own, `ms` in all (the caller's may be what ended the create). The search, its retries for a vendor
@@ -165,12 +177,20 @@ const RECOVER_GAP_MS = 2_000;
165
177
  * included), each found browser's request is read, again after a read that failed or did not list it, and one no read
166
178
  * lists is kept: such a read says nothing of who holds it. One older than a browser of its request that has ended
167
179
  * (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
180
+ * one whose list missed the older may have answered it; where an older one runs, the words say it may be held by none.
181
+ * One left to another create's converge (leftToConverge) is otherwise read again, every RECOVER_GAP_MS within that half
182
+ * (once at least), and kept once a newer one has ended or the last read fails or misses a browser the first read
183
+ * listed. One whose newer browsers all still run at the end was answered by no converge (each
171
184
  * kept its own) and is released. The words say what became of them, for the create's failure; they never carry a URL.
172
185
  */
173
186
  export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS, made) {
187
+ const running = recoverOnce(what, find, release, sleep, ms, made);
188
+ const entry = { by: Date.now() + ms, done: running.then(() => undefined, () => undefined) };
189
+ recovering.add(entry);
190
+ void entry.done.then(() => recovering.delete(entry));
191
+ return running;
192
+ }
193
+ async function recoverOnce(what, find, release, sleep, ms, made) {
174
194
  const signal = AbortSignal.timeout(ms);
175
195
  const settleBy = Date.now() + ms / 2;
176
196
  const reads = Math.max(1, Math.floor(ms / 2 / RECOVER_GAP_MS));
@@ -21,7 +21,7 @@
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, 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, createdOf, vendorFailure, withoutCreateLabel, } from "./browser.js";
25
25
  import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
26
26
  import { httpsBase, keyBase } from "./hosted/rest.js";
27
27
  import { runLifetimeMs, } from "./provider.js";
@@ -641,7 +641,7 @@ export class BrowserbaseProvider {
641
641
  const found = await this.#sessions(labels, signal);
642
642
  if (!found.ok)
643
643
  return found;
644
- return ok(found.value.map((s) => ({ ref: refOf(s), labels: fromMetadata(s.userMetadata), deadline: deadlineOf(s), state: "running", network: "open" })));
644
+ return ok(found.value.map((s) => ({ ref: refOf(s), labels: fromMetadata(s.userMetadata), deadline: deadlineOf(s), state: "running", network: "open", ...createdOf(s.createdAt ?? s.startedAt) })));
645
645
  }
646
646
  /** Always open: a Browserbase browser reaches the open web, and a change is refused in words. */
647
647
  async network(ref, policy, { signal } = {}) {
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.64",
2
+ "version": "0.1.0-beta.66",
3
3
  "source": "sha256:ca76a29aaa9ab0216cefc6badb124b6ab39a5a0094b984fa8d26537633ccad1e"
4
4
  }
package/dist/index.d.ts CHANGED
@@ -20,11 +20,11 @@ export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, en
20
20
  export { ADB_ENV_NAMES, adbEnv, BASE_ENV_NAMES, CHROME_ENV_NAMES, childEnv, chromeEnv, DOCKER_ENV_NAMES, dockerEnv, type HostEnv } from "./child-env.js";
21
21
  export { containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
22
22
  export { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, type ArchilMount, type ArchilEgress, type ArchilMountOptions, type ArchilRoot, type ProviderNote, archilEgressOf, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, archilSync, claimEpoch, helperSha256, MOUNT_LABEL, mountDrift, mountWords, type RecordedFolder, type RecordedSource, readMount, recordedFolder, recordedMount, SYNC_LABELS, syncingClient, } from "./mount-archil.js";
23
- export { type BrowserComputerProvider, type BrowserDownloads, type BrowserFile, type BrowserProfiles, type BrowserSessionUsage, browserSpecRefusals, type BrowserStream, isBrowserProvider, BrowserVendorError, CREATE_LABEL, ATTEMPT_LABEL, causeOf, memoryUrls, RECOVER_MS, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
23
+ export { type BrowserComputerProvider, type BrowserDownloads, type BrowserFile, type BrowserProfiles, type BrowserSessionUsage, browserSpecRefusals, type BrowserStream, isBrowserProvider, BrowserVendorError, CREATE_LABEL, ATTEMPT_LABEL, causeOf, memoryUrls, RECOVER_MS, recoverCreate, recoveriesInFlight, type RecoveryInFlight, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
24
24
  export { CHROME_ENV, CHROME_FLAGS, checkChrome, chromeFence, findChrome, killTree, NO_CHROME } from "./chrome.js";
25
25
  export { DAEMON_IN_COMPUTER, helloDrift, type HelloExpected } from "./drift.js";
26
26
  export { drift, hostOf, inspectDrift, mountOf, networkOf, type DockerHost, type DockerInfo, type DockerInspect, type DriftExpected } from "./docker/inspect.js";
27
- export { type ReleasedOlder, releaseOlder, sweep, type SweepOptions, type Swept } from "./janitor.js";
27
+ export { type ReleasedOlder, type ReleasedUnheld, releaseOlder, releaseUnheld, sweep, type SweepOptions, type Swept, type UnheldHooks } from "./janitor.js";
28
28
  export { EPOCH_LABEL, epochOf, epochProblem, IDLE_TTL_LABEL, OWNER_LABEL, OWNER_SERVER_LABEL, ownerFilter, ownerLabels, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, runLabels, runProblem } from "./labels.js";
29
29
  export { waitUntil, type WaitOptions } from "./wait.js";
30
30
  export { type BuiltinProviderId, type ConformanceModule, descriptorOf, isProviderId, type ProviderEnv, providerFor, type ProviderId, providerIds, type ProviderModule, providerModule, type ProviderOptions, providers, } from "./providers.js";
package/dist/index.js CHANGED
@@ -24,13 +24,13 @@ export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, en
24
24
  export { ADB_ENV_NAMES, adbEnv, BASE_ENV_NAMES, CHROME_ENV_NAMES, childEnv, chromeEnv, DOCKER_ENV_NAMES, dockerEnv } from "./child-env.js";
25
25
  export { containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
26
26
  export { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, archilEgressOf, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, archilSync, claimEpoch, helperSha256, MOUNT_LABEL, mountDrift, mountWords, readMount, recordedFolder, recordedMount, SYNC_LABELS, syncingClient, } from "./mount-archil.js";
27
- export { browserSpecRefusals, isBrowserProvider, BrowserVendorError, CREATE_LABEL, ATTEMPT_LABEL, causeOf, memoryUrls, RECOVER_MS, } from "./browser.js";
27
+ export { browserSpecRefusals, isBrowserProvider, BrowserVendorError, CREATE_LABEL, ATTEMPT_LABEL, causeOf, memoryUrls, RECOVER_MS, recoverCreate, recoveriesInFlight, } from "./browser.js";
28
28
  // Local Chrome's provider class is on its provider id's subpath (@parcha/agentrun-computer/local-chrome), as every
29
29
  // provider's is; the Chrome helpers it runs on are not a provider and stay here.
30
30
  export { CHROME_ENV, CHROME_FLAGS, checkChrome, chromeFence, findChrome, killTree, NO_CHROME } from "./chrome.js";
31
31
  export { DAEMON_IN_COMPUTER, helloDrift } from "./drift.js";
32
32
  export { drift, hostOf, inspectDrift, mountOf, networkOf } from "./docker/inspect.js";
33
- export { releaseOlder, sweep } from "./janitor.js";
33
+ export { releaseOlder, releaseUnheld, sweep } from "./janitor.js";
34
34
  export { EPOCH_LABEL, epochOf, epochProblem, IDLE_TTL_LABEL, OWNER_LABEL, OWNER_SERVER_LABEL, ownerFilter, ownerLabels, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, runLabels, runProblem } from "./labels.js";
35
35
  export { waitUntil } from "./wait.js";
36
36
  export { descriptorOf, isProviderId, providerFor, providerIds, providerModule, providers, } from "./providers.js";
package/dist/janitor.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CallContext, ComputerOwner, ComputerProvider, ComputerRef } from "./provider.js";
1
+ import type { CallContext, ComputerInfo, ComputerOwner, ComputerProvider, ComputerRef } from "./provider.js";
2
2
  import { type Result } from "./result.js";
3
3
  export interface SweepOptions {
4
4
  /** Only computers with all of these labels; default every computer the provider made. */
@@ -72,3 +72,55 @@ export interface ReleasedOlder {
72
72
  * persistence) of a lower epoch is detached, never deleted: its state is the agent's, and the new claim attaches it.
73
73
  */
74
74
  export declare function releaseOlder(provider: ComputerProvider, run: string, epoch: number, { signal }?: CallContext): Promise<Result<ReleasedOlder>>;
75
+ /** What a host records around each release releaseUnheld makes. `releasing` runs before a computer's release is sent: a
76
+ * host saves what it will book the computer's time by (its id, and when its vendor made it), so a process that ends
77
+ * between the release and its booking leaves a record a later one books from. One that throws holds that computer back:
78
+ * it is not released, and is named in `failed`. `released` runs once a computer's release answered, before the next
79
+ * release is sent: a host books that one's time there, so a later release that does not answer leaves it booked. One
80
+ * that throws ends the sweep with its error. */
81
+ export interface UnheldHooks {
82
+ releasing?: (computer: {
83
+ ref: ComputerRef;
84
+ labels: Record<string, string>;
85
+ createdAt?: Date;
86
+ }) => Promise<void>;
87
+ released?: (computer: {
88
+ ref: ComputerRef;
89
+ labels: Record<string, string>;
90
+ createdAt?: Date;
91
+ }) => Promise<void>;
92
+ }
93
+ export interface ReleasedUnheld {
94
+ /** The run's computers of this epoch that nothing held, released: each with its labels and, where its listing says,
95
+ * when its vendor made it (the time a host books for it). */
96
+ released: Array<{
97
+ ref: ComputerRef;
98
+ labels: Record<string, string>;
99
+ createdAt?: Date;
100
+ }>;
101
+ /** The run's computers of this epoch that `held` kept, left as they are. */
102
+ held: ComputerRef[];
103
+ /** Each release that failed, with its words: the computer is left to its lifetime, and its labels let a sweep find it. */
104
+ failed: Array<{
105
+ ref: ComputerRef;
106
+ problem: string;
107
+ }>;
108
+ }
109
+ /**
110
+ * When a claim lets its run go: deletes every computer of the run labelled with this claim's epoch that `held` does not
111
+ * keep. A create whose reply was lost can leave a computer that no claim holds (one that another create's converge did
112
+ * not answer, which its own recovery kept), and a vendor that ends its computers itself (lifetime "vendor") runs it to
113
+ * its lifetime otherwise: the janitor's sweep refuses such a provider, and releaseOlder takes only lower epochs.
114
+ *
115
+ * It lists by the run's label and holds each listed computer to it, as releaseOlder does: a computer of another run is
116
+ * never touched, whatever list gives. A computer of another epoch is left (a lower one is the next claim's releaseOlder,
117
+ * a higher one a later claim's own), and so is one whose epoch cannot be read, and an agent's computer (an owner label,
118
+ * or an info marked owned, of a provider that declares persistence), which is never a run's to end. `held` is asked of
119
+ * each computer of the run and epoch once the list has answered, so a host reads what it holds after the list: what it
120
+ * made before then is in its own record.
121
+ *
122
+ * Every release is attempted, and each that fails is named in the result, never an error: the ones released are
123
+ * released whatever the others did, so a host books each. A list that fails is the error. An aborted call starts no
124
+ * further release; the result names what it released.
125
+ */
126
+ export declare function releaseUnheld(provider: ComputerProvider, run: string, epoch: number, held: (info: ComputerInfo) => boolean | Promise<boolean>, { signal, releasing, released: told }?: CallContext & UnheldHooks): Promise<Result<ReleasedUnheld>>;
package/dist/janitor.js CHANGED
@@ -181,3 +181,62 @@ export async function releaseOlder(provider, run, epoch, { signal } = {}) {
181
181
  return failAs(firstError, `${what} is incomplete: ${done()}`);
182
182
  return ok({ released, detached, kept, unproven });
183
183
  }
184
+ /**
185
+ * When a claim lets its run go: deletes every computer of the run labelled with this claim's epoch that `held` does not
186
+ * keep. A create whose reply was lost can leave a computer that no claim holds (one that another create's converge did
187
+ * not answer, which its own recovery kept), and a vendor that ends its computers itself (lifetime "vendor") runs it to
188
+ * its lifetime otherwise: the janitor's sweep refuses such a provider, and releaseOlder takes only lower epochs.
189
+ *
190
+ * It lists by the run's label and holds each listed computer to it, as releaseOlder does: a computer of another run is
191
+ * never touched, whatever list gives. A computer of another epoch is left (a lower one is the next claim's releaseOlder,
192
+ * a higher one a later claim's own), and so is one whose epoch cannot be read, and an agent's computer (an owner label,
193
+ * or an info marked owned, of a provider that declares persistence), which is never a run's to end. `held` is asked of
194
+ * each computer of the run and epoch once the list has answered, so a host reads what it holds after the list: what it
195
+ * made before then is in its own record.
196
+ *
197
+ * Every release is attempted, and each that fails is named in the result, never an error: the ones released are
198
+ * released whatever the others did, so a host books each. A list that fails is the error. An aborted call starts no
199
+ * further release; the result names what it released.
200
+ */
201
+ export async function releaseUnheld(provider, run, epoch, held, { signal, releasing, released: told } = {}) {
202
+ const problem = runProblem(run) ?? epochProblem(epoch);
203
+ if (problem !== undefined)
204
+ return fail("invalid", problem);
205
+ if (signal?.aborted)
206
+ return fail("aborted", `the release of run ${JSON.stringify(run)}'s unheld computers was aborted before it began`);
207
+ const listed = await provider.list({ [RUN_LABEL]: run }, { signal });
208
+ if (!listed.ok)
209
+ return failAs(listed.error, `could not list run ${JSON.stringify(run)}'s computers: ${listed.error.message}`);
210
+ const { persistence } = provider.capabilities();
211
+ const result = { released: [], held: [], failed: [] };
212
+ for (const info of listed.value) {
213
+ const { ref, labels } = info;
214
+ if (labels?.[RUN_LABEL] !== run)
215
+ continue;
216
+ const read = epochOf(labels);
217
+ if (!read.ok || read.value !== epoch || tenureOf(info, persistence).agent)
218
+ continue;
219
+ if (await held(info)) {
220
+ result.held.push(ref);
221
+ continue;
222
+ }
223
+ if (signal?.aborted)
224
+ break;
225
+ const computer = { ref, labels, ...(info.createdAt instanceof Date ? { createdAt: info.createdAt } : {}) };
226
+ try {
227
+ await releasing?.(computer);
228
+ }
229
+ catch (error) {
230
+ result.failed.push({ ref, problem: `its release was not sent, as what books its time could not be saved first: ${error instanceof Error ? error.message : String(error)}` });
231
+ continue;
232
+ }
233
+ const released = await provider.release(ref, "delete");
234
+ if (!released.ok) {
235
+ result.failed.push({ ref, problem: released.error.message });
236
+ continue;
237
+ }
238
+ result.released.push(computer);
239
+ await told?.(computer);
240
+ }
241
+ return ok(result);
242
+ }
package/dist/kernel.js CHANGED
@@ -20,7 +20,7 @@ import { randomBytes } from "node:crypto";
20
20
  import { readFileSync } from "node:fs";
21
21
  import { KERNEL } from "./descriptors/kernel.js";
22
22
  import { BROWSER_IMAGE } from "./descriptors/shared.js";
23
- import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, releaseConfirmed, boundedRelease, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
23
+ import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, releaseConfirmed, boundedRelease, restCall, causedFail, createdOf, vendorFailure, withoutCreateLabel, } from "./browser.js";
24
24
  import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
25
25
  import { httpsBase } from "./hosted/rest.js";
26
26
  import { runLifetimeMs, } from "./provider.js";
@@ -463,7 +463,7 @@ export class KernelProvider {
463
463
  if (!found.ok)
464
464
  return found;
465
465
  // Kernel's timeout is idle time, not a wall clock: no deadline to read.
466
- return ok(found.value.map(({ id, tags }) => ({ ref: refOf(id), labels: tags, deadline: undefined, state: "running", network: "open" })));
466
+ return ok(found.value.map(({ id, tags, createdAt }) => ({ ref: refOf(id), labels: tags, deadline: undefined, state: "running", network: "open", ...createdOf(createdAt) })));
467
467
  }
468
468
  /** Always open: a Kernel browser reaches the open web, and a change is refused in words. */
469
469
  async network(ref, policy, { signal } = {}) {
@@ -344,6 +344,9 @@ export interface ComputerInfo {
344
344
  owner?: ComputerOwner;
345
345
  /** An agent's computer that is detached now: when it was detached, the janitor's idle clock. Absent otherwise. */
346
346
  detachedAt?: Date;
347
+ /** When the vendor made it, where its listing says (a browser vendor's session list does): what a host that releases
348
+ * one no claim held (releaseUnheld) books its time from. Absent where the listing does not say. */
349
+ createdAt?: Date;
347
350
  }
348
351
  export interface CallContext {
349
352
  signal?: AbortSignal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-computer",
3
- "version": "0.1.0-beta.64",
3
+ "version": "0.1.0-beta.66",
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",