From b93bcef16a0a590ad4394260656ae539a0a2cf86 Mon Sep 17 00:00:00 2001 From: voiys Date: Mon, 16 Nov 2026 23:16:25 +0000 Subject: [PATCH 1/2] fix(durable-objects): don't crash Durable Objects that have no container --- docs/internals/durable-objects.mdx | 4 ++-- docs/modules/sandbox.mdx | 4 ++-- .../src/bindings/durable-objects/state.test.ts | 2 +- .../src/bindings/durable-objects/state.ts | 16 +++++++--------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/internals/durable-objects.mdx b/docs/internals/durable-objects.mdx index f0b6f19..0e4ca5f 100644 --- a/docs/internals/durable-objects.mdx +++ b/docs/internals/durable-objects.mdx @@ -322,8 +322,8 @@ heavier than workerd's in-isolate reset. intentionally incomplete. `ctx.facets` is described in [Facets](../modules/durable-objects#facets). `ctx.container` works for classes listed under wrangler `containers`. It runs one sandbox per object on `ORANGE_SANDBOX_PROVIDER`, so only Cloudflare Sandbox -images run. See [Sandbox](../modules/sandbox). For other classes it throws a -`NotSupportedError`. Reading `ctx.props`, `ctx.restore`, +images run. See [Sandbox](../modules/sandbox). For other classes it is +`undefined`, as on Cloudflare. Reading `ctx.props`, `ctx.restore`, `ctx.configureReadReplication`, `ctx.primaryStub`, or `ctx.version` throws a `NotSupportedError`. Other names that workerd does not define on `DurableObjectState`, such as `ctx.tracing`, read as `undefined`, as diff --git a/docs/modules/sandbox.mdx b/docs/modules/sandbox.mdx index 02facbb..087020e 100644 --- a/docs/modules/sandbox.mdx +++ b/docs/modules/sandbox.mdx @@ -353,8 +353,8 @@ preview URLs. #### ctx.container A class that `containers` lists gets a `ctx.container` that runs one sandbox -per Durable Object on `ORANGE_SANDBOX_PROVIDER`. In any other class, reading -`ctx.container` throws a `NotSupportedError`. +per Durable Object on `ORANGE_SANDBOX_PROVIDER`. In any other class, +`ctx.container` is `undefined`, as on Cloudflare. - `start()` connects to the object's stored sandbox, or creates one. The image must be a Cloudflare Sandbox image: its reference, or the Dockerfile it diff --git a/packages/runtime-node/src/bindings/durable-objects/state.test.ts b/packages/runtime-node/src/bindings/durable-objects/state.test.ts index b709759..81e2bc6 100644 --- a/packages/runtime-node/src/bindings/durable-objects/state.test.ts +++ b/packages/runtime-node/src/bindings/durable-objects/state.test.ts @@ -131,7 +131,7 @@ test("exposes the object id, delegates waitUntil, and diagnoses excluded state", assert.deepEqual(pending, [task]); assert.deepEqual(generation.state.props, {}); assert.throws(() => generation.state.facets, /facets is not implemented/); - assert.throws(() => generation.state.container, /container is not implemented/); + assert.equal(generation.state.container, undefined); }); test("makes abort uncatchable at the event boundary and poisons the generation", async () => { diff --git a/packages/runtime-node/src/bindings/durable-objects/state.ts b/packages/runtime-node/src/bindings/durable-objects/state.ts index e8007d7..9094446 100644 --- a/packages/runtime-node/src/bindings/durable-objects/state.ts +++ b/packages/runtime-node/src/bindings/durable-objects/state.ts @@ -459,16 +459,14 @@ class InitialDurableObjectState implements DurableObjectState { } // Classes listed under wrangler `containers` get a Container backed by the - // ORANGE_SANDBOX_PROVIDER sandbox provider. - get container(): object { + // ORANGE_SANDBOX_PROVIDER sandbox provider. Any other class has no container + // and reads `undefined`, as workerd's optional `container` does: + // https://github.com/cloudflare/workerd/blob/ebf43c5fcdc99a436a95f00384dfed671c75da2e/src/workerd/api/actor-state.h#L673-L675 + get container(): object | undefined { if (this.#container !== undefined) return this.#container; - const container = - this.#className === undefined - ? undefined - : containerForDurableObject(this.#className, String(this.id), () => this.storage); - if (container === undefined) throw stateUnsupported("container"); - this.#container = container; - return container; + if (this.#className === undefined) return undefined; + this.#container = containerForDurableObject(this.#className, String(this.id), () => this.storage); + return this.#container; } get facets(): DurableObjectFacets { From 891ab1d46853b1814c3021e8700cfdef3ac53e70 Mon Sep 17 00:00:00 2001 From: voiys Date: Tue, 17 Nov 2026 01:34:44 +0000 Subject: [PATCH 2/2] fix(durable-objects): update the e2e state probe and compat notes for ctx.container --- packages/cloudflare-conformance/compat/matrix.json | 4 ++-- packages/cloudflare-conformance/compat/products.json | 2 +- .../runtime-node/src/modules/cloudflare-sandbox/container.ts | 4 ++-- tests/durable-objects/durable-object-rpc-fetch.test.ts | 3 ++- tests/fixtures/durable-object-rpc-fetch-worker.ts | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/cloudflare-conformance/compat/matrix.json b/packages/cloudflare-conformance/compat/matrix.json index f3e4c14..ba5019e 100644 --- a/packages/cloudflare-conformance/compat/matrix.json +++ b/packages/cloudflare-conformance/compat/matrix.json @@ -11158,7 +11158,7 @@ "name": "ctx.container", "status": "partial", "cloudflare": "Controls the container attached to the object.", - "orange": "Classes listed under wrangler containers get a Container that runs one sandbox per object on ORANGE_SANDBOX_PROVIDER. start(), exec(), monitor(), destroy(), signal(), and getTcpPort().fetch() work. Other classes throw NotSupportedError.", + "orange": "Classes listed under wrangler containers get a Container that runs one sandbox per object on ORANGE_SANDBOX_PROVIDER. start(), exec(), monitor(), destroy(), signal(), and getTcpPort().fetch() work. Other classes read ctx.container as undefined, as on Cloudflare.", "notes": "Only Cloudflare Sandbox images run; other images and start({ entrypoint }) throw. exec({ pty }), exec({ stdin }), interceptOutboundHttp(), interceptAllOutboundHttp(), interceptOutboundHttps(), snapshotContainer(), and inspect() throw. setInactivityTimeout() is a no-op. See docs/modules/sandbox.mdx.", "evidence": [ { @@ -14510,7 +14510,7 @@ "status": "alternative", "cloudflare": "Configures Containers bound to Durable Object classes.", "orange": "Accepted with one warning. No container image runs. Sandbox classes from @cloudflare/sandbox, and other classes listed under containers, run on the ORANGE_SANDBOX_PROVIDER backend (default: local).", - "notes": "A listed class's ctx.container runs one sandbox per object, and start() takes only a Cloudflare Sandbox image: an image reference or Dockerfile that names cloudflare/sandbox. A class that containers does not list throws NotSupportedError from ctx.container. See do-ctx-container and docs/modules/sandbox.mdx.", + "notes": "A listed class's ctx.container runs one sandbox per object, and start() takes only a Cloudflare Sandbox image: an image reference or Dockerfile that names cloudflare/sandbox. A class that containers does not list reads ctx.container as undefined. See do-ctx-container and docs/modules/sandbox.mdx.", "evidence": [ { "kind": "code", diff --git a/packages/cloudflare-conformance/compat/products.json b/packages/cloudflare-conformance/compat/products.json index 6df4209..fa45ed5 100644 --- a/packages/cloudflare-conformance/compat/products.json +++ b/packages/cloudflare-conformance/compat/products.json @@ -137,7 +137,7 @@ "product": "Containers", "orange": "No container runtime. A class listed under containers gets a ctx.container that runs one sandbox per object on ORANGE_SANDBOX_PROVIDER", "status": "partial", - "note": "Images are not built or run, and start() takes only a Cloudflare Sandbox image (cloudflare/sandbox). start(), exec(), monitor(), destroy(), signal(), and getTcpPort().fetch() work. start({ entrypoint }), exec({ pty }), exec({ stdin }), the outbound HTTP intercepts, snapshotContainer(), and inspect() throw. ctx.container throws NotSupportedError in a class that containers does not list.", + "note": "Images are not built or run, and start() takes only a Cloudflare Sandbox image (cloudflare/sandbox). start(), exec(), monitor(), destroy(), signal(), and getTcpPort().fetch() work. start({ entrypoint }), exec({ pty }), exec({ stdin }), the outbound HTTP intercepts, snapshotContainer(), and inspect() throw. ctx.container is undefined in a class that containers does not list.", "evidence": ["src/config/load-wrangler.ts", "packages/runtime-node/src/bindings/durable-objects/state.ts", "packages/runtime-node/src/modules/cloudflare-sandbox/container.ts", "tests/bindings/sandbox.test.ts", "docs/modules/sandbox.mdx"] }, { diff --git a/packages/runtime-node/src/modules/cloudflare-sandbox/container.ts b/packages/runtime-node/src/modules/cloudflare-sandbox/container.ts index bbb3787..f552ef7 100644 --- a/packages/runtime-node/src/modules/cloudflare-sandbox/container.ts +++ b/packages/runtime-node/src/modules/cloudflare-sandbox/container.ts @@ -50,8 +50,8 @@ export function configureContainerClasses(classes: readonly ContainerClass[]): v } /** Returns the container of a Durable Object, or undefined when its class has none. */ -// Storage is read only for listed classes, so other classes get the -// unsupported error even before storage exists. +// Storage is read only for listed classes, so other classes get undefined +// even before storage exists. export function containerForDurableObject(className: string, owner: string, storage: () => ContainerStorage): object | undefined { const images = containerClasses.get(className); return images === undefined ? undefined : new SandboxContainer(owner, storage(), images); diff --git a/tests/durable-objects/durable-object-rpc-fetch.test.ts b/tests/durable-objects/durable-object-rpc-fetch.test.ts index 5314827..ce91575 100644 --- a/tests/durable-objects/durable-object-rpc-fetch.test.ts +++ b/tests/durable-objects/durable-object-rpc-fetch.test.ts @@ -318,7 +318,8 @@ test("runs Durable Object RPC and fetch through the Worker binding and Rivet act assert.ok(isRecord(state)); assert.equal(state.startupReady, true); assert.match(String(state.id), /^[a-f0-9]{64}$/); - assert.deepEqual(state.diagnostics, ["DurableObjectState.container is not implemented"]); + assert.deepEqual(state.diagnostics, []); + assert.equal(state.containerIsUndefined, true); assert.equal(state.exportsCounterNamespace, true); const initialGeneration = state.generation; assert.equal(typeof initialGeneration, "number"); diff --git a/tests/fixtures/durable-object-rpc-fetch-worker.ts b/tests/fixtures/durable-object-rpc-fetch-worker.ts index 6c4a2cb..562a9be 100644 --- a/tests/fixtures/durable-object-rpc-fetch-worker.ts +++ b/tests/fixtures/durable-object-rpc-fetch-worker.ts @@ -387,6 +387,7 @@ export class Counter extends DurableObject { const exportedCounter: unknown = Reflect.get(Reflect.get(this.ctx, "exports"), "Counter"); return { diagnostics, + containerIsUndefined: Reflect.get(this.ctx, "container") === undefined, exportsCounterNamespace: typeof exportedCounter === "object" && exportedCounter !== null &&