A Thread Object owns a conversation’s durable state and live execution. Your Worker
authenticates requests and routes them to that owner. SQLite retains accepted work
across eviction; alarms bring the Object back to advance it.
Cloudflare Thread ownership. Your Worker sends authorized input to a Thread Object. The Object commits to its SQLite database and effect-cf alarms drive pending work.
Feeds the output services of the dependency layer into the requirements of
this layer, returning a layer that only provides the services from this layer.
When to use
Use when you need to hide an implementation dependency layer from callers.
Details
In serviceLayer.pipe(Layer.provide(dependencyLayer)), the dependency layer is
built first and is used to satisfy the requirements of serviceLayer.
Export a composed application Layer as a native Durable Object class.
Bootstrap services are provided to the whole graph before it acquires, so application Layers
can yield effect-cf's WorkerEnvironment and DurableObjectState, derived identity, Digest, and SecureRandom.
Effect Config reads scalar Worker vars and secrets through effect-cf's environment provider;
WorkerEnvironment exposes resource bindings without a separate config Layer.
Application dependencies remain visible until Layer.provide satisfies them. effect-cf owns the
cached ManagedRuntime, native RPC methods, event scopes, and telemetry flushing.
Initialization is local and bounded inside the constructor gate. Cloudflare eviction does not
guarantee finalizers; put resources requiring timely release in scoped operations or eventLayer.
Name of the Worker env binding carrying THIS class's DurableObjectNamespace — the
Object's route back to sibling Thread Objects for the WP2 cross-Object port calls
and remote wakes (DEPLOY-010: the binding enters through a Layer, never ambiently).
Head of the minted producer identity {producerPrefix}:{threadId}.
producerPrefix:"travel-worker",
}){}
Bind the exported class as a SQLite Durable Object under THREADS, enable
nodejs_compat, and supply the provider secret. The
runnable travel planner
includes deployment and application wiring. No separate storage Layer is needed.
CloudflareThreadClient.layerFromBinding({ namespace: env.THREADS }) supplies the
client. Submit authenticated input with a Thread ID, principal, idempotency key, and
definition digests. Admission arms maintenance before accepting work and returns a
receipt after durable writes. By default, the submit event also starts the admitted work
in an effect-cf processing scope. The receipt does not wait for execution or a model request.
Use awaitSettlementRecord(receipt) for the canonical terminal record and decode
ordinary completed output with the agent’s Schema. Use readPage and awaitProgress
for retained updates. Cancelling observation does not abort accepted work.
watchText(threadId) supplies provisional text and available provider reasoning
summaries. Reconcile it against canonical records; reset or discard drafts as
directed by its frames. Canonical completion permanently retires matching drafts,
including after reconnects. Drafts disappear on eviction.
Intermediary Workers can forward watchTextBytes(threadId) without decoding or
re-encoding NDJSON. Blank keepalive lines every 15 seconds help idle HTTP
connections detect disconnected readers. At the final consumer, use
decodeLiveText(threadId, bytes) from @yielded/agent-platform-cloudflare/live-text
to discard keepalives and validate frames and their lifecycle in a browser or
Worker. Both streaming client methods cancel the remote subscription when their
stream scope closes.
effect-cf owns the native alarm. ThreadObject.make registers manual Thread
maintenance and composes application registrations from options.alarms. Do not
write the raw alarm slot or replace its handler.
dispatchAfterEvent defaults to true, allowing submit to start admitted work immediately
and other events to dispatch due work. To opt out, provide DurableObjectAlarm.ScheduleConfiguration with
{ dispatchAfterEvent: false } through Layer.provideMerge on the application Layer.
In that mode, alarms still start work promptly; the recovery window does not delay execution.
recoveryWindowMillis controls recovery after interruption without another client request.
After activity, the Object retains one wake for this window and reuses it for nearby requests.
An empty wake clears itself. A longer window can avoid an alarm write before the first model
request, in exchange for slower recovery without a client. Reopening an Object with pending
work still schedules prompt recovery. Set the window to 0 to restore the short recovery
deadlines and immediate idle cancellation.
Setting
Default
Admission queue depth per Thread
256 nonterminal Submissions
Encoded input limit
1,900,000 bytes
Database admission ceiling
9,000,000,000 bytes
Failed/no-progress pass backoff
100 ms base, 5 seconds cap
Recovery window (recoveryWindowMillis)
60,000 ms (60 seconds)
An alarm has a ten-minute cooperative yield boundary and fourteen-minute watchdog.
These are event limits; agent maxDuration applies to each active durable Attempt
using the Run’s original allowance. Suspension is outside that duration. An explicit
Unknown outcome stays unresolved; a restart does not authorize replay.
Provide model, tool, and context Layers before constructing the Object. They are
acquired per incarnation. Keep initialization local and bounded; eviction does not
guarantee finalizers. Use scoped operations or eventLayer for timely cleanup.
Keep RPC private and configure operationAuthorizer; its default trusts service possession.
Acquire CloudflareTracer.layer in eventLayer for invocation-specific tracing.
Use ThreadObject.layerInHost to place logical Threads in an existing Object.
Share its SQL client and mutation gate; keep placement stable. Register
ThreadObject.alarms with the host’s DurableObjectAlarm.mergeAll and call
ThreadMaintenance.ensureAlarm during local initialization. Follow the
shared-owner example.
MemoryObject.make and CloudflareMemoryClient provide separately owned documents
shared across Threads. You choose namespaces and authorize access. See the
memory example
and context guide.
The Node-safe /cloudflare-ai-gateway subpath configures upstream provider clients;
model behavior stays with Effect AI. Browser and
Code Mode adapters are independent capabilities.