Skip to content
Back to skills

Cloudflare Durable Objects Knowledge Patch

ASecurity

Cloudflare Durable Objects

  • 25 stars
  • 0 votes
  • 0 copies
  • 9 views
  • Added September 5, 2026
developmentjavascripttypescriptpythonjavasqltestingapibackend

Works with

  • cursor
  • api

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill cloudflare-durable-objects-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cloudflare Durable Objects Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cloudflare Durable Objects Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-cloudflare-durable-objects-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-cloudflare-durable-objects-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cloudflare-durable-objects-knowledge-patch
description: Cloudflare Durable Objects
version: null
license: MIT
metadata:
  author: Nevaberry
---


# Cloudflare Durable Objects

Load this skill when changing Durable Object class lifecycle declarations,
storage, alarms, placement, RPC, WebSockets, or Workers tests. It also covers
code rollout, tracing, Preview profiling, spending limits, and Container TCP routing.
Use the quick references below for compatibility-sensitive decisions and the
topic files for complete conditions, limits, and examples.

## Reference index

| Reference | Topics |
| --- | --- |
| [Deployment and class lifecycle](references/deployment-lifecycle.md) | Class exports, legacy migrations, rename and transfer sequencing, code rollout, development, logs, traces, profiles, spending limits |
| [Storage and SQL](references/storage-and-sql.md) | SQLite availability, schema migrations, SQL cursors, transactions, KV APIs, recovery bookmarks, data and alarm deletion |
| [Concurrency, eviction, and alarms](references/concurrency-eviction-and-alarms.md) | Initialization, Dynamic Workers, hibernation, pending I/O, shutdown, aborts, alarm retries |
| [Identity and placement](references/identity-and-placement.md) | Named and serialized IDs, jurisdictions, location hints, loopback and Actors SDK routing, RPC retries, Container TCP routing |
| [WebSocket hibernation](references/websocket-hibernation.md) | Tags, attachments, automatic responses, close handling, event limits, Python, local runtime requirements |
| [Testing Durable Objects](references/testing.md) | Vitest dependencies and plugin setup, binding types, HTTP tests, shared storage, IDs, eviction, alarms |

## Deployment constraints and compatibility changes

### Namespace provisioning and storage choice

Accounts without an existing KV-backed namespace must use SQLite for new
namespaces. A legacy `new_classes` migration fails on those accounts; use
`new_sqlite_classes` when using migrations.

For `exports`, new namespaces require `sqlite`. Adopt existing namespaces with
their current backend: `storage: "sqlite"` for `new_sqlite_classes`, or
`storage: "legacy-kv"` for `new_classes`. The backend is immutable after
provisioning; a mismatch fails with `storage_type_mismatch`.
Set `storage` on live and `expecting-transfer` entries; omit it on tombstones.

### Class lifecycle declarations

Use `exports` in place of `migrations`, keyed by class name. The default state
is `created`; `deleted`, `renamed`, and `transferred` are tombstones, and
`expecting-transfer` prepares the receiving class.

A code export alone does not provision a namespace. Every provisioned namespace
needs a live entry or tombstone, and every live entry must name a code export.
Removing both the entry and class leaves an orphaned namespace and fails deploy.

After adopting `exports`, switching back to `migrations` is rejected. Omitting
both fields reconciles against an empty map. Apply lifecycle changes with
`wrangler deploy`: `wrangler versions upload` rejects configurations containing
`exports` entries, gradual deployments cannot apply these changes, and rollbacks
cannot cross an `exports` lifecycle change.

Named environments inherit top-level `exports` unless overridden with
`env.<name>.exports`. Each environment has its own namespaces, so inherited
tombstones act on that environment's namespaces when deployed.

### Deletion, rename, and transfer sequencing

- For a `deleted` tombstone, remove the class export and local binding.
  Other Workers must drop their bindings before the namespace and data are
  permanently deleted. Redeploy Workers listed by
  `tombstone_delete_blocked_by_external_bindings` without those bindings first.
- For a rename, keep both names exported during rollout and make the destination
  a live entry in the same map. Free an occupied destination with a `deleted`
  tombstone in a prior deploy. Remove the old code alias only after rollout.
- For an `exports` transfer, prepare the target with `expecting-transfer`
  before adding its local binding, then commit from the source with `transferred`.
  After source rollout, deploy the target with a live entry matching the backend
  and add its binding. The Workers must share an account and dispatch namespace
  context; the source must own the namespace and the target name must be available.
- Remove old tombstones once Wrangler lists them under `Safe to remove from exports`.
  A `stale_tombstone` can still be needed by external bindings.

See the deployment reference for the full rename, transfer, cancellation,
binding cleanup, and legacy migration procedures.

### Alarm deletion and abort retries

From Worker compatibility date `2026-02-24`, `deleteAll()` clears stored data and
the scheduled alarm on both SQLite-backed and KV-backed objects. On earlier dates,
enable `delete_all_deletes_alarm` in `compatibility_flags`, or call `deleteAlarm()`
separately. SQLite data deletion is atomic; a failed legacy KV deletion can leave keys.

An in-progress alarm interrupted by `ctx.abort()` retries after reset by default.
Pass `{ retryAlarm: false }` as the second argument on every abort path that should
suppress it, including concurrent requests. Local use requires Wrangler 4.126.0
or later. `ctx.abort()` immediately resets the object; its logged JavaScript
`Error` bypasses application `catch` blocks.

### WebSocket close compatibility

`web_socket_auto_reply_to_close` is enabled by default from compatibility date
`2026-04-07`. With it disabled, call `ws.close(code, reason)` in
`webSocketClose()` to avoid abnormal closure (`1006`).

## Storage quick reference

- `PRAGMA user_version` is unsupported. Track applied schema migrations in a table
  and check it when each object instance initializes.
- Consecutive SQLite writes without an intervening `await` share an implicit
  transaction. Use `this.ctx.storage.transaction()` for awaited writes that must
  commit together. SQL and KV operations on `ctx.storage` participate in that
  callback without its `txn` argument.
- `transactionSync()` takes a synchronous callback and rolls back if it throws.
  `ctx.storage.sql.exec()` rejects transaction-control SQL such as
  `BEGIN TRANSACTION` and `SAVEPOINT`.
- Materialize SQL rows with `cursor.toArray()` or `Array.from(cursor)` before
  yielding. A cursor resumed after `await` can see later changes, including
  writes from an implicit transaction that may still roll back.
- Multi-statement `ctx.storage.sql.exec()` binds arguments to the final statement
  and returns its cursor. Use separate calls for earlier statements needing bindings.
- `cursor.raw()` and object iteration advance the same cursor; `toArray()` consumes
  remaining rows. On a fresh cursor, `one()` throws for zero or multiple rows.
- SQL numbers can round large 64-bit integers. Select `CAST(id AS TEXT)` for an exact value.
- SQLite `ctx.storage.kv` provides synchronous KV access to the same data as the
  asynchronous API. That data is inaccessible through SQL, even if `__cf_kv` is listed.
- The output gate holds outbound `fetch()` requests and replies until pending
  storage writes commit. With `allowUnconfirmed`, await `storage.sync()` before
  sending a message that depends on prior writes being durable.
- In deployed SQLite-backed objects, recovery bookmarks restore SQL and KV.
  `getBookmarkForTime()` accepts a date or epoch milliseconds within the past
  30 days; await `onNextSessionRestoreBookmark()` and restart the object.

## Concurrency, eviction, and code rollout

A `ctx.blockConcurrencyWhile()` callback resets the object if it exceeds
30 seconds or lets an exception escape. Handle recoverable initialization errors
inside it if the instance can continue safely. The runtime can deliver events the
callback explicitly initiates while holding unrelated events until completion.

Eligible objects can hibernate after 10 seconds of inactivity. A non-hibernatable
idle object is normally evicted after 70–140 seconds. Active outbound TCP sockets
opened with `connect()` and outbound WebSockets defer idle eviction for up to
15 minutes per connection; reaching that cap does not close the connection.

From compatibility date `2026-10-01`, pending service binding requests, calls to
other Durable Objects, `this.ctx.container.monitor()`, promises passed to
`this.ctx.waitUntil()`, and pending timers prevent idle eviction for up to
15 minutes per operation. Enable this on older dates with
`durable_object_io_tasks_prevent_eviction`, or opt out with
`durable_object_io_tasks_do_not_prevent_eviction`.

After deployment, active objects can keep their code for up to 300 seconds by
default. Hibernation within the window adopts new code on the next request while
keeping hibernatable WebSockets connected; expiry resets the object. Runtime
updates can reset it sooner. `max_delay` accepts 0–86400 seconds with millisecond
precision in `durable_objects.code_update_strategy` using `mode = "deferred"`.
Keep Worker and Durable Object RPC interfaces compatible across versions;
version skew can last for the duration of a gradual deployment.

## Identity, calls, and routing

`this.ctx.id.name` exposes names from `idFromName()` or `getByName()`, including
in alarms. It is `undefined` for `newUniqueId()`, access through `idFromString()`,
or names longer than 1,024 bytes. Restore serialized IDs through their original
namespace; invalid strings or another namespace's IDs throw synchronously.

The `us` jurisdiction keeps execution and persisted data in the United States;
calling Workers can access the object from anywhere. The same name produces
different IDs in different jurisdictions and in the unscoped namespace.
`getByName(name, { locationHint })` accepts a best-effort initial placement hint.

Eligible `fetch()` and RPC delivery failures from Workers or other Durable Objects
get up to four retries started within 10 seconds by default. Object-thrown
exceptions and errors with `.overloaded` set to `true` are skipped. If delivery
is uncertain, the object rejects a retry when the first attempt arrived; mark
an idempotent method with `retryable()` to allow execution again in that case.

With Wrangler 4.158.0 or later, use `retryable()` and configure a stub's `retry`
through `get()` or `getByName()`: `maxRetries` is 0–10 and `timeoutMs` is
500–60,000. Set `maxRetries: 0` when the caller handles retries.
The identity reference also covers loopback bindings, Actors SDK routing, and
Spectrum's public beta for inbound TCP through a Durable Object to a Container.

## WebSockets and tests

Attachments store a structured-clone snapshot of up to 16,384 serialized bytes
for a connection's lifetime, including hibernation. Save changes again with
`ws.serializeAttachment(value)` and handle a missing attachment as `null`.
Protocol Ping frames receive Pong without waking the object; control frames
bypass `webSocketMessage()`. A single `WebSocketRequestResponsePair` can answer
matching messages on all hibernatable sockets without waking the object.

Tests in one file using the same object ID share persisted writes. Use fresh IDs
when a test needs empty storage. Test eviction waits up to 30 seconds for requests
to drain; the next stub call gets a fresh instance with persisted storage intact.
WebSockets hibernate by default during eviction; `webSockets: "close"` closes them.
`runDurableObjectAlarm(stub)` fires a pending alarm immediately and returns whether
one ran. Restart `wrangler dev` after code edits when testing alarms.
The testing reference preserves both Workers test integration and plugin setup,
including their package dependencies, TypeScript types, and examples.

## Operational checks

Starting in Wrangler 4.116.0, `wrangler check startup` reports raw and gzip bundle
sizes plus local CPU timing. Deploy or upload a version for authoritative startup
timing. Enabling `wrangler tail` or dashboard logs can replace a running object;
WebSocket request logs arrive when the connection closes.

Workers tracing follows JavaScript RPC calls into Durable Objects. Preview
profiling uses that Preview's object IDs because each Preview has its own namespaces.
Account-wide Durable Object spend limits count recorded spend for the current
billing period. Reporting and blocking can lag, so spend can exceed the threshold;
turn off **Block usage** for email alerts alone.

Files in this skill

  • SKILL.md7.4 KB
  • coverage.json1.2 KB
  • references/concurrency-eviction-and-alarms.md3.7 KB
  • references/deployment-lifecycle.md4.9 KB
  • references/identity-and-placement.md2 KB
  • references/storage-and-sql.md3.1 KB
  • references/testing.md2.4 KB
  • references/websocket-hibernation.md2.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.