Open-source Cloudflare DST · TypeScript · Zero deps · Miniflare

Deterministic simulation testing for Cloudflare.

Explore failures in Workers and Durable Objects by varying request order, duplicate delivery, retries, and eviction. Give Cloudflake a scenario, an invariant, and a seed—every failure replays identically.

npm install -D cloudflake
npm install -D miniflare@4   # optional: real Workers in workerd
Cloudflake cereal box illustration featuring a red cloud, bold black Cloud Flake lettering, pink cloud-shaped cereal flakes, and a lightning bolt shattering a red bowl

Seeded replay & fault minimization

Finds distributed bugs. Minimizes the fault trigger.

Built in the tradition of FoundationDB, TigerBeetle VOPR, and Antithesis—and pairable with Hegel for shrinking workload inputs—Cloudflake explores thousands of virtual-time schedules, delta-debugs injected faults, and prints an exact replay command.

CLOUDFLAKE_PROBE=1 node test/probe.mjs exit 1
FAIL  Cloudflake Exploratory Probe: payments-exploration
      Explored 1,420 seeds, 38,910 steps in 0.42s (3,380 runs/s)
      Invariant 'one posting per payment' failed on seed=17 (expected 56, got 63)

Minimal fault trigger (minimized from 9 injected faults to 1):
  - t=14ms [duplicate] queue payments deliver batch #3 (msg-04)

Hint: Duplicate delivery triggered this failure. Deduplicate writes by a stable idempotency key.
Replay deterministically: CLOUDFLAKE_SEED=17 CLOUDFLAKE_PROBE=1 node test/probe.mjs

Architecture

In-process speed. Real workerd fidelity.

Start with zero-dependency TypeScript model tests at ~4.9M events/sec, then run the exact same scheduling API against real bundled Workers, SQLite Durable Objects, Queues, KV, R2, and D1 inside Miniflare and workerd.

01 · Virtual event calendar

Zero-dep TypeScript scheduler

Binary-heap virtual clock with 128-bit xoshiro128++ PRNG streams, TigerBeetle-style swarm fault profiles (sim.profile), Antithesis assertions (always, sometimes, reachable), and Wing-Gong linearizability checks.

02 · Cloudflare failure models

Duplicates, resets & evictions

Fast in-process simulators for Queue batches and DLQs, DO alarm retries, eventually consistent KV stale reads, Durable Object eviction and blockConcurrencyWhile gates, waitUntil drops, and ambiguous gray RPC failures.

03 · Real workerd bindings

Same API on real Workers

Drop in cloudflake/miniflare (simulateWorkers, createBindingProxies, controlServiceBinding, doNemesis) to drive real bindings on virtual time with zero application code changes.

Control points

Core DST engine and Workers adapter.

Every source of Cloudflare nondeterminism sits behind one deterministic seed—from model tests to multi-Worker workerd campaigns.

Cloudflake core simulation APIs and Miniflare Workers adapter primitives
API Behavior
simulate / campaign Run one seeded schedule or explore thousands of seeds with aggregated Antithesis property coverage (always, sometimes, reachable, unreachable) and failure bucketing.
sim.deliver / sim.profile Inject seeded latency distributions (uniform, exponential, pareto, bimodal), zero-step drops, 1..maxDuplicates extra deliveries, ambiguous gray failures, and per-seed swarm fault regimes.
simulatedQueue / Alarm / KV / DO In-process simulators for multi-message Queue batches + DLQ, exponential-backoff alarms, stale KV reads + TTLs, DO eviction / abort / input gates, waitUntil drops, and outbound fetch faults.
HistoryRecorder / checkLinearizability Wing-Gong linearizability checker supporting definite ok/fail and indeterminate ambiguous outcomes against a pure sequential reference model.
minimizeFaults / exploreMultiverse Delta-debug a failing seed to the minimal subset of injected faults that still reproduces the bug, or branch from snapshots guided by coverage edges and assertions.
probe / probeWorkers Local exploratory probers (auto-skip in CI unless CLOUDFLAKE_PROBE=1) that run time-budgeted campaigns, bucket failures, minimize faults, and print agent-ready diagnostic guidance.
simulateWorkers / createBindingProxies Run real bundled Workers in workerd with drop-in Queue, KV, and Durable Object RPC proxies, synced virtual time (controlServiceBinding), outboundFaultService, and doNemesis eviction chaos.

In-process model test

Explore 1,000 schedules in milliseconds

Verify queue idempotency before spinning up a runtime. Remove the posted.has(id) guard to prove the campaign catches duplicate deliveries, then replay the failing seed.

import assert from 'node:assert/strict'
import { campaign, simulate, simulatedQueue } from 'cloudflake'

async function payments(sim) {
  const posted = new Set()
  let balance = 0
  const queue = simulatedQueue(sim, 'payments', ({ messages }) => {
    for (const { id, body } of messages) {
      if (posted.has(id)) continue
      posted.add(id)
      balance += body.amount
    }
  }, { duplicate: 0.5 })

  sim.invariant('one posting', () => assert.equal(balance, 7 * posted.size))
  for (let i = 0; i < 8; i++) await queue.send({ amount: 7 })
  sim.onIdle('settled', () => assert.equal(balance, 56))
}

await campaign({ seed: 0, runs: 1000 }, payments)
await simulate({ seed: 42, onStep: console.log }, payments)

Real Workers & Hegel

Drive real bindings in workerd

Graduate to SQLite Durable Objects, R2, D1, and Queues with cloudflake/miniflare—or pair with Hegel to shrink workload inputs and scheduling seeds together.

import assert from 'node:assert/strict'
import { simulateWorkers } from 'cloudflake/miniflare'

await simulateWorkers(
  { seed: 42 },
  () => ({
    modules: true,
    scriptPath: './build/worker.mjs',
    compatibilityDate: '2026-07-01',
    durableObjects: { BOOK: { className: 'Book', useSQLite: true } },
    r2Buckets: ['FILES'],
  }),
  (sim, runtime) => {
    sim.deliver('upload invoice 17', async () => {
      const res = await runtime.dispatchFetch(
        'https://app.test/invoices/17',
        { method: 'PUT', body: 'invoice data' },
      )
      assert.ok(res.ok)
    }, { maxDelay: 50, duplicate: 1 })

    sim.onIdle('one stored invoice', async () => {
      const bucket = await runtime.getR2Bucket('FILES')
      assert.equal((await bucket.list()).objects.length, 1)
    })
  },
)

Coding agents

Hand Cloudflake to your agent.

Install the skill directly into Claude Code, Codex, Cursor, or Antigravity, or paste the prompt below—your agent fetches https://cloudflake.dev/skill.md and writes, verifies, and replays simulation tests for your Workers.

npx skills add economico/cloudflake
Follow https://cloudflake.dev/skill.md to write Cloudflake simulation tests for our queue consumer and Durable Objects. Check that duplicate delivery, retries, and eviction cannot double-count, break the guard deliberately to confirm the test catches it, run a campaign of at least 500 seeds, and report any failing seed with its replay command.

Questions

Before you run your first campaign

How fast is the in-process scheduler?
The core scheduler runs in process on Node 24+ with zero runtime dependencies over a binary-heap event calendar—around 4.9 million events per second on the isolated benchmark—so thousands of model seeds finish in seconds.
Does a seed replay workerd runs identically?
Cloudflake controls virtual time, PRNG streams, scheduled events, checkpoints, and controlServiceBinding hooks (Date.now(), Math.random(), crypto.randomUUID(), alarms, and waitUntil). Native workerd internals outside those hooks need injected clocks, entropy, or service doubles for exact replay.
How does Cloudflake pair with Hegel?
Draw both your workload values (amounts, payloads, operation lists) and the Cloudflake scheduling seed with @hegeldev/hegel so Hegel shrinks both together. Save the minimized inputs alongside the failing seed for permanent regressions.
How should I split CI tests vs. local probing?
Keep fixed small-seed campaign() runs and regression seeds in CI. Put longer exploratory probe() and probeWorkers() scripts locally—they skip automatically when CI is set unless you pass CLOUDFLAKE_PROBE=1.