@fungi.computer/oyster 0.8.2 → 0.9.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/README.md +21 -17
- package/dist/agents.js +3 -0
- package/dist/apps/catalog.d.ts +11 -0
- package/dist/apps/catalog.js +1 -0
- package/dist/apps/gate.d.ts +2 -2
- package/dist/apps/installation.d.ts +7 -7
- package/dist/apps/permissions.d.ts +5 -5
- package/dist/boot-host-script.js +1 -1
- package/dist/build/candidate-cli.mjs +1 -0
- package/dist/host.js +11 -4
- package/dist/installation-client.d.ts +6 -5
- package/dist/installation-client.js +21 -17
- package/dist/installation-execution.js +41 -8
- package/dist/installation-operations.d.ts +30 -8
- package/dist/installation-operations.js +122 -24
- package/dist/instance-refusal.d.ts +4 -2
- package/dist/instance-refusal.js +5 -1
- package/dist/mcp.d.ts +4 -2
- package/dist/page/mount.d.ts +8 -1
- package/dist/page/mount.js +72 -6
- package/dist/page-script.js +3 -3
- package/dist/standalone/app-set.js +6 -7
- package/dist/standalone/computer-fleet.d.ts +8 -2
- package/dist/standalone/computer-fleet.js +21 -17
- package/dist/standalone/registry.js +9 -0
- package/dist/standalone/workflow-host.d.ts +5 -5
- package/dist/standalone/workflow-trigger-host.d.ts +1 -1
- package/docs/api/apps.md +31 -31
- package/docs/api/host.md +157 -0
- package/docs/api/mcp.md +6 -4
- package/docs/api/page/mount.md +6 -1
- package/docs/api/workers.md +3 -3
- package/docs/site/agent-quickstart.mdx +4 -2
- package/package.json +16 -16
|
@@ -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/dist/host.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hostGateFacts, releaseCache } from "./internal/host-gate.js";
|
|
2
|
-
import { InstallationOperationError, installationCommandIds, installationRequestIdSchema, } from "./installation-operations.js";
|
|
2
|
+
import { InstallationOperationError, installationCommandIds, installationRequestIdSchema, installationWaitQuerySchema, maxSettlementWaitMs, } from "./installation-operations.js";
|
|
3
3
|
import { completedInstallationResponse, observeInstallation, InstallationObservationError, } from "./installation-client.js";
|
|
4
4
|
import { instanceRefusalBody, instanceRefusalStatus, } from "./instance-refusal.js";
|
|
5
5
|
import { appSandbox } from "./app-sandbox.js";
|
|
@@ -168,7 +168,7 @@ export async function installOrSelect(host, installationId, release, principal,
|
|
|
168
168
|
return completedInstallationResponse(await observeInstallation({
|
|
169
169
|
requestId,
|
|
170
170
|
initial: admitted,
|
|
171
|
-
read: () => operations.
|
|
171
|
+
read: () => operations.awaitSettled(requestId, installationId, maxSettlementWaitMs),
|
|
172
172
|
signal,
|
|
173
173
|
}));
|
|
174
174
|
}
|
|
@@ -649,11 +649,18 @@ export function oysterRouteTable(host) {
|
|
|
649
649
|
const key = installationRequestIdSchema.safeParse(context.req.query("requestId"));
|
|
650
650
|
if (!key.success)
|
|
651
651
|
return refusal(400, "Invalid installation request identity");
|
|
652
|
+
const wait = installationWaitQuerySchema.safeParse(context.req.query("waitMs"));
|
|
653
|
+
if (!wait.success)
|
|
654
|
+
return refusal(400, "Invalid installation wait");
|
|
652
655
|
const operations = host.installations.operations;
|
|
653
656
|
if (operations === undefined)
|
|
654
657
|
return refusal(503, "Installation commands unavailable");
|
|
655
658
|
try {
|
|
656
|
-
const
|
|
659
|
+
const installationId = context.req.param("installationId");
|
|
660
|
+
// With waitMs, the owner answers when it settles the command.
|
|
661
|
+
const operation = wait.data === undefined
|
|
662
|
+
? await operations.read(key.data, installationId)
|
|
663
|
+
: await operations.awaitSettled(key.data, installationId, wait.data);
|
|
657
664
|
return operation === null
|
|
658
665
|
? refusal(404, "Installation request not found")
|
|
659
666
|
: Response.json(operation);
|
|
@@ -878,7 +885,7 @@ export function oysterRouteTable(host) {
|
|
|
878
885
|
// desktop chrome belongs to the shell.
|
|
879
886
|
return new Response(config.workbench
|
|
880
887
|
? `${head}<style>html,body,#oyster-shell{margin:0;height:100%}body{font-family:var(--font-sans)}</style><div id="oyster-shell"></div>${tail}`
|
|
881
|
-
: `${head}<style>html,body{margin:0;height:100%}iframe{border:0;width:100%;height:100%;display:block}</style><iframe id="oyster-app" sandbox="${appSandbox}" allowfullscreen
|
|
888
|
+
: `${head}<style>html,body{margin:0;height:100%}iframe{border:0;width:100%;height:100%;display:block}</style><iframe id="oyster-app" sandbox="${appSandbox}" allowfullscreen title="${escapeHtml(installation.installationId)}"></iframe>${tail}`, {
|
|
882
889
|
headers: {
|
|
883
890
|
"Content-Type": "text/html; charset=utf-8",
|
|
884
891
|
"Cache-Control": "no-store",
|
|
@@ -16,14 +16,17 @@ export declare class InstallationObservationError extends Error {
|
|
|
16
16
|
readonly requestId: string;
|
|
17
17
|
constructor(requestId: string, options?: ErrorOptions);
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Observe one retained command, over either HTTP or the host's decoded port.
|
|
21
|
+
* Each `read` is the owner's settlement wait: it answers as soon as the owner
|
|
22
|
+
* settles (or admits) the command, or with the still-pending state after the
|
|
23
|
+
* owner's bounded wait, so this loop never sleeps between reads.
|
|
24
|
+
*/
|
|
20
25
|
export declare function observeInstallation(input: Readonly<{
|
|
21
26
|
requestId: string;
|
|
22
27
|
initial: InstallationOperation | null;
|
|
23
28
|
read(): Promise<InstallationOperation | null>;
|
|
24
29
|
signal: AbortSignal;
|
|
25
|
-
pollMs?: number;
|
|
26
|
-
idle?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
27
30
|
}>): Promise<InstallationCompletion>;
|
|
28
31
|
/** Completed HTTP meaning shared by pack and the retained PUT selection door. */
|
|
29
32
|
export declare function completedInstallationResponse(operation: InstallationCompletion): Response;
|
|
@@ -36,8 +39,6 @@ export declare function installOnOyster(input: Readonly<{
|
|
|
36
39
|
key: string;
|
|
37
40
|
installationId: string;
|
|
38
41
|
release: Release;
|
|
39
|
-
pollMs?: number;
|
|
40
|
-
idle?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
41
42
|
/** Once, after the owner supplies a correlated record, even after a lost ack. */
|
|
42
43
|
onAdmitted?: (operation: InstallationOperation) => void;
|
|
43
44
|
}> & InstallationObservationBudget): Promise<InstallationCompletion>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
1
|
import { addAbortListener } from "node:events";
|
|
3
2
|
import * as Schema from "effect/Schema";
|
|
4
3
|
import { releaseSchema } from "@fungi.computer/puffball/effect";
|
|
5
4
|
import { instanceRefusalBody } from "./instance-refusal.js";
|
|
6
|
-
import { installationOperationSchema, installationCommandIds, } from "./installation-operations.js";
|
|
5
|
+
import { installationOperationSchema, installationCommandIds, maxSettlementWaitMs, } from "./installation-operations.js";
|
|
7
6
|
/**
|
|
8
7
|
* Installer-owned observer budget, matching the standalone installer's existing
|
|
9
8
|
* twenty-minute default. Not an App grant lifetime or a server execution limit.
|
|
@@ -26,8 +25,12 @@ export class InstallationObservationError extends Error {
|
|
|
26
25
|
this.requestId = requestId;
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Observe one retained command, over either HTTP or the host's decoded port.
|
|
30
|
+
* Each `read` is the owner's settlement wait: it answers as soon as the owner
|
|
31
|
+
* settles (or admits) the command, or with the still-pending state after the
|
|
32
|
+
* owner's bounded wait, so this loop never sleeps between reads.
|
|
33
|
+
*/
|
|
31
34
|
export async function observeInstallation(input) {
|
|
32
35
|
try {
|
|
33
36
|
input.signal.throwIfAborted();
|
|
@@ -54,8 +57,6 @@ export async function observeInstallation(input) {
|
|
|
54
57
|
listener?.[Symbol.dispose]();
|
|
55
58
|
}
|
|
56
59
|
input.signal.throwIfAborted();
|
|
57
|
-
if (operation === null || operation.state === "pending")
|
|
58
|
-
await (input.idle ?? idle)(input.pollMs ?? 5_000, input.signal);
|
|
59
60
|
}
|
|
60
61
|
return operation;
|
|
61
62
|
}
|
|
@@ -149,26 +150,29 @@ export async function installOnOyster(input) {
|
|
|
149
150
|
throw new InstallationObservationError(requestId);
|
|
150
151
|
const statusUrl = new URL(`/api/installations/${encodeURIComponent(input.installationId)}/status`, input.url);
|
|
151
152
|
statusUrl.searchParams.set("requestId", requestId);
|
|
152
|
-
|
|
153
|
+
const settlementUrl = new URL(statusUrl);
|
|
154
|
+
settlementUrl.searchParams.set("waitMs", String(maxSettlementWaitMs));
|
|
155
|
+
// Without an acknowledgement, read once at once so the caller learns of
|
|
156
|
+
// its admission promptly; every later read is the owner's settlement wait.
|
|
157
|
+
let readOnce = false;
|
|
158
|
+
return await observeInstallation({
|
|
153
159
|
requestId,
|
|
154
160
|
initial: operation,
|
|
155
161
|
signal,
|
|
156
162
|
read: async () => {
|
|
163
|
+
const url = admitted || readOnce ? settlementUrl : statusUrl;
|
|
164
|
+
readOnce = true;
|
|
157
165
|
// Like decoded RPC reads, transport errors reach the observer with
|
|
158
166
|
// their original cause; they are not an authoritative pending read.
|
|
159
|
-
|
|
167
|
+
// A 404 is the owner's answer: not admitted (yet).
|
|
168
|
+
const observed = await fetch(url, { headers, signal });
|
|
160
169
|
if (observed.status === 200)
|
|
161
170
|
return decode(observed);
|
|
162
|
-
if (observed.status
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
if (observed.status === 404)
|
|
172
|
+
return null;
|
|
173
|
+
throw new InstallationObservationError(requestId);
|
|
165
174
|
},
|
|
166
|
-
};
|
|
167
|
-
if (input.pollMs !== undefined)
|
|
168
|
-
observation = { ...observation, pollMs: input.pollMs };
|
|
169
|
-
if (input.idle !== undefined)
|
|
170
|
-
observation = { ...observation, idle: input.idle };
|
|
171
|
-
return await observeInstallation(observation);
|
|
175
|
+
});
|
|
172
176
|
}
|
|
173
177
|
catch (cause) {
|
|
174
178
|
if (cause instanceof InstallationObservationError)
|
|
@@ -7,6 +7,7 @@ import { applyInstallationCommand, isCommittedInstallation, } from "./apps/insta
|
|
|
7
7
|
import { deriveDeclaredOperations } from "./apps/operations.js";
|
|
8
8
|
import { pendingCapabilities } from "./apps/permissions.js";
|
|
9
9
|
import { BootGateError } from "./boot-gate.js";
|
|
10
|
+
import { failureDiagnostic } from "./cause-class.js";
|
|
10
11
|
import { guestLimits } from "./guest-policy.js";
|
|
11
12
|
import { instanceSchema, selectionOf } from "./index.js";
|
|
12
13
|
import { ReleaseError, verifyRelease } from "./release.js";
|
|
@@ -22,6 +23,28 @@ const unconfirmed = {
|
|
|
22
23
|
state: "unconfirmed",
|
|
23
24
|
outcome: "outcome_unknown",
|
|
24
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Delays before each further preparation attempt. A cold Instance (first
|
|
28
|
+
* backend construction, a Durable Object reset or an overloaded isolate) can
|
|
29
|
+
* fail its first generic preparation and pass the next one.
|
|
30
|
+
*/
|
|
31
|
+
const preparationRetryDelaysMs = [500, 2_000];
|
|
32
|
+
/** Retry only generic preparation failures; typed refusals are final. */
|
|
33
|
+
async function prepareWithRetry(prepare) {
|
|
34
|
+
for (let attempt = 1;; attempt++) {
|
|
35
|
+
const prepared = await prepare();
|
|
36
|
+
if (prepared.ok || prepared.code !== "failed")
|
|
37
|
+
return prepared;
|
|
38
|
+
console.error("Installation preparation failed", {
|
|
39
|
+
attempt,
|
|
40
|
+
causeClass: prepared.causeClass,
|
|
41
|
+
});
|
|
42
|
+
const wait = preparationRetryDelaysMs[attempt - 1];
|
|
43
|
+
if (wait === undefined)
|
|
44
|
+
return prepared;
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
25
48
|
/** Ordinary Worker-side verification and lifecycle I/O for one retained intent. */
|
|
26
49
|
export async function executeInstallation(host, input) {
|
|
27
50
|
let command = retainedInstallationCommandSchema.parse(input);
|
|
@@ -45,9 +68,13 @@ export async function executeInstallation(host, input) {
|
|
|
45
68
|
verified = await verifyRelease(host.artifacts, command.admission.release);
|
|
46
69
|
}
|
|
47
70
|
catch (cause) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
if (cause instanceof ReleaseError)
|
|
72
|
+
return refused(422, cause.code);
|
|
73
|
+
console.error("Installation release verification failed", {
|
|
74
|
+
requestId: command.admission.requestId,
|
|
75
|
+
...failureDiagnostic(cause),
|
|
76
|
+
});
|
|
77
|
+
return unconfirmed;
|
|
51
78
|
}
|
|
52
79
|
if (command.plan === null) {
|
|
53
80
|
const declaration = verified.declaration ?? emptyAppDeclaration;
|
|
@@ -123,16 +150,22 @@ export async function executeInstallation(host, input) {
|
|
|
123
150
|
uiCheck = await host.bootUi(verified.release);
|
|
124
151
|
}
|
|
125
152
|
catch (cause) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
153
|
+
if (cause instanceof BootGateError)
|
|
154
|
+
return refused(422, cause.code);
|
|
155
|
+
console.error("Installation UI boot check failed", {
|
|
156
|
+
requestId: command.admission.requestId,
|
|
157
|
+
...failureDiagnostic(cause),
|
|
158
|
+
});
|
|
159
|
+
return unconfirmed;
|
|
129
160
|
}
|
|
130
161
|
}
|
|
131
162
|
else {
|
|
132
|
-
const prepared = await instance.prepare(state, next.release);
|
|
163
|
+
const prepared = await prepareWithRetry(() => instance.prepare(state, next.release));
|
|
133
164
|
if (!prepared.ok)
|
|
165
|
+
// Preparation never changes the active runtime and runs before the
|
|
166
|
+
// commit, so a generic failure here leaves the previous release live.
|
|
134
167
|
return prepared.code === "failed"
|
|
135
|
-
?
|
|
168
|
+
? refused(503, "installation_not_applied")
|
|
136
169
|
: refused(instanceRefusalStatus(prepared.code), prepared.code);
|
|
137
170
|
uiCheck = prepared.value;
|
|
138
171
|
}
|
|
@@ -32,7 +32,7 @@ declare const installationOutcomeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
32
32
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
33
33
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
34
34
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
35
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
35
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
36
36
|
capabilityApproved: z.ZodLiteral<true>;
|
|
37
37
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
38
38
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -250,7 +250,7 @@ export declare const installationOperationSchema: z.ZodDiscriminatedUnion<[z.Zod
|
|
|
250
250
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
251
251
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
252
252
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
253
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
253
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
254
254
|
capabilityApproved: z.ZodLiteral<true>;
|
|
255
255
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
256
256
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -431,7 +431,7 @@ export declare const retainedInstallationCommandSchema: z.ZodObject<{
|
|
|
431
431
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
432
432
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
433
433
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
434
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
434
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
435
435
|
capabilityApproved: z.ZodLiteral<true>;
|
|
436
436
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
437
437
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -492,7 +492,7 @@ export declare const retainedInstallationCommandSchema: z.ZodObject<{
|
|
|
492
492
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
493
493
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
494
494
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
495
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
495
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
496
496
|
capabilityApproved: z.ZodLiteral<true>;
|
|
497
497
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
498
498
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -598,6 +598,12 @@ export type InstallationOperations = Readonly<{
|
|
|
598
598
|
admit(input: InstallationAdmission): Promise<InstallationOperation>;
|
|
599
599
|
/** The operation's current state, when it names this installation. */
|
|
600
600
|
read(requestId: string, installationId: string): Promise<InstallationOperation | null>;
|
|
601
|
+
/**
|
|
602
|
+
* The operation once it leaves pending, or its current state when it is
|
|
603
|
+
* still pending (or not yet admitted) after at most `waitMs`. The owner
|
|
604
|
+
* answers the moment it settles the command; there is no caller poll.
|
|
605
|
+
*/
|
|
606
|
+
awaitSettled(requestId: string, installationId: string, waitMs: number): Promise<InstallationOperation | null>;
|
|
601
607
|
/** Only pending recovery is executable; terminal history returns null. */
|
|
602
608
|
load(requestId: string): Promise<RetainedInstallationCommand | null>;
|
|
603
609
|
/** Record the executor's one reduced installation for this command. */
|
|
@@ -605,6 +611,13 @@ export type InstallationOperations = Readonly<{
|
|
|
605
611
|
/** Commit the planned installation against its exact baseline. */
|
|
606
612
|
commit(requestId: string, uiCheck: UiBootCheckOutcome | null): Promise<InstallationCommit>;
|
|
607
613
|
}>;
|
|
614
|
+
/**
|
|
615
|
+
* One owner wait's bound, under ordinary HTTP idle timeouts; an observer that
|
|
616
|
+
* needs longer simply waits again.
|
|
617
|
+
*/
|
|
618
|
+
export declare const maxSettlementWaitMs = 25000;
|
|
619
|
+
/** The status door's optional `waitMs` query: whole milliseconds, bounded. */
|
|
620
|
+
export declare const installationWaitQuerySchema: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>;
|
|
608
621
|
declare const installationOperationRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
609
622
|
action: z.ZodLiteral<"admit">;
|
|
610
623
|
scope: z.ZodObject<{
|
|
@@ -655,6 +668,15 @@ declare const installationOperationRequestSchema: z.ZodDiscriminatedUnion<[z.Zod
|
|
|
655
668
|
}, z.core.$strict>;
|
|
656
669
|
requestId: z.ZodString;
|
|
657
670
|
installationId: z.ZodLazy<z.ZodString>;
|
|
671
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
672
|
+
action: z.ZodLiteral<"await">;
|
|
673
|
+
scope: z.ZodObject<{
|
|
674
|
+
tenantId: z.ZodPipe<z.ZodUnknown, z.ZodTransform<string & import("effect/Brand").Brand<"OysterTenantId">, unknown>>;
|
|
675
|
+
origin: z.ZodURL;
|
|
676
|
+
}, z.core.$strict>;
|
|
677
|
+
requestId: z.ZodString;
|
|
678
|
+
installationId: z.ZodLazy<z.ZodString>;
|
|
679
|
+
waitMs: z.ZodNumber;
|
|
658
680
|
}, z.core.$strict>, z.ZodObject<{
|
|
659
681
|
action: z.ZodLiteral<"load">;
|
|
660
682
|
scope: z.ZodObject<{
|
|
@@ -694,7 +716,7 @@ declare const installationOperationRequestSchema: z.ZodDiscriminatedUnion<[z.Zod
|
|
|
694
716
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
695
717
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
696
718
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
697
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
719
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
698
720
|
capabilityApproved: z.ZodLiteral<true>;
|
|
699
721
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
700
722
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -914,7 +936,7 @@ declare const installationOperationReplySchema: z.ZodDiscriminatedUnion<[z.ZodOb
|
|
|
914
936
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
915
937
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
916
938
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
917
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
939
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
918
940
|
capabilityApproved: z.ZodLiteral<true>;
|
|
919
941
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
920
942
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -1058,7 +1080,7 @@ declare const installationOperationReplySchema: z.ZodDiscriminatedUnion<[z.ZodOb
|
|
|
1058
1080
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
1059
1081
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
1060
1082
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
1061
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
1083
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
1062
1084
|
capabilityApproved: z.ZodLiteral<true>;
|
|
1063
1085
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
1064
1086
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -1119,7 +1141,7 @@ declare const installationOperationReplySchema: z.ZodDiscriminatedUnion<[z.ZodOb
|
|
|
1119
1141
|
authorityVersion: z.ZodLazy<z.ZodNumber>;
|
|
1120
1142
|
declaredOperationsDigest: z.ZodPipe<z.ZodUnknown, z.ZodTransform<import("@fungi.computer/puffball").Sha256Digest, unknown>>;
|
|
1121
1143
|
approvedGrants: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
1122
|
-
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
1144
|
+
capability: z.ZodPipe<z.ZodUnknown, z.ZodTransform<"approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage", unknown>>;
|
|
1123
1145
|
capabilityApproved: z.ZodLiteral<true>;
|
|
1124
1146
|
operations: z.ZodLazy<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
1125
1147
|
resources: z.ZodUnion<readonly [z.ZodLiteral<"tenant-scope">, z.ZodReadonly<z.ZodArray<z.ZodLazy<z.ZodReadonly<z.ZodObject<{
|
|
@@ -7,6 +7,7 @@ import { hostActorSchema } from "@fungi.computer/puffball/app-method-runtime";
|
|
|
7
7
|
import { installationIdSchema, installationSchema, isCommittedInstallation, ownerCodec, } from "./apps/installation.js";
|
|
8
8
|
import { instanceIds, instanceIdSchema } from "./instance-id.js";
|
|
9
9
|
import { tenantIdSchema, tenantScope } from "./tenant.js";
|
|
10
|
+
import { failureDiagnostic } from "./cause-class.js";
|
|
10
11
|
import { uiBootCheckOutcomeSchema, } from "./boot-gate.js";
|
|
11
12
|
// Request identity has Watchdog's public job-key bound; it is not a retry cap.
|
|
12
13
|
export const installationRequestIdSchema = z.string().min(1).max(256);
|
|
@@ -132,6 +133,18 @@ const storedCommandSchema = z.union([
|
|
|
132
133
|
const inputDigest = (input) => createHash("sha256")
|
|
133
134
|
.update(JSON.stringify(installationAdmissionSchema.parse(input)))
|
|
134
135
|
.digest("hex");
|
|
136
|
+
/**
|
|
137
|
+
* One owner wait's bound, under ordinary HTTP idle timeouts; an observer that
|
|
138
|
+
* needs longer simply waits again.
|
|
139
|
+
*/
|
|
140
|
+
export const maxSettlementWaitMs = 25_000;
|
|
141
|
+
/** The status door's optional `waitMs` query: whole milliseconds, bounded. */
|
|
142
|
+
export const installationWaitQuerySchema = z
|
|
143
|
+
.string()
|
|
144
|
+
.regex(/^\d{1,5}$/u)
|
|
145
|
+
.transform(Number)
|
|
146
|
+
.pipe(z.number().int().max(maxSettlementWaitMs))
|
|
147
|
+
.optional();
|
|
135
148
|
const installationOperationRequestSchema = z.discriminatedUnion("action", [
|
|
136
149
|
z.strictObject({
|
|
137
150
|
action: z.literal("admit"),
|
|
@@ -144,6 +157,13 @@ const installationOperationRequestSchema = z.discriminatedUnion("action", [
|
|
|
144
157
|
requestId: installationRequestIdSchema,
|
|
145
158
|
installationId: installationIdSchema,
|
|
146
159
|
}),
|
|
160
|
+
z.strictObject({
|
|
161
|
+
action: z.literal("await"),
|
|
162
|
+
scope: scopeSchema,
|
|
163
|
+
requestId: installationRequestIdSchema,
|
|
164
|
+
installationId: installationIdSchema,
|
|
165
|
+
waitMs: z.number().int().min(0).max(maxSettlementWaitMs),
|
|
166
|
+
}),
|
|
147
167
|
z.strictObject({
|
|
148
168
|
action: z.literal("load"),
|
|
149
169
|
scope: scopeSchema,
|
|
@@ -228,6 +248,18 @@ export function installationOperationsPort(send, scope) {
|
|
|
228
248
|
throw new InstallationOperationError("unavailable");
|
|
229
249
|
return reply.operation;
|
|
230
250
|
},
|
|
251
|
+
async awaitSettled(requestId, installationId, waitMs) {
|
|
252
|
+
const reply = await call({
|
|
253
|
+
action: "await",
|
|
254
|
+
scope,
|
|
255
|
+
requestId,
|
|
256
|
+
installationId,
|
|
257
|
+
waitMs,
|
|
258
|
+
});
|
|
259
|
+
if (reply.kind !== "operation")
|
|
260
|
+
throw new InstallationOperationError("unavailable");
|
|
261
|
+
return reply.operation;
|
|
262
|
+
},
|
|
231
263
|
async load(requestId) {
|
|
232
264
|
const reply = await call({ action: "load", scope, requestId });
|
|
233
265
|
if (reply.kind !== "command")
|
|
@@ -403,6 +435,19 @@ export async function createInstallationOperations(ports) {
|
|
|
403
435
|
? null
|
|
404
436
|
: readStored(installationOutcomeSchema, encoded);
|
|
405
437
|
};
|
|
438
|
+
// Callers waiting for one command to leave pending (or to be admitted). The
|
|
439
|
+
// settlement is projected inside Watchdog's transaction, so waiters are woken
|
|
440
|
+
// only after the tick that ran it has returned, and re-read committed state.
|
|
441
|
+
const waiters = new Map();
|
|
442
|
+
const settledInTick = new Set();
|
|
443
|
+
const wake = (requestId) => {
|
|
444
|
+
const waiting = waiters.get(requestId);
|
|
445
|
+
if (waiting === undefined)
|
|
446
|
+
return;
|
|
447
|
+
waiters.delete(requestId);
|
|
448
|
+
for (const resume of waiting)
|
|
449
|
+
resume();
|
|
450
|
+
};
|
|
406
451
|
const watchdog = await Watchdog.make({
|
|
407
452
|
owner,
|
|
408
453
|
isAlive: () => Promise.resolve(false),
|
|
@@ -420,15 +465,23 @@ export async function createInstallationOperations(ports) {
|
|
|
420
465
|
ports.generation() === command.generation &&
|
|
421
466
|
same(ports.get(command.installationId), proposed.installation)) ||
|
|
422
467
|
(proposed?.state === "refused" && settled.outcome === "failed");
|
|
468
|
+
const stopped = settled.outcome === "interrupted" || settled.outcome === "cancelled";
|
|
469
|
+
// The commit marks the plan prepared in this owner before its
|
|
470
|
+
// compare-and-put, and a settled command can never commit later. An
|
|
471
|
+
// unprepared plan whose target is not the current row therefore proves
|
|
472
|
+
// this request changed nothing: the previous release is still selected.
|
|
473
|
+
const neverCommitted = !stopped &&
|
|
474
|
+
command.plan?.prepared !== true &&
|
|
475
|
+
(command.plan === null ||
|
|
476
|
+
!same(ports.get(command.installationId), command.plan.installation));
|
|
423
477
|
const result = definitive
|
|
424
478
|
? proposed
|
|
425
|
-
:
|
|
426
|
-
state: "
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
? settled.outcome
|
|
430
|
-
|
|
431
|
-
};
|
|
479
|
+
: neverCommitted
|
|
480
|
+
? { state: "refused", status: 503, code: "installation_not_applied" }
|
|
481
|
+
: {
|
|
482
|
+
state: "unconfirmed",
|
|
483
|
+
outcome: stopped ? settled.outcome : "outcome_unknown",
|
|
484
|
+
};
|
|
432
485
|
const operation = terminalOperationSchema.parse(result.state === "succeeded"
|
|
433
486
|
? {
|
|
434
487
|
...command.operation,
|
|
@@ -453,6 +506,7 @@ export async function createInstallationOperations(ports) {
|
|
|
453
506
|
operation,
|
|
454
507
|
});
|
|
455
508
|
owner.sql.exec("UPDATE installation_commands SET provisional_outcome=NULL WHERE request_id=?", payload);
|
|
509
|
+
settledInTick.add(payload);
|
|
456
510
|
},
|
|
457
511
|
execute: async (job) => {
|
|
458
512
|
const command = load(installationRequestIdSchema.parse(job.payload));
|
|
@@ -460,7 +514,19 @@ export async function createInstallationOperations(ports) {
|
|
|
460
514
|
return { kind: "outcome_unknown" };
|
|
461
515
|
// Persist the wake handoff before awaiting work in another execution context.
|
|
462
516
|
await ports.scheduleWake(Date.now());
|
|
463
|
-
|
|
517
|
+
let executed;
|
|
518
|
+
try {
|
|
519
|
+
executed = await ports.execute(command);
|
|
520
|
+
}
|
|
521
|
+
catch (cause) {
|
|
522
|
+
// Watchdog keeps only a closed failure reason; keep the cause here.
|
|
523
|
+
console.error("Installation execution failed", {
|
|
524
|
+
requestId: command.admission.requestId,
|
|
525
|
+
...failureDiagnostic(cause),
|
|
526
|
+
});
|
|
527
|
+
throw cause;
|
|
528
|
+
}
|
|
529
|
+
const result = installationOutcomeSchema.parse(executed);
|
|
464
530
|
const latest = load(command.admission.requestId);
|
|
465
531
|
if (latest === null || !("admission" in latest))
|
|
466
532
|
throw new InstallationOperationError("stale_authority");
|
|
@@ -489,6 +555,16 @@ export async function createInstallationOperations(ports) {
|
|
|
489
555
|
throw new InstallationOperationError("stale_authority");
|
|
490
556
|
return command;
|
|
491
557
|
};
|
|
558
|
+
/** The caller's operation, when it names this installation in its scope. */
|
|
559
|
+
const observed = (request) => {
|
|
560
|
+
const command = load(request.requestId);
|
|
561
|
+
return command !== null &&
|
|
562
|
+
same(command.scope, request.scope) &&
|
|
563
|
+
(command.operation.installationId === request.installationId ||
|
|
564
|
+
command.operation.requestedInstallationId === request.installationId)
|
|
565
|
+
? operationOf(command)
|
|
566
|
+
: null;
|
|
567
|
+
};
|
|
492
568
|
const dispatch = async (raw) => {
|
|
493
569
|
const request = installationOperationRequestSchema.parse(raw);
|
|
494
570
|
const scope = tenantScope(request.scope.tenantId, request.scope.origin);
|
|
@@ -501,7 +577,7 @@ export async function createInstallationOperations(ports) {
|
|
|
501
577
|
// An orphan wake is harmless; an accepted row with no wake is not.
|
|
502
578
|
// No external await separates this persisted wake from atomic admission.
|
|
503
579
|
await ports.scheduleWake(Date.now());
|
|
504
|
-
|
|
580
|
+
const admitted = owner.transactionSync(() => {
|
|
505
581
|
const prior = load(request.input.requestId);
|
|
506
582
|
if (prior !== null) {
|
|
507
583
|
if (("admission" in prior
|
|
@@ -560,24 +636,41 @@ export async function createInstallationOperations(ports) {
|
|
|
560
636
|
});
|
|
561
637
|
return { kind: "operation", operation };
|
|
562
638
|
});
|
|
639
|
+
// A waiter whose admission acknowledgement was lost learns of it now.
|
|
640
|
+
wake(request.input.requestId);
|
|
641
|
+
return admitted;
|
|
563
642
|
}
|
|
564
|
-
if (request.action === "
|
|
643
|
+
if (request.action === "load") {
|
|
565
644
|
const command = load(request.requestId);
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
645
|
+
return {
|
|
646
|
+
kind: "command",
|
|
647
|
+
command: command !== null &&
|
|
648
|
+
same(command.scope, request.scope) &&
|
|
649
|
+
"admission" in command
|
|
650
|
+
? command
|
|
651
|
+
: null,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
if (request.action === "read")
|
|
655
|
+
return { kind: "operation", operation: observed(request) };
|
|
656
|
+
if (request.action === "await") {
|
|
657
|
+
const current = observed(request);
|
|
658
|
+
if (current !== null && current.state !== "pending")
|
|
659
|
+
return { kind: "operation", operation: current };
|
|
660
|
+
await new Promise((resolve) => {
|
|
661
|
+
const waiting = waiters.get(request.requestId) ?? new Set();
|
|
662
|
+
const resume = () => {
|
|
663
|
+
clearTimeout(timer);
|
|
664
|
+
waiting.delete(resume);
|
|
665
|
+
if (waiting.size === 0 && waiters.get(request.requestId) === waiting)
|
|
666
|
+
waiters.delete(request.requestId);
|
|
667
|
+
resolve();
|
|
580
668
|
};
|
|
669
|
+
const timer = setTimeout(resume, request.waitMs);
|
|
670
|
+
waiting.add(resume);
|
|
671
|
+
waiters.set(request.requestId, waiting);
|
|
672
|
+
});
|
|
673
|
+
return { kind: "operation", operation: observed(request) };
|
|
581
674
|
}
|
|
582
675
|
const command = requireCommand(request.requestId, request.scope);
|
|
583
676
|
if (request.action === "plan") {
|
|
@@ -647,6 +740,11 @@ export async function createInstallationOperations(ports) {
|
|
|
647
740
|
return await watchdog.tick();
|
|
648
741
|
}
|
|
649
742
|
finally {
|
|
743
|
+
// After the tick, never inside its transaction. A rolled-back
|
|
744
|
+
// settlement wakes a waiter that re-reads pending and waits again.
|
|
745
|
+
for (const requestId of settledInTick)
|
|
746
|
+
wake(requestId);
|
|
747
|
+
settledInTick.clear();
|
|
650
748
|
if (await watchdog.hasPendingWork())
|
|
651
749
|
await ports.scheduleWake(Date.now());
|
|
652
750
|
else {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { AppInstanceErrorCode } from "./index.js";
|
|
2
2
|
/** The retained HTTP meaning of a known Instance refusal, never generic failed. */
|
|
3
3
|
export declare function instanceRefusalStatus(code: AppInstanceErrorCode): number;
|
|
4
|
-
/**
|
|
4
|
+
/** The host-authored settlement for an installation that changed nothing. */
|
|
5
|
+
export declare const installationNotAppliedMessage = "The new release was not applied: Oyster could not prepare it. The previous release is still installed; install again to retry.";
|
|
6
|
+
/** Only closed host-authored reasons produce a caller-facing message. */
|
|
5
7
|
export declare function instanceRefusalBody(code: string): {
|
|
6
|
-
error:
|
|
8
|
+
error: string;
|
|
7
9
|
message: string;
|
|
8
10
|
} | {
|
|
9
11
|
error: string;
|