hn.today

Pi Durable on Cloudflare – Earendil

earendil.com9 points1 comments
Screenshot of Pi Durable on Cloudflare – Earendil

Pi Durable is a harness for agents that must preserve work across long idle periods without keeping a server running continuously. The design pairs one agent session with one Cloudflare Durable Object, addressed by a shareable session ID. Each object stores its session in SQLite, can hibernate while idle, and resumes when a request, WebSocket message, or alarm arrives. The walkthrough builds a multiplayer chat agent: participants share a session but can create separate conversations or fork one from a chosen message. Durable event streams provide clients with an initial snapshot and subsequent transcript, tool, and task updates. Request receipts make conversation creation safe to retry after a dropped connection, while messages sent during model activity are queued and answered in order.

Durability also requires restoring active views, recovering interrupted tasks, and waking for scheduled work. On startup, the object reopens its harness and event streams, then derives its single Cloudflare alarm from Pi’s persisted task deadlines; idempotent alarm handling and stable request IDs prevent duplicate work. A scheduled task can resume when its deadline arrives, and unfinished work receives a recovery alarm. For questions spanning conversations, a replay-safe search tool creates a subagent conversation owned by its task. The subagent searches user and assistant messages across the session’s other conversations, but excludes its own output and results from earlier searches. The implementation also supplies a Cloudflare SQLite adapter and a conformance suite for validating alternative storage backends.

Read on earendil.com1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in AI

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.