Skip to content
AI Primer
workflow

Pi Durable prototype resumes Android agent work after worker restarts

Mario Zechner's Pi Durable prototype runs an agent runtime on Android while calling remote models. Shared sessions and subagents are supported, and work resumes after worker restarts.

4 min read
Pi Durable prototype resumes Android agent work after worker restarts
Pi Durable prototype resumes Android agent work after worker restarts

TL;DR

Zechner turned worker restarts into hot reload, a delightfully blunt way to make the app edit itself. A guest tried to send an SMS from the phone, but Termux reported its API was unavailable.

Android runtime

Zechner built the prototype directly on the phone in roughly 24 hours, with no cloud VM hosting its agent runtime.

Pi Codemode also runs inside Termux on Android:

Checkpoints and tool replay

Pi Durable's recovery example opens the same persisted storage in a replacement process, then calls harness.resume() to continue unfinished tasks from their checkpoints. SQLite and JSONL provide persistent storage; the in-memory backend does not survive process death.

The documented recovery behavior distinguishes:

  • Interrupted model requests: send the request again; preserve the partial answer in the transcript, marked aborted.
  • Interrupted tool calls: rerun tools declared replay: "safe"; otherwise tell the model the call was interrupted, including output captured so far.
  • Queued messages: retain their place in the queue.
  • Retried submissions: reuse the original submission when the client supplies the same requestId, rather than enqueueing it twice.

In an independent kill-9 test, a replay-safe search ran again while an unsafe booking was reported as interrupted instead of repeated.

Worker hot reload

Zechner split reloads into two paths:

  • Web UI: hot module replacement.
  • Server and session workers: kill and respawn the processes; Pi Durable recovers their saved work.

Ordinary Pi lost in-flight work in that server-and-worker setup, he explained in a comparison. Durable resumes it automatically after the restart.

Shared sessions

Zechner exposed the phone-hosted server through ngrok and reported 130 concurrent viewers.

Pi Durable's multiplayer documentation describes three client behaviors:

  1. Join or reconnect: receive the current transcript, streamed answer, running tools and their output, queued messages, agent configuration, and usage.
  2. Stay connected: subscribe to changes after receiving that initial view.
  3. Send input: steer a running conversation after its current tool calls, or queue a follow-up.

One process owns each storage backend, with other clients attaching to that process, according to Earendil's storage design.

Subagent conversations

The phone app exposes subagents. Pi Durable leaves their implementation to application code; its reference example creates child conversations owned by a tool task.

  • Each child can have its own model, tools and instructions, and tracks its own cost.
  • A replay-safe parent tool locates the existing child after a restart and waits for the same submission's answer.
  • Aborting the owning tool call also aborts its child conversation.

The initial Android prototype with subagents

Experimental packages

Pi Durable shipped alongside Pi 1.0 on October 1 as an experimental, MIT-licensed package. Earendil's announcement lists this installation command:

Foreground service

The Android runtime uses a foreground service, Zechner said in a battery discussion. He attributed its low battery use to spending most of its time waiting for model responses, while flagging Rust compilation as a more demanding workload.

On his Pixel 11, he reported 24 hours of continuous operation without exhausting the battery.

Further reading

Discussion across the web

Where this story is being discussed, in original context.

On X· 8 threads
TL;DR3 posts
Android runtime2 posts
Checkpoints and tool replay1 post
Worker hot reload1 post
Shared sessions2 posts
Subagent conversations1 post
Experimental packages3 posts
Foreground service2 posts
Share on X