@moinulmoin/eden-runtime-cloudflare 0.7.0 → 0.7.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 +35 -11
- package/dist/eve-host-runtime.js +47 -13
- package/package.json +2 -2
|
@@ -24323,6 +24323,7 @@ function createEveReadinessGate(options) {
|
|
|
24323
24323
|
|
|
24324
24324
|
// src/eve-host-runtime.ts
|
|
24325
24325
|
var EVE_CLOUDFLARE_CONTAINERS_CA_PATH = "/etc/cloudflare/certs/cloudflare-containers-ca.crt";
|
|
24326
|
+
var EVE_HOST_STALE_WORKER_REASON = "stale Worker version";
|
|
24326
24327
|
var EVE_HOST_ENTRYPOINT = Object.freeze([
|
|
24327
24328
|
"/bin/sh",
|
|
24328
24329
|
"-c",
|
|
@@ -24866,6 +24867,9 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
24866
24867
|
}
|
|
24867
24868
|
async fetch(request) {
|
|
24868
24869
|
const requestDeploymentId = request.headers.get("x-eden-eve-deployment-id") ?? void 0;
|
|
24870
|
+
if (requestDeploymentId !== void 0 && requestDeploymentId !== this.env.EDEN_EVE_DEPLOYMENT_ID) {
|
|
24871
|
+
this.ctx.abort(EVE_HOST_STALE_WORKER_REASON);
|
|
24872
|
+
}
|
|
24869
24873
|
const response = await this.forwardToEve(request);
|
|
24870
24874
|
if (requestDeploymentId !== void 0 && requestDeploymentId === this.env.EDEN_EVE_DEPLOYMENT_ID && this.readinessEvidence !== void 0 && this.imageVerified) {
|
|
24871
24875
|
const headers = new Headers(response.headers);
|
|
@@ -24994,20 +24998,40 @@ function createEveHostWorker(options) {
|
|
|
24994
24998
|
}
|
|
24995
24999
|
return namespace.getByName(options.stableContainerInstanceName);
|
|
24996
25000
|
};
|
|
25001
|
+
const forwardToContainer = async (request, env) => {
|
|
25002
|
+
const metadata = {
|
|
25003
|
+
publicOrigin: options.publicOrigin,
|
|
25004
|
+
deploymentId: options.deploymentId,
|
|
25005
|
+
generationId: options.generationId,
|
|
25006
|
+
correlationId: globalThis.crypto.randomUUID(),
|
|
25007
|
+
...options.runtimeRevisionHandle === void 0 ? {} : { runtimeRevisionHandle: options.runtimeRevisionHandle }
|
|
25008
|
+
};
|
|
25009
|
+
const forwarded = createTrustedEveRequest(request, metadata);
|
|
25010
|
+
const bodyless = forwarded.body === null ? forwarded : createTrustedEveRequest(new Request(
|
|
25011
|
+
new URL(EVE_HOST_DEFAULTS.healthPath, options.publicOrigin),
|
|
25012
|
+
{ signal: forwarded.signal }
|
|
25013
|
+
), metadata);
|
|
25014
|
+
let container = resolveContainer(env);
|
|
25015
|
+
let response;
|
|
25016
|
+
try {
|
|
25017
|
+
response = await container.fetch(bodyless);
|
|
25018
|
+
} catch (error61) {
|
|
25019
|
+
if (!(error61 instanceof Error) || !error61.message.includes(EVE_HOST_STALE_WORKER_REASON)) {
|
|
25020
|
+
throw error61;
|
|
25021
|
+
}
|
|
25022
|
+
container = resolveContainer(env);
|
|
25023
|
+
response = await container.fetch(bodyless);
|
|
25024
|
+
}
|
|
25025
|
+
if (bodyless === forwarded) return response;
|
|
25026
|
+
await response.body?.cancel();
|
|
25027
|
+
return container.fetch(forwarded);
|
|
25028
|
+
};
|
|
24997
25029
|
return {
|
|
24998
25030
|
async fetch(request, env) {
|
|
24999
25031
|
if (isEveWorkflowInternalRoute(new URL(request.url).pathname)) {
|
|
25000
25032
|
return new Response(null, { status: 404 });
|
|
25001
25033
|
}
|
|
25002
|
-
const
|
|
25003
|
-
const forwarded = createTrustedEveRequest(request, {
|
|
25004
|
-
publicOrigin: options.publicOrigin,
|
|
25005
|
-
deploymentId: options.deploymentId,
|
|
25006
|
-
generationId: options.generationId,
|
|
25007
|
-
correlationId: globalThis.crypto.randomUUID(),
|
|
25008
|
-
...options.runtimeRevisionHandle === void 0 ? {} : { runtimeRevisionHandle: options.runtimeRevisionHandle }
|
|
25009
|
-
});
|
|
25010
|
-
const response = await container.fetch(forwarded);
|
|
25034
|
+
const response = await forwardToContainer(request, env);
|
|
25011
25035
|
const headers = new Headers(response.headers);
|
|
25012
25036
|
headers.set("x-eden-eve-worker-name", options.workerName);
|
|
25013
25037
|
headers.set("x-eden-eve-public-origin", options.publicOrigin);
|
|
@@ -25038,9 +25062,9 @@ function createEveHostWorker(options) {
|
|
|
25038
25062
|
));
|
|
25039
25063
|
if (!due) return;
|
|
25040
25064
|
ctx.waitUntil(
|
|
25041
|
-
|
|
25065
|
+
forwardToContainer(new Request(
|
|
25042
25066
|
new URL(EVE_HOST_DEFAULTS.healthPath, options.publicOrigin)
|
|
25043
|
-
)).catch((error61) => {
|
|
25067
|
+
), env).catch((error61) => {
|
|
25044
25068
|
console.error(
|
|
25045
25069
|
"The scheduled wake request failed:",
|
|
25046
25070
|
error61 instanceof Error ? error61.message : "unknown"
|
package/dist/eve-host-runtime.js
CHANGED
|
@@ -2,6 +2,7 @@ import { DurableObject, WorkerEntrypoint } from "cloudflare:workers";
|
|
|
2
2
|
import { WorldCore } from "@moinulmoin/eden-world-cloudflare/core";
|
|
3
3
|
import { EVE_HOST_DEFAULTS, EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS, EVE_SCHEDULE_WAKE_LEAD_MS, parseEveSleepAfterMs, EveHostError, assertNonEmpty, assertStableOrigin, createEveReadinessGate, createTrustedEveRequest, eveScheduleCronFiresWithin, readProtectedRuntimeVariables, WORKER_NAME_PATTERN, isEveWorkflowInternalRoute, } from "./eve-host.js";
|
|
4
4
|
const EVE_CLOUDFLARE_CONTAINERS_CA_PATH = "/etc/cloudflare/certs/cloudflare-containers-ca.crt";
|
|
5
|
+
const EVE_HOST_STALE_WORKER_REASON = "stale Worker version";
|
|
5
6
|
/**
|
|
6
7
|
* Cloudflare's durable_object containers expose `/dev/kvm`, which makes Eve's
|
|
7
8
|
* `DefaultSandbox` pick microsandbox at runtime, while Eden's isolated builder
|
|
@@ -604,6 +605,13 @@ export class EveHostDurableContainer extends DurableObject {
|
|
|
604
605
|
}
|
|
605
606
|
async fetch(request) {
|
|
606
607
|
const requestDeploymentId = request.headers.get("x-eden-eve-deployment-id") ?? undefined;
|
|
608
|
+
if (requestDeploymentId !== undefined &&
|
|
609
|
+
requestDeploymentId !== this.env.EDEN_EVE_DEPLOYMENT_ID) {
|
|
610
|
+
// A live container/monitor can pin the DO to an older Worker version.
|
|
611
|
+
// Reset the DO, not its container or storage; the retry's current code
|
|
612
|
+
// reconciles the image and carries sandbox sessions through the update.
|
|
613
|
+
this.ctx.abort(EVE_HOST_STALE_WORKER_REASON);
|
|
614
|
+
}
|
|
607
615
|
const response = await this.forwardToEve(request);
|
|
608
616
|
// Reporting the verified start back lets deploy health-gate promotion on
|
|
609
617
|
// the served container actually running this generation's image: the
|
|
@@ -725,6 +733,43 @@ export function createEveHostWorker(options) {
|
|
|
725
733
|
}
|
|
726
734
|
return namespace.getByName(options.stableContainerInstanceName);
|
|
727
735
|
};
|
|
736
|
+
const forwardToContainer = async (request, env) => {
|
|
737
|
+
const metadata = {
|
|
738
|
+
publicOrigin: options.publicOrigin,
|
|
739
|
+
deploymentId: options.deploymentId,
|
|
740
|
+
generationId: options.generationId,
|
|
741
|
+
correlationId: globalThis.crypto.randomUUID(),
|
|
742
|
+
...(options.runtimeRevisionHandle === undefined
|
|
743
|
+
? {}
|
|
744
|
+
: { runtimeRevisionHandle: options.runtimeRevisionHandle }),
|
|
745
|
+
};
|
|
746
|
+
const forwarded = createTrustedEveRequest(request, metadata);
|
|
747
|
+
// Synchronize the DO version before sending an upload. Cloning a body
|
|
748
|
+
// would retain an unread tee of the entire upload in isolate memory.
|
|
749
|
+
const bodyless = forwarded.body === null
|
|
750
|
+
? forwarded
|
|
751
|
+
: createTrustedEveRequest(new Request(new URL(EVE_HOST_DEFAULTS.healthPath, options.publicOrigin), { signal: forwarded.signal }), metadata);
|
|
752
|
+
let container = resolveContainer(env);
|
|
753
|
+
let response;
|
|
754
|
+
try {
|
|
755
|
+
response = await container.fetch(bodyless);
|
|
756
|
+
}
|
|
757
|
+
catch (error) {
|
|
758
|
+
if (!(error instanceof Error) ||
|
|
759
|
+
!error.message.includes(EVE_HOST_STALE_WORKER_REASON)) {
|
|
760
|
+
throw error;
|
|
761
|
+
}
|
|
762
|
+
// Only the pre-forwarding stale abort is safe to retry. A failed stub
|
|
763
|
+
// can remain broken, so resolve it again and retry the bodyless request once.
|
|
764
|
+
container = resolveContainer(env);
|
|
765
|
+
response = await container.fetch(bodyless);
|
|
766
|
+
}
|
|
767
|
+
if (bodyless === forwarded)
|
|
768
|
+
return response;
|
|
769
|
+
await response.body?.cancel();
|
|
770
|
+
// Stream the original body exactly once, outside the retry path.
|
|
771
|
+
return container.fetch(forwarded);
|
|
772
|
+
};
|
|
728
773
|
return {
|
|
729
774
|
async fetch(request, env) {
|
|
730
775
|
// Queue deliveries to these endpoints arrive through the container's
|
|
@@ -733,17 +778,7 @@ export function createEveHostWorker(options) {
|
|
|
733
778
|
if (isEveWorkflowInternalRoute(new URL(request.url).pathname)) {
|
|
734
779
|
return new Response(null, { status: 404 });
|
|
735
780
|
}
|
|
736
|
-
const
|
|
737
|
-
const forwarded = createTrustedEveRequest(request, {
|
|
738
|
-
publicOrigin: options.publicOrigin,
|
|
739
|
-
deploymentId: options.deploymentId,
|
|
740
|
-
generationId: options.generationId,
|
|
741
|
-
correlationId: globalThis.crypto.randomUUID(),
|
|
742
|
-
...(options.runtimeRevisionHandle === undefined
|
|
743
|
-
? {}
|
|
744
|
-
: { runtimeRevisionHandle: options.runtimeRevisionHandle }),
|
|
745
|
-
});
|
|
746
|
-
const response = await container.fetch(forwarded);
|
|
781
|
+
const response = await forwardToContainer(request, env);
|
|
747
782
|
const headers = new Headers(response.headers);
|
|
748
783
|
headers.set("x-eden-eve-worker-name", options.workerName);
|
|
749
784
|
headers.set("x-eden-eve-public-origin", options.publicOrigin);
|
|
@@ -768,8 +803,7 @@ export function createEveHostWorker(options) {
|
|
|
768
803
|
return;
|
|
769
804
|
// Wake only: the in-process Nitro runner inside the container
|
|
770
805
|
// fires the tick itself, so the schedule runs exactly once.
|
|
771
|
-
ctx.waitUntil(
|
|
772
|
-
.fetch(new Request(new URL(EVE_HOST_DEFAULTS.healthPath, options.publicOrigin)))
|
|
806
|
+
ctx.waitUntil(forwardToContainer(new Request(new URL(EVE_HOST_DEFAULTS.healthPath, options.publicOrigin)), env)
|
|
773
807
|
.catch((error) => {
|
|
774
808
|
console.error("The scheduled wake request failed:", error instanceof Error ? error.message : "unknown");
|
|
775
809
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moinulmoin/eden-runtime-cloudflare",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.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.7.
|
|
23
|
+
"@moinulmoin/eden-world-cloudflare": "0.7.2",
|
|
24
24
|
"@cloudflare/workers-types": "5.20261006.1"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|