@fungi.computer/computer 0.4.2 → 0.5.0
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/dist/container-policy.d.ts +5 -1
- package/dist/container-policy.js +6 -2
- package/dist/fleet/index.d.ts +1 -0
- package/dist/fleet/index.js +1 -0
- package/dist/fleet/keep-awake.d.ts +4 -0
- package/dist/fleet/keep-awake.js +14 -0
- package/dist/fleet/lifecycle.d.ts +9 -0
- package/dist/fleet/lifecycle.js +44 -28
- package/dist/fleet/runtime-usage.d.ts +10 -5
- package/dist/fleet/runtime-usage.js +12 -8
- package/dist/fleet/wire.d.ts +2 -0
- package/dist/fleet/wire.js +4 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -3
- package/dist/on-box-vm.d.ts +1 -1
- package/dist/on-box-vm.js +7 -4
- package/dist/team-candidate-builder.mjs +1 -0
- package/package.json +4 -5
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/** The one idle window: a Computer sleeps this long after its last activity. */
|
|
1
2
|
export declare const computerContainerSleepAfterMs: number;
|
|
3
|
+
/** A kept-awake container's platform backstop: the 24 hour runtime ceiling. */
|
|
4
|
+
export declare const computerKeepAwakeTimeoutMs: number;
|
|
2
5
|
export declare function hostedComputerContainersPaused(hostedComputers: string | undefined): boolean;
|
|
3
6
|
export declare class ComputerContainersPausedError extends Error {
|
|
4
7
|
constructor();
|
|
5
8
|
}
|
|
6
9
|
export declare function assertComputerContainersEnabled(hostedComputers: string | undefined): void;
|
|
7
|
-
|
|
10
|
+
/** The platform inactivity timeout is a backstop; ComputerDO owns idle sleep. */
|
|
11
|
+
export declare function configureComputerContainer(container: Pick<Container, "setInactivityTimeout"> | undefined, keepAwake: boolean): Promise<void>;
|
package/dist/container-policy.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/** The one idle window: a Computer sleeps this long after its last activity. */
|
|
2
3
|
export const computerContainerSleepAfterMs = 15 * 60 * 1_000;
|
|
4
|
+
/** A kept-awake container's platform backstop: the 24 hour runtime ceiling. */
|
|
5
|
+
export const computerKeepAwakeTimeoutMs = 24 * 60 * 60 * 1_000;
|
|
3
6
|
const hostedComputersSchema = z
|
|
4
7
|
.enum(["enabled", "paused"])
|
|
5
8
|
.default("enabled")
|
|
@@ -17,8 +20,9 @@ export function assertComputerContainersEnabled(hostedComputers) {
|
|
|
17
20
|
if (hostedComputerContainersPaused(hostedComputers))
|
|
18
21
|
throw new ComputerContainersPausedError();
|
|
19
22
|
}
|
|
20
|
-
|
|
23
|
+
/** The platform inactivity timeout is a backstop; ComputerDO owns idle sleep. */
|
|
24
|
+
export async function configureComputerContainer(container, keepAwake) {
|
|
21
25
|
if (container === undefined)
|
|
22
26
|
throw new Error("Computer Durable Object is not container-enabled");
|
|
23
|
-
await container.setInactivityTimeout(computerContainerSleepAfterMs);
|
|
27
|
+
await container.setInactivityTimeout(keepAwake ? computerKeepAwakeTimeoutMs : computerContainerSleepAfterMs);
|
|
24
28
|
}
|
package/dist/fleet/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { checkComputerGrant, type ComputerAdmission } from "./admission.js";
|
|
|
3
3
|
export { createFleetBacking } from "./backing.js";
|
|
4
4
|
export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, ComputerBackingError, type ComputerAction, type ComputerProvenance, type ComputerGrant, type ComputerRuntimeState, type ComputerFact, type ComputerBackendsProjection, type ComputerBackingChange, type LocalBackendAttachInput, type LocalBackendDetachInput, } from "./wire.js";
|
|
5
5
|
export { ComputerRuntimeUsage } from "./runtime-usage.js";
|
|
6
|
+
export { computerKeepAwake } from "./keep-awake.js";
|
|
6
7
|
export { computerUsageIntervalSchema, type ComputerUsageInterval, } from "./wire.js";
|
|
7
8
|
export { createFleetInventory } from "./inventory.js";
|
|
8
9
|
export { ComputerInventoryError, computerCreateRequestSchema, computerPageSchema, type ComputerCreateRequest, type ComputerPage, type FleetActor, type FleetComputer, } from "./inventory-wire.js";
|
package/dist/fleet/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { checkComputerGrant } from "./admission.js";
|
|
|
3
3
|
export { createFleetBacking } from "./backing.js";
|
|
4
4
|
export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, ComputerBackingError, } from "./wire.js";
|
|
5
5
|
export { ComputerRuntimeUsage } from "./runtime-usage.js";
|
|
6
|
+
export { computerKeepAwake } from "./keep-awake.js";
|
|
6
7
|
export { computerUsageIntervalSchema, } from "./wire.js";
|
|
7
8
|
export { createFleetInventory } from "./inventory.js";
|
|
8
9
|
export { ComputerInventoryError, computerCreateRequestSchema, computerPageSchema, } from "./inventory-wire.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
|
|
2
|
+
/** This Computer's durable Keep awake opt-in. Absence means off: an idle
|
|
3
|
+
* Computer sleeps, and only an intentional opt-in keeps it up and metered. */
|
|
4
|
+
export declare function computerKeepAwake(sql: WatchdogSqliteOwner["sql"], enabled?: boolean): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** This Computer's durable Keep awake opt-in. Absence means off: an idle
|
|
3
|
+
* Computer sleeps, and only an intentional opt-in keeps it up and metered. */
|
|
4
|
+
export function computerKeepAwake(sql, enabled) {
|
|
5
|
+
sql.exec("CREATE TABLE IF NOT EXISTS computer_keep_awake (singleton INTEGER PRIMARY KEY CHECK (singleton=1), enabled INTEGER NOT NULL CHECK (enabled IN (0,1))) STRICT");
|
|
6
|
+
if (enabled !== undefined)
|
|
7
|
+
sql.exec("INSERT INTO computer_keep_awake (singleton,enabled) VALUES (1,?) ON CONFLICT (singleton) DO UPDATE SET enabled=excluded.enabled", enabled ? 1 : 0);
|
|
8
|
+
const row = sql
|
|
9
|
+
.exec("SELECT enabled FROM computer_keep_awake WHERE singleton=1")
|
|
10
|
+
.toArray()[0];
|
|
11
|
+
return row === undefined
|
|
12
|
+
? false
|
|
13
|
+
: z.union([z.literal(0), z.literal(1)]).parse(row.enabled) === 1;
|
|
14
|
+
}
|
|
@@ -88,7 +88,16 @@ export declare class FleetLifecycle {
|
|
|
88
88
|
syncRecycledWorkspace(backing: HostedBacking): Promise<void>;
|
|
89
89
|
private finishVmRecycle;
|
|
90
90
|
private recycleQuietVms;
|
|
91
|
+
/** Whether this Computer is metered without fresh activity: a dispatch is
|
|
92
|
+
* in flight, or its owner opted into Keep awake. */
|
|
93
|
+
private get awake();
|
|
94
|
+
/** Metering never runs past the last activity of a Computer that is not awake. */
|
|
95
|
+
private billedThrough;
|
|
96
|
+
/** Whether an idle runtime has passed its sleep window. */
|
|
97
|
+
private sleepDue;
|
|
91
98
|
private observeRuntime;
|
|
99
|
+
/** Whether the runtime still runs, and when it stopped if it does not. */
|
|
100
|
+
private readRuntime;
|
|
92
101
|
awaitRecycle(): Promise<void>;
|
|
93
102
|
/** Reconcile durable observations before the host delivers usage facts. */
|
|
94
103
|
observe(): Promise<HostedBacking[]>;
|
package/dist/fleet/lifecycle.js
CHANGED
|
@@ -4,6 +4,7 @@ import { attachedBackendId, } from "../computer-backends.js";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { ComputerRuntimeUsage } from "./runtime-usage.js";
|
|
6
6
|
import { checkComputerGrant } from "./admission.js";
|
|
7
|
+
import { computerKeepAwake } from "./keep-awake.js";
|
|
7
8
|
const vmRecycleAfterMs = 23 * 60 * 60 * 1_000;
|
|
8
9
|
const vmRecycleQuietMs = 30_000;
|
|
9
10
|
const runtimeWatchSchema = z.lazy(() => z.coerce.number().int().min(1_000).max(3_600_000).catch(60_000));
|
|
@@ -132,15 +133,13 @@ export class FleetLifecycle {
|
|
|
132
133
|
throw new FleetGrantRefused();
|
|
133
134
|
this.#hostedOperations++;
|
|
134
135
|
try {
|
|
135
|
-
|
|
136
|
-
this.usage.touchActivity(backing, Date.now());
|
|
136
|
+
this.usage.touchActivity(backing, Date.now());
|
|
137
137
|
return await run();
|
|
138
138
|
}
|
|
139
139
|
finally {
|
|
140
140
|
this.#hostedOperations--;
|
|
141
141
|
this.#lastHostedActivity = Date.now();
|
|
142
|
-
|
|
143
|
-
this.usage.touchActivity(backing, this.#lastHostedActivity);
|
|
142
|
+
this.usage.touchActivity(backing, this.#lastHostedActivity);
|
|
144
143
|
if (backing.kind === "on-box-vm") {
|
|
145
144
|
if (!this.usage.hasOpen(backing))
|
|
146
145
|
this.#facts.push({ kind: "reservation.release" });
|
|
@@ -166,8 +165,7 @@ export class FleetLifecycle {
|
|
|
166
165
|
return;
|
|
167
166
|
lastRecordedAt = now;
|
|
168
167
|
this.#lastHostedActivity = now;
|
|
169
|
-
|
|
170
|
-
this.usage.touchActivity(backing, now);
|
|
168
|
+
this.usage.touchActivity(backing, now);
|
|
171
169
|
};
|
|
172
170
|
if (socket !== null) {
|
|
173
171
|
const pair = new WebSocketPair();
|
|
@@ -267,7 +265,7 @@ export class FleetLifecycle {
|
|
|
267
265
|
if (!(current.running && current.runtimeId === row.runtimeId)) {
|
|
268
266
|
this.usage.observe(row.runtimeId, {
|
|
269
267
|
running: false,
|
|
270
|
-
|
|
268
|
+
at: this.billedThrough(row.runtimeId, row.requestedAt),
|
|
271
269
|
});
|
|
272
270
|
if (current.running && current.runtimeId !== null)
|
|
273
271
|
this.containerRuntimeStarted({
|
|
@@ -330,32 +328,50 @@ export class FleetLifecycle {
|
|
|
330
328
|
}
|
|
331
329
|
}
|
|
332
330
|
}
|
|
331
|
+
/** Whether this Computer is metered without fresh activity: a dispatch is
|
|
332
|
+
* in flight, or its owner opted into Keep awake. */
|
|
333
|
+
get awake() {
|
|
334
|
+
return (this.#hostedOperations > 0 || computerKeepAwake(this.ports.storage.sql));
|
|
335
|
+
}
|
|
336
|
+
/** Metering never runs past the last activity of a Computer that is not awake. */
|
|
337
|
+
billedThrough(runtimeId, at) {
|
|
338
|
+
if (this.awake)
|
|
339
|
+
return at;
|
|
340
|
+
return Math.min(at, this.usage.lastActivity(runtimeId, at) ?? at);
|
|
341
|
+
}
|
|
342
|
+
/** Whether an idle runtime has passed its sleep window. */
|
|
343
|
+
sleepDue(runtimeId, now) {
|
|
344
|
+
if (this.awake)
|
|
345
|
+
return false;
|
|
346
|
+
const last = this.usage.lastActivity(runtimeId, now);
|
|
347
|
+
return last !== null && now >= last + computerContainerSleepAfterMs;
|
|
348
|
+
}
|
|
333
349
|
async observeRuntime(runtimeId, backing, newest) {
|
|
334
350
|
const now = Date.now();
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
await container.destroy(new Error("Computer idle timeout"));
|
|
344
|
-
}
|
|
345
|
-
catch (cause) {
|
|
346
|
-
this.diagnostic("computer_idle_stop_failed", "idle_stop", cause);
|
|
347
|
-
return { running: true, endedAt: now };
|
|
348
|
-
}
|
|
349
|
-
return { running: false, endedAt: deadline };
|
|
350
|
-
}
|
|
351
|
-
return { running: true, endedAt: now };
|
|
351
|
+
const { running, exitedAt } = await this.readRuntime(runtimeId, backing, newest, now);
|
|
352
|
+
if (running && this.sleepDue(runtimeId, now)) {
|
|
353
|
+
try {
|
|
354
|
+
await this.destroyRuntime(backing, "Computer idle timeout");
|
|
355
|
+
}
|
|
356
|
+
catch (cause) {
|
|
357
|
+
this.diagnostic("computer_idle_stop_failed", "idle_stop", cause);
|
|
358
|
+
return { running: true, at: this.billedThrough(runtimeId, now) };
|
|
352
359
|
}
|
|
353
|
-
return { running: false,
|
|
360
|
+
return { running: false, at: this.billedThrough(runtimeId, now) };
|
|
354
361
|
}
|
|
362
|
+
return { running, at: this.billedThrough(runtimeId, exitedAt) };
|
|
363
|
+
}
|
|
364
|
+
/** Whether the runtime still runs, and when it stopped if it does not. */
|
|
365
|
+
async readRuntime(runtimeId, backing, newest, now) {
|
|
366
|
+
if (backing.kind === "platform-container")
|
|
367
|
+
return {
|
|
368
|
+
running: newest && this.ports.backend.state.container?.running === true,
|
|
369
|
+
exitedAt: now,
|
|
370
|
+
};
|
|
355
371
|
const state = await this.ports.backend.onBoxVmHost(backing.hostId).state();
|
|
356
372
|
return {
|
|
357
373
|
running: state.running && state.runtimeId === runtimeId,
|
|
358
|
-
|
|
374
|
+
exitedAt: Math.min(now, state.exit?.exitedAt ?? now),
|
|
359
375
|
};
|
|
360
376
|
}
|
|
361
377
|
async awaitRecycle() {
|
|
@@ -429,12 +445,12 @@ export class FleetLifecycle {
|
|
|
429
445
|
await this.ports.backend.state.container.destroy(new Error(reason));
|
|
430
446
|
return this.observeOpenRuntimes();
|
|
431
447
|
}
|
|
432
|
-
async destroyRuntime(backing) {
|
|
448
|
+
async destroyRuntime(backing, reason = "Computer usage delivery unavailable") {
|
|
433
449
|
if (backing.kind === "on-box-vm") {
|
|
434
450
|
await this.ports.backend.onBoxVmHost(backing.hostId).destroy();
|
|
435
451
|
return;
|
|
436
452
|
}
|
|
437
453
|
if (this.ports.backend.state.container !== undefined)
|
|
438
|
-
await this.ports.backend.state.container.destroy(new Error(
|
|
454
|
+
await this.ports.backend.state.container.destroy(new Error(reason));
|
|
439
455
|
}
|
|
440
456
|
}
|
|
@@ -4,9 +4,9 @@ import type { ComputerFact, ComputerProvenance, ComputerUsageInterval } from "./
|
|
|
4
4
|
/**
|
|
5
5
|
* Computer-local interval ledger; the host owns usage settlement.
|
|
6
6
|
*
|
|
7
|
-
* A running runtime's checkpoint advances at most once per `checkpointMs
|
|
8
|
-
*
|
|
9
|
-
* can deliver it idempotently.
|
|
7
|
+
* A running runtime's checkpoint advances at most once per `checkpointMs`, and
|
|
8
|
+
* only as far as its owner says it is billed through. Repeated reads inside one
|
|
9
|
+
* checkpoint expose the same interval so the host can deliver it idempotently.
|
|
10
10
|
*/
|
|
11
11
|
export declare class ComputerRuntimeUsage {
|
|
12
12
|
private readonly sql;
|
|
@@ -15,7 +15,8 @@ export declare class ComputerRuntimeUsage {
|
|
|
15
15
|
ensure(): void;
|
|
16
16
|
started(start: ContainerRuntimeStart): void;
|
|
17
17
|
touchActivity(backing: HostedBacking, at: number): void;
|
|
18
|
-
|
|
18
|
+
/** The last recorded activity of an open runtime; a missing record starts now. */
|
|
19
|
+
lastActivity(runtimeId: string, now: number): number | null;
|
|
19
20
|
hasOpen(backing: HostedBacking): boolean;
|
|
20
21
|
hasAnyOpen(): boolean;
|
|
21
22
|
open(): {
|
|
@@ -37,9 +38,13 @@ export declare class ComputerRuntimeUsage {
|
|
|
37
38
|
requestRecycle(runtimeId: string, backing: HostedBacking, requestedAt: number): void;
|
|
38
39
|
finishRecycle(runtimeId: string): void;
|
|
39
40
|
oldestVmStart(): number | null;
|
|
41
|
+
/**
|
|
42
|
+
* Record a runtime observation. `at` is the end of an ended runtime, or the
|
|
43
|
+
* billed-through time of a running one; checkpoints never move backward.
|
|
44
|
+
*/
|
|
40
45
|
observe(runtimeId: string, observed: {
|
|
41
46
|
running: boolean;
|
|
42
|
-
|
|
47
|
+
at: number;
|
|
43
48
|
}): void;
|
|
44
49
|
pending(): ComputerUsageInterval[];
|
|
45
50
|
/** Read delivery facts without changing the retained checkpoint or acknowledgment. */
|
|
@@ -3,9 +3,9 @@ import { hostedBackingSchema, } from "../computer-backends.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Computer-local interval ledger; the host owns usage settlement.
|
|
5
5
|
*
|
|
6
|
-
* A running runtime's checkpoint advances at most once per `checkpointMs
|
|
7
|
-
*
|
|
8
|
-
* can deliver it idempotently.
|
|
6
|
+
* A running runtime's checkpoint advances at most once per `checkpointMs`, and
|
|
7
|
+
* only as far as its owner says it is billed through. Repeated reads inside one
|
|
8
|
+
* checkpoint expose the same interval so the host can deliver it idempotently.
|
|
9
9
|
*/
|
|
10
10
|
export class ComputerRuntimeUsage {
|
|
11
11
|
sql;
|
|
@@ -29,7 +29,8 @@ export class ComputerRuntimeUsage {
|
|
|
29
29
|
this.sql.exec("UPDATE hub_computer_runtime_activity SET last_activity_at=MAX(last_activity_at, ?) WHERE runtime_id IN (SELECT runtime_id FROM hub_computer_runtime_usage WHERE backing=? AND ended=0)", at, encodedBacking);
|
|
30
30
|
this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_activity (runtime_id, last_activity_at) SELECT runtime_id, ? FROM hub_computer_runtime_usage WHERE backing=? AND ended=0", at, encodedBacking);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
/** The last recorded activity of an open runtime; a missing record starts now. */
|
|
33
|
+
lastActivity(runtimeId, now) {
|
|
33
34
|
this.ensure();
|
|
34
35
|
this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_activity (runtime_id, last_activity_at) SELECT runtime_id, ? FROM hub_computer_runtime_usage WHERE runtime_id=? AND ended=0", now, runtimeId);
|
|
35
36
|
const row = this.sql
|
|
@@ -37,7 +38,7 @@ export class ComputerRuntimeUsage {
|
|
|
37
38
|
.toArray()[0];
|
|
38
39
|
return row === undefined
|
|
39
40
|
? null
|
|
40
|
-
: z.number().int().nonnegative().parse(row.last_activity_at)
|
|
41
|
+
: z.number().int().nonnegative().parse(row.last_activity_at);
|
|
41
42
|
}
|
|
42
43
|
hasOpen(backing) {
|
|
43
44
|
this.ensure();
|
|
@@ -102,13 +103,16 @@ export class ComputerRuntimeUsage {
|
|
|
102
103
|
.exec("SELECT MIN(started_at) AS started_at FROM hub_computer_runtime_usage WHERE ended=0 AND json_extract(backing,'$.kind')='on-box-vm'")
|
|
103
104
|
.toArray()[0]?.started_at ?? null);
|
|
104
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Record a runtime observation. `at` is the end of an ended runtime, or the
|
|
108
|
+
* billed-through time of a running one; checkpoints never move backward.
|
|
109
|
+
*/
|
|
105
110
|
observe(runtimeId, observed) {
|
|
106
111
|
if (!observed.running) {
|
|
107
|
-
this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = MAX(observed_at, ?), ended = 1 WHERE runtime_id = ?", observed.
|
|
112
|
+
this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = MAX(observed_at, ?), ended = 1 WHERE runtime_id = ?", observed.at, runtimeId);
|
|
108
113
|
return;
|
|
109
114
|
}
|
|
110
|
-
|
|
111
|
-
this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = ? WHERE runtime_id = ? AND ended = 0 AND observed_at <= ?", now, runtimeId, now - this.checkpointMs);
|
|
115
|
+
this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = ? WHERE runtime_id = ? AND ended = 0 AND observed_at < ? AND observed_at <= ?", observed.at, runtimeId, observed.at, Date.now() - this.checkpointMs);
|
|
112
116
|
}
|
|
113
117
|
pending() {
|
|
114
118
|
return this.sql
|
package/dist/fleet/wire.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare const computerStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
75
75
|
running: "running";
|
|
76
76
|
sleeping: "sleeping";
|
|
77
77
|
starting: "starting";
|
|
78
|
+
start_failed: "start_failed";
|
|
78
79
|
}>;
|
|
79
80
|
}, z.core.$strict>, z.ZodObject<{
|
|
80
81
|
state: z.ZodLiteral<"queued">;
|
|
@@ -197,6 +198,7 @@ export declare const computerFactSchema: z.ZodLazy<z.ZodDiscriminatedUnion<[z.Zo
|
|
|
197
198
|
running: "running";
|
|
198
199
|
sleeping: "sleeping";
|
|
199
200
|
starting: "starting";
|
|
201
|
+
start_failed: "start_failed";
|
|
200
202
|
}>;
|
|
201
203
|
}, z.core.$strict>, z.ZodObject<{
|
|
202
204
|
state: z.ZodLiteral<"queued">;
|
package/dist/fleet/wire.js
CHANGED
|
@@ -32,7 +32,10 @@ export const computerGrantSchema = z.strictObject({
|
|
|
32
32
|
});
|
|
33
33
|
/** State visible without knowing which application hosts the Computer. */
|
|
34
34
|
export const computerStateSchema = z.discriminatedUnion("state", [
|
|
35
|
-
|
|
35
|
+
// start_failed: a queued start ended without running; start again.
|
|
36
|
+
z.strictObject({
|
|
37
|
+
state: z.enum(["running", "sleeping", "starting", "start_failed"]),
|
|
38
|
+
}),
|
|
36
39
|
z.strictObject({
|
|
37
40
|
state: z.literal("queued"),
|
|
38
41
|
position: z.number().int().positive(),
|
package/dist/index.d.ts
CHANGED
|
@@ -140,6 +140,11 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
|
|
|
140
140
|
constructor(ctx: DurableObjectState, env: ComputerEnv);
|
|
141
141
|
/** Host-admitted settings write; egress reads the current durable value. */
|
|
142
142
|
internetAccess(enabled?: boolean): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Host-admitted Keep awake write. The fleet's idle policy and metering read
|
|
145
|
+
* the durable value; a container's platform backstop follows it.
|
|
146
|
+
*/
|
|
147
|
+
keepAwake(enabled?: boolean): Promise<boolean>;
|
|
143
148
|
/** Ordinary Computers have no credential host; resource hosts override it. */
|
|
144
149
|
protected executionHooks(): ComputerExecutionHostHooks | undefined;
|
|
145
150
|
/**
|
package/dist/index.js
CHANGED
|
@@ -74,8 +74,9 @@ import { ComputerOperationRecord } from "./operation-record.js";
|
|
|
74
74
|
import { createComputerExecutionLifecycle } from "./execution-lifecycle.js";
|
|
75
75
|
import { applyWorkspacePatch } from "./files-patch.js";
|
|
76
76
|
import { ComputerProcessInventory, drainProcessExit, failedObservation, observeProcess, } from "./process-inventory.js";
|
|
77
|
-
import { assertComputerContainersEnabled,
|
|
77
|
+
import { assertComputerContainersEnabled, ComputerContainersPausedError, configureComputerContainer, hostedComputerContainersPaused, } from "./container-policy.js";
|
|
78
78
|
import { OnBoxVmContainerHost, onBoxVmPlacement, } from "./on-box-vm.js";
|
|
79
|
+
import { computerKeepAwake } from "./fleet/keep-awake.js";
|
|
79
80
|
import { attachedBackendId, describeAttachedBackend, routeComputerBackend, } from "./computer-backends.js";
|
|
80
81
|
import { MeteredContainerHost } from "./metered-container-host.js";
|
|
81
82
|
import { LocalBackendConnections, LocalWorkspaceBackend, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
|
|
@@ -237,7 +238,7 @@ class ContainerComputer extends ContainerComputerBase {
|
|
|
237
238
|
if (ctx.container === undefined ||
|
|
238
239
|
hostedComputerContainersPaused(env.HOSTED_COMPUTERS))
|
|
239
240
|
return;
|
|
240
|
-
ctx.waitUntil(configureComputerContainer(ctx.container));
|
|
241
|
+
ctx.waitUntil(configureComputerContainer(ctx.container, computerKeepAwake(ctx.storage.sql)));
|
|
241
242
|
}
|
|
242
243
|
getWorkspaceContainer() {
|
|
243
244
|
assertComputerContainersEnabled(this.bindings.HOSTED_COMPUTERS);
|
|
@@ -352,7 +353,7 @@ class ContainerComputer extends ContainerComputerBase {
|
|
|
352
353
|
}
|
|
353
354
|
/** Let the consuming owner admit boots while preserving the runtime host seam. */
|
|
354
355
|
createOnBoxVmHost(placement) {
|
|
355
|
-
return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString()
|
|
356
|
+
return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString());
|
|
356
357
|
}
|
|
357
358
|
/** Whether a hosted backend's runtime is running now. */
|
|
358
359
|
async containerRunning(backing) {
|
|
@@ -490,6 +491,18 @@ export class ComputerDO extends ContainerComputer {
|
|
|
490
491
|
internetAccess(enabled) {
|
|
491
492
|
return computerInternetAccess(this.state.storage.sql, enabled);
|
|
492
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Host-admitted Keep awake write. The fleet's idle policy and metering read
|
|
496
|
+
* the durable value; a container's platform backstop follows it.
|
|
497
|
+
*/
|
|
498
|
+
async keepAwake(enabled) {
|
|
499
|
+
const kept = computerKeepAwake(this.state.storage.sql, enabled);
|
|
500
|
+
if (enabled !== undefined &&
|
|
501
|
+
this.state.container !== undefined &&
|
|
502
|
+
!hostedComputerContainersPaused(this.bindings.HOSTED_COMPUTERS))
|
|
503
|
+
await configureComputerContainer(this.state.container, kept);
|
|
504
|
+
return kept;
|
|
505
|
+
}
|
|
493
506
|
#binaryFileTail = Promise.resolve(undefined);
|
|
494
507
|
#operationRecord;
|
|
495
508
|
#processRecord;
|
package/dist/on-box-vm.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export declare class OnBoxVmTimeoutError extends OnBoxVmTimeoutError_base<{
|
|
|
74
74
|
/** One Durable Object's view of its microVM through the host service. */
|
|
75
75
|
export declare class OnBoxVmContainerHost implements IWorkspaceContainerAPI {
|
|
76
76
|
#private;
|
|
77
|
-
constructor(placement: OnBoxVmPlacement, env: OnBoxVmEnv, vmId: string
|
|
77
|
+
constructor(placement: OnBoxVmPlacement, env: OnBoxVmEnv, vmId: string);
|
|
78
78
|
/** Signed host-wide inventory; includes VMs outside this Hub's directory. */
|
|
79
79
|
inventory(): Promise<OnBoxVmInventory>;
|
|
80
80
|
start(env: Record<string, string>, enableInternet: boolean): Promise<{
|
package/dist/on-box-vm.js
CHANGED
|
@@ -90,6 +90,11 @@ const vmInventorySchema = z.array(vmStateSchema.extend({
|
|
|
90
90
|
const vmStartSchema = z.lazy(() => z.strictObject({
|
|
91
91
|
runtimeId: z.string().min(1).max(128),
|
|
92
92
|
}));
|
|
93
|
+
/**
|
|
94
|
+
* vmd's own traffic timer is only a backstop at its maximum: ComputerDO owns
|
|
95
|
+
* idle sleep, so a kept-awake VM is not stopped by the host while it is quiet.
|
|
96
|
+
*/
|
|
97
|
+
const vmHostSleepBackstopMs = 24 * 60 * 60 * 1_000;
|
|
93
98
|
/** A bounded control-plane wait, not the VM's execution or allocation lifetime. */
|
|
94
99
|
const vmControlTimeoutMs = 60_000;
|
|
95
100
|
/** The host's outcome is unknown after a timeout; this is not evidence of offline. */
|
|
@@ -119,15 +124,13 @@ export class OnBoxVmContainerHost {
|
|
|
119
124
|
#placement;
|
|
120
125
|
#env;
|
|
121
126
|
#vmId;
|
|
122
|
-
|
|
123
|
-
constructor(placement, env, vmId, sleepAfterMs) {
|
|
127
|
+
constructor(placement, env, vmId) {
|
|
124
128
|
this.#placement = placement;
|
|
125
129
|
this.#env = env;
|
|
126
130
|
this.#vmId = z
|
|
127
131
|
.string()
|
|
128
132
|
.regex(/^[0-9a-f]{64}$/)
|
|
129
133
|
.parse(vmId);
|
|
130
|
-
this.#sleepAfterMs = sleepAfterMs;
|
|
131
134
|
}
|
|
132
135
|
async #call(operation, schema, body) {
|
|
133
136
|
let path = `/vms/${this.#vmId}`;
|
|
@@ -161,7 +164,7 @@ export class OnBoxVmContainerHost {
|
|
|
161
164
|
const started = await this.#call(operation, vmStartSchema, {
|
|
162
165
|
env,
|
|
163
166
|
enableInternet,
|
|
164
|
-
sleepAfterMs:
|
|
167
|
+
sleepAfterMs: vmHostSleepBackstopMs,
|
|
165
168
|
});
|
|
166
169
|
return { runtimeId: started.runtimeId };
|
|
167
170
|
}
|
|
@@ -19718,6 +19718,7 @@ var appCapabilityIds = [
|
|
|
19718
19718
|
"computer.execute",
|
|
19719
19719
|
"llm.generation",
|
|
19720
19720
|
"media.generation",
|
|
19721
|
+
"media.share",
|
|
19721
19722
|
"games:servers",
|
|
19722
19723
|
"git.repository",
|
|
19723
19724
|
"apps.open",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/computer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Cloudflare Computer host for one durable Fungi Computer",
|
|
6
6
|
"type": "module",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@fungi.computer/capnweb": "0.12.0",
|
|
61
61
|
"@fungi.computer/cloudflare-computer": "0.2.1-fungi.2",
|
|
62
62
|
"@fungi.computer/cordyceps": "0.4.0",
|
|
63
|
-
"@fungi.computer/knapsack": "0.4.
|
|
63
|
+
"@fungi.computer/knapsack": "0.4.4",
|
|
64
64
|
"@fungi.computer/seam": "0.2.0",
|
|
65
65
|
"@fungi.computer/watchdog": "0.1.0",
|
|
66
|
-
"@fungi.computer/computer-contract": "0.0.
|
|
66
|
+
"@fungi.computer/computer-contract": "0.0.9",
|
|
67
67
|
"effect": "4.0.2",
|
|
68
68
|
"just-bash": "3.4.2",
|
|
69
69
|
"zod": "4.4.3"
|
|
@@ -118,9 +118,8 @@
|
|
|
118
118
|
"test:nightly": "bash ../../tooling/proof-runner/run-proof.sh node test/egress-proof.mjs",
|
|
119
119
|
"test:app-method-execution": "node test/app-method-execution-proof.mjs",
|
|
120
120
|
"test:execution-lifecycle": "node test/execution-lifecycle-proof.mjs",
|
|
121
|
-
"test:unit": "node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs",
|
|
121
|
+
"test:unit": "node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/proof-client.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs",
|
|
122
122
|
"test:fleet-native": "node test/fleet.native.mjs",
|
|
123
|
-
"test:light-shell:native": "node --import tsx test/light-shell.native.mjs --state",
|
|
124
123
|
"assemble:image": "node scripts/assemble-image.mjs"
|
|
125
124
|
}
|
|
126
125
|
}
|