Skip to content

docs(plans): require host-independent Durable Object adapters with opt-in effect-cf and plain Workers hosts - #66

Closed
systemfsoftware-bot wants to merge 4 commits into
mainfrom
docs/composable-cloudflare-hosts
Closed

systemfsoftware-bot wants to merge 4 commits into
mainfrom
docs/composable-cloudflare-hosts

Conversation

@systemfsoftware-bot

@systemfsoftware-bot systemfsoftware-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Adds a plan for restructuring @systemfsoftware/agent-platform-cloudflare so its Durable Object logic does not depend on one host. It holds the requirements and, as of the latest commit, the implementation plan.

The Thread, scheduling, subscription and memory objects become host-independent services over plain DurableObjectState and Env. Each host is an opt-in adapter: one for effect-cf, one for plain Cloudflare Workers, which also covers classes that an Alchemy bridge constructs. Neither adapter is the default, and effect-cf drops to at most an optional peer.

Requirements the plan sets:

  • One owner per object for the single alarm slot. Alchemy's alarm reconcile sets the slot to its own earliest row or deletes it, so two multiplexers in one object drop wakes.
  • The same split on the client side.
  • A consumer's own methods can sit on the same class as the library's methods.
  • Initialization keeps its local-only gate.
  • Telemetry is flushed once per event, with no second flush under a host that already flushes.
  • Fibers are scoped to the event that forked them.

Implementation plan

The plan was resolved against the installed sources of effect-cf 0.59.0, Alchemy 2.0.0-beta.87, Effect 4.1.5 and @cloudflare/workers-types. Its ten units, in dependency order:

  1. A deployed wake probe, built first so it can run while the other units are built.
  2. Library-owned host ports, plus replacements for the three pure effect-cf RPC helpers.
  3. The alarm users moved onto the library alarm port.
  4. Host-independent object definitions for all four domains.
  5. Client contracts with one client implementation per adapter.
  6. The effect-cf adapter.
  7. A library alarm multiplexer for the plain adapter, with an owned-slot mode and a host-slot mode.
  8. The plain Workers adapter, as a class factory and as a method shape a host can build its own class from.
  9. The package surface and the in-repository consumers.
  10. Dual-adapter verification fixtures.

Findings that shaped it:

  • Alchemy dispatches only flat own properties of the built shape, and those must return an Effect or a Stream. Library methods therefore keep their flat names, and composition refuses a colliding consumer method.
  • Alchemy exposes a public makeCallback registration, which can only be called while the instance is being constructed. The plain adapter's host-slot mode hands its next due time to that callback and never writes the slot itself.
  • The existing Thread custom-host path, layerInHost with handleRpc, avoids effect-cf's class wrapper. It still needs effect-cf's alarm multiplexer, so the Problem Frame now says so.

Every proposed test and check names the failure it catches and is held for admission. Open design questions are listed at the end of the plan.

Cross-call wake delivery is a provisional baseline. Local workerd with nodejs_compat showed no AsyncLocalStorage error when a fiber parked on a Deferred or Latch was resumed by a later call, whether the parking call was still open or had returned. The resumed fibers read storage, read getStore() and called an AsyncLocalStorage.bind function, and all succeeded. vitest run --project workerd test/progress-wait.test.ts also passed 3/3. However, local workerd also runs a case that failed in deployment without error, so the plan requires a deployed probe (R18) before a wake transport is committed. That probe also measures held-wait billed duration and hibernation.

Rejected alternatives:

  • An Alchemy-specific adapter.
  • A host Layer passed into ThreadObject.make. Both hosts are outer wrappers that create the runtime, so a host cannot be an inner Layer.
  • Moving only the Thread object.
  • A nested or namespaced method object for library RPC methods. Alchemy cannot dispatch to one.
  • Migrating alarm rows when a live object switches adapter. No deployed consumer needs it.

No code changes.

… Object adapters

Adds the Planning Contract, ten implementation units in dependency order, the verification contract and definition of done to the composable Cloudflare hosts plan, resolved against the installed effect-cf, Alchemy, Effect and workers-types sources. The deferred-to-planning questions are resolved or carried to Open Questions, and the deployed wake probe remains the gate on the wake-transport choice.
@systemfsoftware-bot

Copy link
Copy Markdown
Contributor Author

Superseded by #67. This plan adds a second Durable Object adapter that rebuilds effect-cf's runtime, stub cache and trace context next to it. The new plan makes the change inside effect-cf instead: a host-neutral instance core, a hosted mount form, and a delegated alarm slot. The agent package then keeps one substrate and works under Alchemy and plain Workers alike.

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.

1 participant