An entity holding Entity.keepAlive, or running a persisted request, keeps
an alarm armed one heartbeat ahead. Cloudflare never re-creates an evicted
object by itself, so that alarm is what brings it back after a deploy,
runtime update, or eviction: it rebuilds a kept-alive entity and restores
its hold, and replays every unprocessed row instead of only due DeliverAt
rows.
- cluster_entity_state stores the keep-alive flag and the encoded name, so
an alarm wake without id.name still resolves the entity.
- The holder count stays in memory, per handler build, and resets when the
build is invalidated. The flag is written in a forked fiber (inline would
deadlock inside withTransaction), and a release writes 0 before the hold
opens.
- One nextAlarmAt covers due rows, unrun unprocessed rows, and the
heartbeat; the alarm arms it before awaiting replayed handlers.
- keepAliveHeartbeat on CloudflareCluster.layer and
AlchemyCloudflareCluster.make, 30 seconds by default.
Recovery.test.ts now covers only unprocessed persisted-message replay
after a restart. The keep-alive restart test moves unchanged to
KeepAliveRecovery.test.ts, which is tracked separately.
Both tests fail until the entity Durable Object wakes itself after a
restart: a keep-alive entity is not rebuilt, and an unprocessed persisted
tell replays only on the next contact.
Remove coverage repeated across seams, keeping one focused test per
contract plus the regression tests for fixed bugs. The end-to-end Miniflare
suite is the primary coverage; unit tests stay only where a contract is not
observable end to end.
- Delete the second Miniflare harness (CloudflareDurableObjects.test.ts and
its fixture worker). Its distinct contracts move to EntityManager unit
tests on the shared node:sqlite storage: unacknowledged stream chunks do
not block other requests, undecodable replay rows are skipped, an ask
deduplicated onto a tell is rejected, and interrupting a deduplicated
delayed waiter leaves the original. The DO-to-DO delayed reply moves to
the integration fixture's Relay entity.
- Delete ClusterCron and EntityKeepAlive unit tests, which repeat the
integration tests.
- Drop unit tests repeated by integration or by the shared PersistedQueue
contract suite, and implementation-coupled program tests that asserted
SQL strings and bindings.
- Move EntityMailbox onto the shared node:sqlite storage and drop its
hand-written SQL fake.
- Drop type tests that only checked core Entity or alchemy types.
The entity client builds with its own `Reactivity` instead of looking one up
in the registration context, so `EntitySql.make` is a plain scoped effect and
the handler build adds it to the context in one line. `toLayer` registers
through `flatMap` instead of a generator, and the docs drop the per-build
client lifetime, an implementation detail.
The node:sqlite Durable Object storage fake is shared between the entity
manager and entity SQL tests from `test/fixtures/sqliteStorage.ts`.
Fake-storage unit tests and Miniflare integration tests for the entity
Durable Object's own SQL client: per-entity rows, atomic handler
transactions, `reset` leaving user tables alone, rows surviving an isolate
restart, and the Worker layer's `SqlClient` staying reachable in handlers.
A Miniflare regression test interleaves two handlers through a user
transaction that rolls back, and checks the other handler's stored reply
survives. Type tests cover `CloudflareCluster.toLayer` erasing only
`DurableObjectSqlClient`, requiring `CloudflareSharding`, and being satisfied
by `CloudflareCluster.layer` and `AlchemyCloudflareCluster.make`.
Each entity Durable Object provides `CloudflareCluster.DurableObjectSqlClient`,
an `@effect/sql-sqlite-do` client on its own SQLite storage, to its handler
build and handlers. It is a separate tag, so an app-wide `SqlClient` stays in
place. `CloudflareCluster.toLayer` registers handlers that use it, removing
the service from the layer requirements and requiring `CloudflareSharding`,
which only `CloudflareCluster.layer` provides.
User transactions and mailbox writes share a gate: workerd runs every write
on the object's one SQLite connection inside an open `storage.transaction()`,
so a handler resumed from inside a user transaction could otherwise save its
reply there and lose it to the rollback.
Closes EFF-1842