---
title: "Pi Durable on Cloudflare"
description: "A multiplayer chat agent built on Pi Durable maps each agent session to one SQLite-backed Cloudflare Durable Object, so idle agents hibernate instead of holding a running machine."
url: "https://swe.quest/articles/pi-durable-on-cloudflare-1b649cdf3e489964"
canonical: "https://earendil.com/posts/pi-durable-on-cloudflare/"
source: "Earendil"
published: "2026-10-16"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["ai-agents","serverless","sqlite","realtime","typescript"]
---

# Pi Durable on Cloudflare

A post on [Earendil](https://swe.quest/sources/earendil.md), published 2026-10-16, 8 min read, How-to. Original: [https://earendil.com/posts/pi-durable-on-cloudflare/](https://earendil.com/posts/pi-durable-on-cloudflare/)

## Summary

A multiplayer chat agent built on Pi Durable maps each agent session to one SQLite-backed Cloudflare Durable Object, so idle agents hibernate instead of holding a running machine. The harness reopens in the object constructor under blockConcurrencyWhile, restores per-WebSocket event streams after hibernation, and makes conversation creation and message submission idempotent with request-ID receipts stored in the same commit. Pi's many task deadlines are collapsed onto the single Durable Object alarm, which is recomputed idempotently on each wake, with short recovery alarms for interrupted work. A replay-safe search\_history tool delegates cross-conversation retrieval to a task-owned subagent conversation, and only the final answer returns to the parent.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [SQLite](https://swe.quest/tags/sqlite.md) (Data & databases)
- [Real-time systems](https://swe.quest/tags/realtime.md) (Backend & APIs)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)

## Prerequisites

- Cloudflare Workers
- Durable Objects basics
- WebSockets ([easy posts on Real-time systems](https://swe.quest/tags/realtime.md?difficulty=easy))
- LLM tool calling ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))

## Keywords

Pi Durable, Cloudflare Durable Objects, Durable Object alarms, WebSocket hibernation, SqlStorage, PartySocket, Vitest

## Related posts

- [chDB Durable Layer for agent memory](https://swe.quest/articles/chdb-durable-layer-for-agent-memory-f44e23c2b52592d1.md): ClickHouse · 2026-09-28 · Medium · 14 min read · AI agents, Analytics & OLAP, Storage systems, Replication, Python
  chDB Durable Layer wraps the embedded chDB (ClickHouse) OLAP engine so a local MergeTree working copy can be published to object storage you own (S3, GCS, Azure) and recovered on another host.
- [Building Agents that Don't Break Themselves](https://swe.quest/articles/building-agents-that-don-t-break-themselves-946af945ee4733ac.md): Fly.io · 2026-06-08 · Medium · 6 min read · AI agents, Sandboxing & isolation, Identity & auth, Virtualization
  Separate where an agent lives from where it executes code: keep the agent loop on a durable host and send every shell command to a disposable Sprite sandbox.
- [The Missing Abstraction for AI Agents: The Agent Filesystem](https://swe.quest/articles/the-missing-abstraction-for-ai-agents-the-agent-filesystem-ef7d12c3499d3c42.md): Turso · 2025-11-13 · Medium · 8 min read · AI agents, SQLite, Observability, Storage systems
  AgentFS is an SDK that stores all of an AI agent's state in a single SQLite (Turso) database file: a POSIX-like virtual filesystem, a key-value store, and an append-only tool call audit log.
- [Building AI Agent Databases: A Complete Guide to Database-per-Agent Architecture](https://swe.quest/articles/building-ai-agent-databases-a-complete-guide-to-database-per-agent-architecture-e621ee857e5a5f4f.md): Turso · 2026-07-20 · Medium · 7 min read · Multi-tenancy, AI agents, SQLite, Local-first & sync, Vector search
  Giving each AI agent its own SQLite-style database, instead of sharing tables keyed by tenant\_id or using schema-per-tenant, makes isolation, debugging and cleanup trivial: deleting an agent is a single API call.
- [chDB as the Agent's Local Data Engine](https://swe.quest/articles/chdb-as-the-agent-s-local-data-engine-cfbf1f486cb2ca71.md): ClickHouse · 2026-07-07 · Medium · 16 min read · AI agents, Analytics & OLAP, Resilience, Vector search, Serverless
  Embedding chDB, the in-process ClickHouse engine, inside an agent keeps hot data local, so tool-call latency is bounded by CPU instead of network round trips, jitter and retries.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
