Skip to content

feat(pi): add piDurable() and drain, resume, and c.pi for pi() - #320

Merged
eersnington merged 12 commits into
mainfrom
stack/chore-release-version-rivet-dev-pi-and-rivet-dev-sandbox-adapter-on-their-own-ytlskwsy
Oct 6, 2026
Merged

eersnington merged 12 commits into
mainfrom
stack/chore-release-version-rivet-dev-pi-and-rivet-dev-sandbox-adapter-on-their-own-ytlskwsy

Conversation

@eersnington

@eersnington eersnington commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

A new @rivet-dev/pi/durable entrypoint runs Pi Durable as a Rivet Actor, and pi() survives deploys and gives app code the session.

piDurable()

Pi Durable's conversations, tasks, and documents live in the actor's SQLite database. The actions mirror Pi Durable's Harness, Conversation, and Submission one to one, plus a prompt convenience action.

import { createRegistry } from "@earendil-works/pi-durable";
import { piDurable } from "@rivet-dev/pi/durable";

export const agent = piDurable({
	model: "provider/model",
	registry: createRegistry(),
	sandbox: sandboxProvider,
	documents: [Todos],
	actions: {
		// App actions get the harness as c.pi.
		addTodo: async (c, conversationId: number, item: string) => { … },
	},
});
const conn = client.agent.getOrCreate(["support"]).connect();
const root = await conn.harness.root();
conn.on("pi.events", (frame) => render(frame.events));
await conn.conversation.watchEvents(root.id);

const result = await conn.prompt("Summarize the open tickets");
if (result.status === "unanswered") console.error(result.reason);
  • Runs survive sleep, deploys, and crashes, and resume when the actor wakes. Live work keeps the actor awake. A retry or poll wait longer than a minute lets it sleep, and a scheduled wake reopens it at the deadline.
  • Watches (pi.events, pi.view, pi.taskGraph, pi.doc) go only to the connection that asked. A connection that survives sleep gets them back with a fresh seq 0 frame.
  • Pi's coding tools run in the sandbox. Paths outside the sandbox are rejected, and commands never see the actor host's environment.
  • @earendil-works/pi-durable and @earendil-works/chord are optional peers. Only /durable imports them.

pi()

Before After
Forced stop (deploy) during a run run aborted waits for the run within a 15 minute grace period; a cut-off run resumes on wake through Pi's retry
Caller disconnects or the action times out run aborted run continues; only abort stops it
App actions and hooks no session access c.pi is the AgentSession
Sandbox connected when the session opens connected on the first tool call
Session stored by an older pi-coding-agent read as is migrated with Pi's migration and rewritten
  • pi() and piDurable() share one actor factory: option split, reserved names, the runtime slot on vars, action and sleep-grace defaults, and shutdown hooks.
  • Versions: @rivet-dev/pi and @rivet-dev/sandbox-adapter stay at their published 0.1.0; the release script sets the next version. The docs examples move to pi-coding-agent 1.0.2.

This is part 1 of 11 in a stack:

@railway-app

railway-app Bot commented Oct 5, 2026

Copy link
Copy Markdown

This PR was not deployed automatically as @eersnington does not have access to the Railway project.

In order to get automatic PR deploys, please add @eersnington to your workspace on Railway.

@eersnington
eersnington force-pushed the stack/chore-release-version-rivet-dev-pi-and-rivet-dev-sandbox-adapter-on-their-own-ytlskwsy branch from 7fe8bef to d5471f2 Compare October 5, 2026 23:59
@eersnington eersnington changed the title chore(release): version @rivet-dev/pi and @rivet-dev/sandbox-adapter on their own feat(pi): add piDurable() and drain, resume, and c.pi for pi() Oct 5, 2026
@eersnington
eersnington force-pushed the stack/chore-release-version-rivet-dev-pi-and-rivet-dev-sandbox-adapter-on-their-own-ytlskwsy branch from d5471f2 to fac746b Compare October 6, 2026 00:26
@eersnington
eersnington force-pushed the stack/chore-release-version-rivet-dev-pi-and-rivet-dev-sandbox-adapter-on-their-own-ytlskwsy branch from fac746b to 1b114b7 Compare October 6, 2026 00:45
@eersnington
eersnington merged commit a9c369f into main Oct 6, 2026
1 of 3 checks passed
@eersnington
eersnington deleted the stack/chore-release-version-rivet-dev-pi-and-rivet-dev-sandbox-adapter-on-their-own-ytlskwsy branch October 6, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant