Skip to content

fix(durable-objects): don't crash Durable Objects that have no container - #43

Open
voiys wants to merge 2 commits into
rivet-dev:mainfrom
voiys:fix/do-container-undefined
Open

voiys wants to merge 2 commits into
rivet-dev:mainfrom
voiys:fix/do-container-undefined

Conversation

@voiys

@voiys voiys commented Nov 16, 2026 •

Copy link
Copy Markdown

On Cloudflare, a Durable Object that has no container sees ctx.container as undefined, so code can just check it. On Orange, reading it throws instead, which crashes the object before it starts.

I ran into this during an experiment: seeing whether Workers built with alchemy (an Effect-based infra-as-code tool with a Cloudflare provider) run on Orange as they are. alchemy builds the Worker itself and hands each Durable Object an Effect version of ctx. To build it, it copies ctx.container along with the other fields, which is fine on Cloudflare. On Orange that read threw, so every Durable Object failed to start and every call returned guard.actor_stopped_while_waiting.

  • ctx.container now returns undefined in classes that wrangler containers does not list, matching workerd.
  • Classes that containers lists still get their container, unchanged.
  • The unit test in state.test.ts, the e2e state probe in durable-object-rpc-fetch.test.ts, the sandbox and Durable Objects internals docs, and the compat notes in matrix.json and products.json are updated to match.

With this change the test Worker (a Durable Object counter and KV) runs unchanged under orange dev.

@eersnington

Copy link
Copy Markdown
Member

interesting, could you send me a repro of this?

i've been playing around with alchemy build deployments into openorange as well

@eersnington

Copy link
Copy Markdown
Member

ctx.storage just has partial support atm as well

@voiys

voiys commented Nov 16, 2026

Copy link
Copy Markdown
Author

interesting, could you send me a repro of this?

i've been playing around with alchemy build deployments into openorange as well

yes ofc hold on my clanker threw away the experiment lol

@voiys

voiys commented Nov 17, 2026

Copy link
Copy Markdown
Author

interesting, could you send me a repro of this?

i've been playing around with alchemy build deployments into openorange as well

sry took a while I have bad internet

two repros, both on open-orange 1.0.3 from npm

plain worker, no alchemy

// src/index.js
import { DurableObject } from "cloudflare:workers";

export class Counter extends DurableObject {
  // on cloudflare this is false: a class without a container sees undefined
  hasContainer = this.ctx.container !== undefined;

  async increment() {
    const n = ((await this.ctx.storage.get("n")) ?? 0) + 1;
    await this.ctx.storage.put("n", n);
    return { n, hasContainer: this.hasContainer };
  }
}

export default {
  async fetch(request, env) {
    return Response.json(await env.Counter.getByName("a").increment());
  },
};
// wrangler.jsonc
{
  "name": "container-repro",
  "main": "src/index.js",
  "compatibility_date": "2026-11-01",
  "durable_objects": { "bindings": [{ "name": "Counter", "class_name": "Counter" }] },
  "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Counter"] }]
}

orange dev + curl localhost:8787 gives a 500, and the actor logs DurableObjectState.container is not implemented. on this branch it returns {"n":1,"hasContainer":false}

the alchemy version

alchemy hands each DO an Effect wrapper around ctx, and it copies container while building it, so every alchemy DO hits this even if it never touches containers

i put it up as an example on an experiment branch of my alchemy fork, examples/cloudflare-openorange: a DO counter + KV, pnpm dev to build it, pnpm orange to run it on orange. 500s on 1.0.3, counts up on this branch

nice that you're poking at alchemy builds too, happy to compare notes. i also ran that example unpatched on this branch's build live, on rivet cloud and on a self-hosted engine, and it works on both. the plain repro under wrangler dev (workerd) gives hasContainer: false as expected

and yeah, this one only uses storage get/put so it didn't hit the partial parts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants