@moinulmoin/eden-runtime-cloudflare 0.11.0 → 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.
- package/dist/eden-eve-host-worker.mjs +124 -11
- package/dist/eve-host-runtime.js +30 -3
- package/dist/eve-host.js +4 -0
- package/package.json +2 -2
|
@@ -22724,6 +22724,15 @@ var init_serialization = __esm({
|
|
|
22724
22724
|
});
|
|
22725
22725
|
|
|
22726
22726
|
// ../../node_modules/.pnpm/@workflow+world@5.1.0/node_modules/@workflow/world/dist/start-hook.js
|
|
22727
|
+
function startHookId(runId) {
|
|
22728
|
+
if (!runId.startsWith("wrun_") || runId.length <= "wrun_".length) {
|
|
22729
|
+
throw new Error(`Not a workflow run id: "${runId}"`);
|
|
22730
|
+
}
|
|
22731
|
+
return `hook_${runId.slice("wrun_".length)}`;
|
|
22732
|
+
}
|
|
22733
|
+
function isStartHookId(runId, hookId) {
|
|
22734
|
+
return runId.startsWith("wrun_") && hookId === startHookId(runId);
|
|
22735
|
+
}
|
|
22727
22736
|
var StartHookSchema, START_HOOK_CANDIDATE_MAX_AGE_MS;
|
|
22728
22737
|
var init_start_hook = __esm({
|
|
22729
22738
|
"../../node_modules/.pnpm/@workflow+world@5.1.0/node_modules/@workflow/world/dist/start-hook.js"() {
|
|
@@ -24488,6 +24497,7 @@ var init_core3 = __esm({
|
|
|
24488
24497
|
waitUntil;
|
|
24489
24498
|
retireDeployment;
|
|
24490
24499
|
currentDeploymentId;
|
|
24500
|
+
isDeploymentRemoved;
|
|
24491
24501
|
constructor(opts) {
|
|
24492
24502
|
this.sql = opts.sql;
|
|
24493
24503
|
this.delivery = opts.delivery;
|
|
@@ -24497,6 +24507,7 @@ var init_core3 = __esm({
|
|
|
24497
24507
|
});
|
|
24498
24508
|
this.retireDeployment = opts.retireDeployment;
|
|
24499
24509
|
this.currentDeploymentId = opts.currentDeploymentId;
|
|
24510
|
+
this.isDeploymentRemoved = opts.isDeploymentRemoved;
|
|
24500
24511
|
}
|
|
24501
24512
|
rows(query, ...args) {
|
|
24502
24513
|
return this.sql.exec(query, ...args).toArray();
|
|
@@ -24519,6 +24530,9 @@ var init_core3 = __esm({
|
|
|
24519
24530
|
"CREATE TABLE IF NOT EXISTS workflow_hooks (hook_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, token TEXT NOT NULL, data BLOB NOT NULL)",
|
|
24520
24531
|
"CREATE INDEX IF NOT EXISTS workflow_hooks_run ON workflow_hooks(run_id)",
|
|
24521
24532
|
"CREATE INDEX IF NOT EXISTS workflow_hooks_token ON workflow_hooks(token)",
|
|
24533
|
+
// Decisions outlive Hook disposal and token takeover; retries must never
|
|
24534
|
+
// turn a refused candidate into a second run.
|
|
24535
|
+
"CREATE TABLE IF NOT EXISTS workflow_start_hook_admissions (run_id TEXT PRIMARY KEY, token TEXT NOT NULL, conflicting_run_id TEXT, cancelled INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL)",
|
|
24522
24536
|
// Routing tombstones outlive invocation-data retention; never store payloads here.
|
|
24523
24537
|
"CREATE TABLE IF NOT EXISTS workflow_hook_disposals (run_id TEXT NOT NULL, hook_id TEXT NOT NULL, token TEXT NOT NULL, claimed_run_id TEXT NOT NULL, claimed_hook_id TEXT NOT NULL, PRIMARY KEY(run_id,hook_id))",
|
|
24524
24538
|
"CREATE TABLE IF NOT EXISTS workflow_waits (wait_id TEXT PRIMARY KEY, run_id TEXT NOT NULL, data BLOB NOT NULL)",
|
|
@@ -24561,8 +24575,8 @@ var init_core3 = __esm({
|
|
|
24561
24575
|
return WorkflowRunSchema.parse(value);
|
|
24562
24576
|
}
|
|
24563
24577
|
assertDeploymentActive(deploymentId) {
|
|
24564
|
-
if (this.rows("SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=?", deploymentId).length)
|
|
24565
|
-
throw new WorkflowWorldError(`Deployment ${deploymentId} has been retired
|
|
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 });
|
|
24566
24580
|
}
|
|
24567
24581
|
deliverySettled(messageId, attempt) {
|
|
24568
24582
|
this.sql.exec("UPDATE workflow_delivery_claims SET settled=1 WHERE message_id=? AND attempt=?", messageId, attempt);
|
|
@@ -24820,6 +24834,47 @@ var init_core3 = __esm({
|
|
|
24820
24834
|
}
|
|
24821
24835
|
throw new HookNotFoundError(hookId);
|
|
24822
24836
|
}
|
|
24837
|
+
rejectStartHook(reason) {
|
|
24838
|
+
throw new WorkflowWorldError(`Start Hook admission rejected: ${reason}`, { status: 400, code: "START_HOOK_ADMISSION_REJECTED", reason });
|
|
24839
|
+
}
|
|
24840
|
+
admitStartHook(id, request) {
|
|
24841
|
+
if (request.eventType !== "run_created" && request.eventType !== "run_started")
|
|
24842
|
+
return { request };
|
|
24843
|
+
const input2 = request.eventData;
|
|
24844
|
+
const recorded = this.rows("SELECT * FROM workflow_start_hook_admissions WHERE run_id=?", id)[0];
|
|
24845
|
+
if (recorded?.cancelled)
|
|
24846
|
+
this.rejectStartHook("expired");
|
|
24847
|
+
if (input2?.startHook === void 0) {
|
|
24848
|
+
if (recorded && !this.rows("SELECT id FROM workflow_runs WHERE id=?", id).length)
|
|
24849
|
+
return { request, error: new HookConflictError(String(recorded.token), String(recorded.conflicting_run_id)) };
|
|
24850
|
+
return { request };
|
|
24851
|
+
}
|
|
24852
|
+
const parsed = StartHookSchema.safeParse(input2.startHook);
|
|
24853
|
+
if (!parsed.success)
|
|
24854
|
+
this.rejectStartHook("invalid");
|
|
24855
|
+
const startHook = { ...parsed.data, hookId: startHookId(id) };
|
|
24856
|
+
if (parsed.data.hookId && parsed.data.hookId !== startHook.hookId)
|
|
24857
|
+
this.rejectStartHook("invalid");
|
|
24858
|
+
if (startHook.tokenRetentionUntil && startHook.tokenRetentionUntil.getTime() > this.now() + 30 * 864e5)
|
|
24859
|
+
this.rejectStartHook("invalid");
|
|
24860
|
+
const candidateTime = ulidToDate(id.replace(/^wrun_/, ""))?.getTime();
|
|
24861
|
+
if (candidateTime === void 0 || this.now() - candidateTime > START_HOOK_CANDIDATE_MAX_AGE_MS && (request.eventType === "run_created" || !this.rows("SELECT id FROM workflow_runs WHERE id=?", id).length))
|
|
24862
|
+
this.rejectStartHook("expired");
|
|
24863
|
+
if (recorded) {
|
|
24864
|
+
if (recorded.token !== startHook.token)
|
|
24865
|
+
this.rejectStartHook("token_mismatch");
|
|
24866
|
+
if (recorded.conflicting_run_id)
|
|
24867
|
+
return { request, error: new HookConflictError(startHook.token, String(recorded.conflicting_run_id)) };
|
|
24868
|
+
} else {
|
|
24869
|
+
if (this.rows("SELECT id FROM workflow_runs WHERE id=?", id).length)
|
|
24870
|
+
this.rejectStartHook("ordinary_run");
|
|
24871
|
+
const owner = this.findHook(startHook.token, true);
|
|
24872
|
+
this.sql.exec("INSERT INTO workflow_start_hook_admissions(run_id,token,conflicting_run_id,created_at) VALUES(?,?,?,?)", id, startHook.token, owner?.runId ?? null, this.now());
|
|
24873
|
+
if (owner)
|
|
24874
|
+
return { request, error: new HookConflictError(startHook.token, owner.runId) };
|
|
24875
|
+
}
|
|
24876
|
+
return { request: { ...request, eventData: { ...input2, startHook } } };
|
|
24877
|
+
}
|
|
24823
24878
|
createRun(runId, data) {
|
|
24824
24879
|
if ((data.specVersion ?? SPEC_VERSION_CURRENT) > SPEC_VERSION_CURRENT)
|
|
24825
24880
|
throw new RunNotSupportedError(data.specVersion, SPEC_VERSION_CURRENT);
|
|
@@ -24831,6 +24886,8 @@ var init_core3 = __esm({
|
|
|
24831
24886
|
const now = new Date(this.now());
|
|
24832
24887
|
const run = WorkflowRunSchema.parse(compact({ runId, ...d, status: "pending", attributes: d.attributes ?? {}, createdAt: now, updatedAt: now, specVersion: data.specVersion ?? SPEC_VERSION_CURRENT }));
|
|
24833
24888
|
this.saveRun(run);
|
|
24889
|
+
if (d.startHook)
|
|
24890
|
+
this.saveHook(HookSchema.parse(compact({ ...d.startHook, runId, hookId: startHookId(runId), ownerId: "", projectId: "", environment: "", createdAt: now, specVersion: run.specVersion, isWebhook: false, isSystem: false })));
|
|
24834
24891
|
this.sql.exec("INSERT INTO workflow_event_slots(run_id) VALUES(?)", runId);
|
|
24835
24892
|
const event = this.insertEvent(runId, data);
|
|
24836
24893
|
return { run, event };
|
|
@@ -24839,10 +24896,14 @@ var init_core3 = __esm({
|
|
|
24839
24896
|
const id = runId || (request.eventType === "run_created" ? `wrun_${ulid3(this.now())}` : "");
|
|
24840
24897
|
if (!id)
|
|
24841
24898
|
throw new Error("runId is required for non-run_created events");
|
|
24899
|
+
const hasStartHook = (request.eventType === "run_created" || request.eventType === "run_started") && request.eventData?.startHook !== void 0;
|
|
24842
24900
|
if (request.eventType === "run_created" && runId) {
|
|
24843
24901
|
const error61 = validateUlidTimestamp(id, "wrun_");
|
|
24844
|
-
if (error61)
|
|
24902
|
+
if (error61) {
|
|
24903
|
+
if (hasStartHook)
|
|
24904
|
+
this.rejectStartHook("expired");
|
|
24845
24905
|
throw new WorkflowWorldError(error61);
|
|
24906
|
+
}
|
|
24846
24907
|
}
|
|
24847
24908
|
let digest;
|
|
24848
24909
|
if (request.eventType === "hook_received" && params?.resumeId) {
|
|
@@ -24852,7 +24913,21 @@ var init_core3 = __esm({
|
|
|
24852
24913
|
if (params.resumePayloadDigest && params.resumePayloadDigest !== digest)
|
|
24853
24914
|
throw new WorkflowWorldError("Hook resume digest does not match its payload", { status: 422 });
|
|
24854
24915
|
}
|
|
24855
|
-
|
|
24916
|
+
const result = this.atomic(() => {
|
|
24917
|
+
const admission = this.admitStartHook(id, request);
|
|
24918
|
+
if (admission.error)
|
|
24919
|
+
return admission.error;
|
|
24920
|
+
if (request.eventType === "run_cancelled" && !this.rows("SELECT id FROM workflow_runs WHERE id=?", id).length && this.rows("SELECT run_id FROM workflow_start_hook_admissions WHERE run_id=?", id).length) {
|
|
24921
|
+
this.sql.exec("UPDATE workflow_start_hook_admissions SET cancelled=1 WHERE run_id=?", id);
|
|
24922
|
+
return new WorkflowWorldError("Start Hook candidate cancelled", { status: 409, code: "START_HOOK_CANDIDATE_CANCELLED" });
|
|
24923
|
+
}
|
|
24924
|
+
if (hasStartHook && request.eventType === "run_created" && this.rows("SELECT id FROM workflow_runs WHERE id=?", id).length)
|
|
24925
|
+
return this.eventResult(id, { run: this.run(id) }, params);
|
|
24926
|
+
return this.createSync(id, admission.request, params, digest);
|
|
24927
|
+
});
|
|
24928
|
+
if (result instanceof Error)
|
|
24929
|
+
throw result;
|
|
24930
|
+
return result;
|
|
24856
24931
|
}
|
|
24857
24932
|
createSync(id, request, params, digest) {
|
|
24858
24933
|
const now = new Date(this.now());
|
|
@@ -24866,6 +24941,8 @@ var init_core3 = __esm({
|
|
|
24866
24941
|
let stepCreated = false;
|
|
24867
24942
|
const type = data.eventType;
|
|
24868
24943
|
const correlationId = data.correlationId;
|
|
24944
|
+
if (type === "hook_created" && correlationId && isStartHookId(id, correlationId))
|
|
24945
|
+
throw new WorkflowWorldError("The start Hook id is reserved for atomic admission", { status: 400 });
|
|
24869
24946
|
if (type === "run_created") {
|
|
24870
24947
|
({ run, event } = this.createRun(id, data));
|
|
24871
24948
|
} else {
|
|
@@ -25293,11 +25370,20 @@ var init_core3 = __esm({
|
|
|
25293
25370
|
const body = sqlBytes(row.body);
|
|
25294
25371
|
const message = this.queueMessage(body);
|
|
25295
25372
|
const deploymentId = this.queueTarget(message, row.deployment_id == null ? void 0 : String(row.deployment_id));
|
|
25296
|
-
this.assertDeploymentActive(deploymentId);
|
|
25297
|
-
this.sql.exec("UPDATE workflow_queue_messages SET deployment_id=? WHERE id=?", deploymentId, id);
|
|
25298
25373
|
let transfer = this.rows("SELECT * FROM workflow_sandbox_transfers WHERE message_id=?", id)[0];
|
|
25299
25374
|
const sandbox = transfer ? void 0 : this.successorSandbox(message);
|
|
25300
|
-
const
|
|
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;
|
|
25301
25387
|
if (sandbox && sourceDeploymentId && sourceDeploymentId !== deploymentId) {
|
|
25302
25388
|
this.assertDeploymentActive(sourceDeploymentId);
|
|
25303
25389
|
this.sql.exec("UPDATE workflow_queue_messages SET source_deployment_id=? WHERE id=?", sourceDeploymentId, id);
|
|
@@ -25368,7 +25454,7 @@ var init_core3 = __esm({
|
|
|
25368
25454
|
if (this.currentDeploymentId && ids.includes(this.currentDeploymentId))
|
|
25369
25455
|
throw new WorkflowWorldError("Cannot retire the current deployment", { status: 409 });
|
|
25370
25456
|
const states = this.drainState(ids);
|
|
25371
|
-
if (ids.some((id) => !states[id].drained))
|
|
25457
|
+
if (ids.some((id) => !this.isDeploymentRemoved?.(id) && !states[id].drained))
|
|
25372
25458
|
throw new WorkflowWorldError("Cannot retire a deployment with live runs, queued messages, or unfinished transfers", { status: 409 });
|
|
25373
25459
|
if (!this.retireDeployment)
|
|
25374
25460
|
throw new WorkflowWorldError("Deployment retirement is unavailable", { status: 501 });
|
|
@@ -25752,6 +25838,10 @@ var RESERVED_EVE_HOST_VARIABLES = /* @__PURE__ */ new Set([
|
|
|
25752
25838
|
"PORT",
|
|
25753
25839
|
"NITRO_PORT",
|
|
25754
25840
|
"NODE_ENV",
|
|
25841
|
+
"EVE_DEV",
|
|
25842
|
+
"VERCEL",
|
|
25843
|
+
"VERCEL_ENV",
|
|
25844
|
+
"VERCEL_TARGET_ENV",
|
|
25755
25845
|
"NODE_EXTRA_CA_CERTS",
|
|
25756
25846
|
"WORKFLOW_LOCAL_BASE_URL",
|
|
25757
25847
|
"EDEN_WORLD_URL",
|
|
@@ -26056,7 +26146,7 @@ async function publish(from, to) {
|
|
|
26056
26146
|
var EVE_HOST_ENTRYPOINT = Object.freeze([
|
|
26057
26147
|
"/bin/sh",
|
|
26058
26148
|
"-c",
|
|
26059
|
-
"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"
|
|
26060
26150
|
]);
|
|
26061
26151
|
var EVE_HOST_CONTAINER_ACTIVITY_KEY = "eden.eve.host.last-activity-at";
|
|
26062
26152
|
var EVE_HOST_CONTAINER_SNAPSHOT_KEY = "eden.eve.host.workspace-snapshot";
|
|
@@ -26079,6 +26169,9 @@ var EdenWorldDurableObject = class extends DurableObject {
|
|
|
26079
26169
|
super(ctx, env);
|
|
26080
26170
|
this.core = new WorldCore({
|
|
26081
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,
|
|
26082
26175
|
sql: {
|
|
26083
26176
|
exec: ctx.storage.sql.exec.bind(ctx.storage.sql),
|
|
26084
26177
|
transactionSync: ctx.storage.transactionSync.bind(ctx.storage)
|
|
@@ -26199,6 +26292,9 @@ async function routeEveOutboundRequest(request, env, sourceDeploymentId, expecte
|
|
|
26199
26292
|
}
|
|
26200
26293
|
if (new URL(request.url).pathname === "/__eden/world/rpc") {
|
|
26201
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
|
+
}
|
|
26202
26298
|
const authRequired = route?.worldRpcAuth === true || env.EDEN_EVE_DEPLOYMENTS === void 0 && env.EDEN_EVE_WORLD_RPC_AUTH === true;
|
|
26203
26299
|
if (authRequired) {
|
|
26204
26300
|
const supplied = request.headers.get("x-eden-world-token") ?? "";
|
|
@@ -26280,6 +26376,9 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26280
26376
|
throw new Error("The Container deployment identity does not match its persisted owner.");
|
|
26281
26377
|
}
|
|
26282
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
|
+
}
|
|
26283
26382
|
if (stored === void 0) await this.ctx.storage.put("eden.eve.host.deployment-id", id);
|
|
26284
26383
|
this.deploymentId = id;
|
|
26285
26384
|
this.envVars.EDEN_EVE_DEPLOYMENT_ID = id;
|
|
@@ -26367,7 +26466,7 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26367
26466
|
const id = this.deploymentId;
|
|
26368
26467
|
if (id === void 0) throw new Error("Container deployment identity has not been resolved.");
|
|
26369
26468
|
const record2 = deploymentImages(this.env)[id];
|
|
26370
|
-
if (this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && record2 === void 0
|
|
26469
|
+
if (this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && record2 === void 0) throw new Error(`Deployment ${id} has no retained Container image.`);
|
|
26371
26470
|
return runtime.images[record2?.image ?? "eve"];
|
|
26372
26471
|
}
|
|
26373
26472
|
constructor(ctx, env) {
|
|
@@ -26428,6 +26527,15 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26428
26527
|
if (runtime?.running === true) {
|
|
26429
26528
|
this.ctx.blockConcurrencyWhile(async () => {
|
|
26430
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
|
+
}
|
|
26431
26539
|
await this.identifyDeployment();
|
|
26432
26540
|
await this.registerLoopbackIntercept(runtime);
|
|
26433
26541
|
}
|
|
@@ -26881,7 +26989,12 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26881
26989
|
return response;
|
|
26882
26990
|
}
|
|
26883
26991
|
async retire(deploymentId) {
|
|
26884
|
-
|
|
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)) {
|
|
26885
26998
|
throw new Error("Cannot retire a deployment with active deliveries or transfers.");
|
|
26886
26999
|
}
|
|
26887
27000
|
const runtime = this.containerRuntime();
|
package/dist/eve-host-runtime.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moinulmoin/eden-runtime-cloudflare",
|
|
3
|
-
"version": "0.11.
|
|
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.
|
|
23
|
+
"@moinulmoin/eden-world-cloudflare": "0.11.2",
|
|
24
24
|
"@cloudflare/workers-types": "5.20261006.1"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|