computer icon indicating copy to clipboard operation
computer copied to clipboard

WorkspaceProxy wakes Durable Objects via idFromString(), clearing ctx.id.name for Agents/Lifecycle

Open 4nkitd opened this issue 1 month ago • 1 comments

Describe the bug

When a Durable Object using cloudflare/agents (Lifecycle / Agent / OpenCodeHarness) is paired with @cloudflare/computer's ContainerBackend (or WorkerShellBackend), WorkspaceProxy.#hostStub() and WorkspaceServiceProxy.#hostStub() always resolve the host Durable Object via ns.get(ns.idFromString(id)).

Because a running container outlives Durable Object idle evictions, restarts, and Worker deployments, computerd reconnecting over WorkspaceProxy (/api) is frequently the first caller to wake the Durable Object from a cold start.

In Cloudflare Workers, instantiating a Durable Object via idFromString() does not populate ctx.id.name, so ctx.id.name remains undefined for the entire lifetime of that in-memory Durable Object instance (which stays pinned while the /api WebSocket is open). Any subsequent Lifecycle startup on that instance fails with:

Error: <Class> could not determine its Durable Object name. Address it with idFromName() or getByName().

Expected behavior

WorkspaceRef, WorkspaceProxyProps, and WorkspaceServiceProxyProps should accept an optional name?: string (e.g. this.ctx.id.name) so WorkspaceProxy and WorkspaceServiceProxy resolve the target Durable Object via ns.idFromName(name) (when ns.idFromName(name).toString() === id), preserving ctx.id.name across cold wakes triggered by container callbacks.

A tested patch with workerd unit tests in packages/computer/tests/proxy.test.ts is available at: https://github.com/4nkitd/computer/commit/efb5ded

Steps to reproduce

  1. Create a Durable Object class using withWorkspaceContainer(Base), ContainerBackend, and Lifecycle.install(this) (from agents/lifecycle).
  2. Address the Durable Object via env.Agent.getByName("main") and start a container command so computerd connects back via WorkspaceProxy.
  3. Redeploy the Worker or let the Durable Object evict while the container remains running so computerd reconnects via WorkspaceProxy (ns.get(ns.idFromString(id))) before the next external getByName("main") request.
  4. Trigger lifecycle.start() on the woken Durable Object; ctx.id.name is undefined and Lifecycle throws could not determine its Durable Object name.

Environment

  • @cloudflare/computer: 0.5.1
  • agents: 0.28.1
  • wrangler: 4.151.0 (compatibility_date: 2026-10-15)

4nkitd avatar Oct 15 '26 14:10 4nkitd

Thanks for the bug report, will get this fixed.

aron-cf avatar Oct 15 '26 14:10 aron-cf