Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/internals/durable-objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/sandbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/cloudflare-conformance/compat/matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare-conformance/compat/products.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
16 changes: 7 additions & 9 deletions packages/runtime-node/src/bindings/durable-objects/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tests/durable-objects/durable-object-rpc-fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/durable-object-rpc-fetch-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down