# Durable Objects billing: what keeps an object awake

> Durable Objects bill wall-clock time in memory, not the work done. The timers, sockets and undeleted objects that keep the meter running, and the fixes.

Published 2026-11-22 · https://aiskills402.com/blog/durable-objects-billing-what-keeps-object-awake

Durable Objects billing follows the time an object spends in memory, not the time it spends working, so the bill can be far larger than the work behind it. An object that finishes its job in two seconds keeps billing for as long as something inside it is still pending: a timer, an open promise, a WebSocket accepted the old way. Objects that nobody deletes add a second cost that only grows. Both are easy to recognise once you look at the right numbers. Divide the seconds billed by the number of wake-ups: if the result sits near some time-out in your code instead of near the length of the job, a timer is holding the object. If the count of objects rises and never falls, something creates them and nothing removes them.

## How the meter counts

The [Durable Objects pricing page](https://developers.cloudflare.com/durable-objects/platform/pricing/) bills duration as wall-clock time, both while the object runs and while it sits idle in memory without being allowed to hibernate. Memory is counted as a flat 128 MB for each object, regardless of how much it really uses, so every second awake costs one eighth of a GB-second. The paid plan comes with 400,000 GB-s included per month, and that amount is not handed out per object or per Worker. The [Workers pricing page](https://developers.cloudflare.com/workers/platform/pricing/) describes one paid plan for an account, with Durable Objects usage inside its included usage, so every class in every Worker draws from the same pool.

A quick sum shows how little room that leaves. A 30-day month holds 2,592,000 seconds. One object that never leaves memory uses 324,000 GB-s of the pool, about four fifths of it, and two such objects are over the line on their own ([pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/)).

What happens above the line matters just as much. The pricing page says that usage beyond the included amount is rounded up to the next whole billable unit before the rate is applied, and its own example turns half a million GB-s of excess into a full million ([pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/)). Being slightly over therefore costs the same as being far over within that unit. The useful question about a bill is the distance to the allowance: how much room is left below it, and which single change would push you across. A small saving that still leaves you over, in the same unit, buys nothing.

## When an object is allowed to sleep

The [lifecycle page](https://developers.cloudflare.com/durable-objects/concepts/durable-object-lifecycle/) sets out four conditions, and hibernation needs every one of them: no scheduled `setTimeout` or `setInterval` callback, no unfinished I/O or `waitUntil` promise and no open outbound connection, no socket accepted through the standard WebSocket API, and no request still being handled. When all four hold, the runtime currently hibernates the object after 10 seconds without events, and that idle stretch is not billed. When one fails, the object stays in memory and keeps billing until it has been idle for 70 to 140 seconds and is evicted, and any pending operation can hold it for up to 15 minutes from the moment it started.

Now put that next to an alarm that fires every minute. If anything stops the object from hibernating, the next alarm arrives before the eviction window has closed. The object then never leaves memory and is billed around the clock, however short each job is.

## The timer nobody wrote: AbortSignal.timeout

We ran into this on an alarm object that woke every minute to make a few outbound calls, each guarded by `AbortSignal.timeout`. The calls came back in about two seconds, yet the usage data for 19 November 2026 showed about 61 seconds billed for each wake. The timer behind that signal is not cancelled when the response arrives. It stays pending until its limit has passed, and a pending timer is one of the four things that block hibernation. Every short job paid for the whole limit, and with a fresh alarm every minute the object never got to sleep.

The fix is to build the limit yourself, so that you own the timer and can cancel it:

```ts
async function fetchWithin(input: RequestInfo, init: RequestInit = {}, limitMs = 10_000): Promise<Response> {
  const ctrl = new AbortController();
  const timer = setTimeout(
    () => ctrl.abort(new DOMException(`fetch gave up after ${limitMs} ms`, "TimeoutError")),
    limitMs,
  );
  try {
    return await fetch(input, { ...init, signal: ctrl.signal });
  } finally {
    clearTimeout(timer);
  }
}
```

Two details decide whether this swap is safe. The abort reason is a `DOMException` named `TimeoutError`, the name the built-in signal gives its own reason, so retry logic that checks the error name still recognises a time-out. If some branch compares the message text instead, copy the built-in message into the reason, or that branch will quietly stop matching. And once this function returns, the response body is no longer guarded by any limit; if a slow body matters to you, read it first and cancel the timer after that. With this change in place, the same alarm object spent between 9 and 25 % of its time awake.

The call may not be in your own code at all. A fetch wrapper, an SDK client or a retry helper can create the signal for you, and dependencies only join your code when the Worker is bundled. So search the bundle rather than the source: `npx wrangler deploy --dry-run --outdir dist` builds the Worker without deploying it, and a search of `dist` for `AbortSignal.timeout` covers your code and every library at once. A hit on any path an object runs is a finding, even with a short limit. A request that returns in a blink under a ten-second limit still keeps its object for ten seconds.

## Loops and sockets that never let go

An interval is a timer that is always pending, so an object running `setInterval` can never hibernate. Replace it with an alarm. Each object holds one alarm at a time; to run several schedules, keep the due times in storage and let the `alarm()` handler run whatever is due, then set the next alarm for the earliest remaining time ([alarms API](https://developers.cloudflare.com/durable-objects/api/alarms/)). An object with nothing left to do sets no alarm and stops costing until its next request.

WebSockets are the other classic. A socket accepted with `server.accept()` and event listeners bills duration for the whole time the client stays connected, even when nobody sends a word ([pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/)). With the [hibernation API](https://developers.cloudflare.com/durable-objects/best-practices/websockets/) you call `ctx.acceptWebSocket()` and handle traffic in the `webSocketMessage` and `webSocketClose` methods instead. Clients stay connected while the object sleeps, and no duration accrues during that sleep. Answer keep-alive pings with `setWebSocketAutoResponse`, which the pricing page says adds no wall-clock time. One limit to keep in mind: only an object acting as a WebSocket server can hibernate like this, and an outgoing socket that the object opens keeps it awake.

## Objects that nobody deletes

Duration is the loud cost; storage is the quiet one. An object never removes itself, and its stored data is billed until that data is gone ([pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/)). A design with one object per visitor, cart, room or session grows with every new key. The tidy pattern is an expiry alarm: each use moves the alarm forward, and when it fires with no newer activity, the handler calls `deleteAll()`, which wipes the object's private SQLite database in one atomic step ([storage API](https://developers.cloudflare.com/durable-objects/api/sqlite-storage-api/)). For a Worker whose compatibility date is 2026-02-24 or newer, that call clears a pending alarm as well; with an older date, call `deleteAlarm()` too, or the leftover alarm will still fire.

Remote MCP servers built on the `McpAgent` class hit this at scale. In version 0.20.1 of the agents package, which is what we measured, each `initialize` request that carries no session id creates another object with its own SQLite database, and that object goes away only if the client later sends a DELETE. Scanners and directory probes open a session and walk away. On one account that produced 91,032 objects in seven weeks, counted on 20 November 2026, and almost none of them had ever run a tool.

Cloudflare now marks `McpAgent` as deprecated and feature-frozen ([McpAgent reference](https://developers.cloudflare.com/agents/model-context-protocol/apis/agent-api/)). Its replacement, `createMcpHandler`, builds a fresh server for each request and needs no Durable Object at all ([MCP handler](https://developers.cloudflare.com/agents/model-context-protocol/apis/handler-api/)). If your tools keep no state between calls, that is the whole fix.

Getting rid of a class that has already piled up is a separate decision. Retiring a class deletes its namespace and everything stored in it, permanently, with no trash to restore from ([class lifecycle](https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/)). Do it only after the replacement has served real traffic and nothing reads the old class any more.

People who deploy Next.js through OpenNext have one more object to know about. Its queue object, `DOQueueHandler`, keeps itself in memory no shorter than the revalidation time-out each time a page is revalidated: 10 seconds by default, changed through an environment variable of the adapter. Lowering that value to save duration is a gamble until you have measured how long your revalidations take, since an interrupted one is simply attempted again. The same adapter also leaves every old build behind in R2, which is how [stale OpenNext builds kept piling up in our R2 cache](https://aiskills402.com/blog/opennext-r2-cache-old-builds-cleanup) until we removed them by hand.

## Measure it where the alarms are visible

Do not look for alarm wake-ups in `wrangler tail`. It leaves out the runs that a Durable Object's alarms trigger, so seeing none there proves nothing.

The numbers live in the GraphQL Analytics API. The [metrics page](https://developers.cloudflare.com/durable-objects/observability/metrics-and-analytics/) lists the datasets for Durable Objects and points to introspection for the field names. In our own queries, `durableObjectsPeriodicGroups` carried the duration and active-time sums, which we grouped per namespace and per hour, and `durableObjectsInvocationsAdaptiveGroups` counted invocations and could be grouped by status.

Then do the sum that exposes a held object. Divide GB-s by one eighth, which is 128 MB written in GB ([pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/)), to get seconds in memory, and divide those by the number of invocations to get seconds per wake. A figure close to the real length of the job is healthy. A figure close to a time-out in your code points at a timer. A figure close to the gap between alarms means the object never left memory. Before you compare a dashboard figure with the monthly allowance, check whether it covers the whole billing cycle or only the part that has passed.

## A check that can fail

A billing bug never throws an error, so prove the fix twice, once before the deploy and once after it.

- **In tests,** fake the timers, send a fast mocked response through the real path the object takes (its alarm handler or fetch method, not the helper alone), and assert that no timer is pending afterwards. Then remove the `clearTimeout` call and rerun the test: it has to go red. A test that stays green there never reaches the timer.
- **In the bundle,** make the search for `AbortSignal.timeout` a build step that fails on a hit, because a fake-timer library may not see the timer the built-in signal creates. Prove the step once by adding such a call to a helper and watching the build stop.
- **In production,** compare seconds per wake over a full day before and after the deploy. The new figure should land near the real job length. For pile-ups, the stored bytes in `durableObjectsStorageGroups` should stop climbing once expiry alarms run.

## When this does not apply

- **Our figures are from one account.** The seconds per wake, the share of time awake and the object count were measured on our own Workers in November 2026, with version 0.20.1 of the agents package. A runtime release could start cancelling the built-in signal's timer when the response arrives, so measure seconds per wake before you rewrite code that is fine.
- **The arithmetic assumes the paid plan.** The free plan has a daily duration allowance instead, and once it is used up further operations fail rather than being billed ([pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/)).
- **Far under the allowance, a held object spends margin, not money.** It still matters on the day traffic grows, and it is cheaper to fix while the numbers are small.
- **Only Durable Objects are covered.** Workers CPU, D1 rows and R2 storage follow other rules, and our [earlier look at reviewing Worker code](https://aiskills402.com/blog/llm-workers-review-d1-opennext) deals with several of those while leaving Durable Objects out of scope.
- **Socket hibernation is for servers only.** It works when the object accepts the WebSocket; an object that must hold an outgoing connection open is billed for that time whatever you change.

## Our skills for this topic

- [Durable Object Billing Review](https://aiskills402.com/skills/durable-object-billing-review) reads Durable Object code, wrangler config or a pasted bill and names what holds objects in memory or lets them pile up: uncleared timers, including those hidden in helpers, intervals, sockets that cannot hibernate, objects with no deletion and per-session MCP objects. It gives the code fix for each finding and works out the margin to the allowance.
- [Workers Pitfalls Review](https://aiskills402.com/skills/workers-pitfalls-review) covers the rest of a Worker: D1 parameter and pattern limits, the edge runtime under OpenNext, and outbound fetches that fail without throwing.
- [Cloudflare Cron Trigger Review](https://aiskills402.com/skills/cloudflare-cron-trigger-review) checks a `scheduled()` handler, and an alarm used as a second clock, for jobs that run twice, late or not at all.
