@fungi.computer/oyster 0.21.5 → 0.21.6

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.
@@ -24,24 +24,28 @@ const unconfirmed = {
24
24
  outcome: "outcome_unknown",
25
25
  };
26
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.
27
+ * Delays before each further attempt at one Instance step. A cold Instance
28
+ * (first backend construction, a Durable Object reset or an overloaded
29
+ * isolate) can fail its first generic attempt and pass the next one.
30
30
  */
31
- const preparationRetryDelaysMs = [500, 2_000];
32
- /** Retry only generic preparation failures; typed refusals are final. */
33
- async function prepareWithRetry(prepare) {
31
+ const instanceRetryDelaysMs = [500, 2_000];
32
+ /**
33
+ * Retry only generic Instance failures; typed refusals are final. Both steps
34
+ * are safe to repeat: preparation never changes the active runtime, and apply
35
+ * replays the pinned committed fact (an applied selection is `unchanged`).
36
+ */
37
+ async function withColdRetry(step, run) {
34
38
  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
+ const outcome = await run();
40
+ if (outcome.ok || outcome.code !== "failed")
41
+ return outcome;
42
+ console.error(`Installation ${step} failed`, {
39
43
  attempt,
40
- causeClass: prepared.causeClass,
44
+ causeClass: outcome.causeClass,
41
45
  });
42
- const wait = preparationRetryDelaysMs[attempt - 1];
46
+ const wait = instanceRetryDelaysMs[attempt - 1];
43
47
  if (wait === undefined)
44
- return prepared;
48
+ return outcome;
45
49
  await new Promise((resolve) => setTimeout(resolve, wait));
46
50
  }
47
51
  }
@@ -160,7 +164,7 @@ export async function executeInstallation(host, input) {
160
164
  }
161
165
  }
162
166
  else {
163
- const prepared = await prepareWithRetry(() => instance.prepare(state, next.release));
167
+ const prepared = await withColdRetry("preparation", () => instance.prepare(state, next.release));
164
168
  if (!prepared.ok)
165
169
  // Preparation never changes the active runtime and runs before the
166
170
  // commit, so a generic failure here leaves the previous release live.
@@ -177,13 +181,18 @@ export async function executeInstallation(host, input) {
177
181
  return refused(409, commit.code);
178
182
  if (instance !== null) {
179
183
  // Replay the pinned fact; NEVER derive version N+1 from a current row here.
180
- const applied = await instance.apply(state, next.release);
181
- if (!applied.ok)
184
+ const applied = await withColdRetry("activation", () => instance.apply(state, next.release));
185
+ if (!applied.ok) {
186
+ // The selection is committed, so a persistent generic failure is not
187
+ // "nothing changed": it is a definitive, retryable activation failure.
188
+ if (applied.code === "failed")
189
+ return refused(503, "installation_not_activated");
182
190
  // Native apply can return stale_authority from its POST-application
183
191
  // owner check. That code does not establish that application never ran.
184
- return applied.code === "failed" || applied.code === "stale_authority"
192
+ return applied.code === "stale_authority"
185
193
  ? unconfirmed
186
194
  : refused(instanceRefusalStatus(applied.code), applied.code);
195
+ }
187
196
  const receipt = Schema.decodeUnknownSync(instanceSchema)(applied.value);
188
197
  if (receipt.instanceId !== state.instanceId ||
189
198
  receipt.owner.kind !== "installation" ||
@@ -3,6 +3,8 @@ import type { AppInstanceErrorCode } from "./index.js";
3
3
  export declare function instanceRefusalStatus(code: AppInstanceErrorCode): number;
4
4
  /** The host-authored settlement for an installation that changed nothing. */
5
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
+ /** The host-authored settlement for a committed release whose backend would not start. */
7
+ export declare const installationNotActivatedMessage = "The new release was selected, but its backend did not start. Install again to retry activation.";
6
8
  /** Only closed host-authored reasons produce a caller-facing message. */
7
9
  export declare function instanceRefusalBody(code: string): {
8
10
  error: string;
@@ -14,10 +14,14 @@ export function instanceRefusalStatus(code) {
14
14
  }
15
15
  /** The host-authored settlement for an installation that changed nothing. */
16
16
  export const installationNotAppliedMessage = "The new release was not applied: Oyster could not prepare it. The previous release is still installed; install again to retry.";
17
+ /** The host-authored settlement for a committed release whose backend would not start. */
18
+ export const installationNotActivatedMessage = "The new release was selected, but its backend did not start. Install again to retry activation.";
17
19
  /** Only closed host-authored reasons produce a caller-facing message. */
18
20
  export function instanceRefusalBody(code) {
19
21
  if (code === "installation_not_applied")
20
22
  return { error: code, message: installationNotAppliedMessage };
23
+ if (code === "installation_not_activated")
24
+ return { error: code, message: installationNotActivatedMessage };
21
25
  const boot = bootFailureSchema.safeParse(code);
22
26
  return boot.success
23
27
  ? { error: boot.data, message: new BootGateError(boot.data).message }
@@ -5,7 +5,7 @@ import { setTimeout as sleep } from "node:timers/promises";
5
5
  import * as Option from "effect/Option";
6
6
  import * as Schema from "effect/Schema";
7
7
  import { olderOysterStoreCode } from "../older-oyster-store.js";
8
- import { installationNotAppliedMessage } from "../instance-refusal.js";
8
+ import { installationNotActivatedMessage, installationNotAppliedMessage, } from "../instance-refusal.js";
9
9
  import { publishSource } from "../pack.js";
10
10
  import { appBuildRecipe, readBuildManifest } from "../build/workspace-build.js";
11
11
  import { parseSourceRevision } from "@fungi.computer/puffball";
@@ -374,7 +374,9 @@ export async function installStandaloneAppSet(options) {
374
374
  if (operation.state === "refused")
375
375
  throw new Error(operation.code === "installation_not_applied"
376
376
  ? `${name}: ${installationNotAppliedMessage}`
377
- : `${name} installation refused (${operation.code})`);
377
+ : operation.code === "installation_not_activated"
378
+ ? `${name}: ${installationNotActivatedMessage}`
379
+ : `${name} installation refused (${operation.code})`);
378
380
  const record = operation.installation;
379
381
  if (record === null)
380
382
  throw new Error(`${name} completed installation version is unavailable`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/oyster",
3
- "version": "0.21.5",
3
+ "version": "0.21.6",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Oyster by Fungi: open-source Apps for people and AI agents. Try with one command or run on your own Cloudflare account.",
6
6
  "homepage": "https://docs.fungi.computer/oyster",