@moinulmoin/eden-runtime-cloudflare 0.11.1 → 0.11.2

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.
@@ -24497,6 +24497,7 @@ var init_core3 = __esm({
24497
24497
  waitUntil;
24498
24498
  retireDeployment;
24499
24499
  currentDeploymentId;
24500
+ isDeploymentRemoved;
24500
24501
  constructor(opts) {
24501
24502
  this.sql = opts.sql;
24502
24503
  this.delivery = opts.delivery;
@@ -24506,6 +24507,7 @@ var init_core3 = __esm({
24506
24507
  });
24507
24508
  this.retireDeployment = opts.retireDeployment;
24508
24509
  this.currentDeploymentId = opts.currentDeploymentId;
24510
+ this.isDeploymentRemoved = opts.isDeploymentRemoved;
24509
24511
  }
24510
24512
  rows(query, ...args) {
24511
24513
  return this.sql.exec(query, ...args).toArray();
@@ -24573,8 +24575,8 @@ var init_core3 = __esm({
24573
24575
  return WorkflowRunSchema.parse(value);
24574
24576
  }
24575
24577
  assertDeploymentActive(deploymentId) {
24576
- if (this.rows("SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=?", deploymentId).length)
24577
- throw new WorkflowWorldError(`Deployment ${deploymentId} has been retired`, { status: 409 });
24578
+ if (this.isDeploymentRemoved?.(deploymentId) || this.rows("SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=?", deploymentId).length)
24579
+ throw new WorkflowWorldError(`Deployment ${deploymentId} has been retired; its sessions ended. Start a new session.`, { status: 409 });
24578
24580
  }
24579
24581
  deliverySettled(messageId, attempt) {
24580
24582
  this.sql.exec("UPDATE workflow_delivery_claims SET settled=1 WHERE message_id=? AND attempt=?", messageId, attempt);
@@ -25368,11 +25370,20 @@ var init_core3 = __esm({
25368
25370
  const body = sqlBytes(row.body);
25369
25371
  const message = this.queueMessage(body);
25370
25372
  const deploymentId = this.queueTarget(message, row.deployment_id == null ? void 0 : String(row.deployment_id));
25371
- this.assertDeploymentActive(deploymentId);
25372
- this.sql.exec("UPDATE workflow_queue_messages SET deployment_id=? WHERE id=?", deploymentId, id);
25373
25373
  let transfer = this.rows("SELECT * FROM workflow_sandbox_transfers WHERE message_id=?", id)[0];
25374
25374
  const sandbox = transfer ? void 0 : this.successorSandbox(message);
25375
- const sourceDeploymentId = transfer ? String(transfer.source_deployment_id) : sandbox?.sourceDeploymentId ?? (row.source_deployment_id == null ? void 0 : String(row.source_deployment_id));
25375
+ const source = transfer ? String(transfer.source_deployment_id) : sandbox?.sourceDeploymentId ?? (row.source_deployment_id == null ? void 0 : String(row.source_deployment_id));
25376
+ if (this.isDeploymentRemoved?.(deploymentId) || source && this.isDeploymentRemoved?.(source) || this.rows("SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=? OR deployment_id=?", deploymentId, source ?? deploymentId).length) {
25377
+ this.atomic(() => {
25378
+ this.sql.exec("UPDATE workflow_sandbox_transfers SET completed=-1 WHERE message_id=? AND completed=0", id);
25379
+ this.deliverySettled(id, attempt);
25380
+ this.sql.exec("UPDATE workflow_queue_messages SET completed=1,idempotency_key=NULL,lease_until=0 WHERE id=?", id);
25381
+ });
25382
+ return;
25383
+ }
25384
+ this.assertDeploymentActive(deploymentId);
25385
+ this.sql.exec("UPDATE workflow_queue_messages SET deployment_id=? WHERE id=?", deploymentId, id);
25386
+ const sourceDeploymentId = source;
25376
25387
  if (sandbox && sourceDeploymentId && sourceDeploymentId !== deploymentId) {
25377
25388
  this.assertDeploymentActive(sourceDeploymentId);
25378
25389
  this.sql.exec("UPDATE workflow_queue_messages SET source_deployment_id=? WHERE id=?", sourceDeploymentId, id);
@@ -25443,7 +25454,7 @@ var init_core3 = __esm({
25443
25454
  if (this.currentDeploymentId && ids.includes(this.currentDeploymentId))
25444
25455
  throw new WorkflowWorldError("Cannot retire the current deployment", { status: 409 });
25445
25456
  const states = this.drainState(ids);
25446
- if (ids.some((id) => !states[id].drained))
25457
+ if (ids.some((id) => !this.isDeploymentRemoved?.(id) && !states[id].drained))
25447
25458
  throw new WorkflowWorldError("Cannot retire a deployment with live runs, queued messages, or unfinished transfers", { status: 409 });
25448
25459
  if (!this.retireDeployment)
25449
25460
  throw new WorkflowWorldError("Deployment retirement is unavailable", { status: 501 });
@@ -25827,6 +25838,10 @@ var RESERVED_EVE_HOST_VARIABLES = /* @__PURE__ */ new Set([
25827
25838
  "PORT",
25828
25839
  "NITRO_PORT",
25829
25840
  "NODE_ENV",
25841
+ "EVE_DEV",
25842
+ "VERCEL",
25843
+ "VERCEL_ENV",
25844
+ "VERCEL_TARGET_ENV",
25830
25845
  "NODE_EXTRA_CA_CERTS",
25831
25846
  "WORKFLOW_LOCAL_BASE_URL",
25832
25847
  "EDEN_WORLD_URL",
@@ -26131,7 +26146,7 @@ async function publish(from, to) {
26131
26146
  var EVE_HOST_ENTRYPOINT = Object.freeze([
26132
26147
  "/bin/sh",
26133
26148
  "-c",
26134
- "rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080"
26149
+ "unset EVE_DEV VERCEL VERCEL_ENV VERCEL_TARGET_ENV; rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080"
26135
26150
  ]);
26136
26151
  var EVE_HOST_CONTAINER_ACTIVITY_KEY = "eden.eve.host.last-activity-at";
26137
26152
  var EVE_HOST_CONTAINER_SNAPSHOT_KEY = "eden.eve.host.workspace-snapshot";
@@ -26154,6 +26169,9 @@ var EdenWorldDurableObject = class extends DurableObject {
26154
26169
  super(ctx, env);
26155
26170
  this.core = new WorldCore({
26156
26171
  ...env.EDEN_EVE_DEPLOYMENT_ID === void 0 ? {} : { currentDeploymentId: env.EDEN_EVE_DEPLOYMENT_ID },
26172
+ // The published route table is authoritative, including before cleanup
26173
+ // has finished fencing and deleting an insecure legacy container.
26174
+ isDeploymentRemoved: (id) => env.EDEN_EVE_DEPLOYMENTS !== void 0 && id !== env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(env)[id] === void 0,
26157
26175
  sql: {
26158
26176
  exec: ctx.storage.sql.exec.bind(ctx.storage.sql),
26159
26177
  transactionSync: ctx.storage.transactionSync.bind(ctx.storage)
@@ -26274,6 +26292,9 @@ async function routeEveOutboundRequest(request, env, sourceDeploymentId, expecte
26274
26292
  }
26275
26293
  if (new URL(request.url).pathname === "/__eden/world/rpc") {
26276
26294
  const route = deploymentImages(env)[deploymentId];
26295
+ if (env.EDEN_EVE_DEPLOYMENTS !== void 0 && route === void 0) {
26296
+ return new Response("Deployment retired; its sessions ended.", { status: 403 });
26297
+ }
26277
26298
  const authRequired = route?.worldRpcAuth === true || env.EDEN_EVE_DEPLOYMENTS === void 0 && env.EDEN_EVE_WORLD_RPC_AUTH === true;
26278
26299
  if (authRequired) {
26279
26300
  const supplied = request.headers.get("x-eden-world-token") ?? "";
@@ -26355,6 +26376,9 @@ var EveHostDurableContainer = class extends DurableObject {
26355
26376
  throw new Error("The Container deployment identity does not match its persisted owner.");
26356
26377
  }
26357
26378
  const record2 = deploymentImages(this.env)[id];
26379
+ if (affinity && record2 === void 0) {
26380
+ throw new Error(`Deployment ${id} has been retired; its sessions ended. Start a new session.`);
26381
+ }
26358
26382
  if (stored === void 0) await this.ctx.storage.put("eden.eve.host.deployment-id", id);
26359
26383
  this.deploymentId = id;
26360
26384
  this.envVars.EDEN_EVE_DEPLOYMENT_ID = id;
@@ -26442,7 +26466,7 @@ var EveHostDurableContainer = class extends DurableObject {
26442
26466
  const id = this.deploymentId;
26443
26467
  if (id === void 0) throw new Error("Container deployment identity has not been resolved.");
26444
26468
  const record2 = deploymentImages(this.env)[id];
26445
- if (this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && record2 === void 0 && id !== "eden-cloudflare") throw new Error(`Deployment ${id} has no retained Container image.`);
26469
+ if (this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && record2 === void 0) throw new Error(`Deployment ${id} has no retained Container image.`);
26446
26470
  return runtime.images[record2?.image ?? "eve"];
26447
26471
  }
26448
26472
  constructor(ctx, env) {
@@ -26503,6 +26527,15 @@ var EveHostDurableContainer = class extends DurableObject {
26503
26527
  if (runtime?.running === true) {
26504
26528
  this.ctx.blockConcurrencyWhile(async () => {
26505
26529
  if (env.EDEN_EVE_DEPLOYMENTS !== void 0) {
26530
+ const stored = await this.ctx.storage.get("eden.eve.host.deployment-id");
26531
+ const namespace = env.EVE_CONTAINER;
26532
+ const owner = stored ?? (this.ctx.id.equals(namespace.idFromName(env.EVE_CONTAINER_INSTANCE_NAME)) ? "eden-cloudflare" : void 0);
26533
+ if (owner !== void 0 && deploymentImages(env)[owner] === void 0) {
26534
+ await runtime.destroy(new Error("deployment-retired"));
26535
+ this.recordContainerStopped();
26536
+ await this.ctx.storage.deleteAlarm();
26537
+ return;
26538
+ }
26506
26539
  await this.identifyDeployment();
26507
26540
  await this.registerLoopbackIntercept(runtime);
26508
26541
  }
@@ -26956,7 +26989,12 @@ var EveHostDurableContainer = class extends DurableObject {
26956
26989
  return response;
26957
26990
  }
26958
26991
  async retire(deploymentId) {
26959
- if (await this.deploymentBusy(deploymentId)) {
26992
+ const removed = this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && deploymentId !== this.env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(this.env)[deploymentId] === void 0;
26993
+ const namespace = this.env.EVE_CONTAINER;
26994
+ if (!this.ctx.id.equals(namespace.idFromName(deploymentInstance(this.env, deploymentId)))) {
26995
+ throw new Error("The retirement target does not match its Container instance.");
26996
+ }
26997
+ if (!removed && await this.deploymentBusy(deploymentId)) {
26960
26998
  throw new Error("Cannot retire a deployment with active deliveries or transfers.");
26961
26999
  }
26962
27000
  const runtime = this.containerRuntime();
@@ -92,7 +92,7 @@ async function publish(from, to) {
92
92
  const EVE_HOST_ENTRYPOINT = Object.freeze([
93
93
  "/bin/sh",
94
94
  "-c",
95
- "rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080",
95
+ "unset EVE_DEV VERCEL VERCEL_ENV VERCEL_TARGET_ENV; rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080",
96
96
  ]);
97
97
  /** Durable Object storage keys owned by `EveHostDurableContainer`. */
98
98
  const EVE_HOST_CONTAINER_ACTIVITY_KEY = "eden.eve.host.last-activity-at";
@@ -138,6 +138,10 @@ export class EdenWorldDurableObject extends DurableObject {
138
138
  super(ctx, env);
139
139
  this.core = new WorldCore({
140
140
  ...(env.EDEN_EVE_DEPLOYMENT_ID === undefined ? {} : { currentDeploymentId: env.EDEN_EVE_DEPLOYMENT_ID }),
141
+ // The published route table is authoritative, including before cleanup
142
+ // has finished fencing and deleting an insecure legacy container.
143
+ isDeploymentRemoved: (id) => env.EDEN_EVE_DEPLOYMENTS !== undefined &&
144
+ id !== env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(env)[id] === undefined,
141
145
  sql: {
142
146
  exec: ctx.storage.sql.exec.bind(ctx.storage.sql),
143
147
  transactionSync: ctx.storage.transactionSync.bind(ctx.storage),
@@ -281,6 +285,9 @@ export async function routeEveOutboundRequest(request, env, sourceDeploymentId,
281
285
  }
282
286
  if (new URL(request.url).pathname === "/__eden/world/rpc") {
283
287
  const route = deploymentImages(env)[deploymentId];
288
+ if (env.EDEN_EVE_DEPLOYMENTS !== undefined && route === undefined) {
289
+ return new Response("Deployment retired; its sessions ended.", { status: 403 });
290
+ }
284
291
  const authRequired = route?.worldRpcAuth === true ||
285
292
  (env.EDEN_EVE_DEPLOYMENTS === undefined && env.EDEN_EVE_WORLD_RPC_AUTH === true);
286
293
  if (authRequired) {
@@ -383,6 +390,9 @@ export class EveHostDurableContainer extends DurableObject {
383
390
  throw new Error("The Container deployment identity does not match its persisted owner.");
384
391
  }
385
392
  const record = deploymentImages(this.env)[id];
393
+ if (affinity && record === undefined) {
394
+ throw new Error(`Deployment ${id} has been retired; its sessions ended. Start a new session.`);
395
+ }
386
396
  if (stored === undefined)
387
397
  await this.ctx.storage.put("eden.eve.host.deployment-id", id);
388
398
  this.deploymentId = id;
@@ -481,7 +491,7 @@ export class EveHostDurableContainer extends DurableObject {
481
491
  if (id === undefined)
482
492
  throw new Error("Container deployment identity has not been resolved.");
483
493
  const record = deploymentImages(this.env)[id];
484
- if (this.env.EDEN_EVE_DEPLOYMENTS !== undefined && record === undefined && id !== "eden-cloudflare")
494
+ if (this.env.EDEN_EVE_DEPLOYMENTS !== undefined && record === undefined)
485
495
  throw new Error(`Deployment ${id} has no retained Container image.`);
486
496
  return runtime.images[record?.image ?? "eve"];
487
497
  }
@@ -543,6 +553,17 @@ export class EveHostDurableContainer extends DurableObject {
543
553
  // container generation is also gone, so both are re-attached here.
544
554
  this.ctx.blockConcurrencyWhile(async () => {
545
555
  if (env.EDEN_EVE_DEPLOYMENTS !== undefined) {
556
+ const stored = await this.ctx.storage.get("eden.eve.host.deployment-id");
557
+ const namespace = env.EVE_CONTAINER;
558
+ const owner = stored ?? (this.ctx.id.equals(namespace.idFromName(env.EVE_CONTAINER_INSTANCE_NAME)) ? "eden-cloudflare" : undefined);
559
+ if (owner !== undefined && deploymentImages(env)[owner] === undefined) {
560
+ // Removed routes must not make the constructor fail before the
561
+ // retirement RPC can destroy a still-running legacy container.
562
+ await runtime.destroy(new Error("deployment-retired"));
563
+ this.recordContainerStopped();
564
+ await this.ctx.storage.deleteAlarm();
565
+ return;
566
+ }
546
567
  await this.identifyDeployment();
547
568
  await this.registerLoopbackIntercept(runtime);
548
569
  }
@@ -1021,7 +1042,13 @@ export class EveHostDurableContainer extends DurableObject {
1021
1042
  async retire(deploymentId) {
1022
1043
  // World routes the fenced target to its named DO. Retirement must not
1023
1044
  // restore or trust a stored owner left by an earlier retirement attempt.
1024
- if (await this.deploymentBusy(deploymentId)) {
1045
+ const removed = this.env.EDEN_EVE_DEPLOYMENTS !== undefined &&
1046
+ deploymentId !== this.env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(this.env)[deploymentId] === undefined;
1047
+ const namespace = this.env.EVE_CONTAINER;
1048
+ if (!this.ctx.id.equals(namespace.idFromName(deploymentInstance(this.env, deploymentId)))) {
1049
+ throw new Error("The retirement target does not match its Container instance.");
1050
+ }
1051
+ if (!removed && await this.deploymentBusy(deploymentId)) {
1025
1052
  throw new Error("Cannot retire a deployment with active deliveries or transfers.");
1026
1053
  }
1027
1054
  const runtime = this.containerRuntime();
package/dist/eve-host.js CHANGED
@@ -576,6 +576,10 @@ const RESERVED_EVE_HOST_VARIABLES = new Set([
576
576
  "PORT",
577
577
  "NITRO_PORT",
578
578
  "NODE_ENV",
579
+ "EVE_DEV",
580
+ "VERCEL",
581
+ "VERCEL_ENV",
582
+ "VERCEL_TARGET_ENV",
579
583
  "NODE_EXTRA_CA_CERTS",
580
584
  "WORKFLOW_LOCAL_BASE_URL",
581
585
  "EDEN_WORLD_URL",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moinulmoin/eden-runtime-cloudflare",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,7 @@
20
20
  "NOTICE"
21
21
  ],
22
22
  "devDependencies": {
23
- "@moinulmoin/eden-world-cloudflare": "0.11.1",
23
+ "@moinulmoin/eden-world-cloudflare": "0.11.2",
24
24
  "@cloudflare/workers-types": "5.20261006.1"
25
25
  },
26
26
  "repository": {