Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@humanlayer/durable-object-durable-streams-server

The Durable Streams protocol server on Cloudflare Workers + Durable Objects, built on the portable @humanlayer/durable-streams-effect-server-core. The Worker routes /v1/stream/{path} to STREAMS.getByName(pathname), so each DO instance owns exactly one stream. Inside the DO, the core routes run on a per-instance runtime via HttpRouter.toWebHandler; alarm() and the cross-DO fork RPC run on a small companion ManagedRuntime.

A Durable Object is a managed per-stream serialized actor — it donates commit atomicity (single-threaded + write coalescing), notification (in-proc state), and per-key lifecycle (idFromName + hibernation). So its Layers are trivial:

Service Durable Object Layer
StreamStore ctx.storage.sql (co-located SQLite)
StreamMutex identity (single-threaded runtime)
StreamHub in-proc PubSub, one per instance
ExpiryScheduler storage.setAlarm / deleteAlarm (+ alarm()runExpiry)
ForkPeer cross-DO RPC: getByName(src).exportFork / releaseFork
StreamRegistry the DO itself — captures the instance's per-stream context and re-provides it
src/
  index.ts            DurableStreamObject (runtime + toWebHandler + alarm + fork RPC) + Worker entry
  substrate/
    durable-state.ts  DurableState / Env adapter tags (below the substrate Services)
    sql-store.ts      StreamStore over ctx.storage.sql
    mutex.ts hub.ts scheduler.ts fork-peer.ts registry.ts
    live.ts           makeCloudflareLive(ctx, env) → { httpAppLayer, rpcLayer }

Run

bun run dev                   # wrangler dev on :8787
bun run check                 # typecheck
bun run conformance           # wrangler dev + the vendored conformance suite
bun run deploy                # wrangler deploy

LONG_POLL_TIMEOUT_MS (wrangler.jsonc var) sets the server long-poll/SSE keep-alive window (3000ms locally; raise for production).

Conformance: 326 / 326 passing against wrangler dev (6 skipped = opt-in metadata subscriptions). Effect v4 bundles and runs on workerd with no nodejs_compat.