| 1 | # Testing |
| 2 | |
| 3 | celld makes three important promises: |
| 4 | |
| 5 | - An acknowledged write is durable. |
| 6 | - A cell has one writer at a time. It never has two. |
| 7 | - Code written for Cloudflare Workers and Durable Objects operates the |
| 8 | same on celld. |
| 9 | |
| 10 | We try to break each promise at the layer where a failure shows most |
| 11 | clearly. We test the API contract with differential execution against the |
| 12 | Cloudflare runtime. We check the coordination protocol against an |
| 13 | exhaustively model-checked specification, and we test it with |
| 14 | deterministic simulation. We test the full system with fault injection |
| 15 | on live fleets. |
| 16 | |
| 17 | ## Conformance: two runtimes, one output |
| 18 | |
| 19 | We test the compatibility promise differentially. We run each Workers and |
| 20 | Durable Objects program twice: once on workerd, the runtime binary that |
| 21 | Cloudflare operates in production, and once on celld, on identical bytes. |
| 22 | The two outputs must be equal. This shows two facts at once: the program |
| 23 | is real Cloudflare code, because workerd accepts it, and celld obeys the |
| 24 | contract, because the outputs are equal. A test cannot agree with our own |
| 25 | runtime by accident. |
| 26 | |
| 27 | The corpus only grows. When celld gets a new API surface, we add fixtures |
| 28 | for that surface, and the fixtures must give equal output on the two |
| 29 | engines. We also port test suites from workerd itself: the Durable |
| 30 | Objects contract, the web-platform globals, and the upstream Web Platform |
| 31 | Tests. Before a release, we also replay scenarios through the full |
| 32 | `celld` binary in each deployment mode: storage, SQL, alarms, streams, |
| 33 | WebSockets, and lifecycle. |
| 34 | |
| 35 | ## Specification: exhaustive at small size |
| 36 | |
| 37 | The coordination protocol is also specified in TLA+. Heyang Zhou wrote |
| 38 | the specifications against celld v0.1.0, and his model checking found |
| 39 | four bugs and a split-brain that lost an acknowledged write. All are |
| 40 | fixed. None had surfaced in our own review or testing. |
| 41 | |
| 42 | Where simulation samples schedules, the checker enumerates them: at a |
| 43 | small configuration it visits every reachable state. The model grants |
| 44 | the implementation a linearizable object store and perfect shared |
| 45 | clocks, so a violation it finds needs no clock skew and no storage |
| 46 | anomaly to occur. The invariants are the first two promises at the top |
| 47 | of this page: one writer for each epoch, and no acknowledged write |
| 48 | lost. The fencing argument itself — that a stale owner's late writes |
| 49 | cannot cost an acknowledged write, because the epoch in the key keeps |
| 50 | its lineage apart — is checked, not asserted. |
| 51 | |
| 52 | Every configuration carries a pinned expected verdict, and most of the |
| 53 | verdicts are failures: each failing configuration models a bug the |
| 54 | protocol once had, or a deliberately broken checker, and the model |
| 55 | must produce the counterexample. A configuration that stops failing |
| 56 | has lost its tooth. One tooth had already fallen out when the |
| 57 | specifications arrived; we repaired it. |
| 58 | |
| 59 | Some specifications model a proposed protocol before it is built. When |
| 60 | the fence on write acknowledgments was redesigned, the design-stage |
| 61 | check produced an eight-state counterexample against the version it |
| 62 | replaced: a dormant cell resumes at its old epoch while its release is |
| 63 | in flight, acknowledges a write, and the takeover that follows |
| 64 | restores without it. The fix shipped; the counterexample stays as a |
| 65 | pinned failure. |
| 66 | |
| 67 | The checker has also removed code: celld once sealed a cell's durable |
| 68 | history at restore, and the verdicts showed the seal defended only the |
| 69 | return of a write that was never acknowledged — an outcome celld does |
| 70 | not promise to prevent — while its permanent cut could turn a |
| 71 | recoverable ordering slip into a permanent loss. The seal is gone. |
| 72 | |
| 73 | The specifications are a hand-synced snapshot, deliberately not in |
| 74 | continuous integration: a silently stale gate is worse than none. In |
| 75 | practice their updates have landed in the same changes that moved the |
| 76 | protocol, and a delta ledger records what the model does not yet |
| 77 | describe, including places where the model is weaker than the code |
| 78 | rather than wrong. Simulation remains the per-commit ratchet; the |
| 79 | model is its exhaustive small-configuration complement. |
| 80 | |
| 81 | ## Simulation: the protocol under adversarial schedules |
| 82 | |
| 83 | The dangerous bugs live in the coordination: a crash during an ownership |
| 84 | handoff, a lease renewal that races a takeover, an alarm that fires |
| 85 | against a partially restored cell. These windows are nanoseconds wide and |
| 86 | open rarely, so a test cannot wait for them. |
| 87 | |
| 88 | Thus the coordination protocol is a |
| 89 | [pure decision core](https://github.com/denoland/celld/tree/main/crates/logic) |
| 90 | with no I/O of its own: the clock, the randomness, and the object store |
| 91 | are interfaces, and a simulator drives the core. The simulated store |
| 92 | injects latency, compare-and-swap races, and lost responses; the clocks |
| 93 | drift apart; a node can crash at each await point. Scripted adversaries |
| 94 | play the cells: a handler that never returns, a write stream that stops |
| 95 | halfway. V8 stays out of the simulation, because V8 is not deterministic. |
| 96 | |
| 97 | A seeded scheduler drives each run, so a failure is not a fluke: the seed |
| 98 | replays it exactly, every time, and we keep the seed until the bug is |
| 99 | dead. We examine each property for safety (two writers in one epoch, a |
| 100 | lost acknowledged write, an expired lease that comes back) and for |
| 101 | liveness (each armed alarm fires, and ownership settles on one node after |
| 102 | a crash). A property must survive tens of thousands of seeds, and the |
| 103 | core protocols have run through millions of different schedules. |
| 104 | |
| 105 | Simulation has a known failure mode: the checker that cannot fail. So |
| 106 | we also test the checkers: we run deliberately broken variants of the |
| 107 | protocol against the properties, and the properties must find the damage. |
| 108 | A suite that stays green against a broken protocol is a broken suite. |
| 109 | |
| 110 | ## Live fleets: what simulation cannot see |
| 111 | |
| 112 | Simulation cannot see the real S3 tail latency, the real kernel and |
| 113 | filesystem behavior, or V8 under memory pressure. The third layer is |
| 114 | therefore a permanent fleet lab: standard VMs from standard providers, |
| 115 | and a real bucket. The workloads rotate: chat rooms under many WebSocket |
| 116 | connections, working sets that shift across tens of thousands of cells |
| 117 | (each cell has a unique checksum), deployment cutovers under load, and |
| 118 | runs that fill the nodes to the memory limit. The lab qualifies each |
| 119 | release, and between releases it pushes the density and the fault |
| 120 | coverage further. Each run makes an archived evidence bundle: the |
| 121 | configuration, the verification sweeps, the node journals, the kernel |
| 122 | logs, and the phase timings. We keep a red run with the same care as a |
| 123 | green run, because a failure that the harness caught is a result, not a |
| 124 | retry. |
| 125 | |
| 126 | We inject the faults between verification passes. A pass fetches each |
| 127 | cell through different nodes and compares the durable state exactly: the |
| 128 | status, the body, and the full message ledger. Each run therefore has a |
| 129 | clean picture before the fault and after it. A cell can be unavailable |
| 130 | for a short time while its ownership moves, but its committed state must |
| 131 | stay complete, and a live node must serve that state again. |
| 132 | |
| 133 | The scenarios attack every seam that we know: |
| 134 | |
| 135 | - Stop a node with `SIGKILL` in the middle of a write stream and delete |
| 136 | its local database, so recovery can only come from the bucket. Every |
| 137 | acknowledged write comes back, because the output gate held each |
| 138 | response until the write was durable. |
| 139 | - Freeze an owner node, write to its cells through other nodes, and |
| 140 | unfreeze it. The node sees that its lease moved and refuses to serve |
| 141 | the old state, and each write from the other nodes lands exactly one |
| 142 | time: one epoch has at most one writer. |
| 143 | - Cut a node off from the bucket. It fences itself, because a node that |
| 144 | cannot replicate must not own cells. |
| 145 | - Throttle the bucket, so it answers each request with a 429. The engine |
| 146 | slows to the write rate of the store and does not amplify the |
| 147 | throttle, because a node that knows its replicated position does not |
| 148 | ask a slow store for extra listings. |
| 149 | - Stop a full host at the provider level in the middle of a workload. |
| 150 | Its cells move to the other nodes, and the returning host joins again |
| 151 | with no duplicate residency. |
| 152 | |
| 153 | Across every run of every scenario, no acknowledged write was lost and |
| 154 | no committed state was damaged; the verification sweeps show zero body |
| 155 | faults, zero status faults, and zero lost messages. |
| 156 | |
| 157 | ## A few numbers we trust |
| 158 | |
| 159 | Each number includes the condition of its measurement. A number without |
| 160 | its conditions has no value. |
| 161 | |
| 162 | - **The epoch fence holds under contention.** Five hundred claimants |
| 163 | tried at the same time to own the same cells: 5,500 attempts, one |
| 164 | writer for each epoch, zero violations. |
| 165 | - **A warm resident request is local.** A request to a resident cell does |
| 166 | zero bucket operations and returns in p50 ~1.1 ms and p99 ~7 ms (a |
| 167 | fixed-host measurement). Only a cold activation touches object storage. |
| 168 | - **A durable write waits for a durability proof.** A single node proves |
| 169 | each write through the bucket, so one storage round trip is the minimum |
| 170 | latency for that write. A fleet of two or more nodes can prove a write |
| 171 | when each follower holds it on disk, and a follower fsync is much |
| 172 | faster than a storage round trip: a lab fleet measured about 600 ms for |
| 173 | a bucket proof and about 25 ms for a fleet proof. The bucket upload |
| 174 | races every fleet proof and either one proves the write, so a slow |
| 175 | follower cannot make a write slower than a bucket proof. Concurrent |
| 176 | writes to one cell join one shared upload, so the throughput of one |
| 177 | cell is not one round trip for each write. |
| 178 | - **A restore is normal work.** Placement handles the restore of an |
| 179 | inactive cell as ordinary work, and not as an emergency procedure. The |
| 180 | measured restore times come from the retired external replicator, so this |
| 181 | page gives no number until a fleet run measures `celld-ltx`. |
| 182 | - **Ten small nodes held real scale.** A fleet of ten nodes, each with 4 |
| 183 | vCPU and 8 GB, held 10,000 resident cells and 20,000 concurrent |
| 184 | WebSocket connections. We stopped two of the ten nodes, and the data of |
| 185 | every cell was available again on another node in ~11 s at the tail |
| 186 | (with reserve headroom). |
| 187 | |
| 188 | ## The failure edges we intend to find |
| 189 | |
| 190 | We must also know where a policy stops, so we record the edges instead of |
| 191 | tuning them away. The clearest edge is the reserve headroom: a fleet that |
| 192 | is full to its resident limit has no space for the cells of a lost node, |
| 193 | so a failure of more than one node at the limit degrades the service, |
| 194 | and a fleet with headroom does not. We measure both sides of that line, |
| 195 | the good restoration with reserve and the red case without, because this |
| 196 | measurement is part of the work. |
| 197 | |
| 198 | If you find an edge that we did not find, tell us: a schedule that breaks |
| 199 | a promise, a fault that we did not inject, a number that you cannot |
| 200 | reproduce. That is exactly the bug report that we want: |
| 201 | [github.com/denoland/celld/issues](https://github.com/denoland/celld/issues). |