Skip to content

fix(pi): schedule a recovery wake while Pi work is active - #399

Closed
NathanFlurry wants to merge 4 commits into
stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsukfrom
stack/fix-pi-schedule-a-recovery-wake-while-pi-work-is-active-ponmmwro
Closed

NathanFlurry wants to merge 4 commits into
stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsukfrom
stack/fix-pi-schedule-a-recovery-wake-while-pi-work-is-active-ponmmwro

Conversation

@NathanFlurry

Copy link
Copy Markdown
Member

RivetKit's default crash policy leaves a crashed actor asleep, and
keep-awake only lasts while the process does, so an actor that crashed
mid-run stayed asleep until something called it. While Pi Durable's wake
is active, the actor now keeps a pi.wake scheduled about 15 seconds ahead
and re-arms it every 7.5 seconds, cancelling the previous one. When work
ends the wake is cancelled; a stop with work still active keeps it, so the
actor wakes by itself and Pi resumes the run.

A new test runs the agent in a child process, kills it with its engine
while a tool runs, and checks that the run finishes with no call to the
actor.

pi() takes `tools` and `hooks` keyed by name. A tool's
`execute(c, args, api, context)` and every Pi Durable hook, such as
`beforeTool(c, call, api, context)`, get the actor's context first, typed
from the actor's state and vars, so a tool can read `c.key`, read and
write `c.state`, use `c.pi`, and call other actors through `c.client()`.

The harness opens with the actor's context as a context value. Pi derives
every task's context from the one it opens with, so the wrappers find the
actor after a wake and in conversations a tool creates. They are installed
as the `rivet-pi-actor` extension. `registry` is now optional and still
works alongside `tools`.

NathanFlurry commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Stack for rivet-dev/agents

Get stack: forklift get 399
Push local edits: forklift submit
Merge when ready: forklift merge 399

change ponmmwro

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

📟 Pip-Boy · 457eed2

📦 Packages · fresh npm install resolve, no lockfile · this PR vs base

No notable install size, dependency, or entrypoint changes across 10 packages.

All 10 packages · linux-x64-gnu
package (linux-x64-gnu) @latest base this PR Δ vs base packages
@rivet-dev/pi 392.5 MB 392.6 MB 392.6 MB +4.1 KB (+0.0%) 220 (0)
@rivet-dev/sandbox-adapter 114.5 KB 114.5 KB 114.5 KB 0 1 (0)
@sandbox-agent/cli-shared 27.2 KB 27.2 KB 27.2 KB 0 1 (0)
@sandbox-agent/persist-indexeddb 12.4 KB 12.4 KB 12.4 KB 0 1 (0)
@sandbox-agent/persist-postgres 12.3 KB 12.3 KB 12.3 KB 0 1 (0)
@sandbox-agent/persist-rivet 12.2 KB 12.2 KB 12.2 KB 0 1 (0)
@sandbox-agent/persist-sqlite 12.3 KB 12.3 KB 12.3 KB 0 1 (0)
@sandbox-agent/react 41.6 MB 41.9 MB 41.9 MB 0 15 (0)
acp-http-client 6.7 MB 6.7 MB 6.7 MB 0 3 (0)
sandbox-agent 31.0 MB 31.0 MB 31.0 MB 0 8 (0)

🧹 Rust dependencies

Skipped: this PR doesn't change any Rust code or dependencies.

🦀 Binaries

Skipped: this PR doesn't change any Rust code.

⏱ Timing

job wall time slowest step
changes 31s checkout · 23s
zizmor 14s checkout · 9s
footprint 2m45s Run pnpm --dir sandbox-agent install --frozen-lockfile · 55s
⏭ native · ${{ matrix.platform }} — skipped
⏭ self-test — skipped
⏭ hygiene — skipped
report 23s checkout · 10s
🔭 Full CI trace for this commit

One OpenTelemetry trace of CI and Pip-Boy for 457eed2: every job and step, with the sizes above attached. Run after CI finishes.

pnpm install --frozen-lockfile --filter 'pipboy...'
pnpm --filter pipboy pipboy trace --sha 457eed251cc3904f9cfca92a75b934961796966a

Add --otlp <url> to send it to any OTLP/HTTP collector.

Agent instruction: From a rivet-dev/agents checkout, run the commands above, then read the trace file the last command prints. List the slowest jobs and steps and explain where CI time went.

onAnswer gets the actor's context with the open harness as c.pi at
runtime, but its type was the untyped actor context. It is now typed like
the context of tools and hooks: the actor's state, vars, and key, plus
c.pi.

run, onRequest, onWebSocket, and onBeforeActionResponse now run with
c.pi like the other lifecycle hooks, and are typed with it. A workflow's
run function keeps its symbol-keyed config. The synchronous onStateChange
gets c.pi when Pi Durable is already open and never opens it. Hooks that
run before Pi Durable can open (onCreate, onMigrate, onBeforeConnect, and
the create* hooks) are unchanged.
@NathanFlurry
NathanFlurry force-pushed the stack/fix-pi-schedule-a-recovery-wake-while-pi-work-is-active-ponmmwro branch from 4e72a31 to 80c503f Compare November 16, 2026 09:20
@NathanFlurry
NathanFlurry force-pushed the stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk branch from 30a3f71 to e0ab6a0 Compare November 16, 2026 09:20
@NathanFlurry
NathanFlurry force-pushed the stack/fix-pi-schedule-a-recovery-wake-while-pi-work-is-active-ponmmwro branch from 80c503f to 6a1924b Compare November 16, 2026 09:21
RivetKit's default crash policy leaves a crashed actor asleep, and
keep-awake only lasts while the process does, so an actor that crashed
mid-run stayed asleep until something called it. While Pi Durable's wake
is active, the actor now keeps a pi.wake scheduled about 15 seconds ahead
and re-arms it every 7.5 seconds, cancelling the previous one. When work
ends the wake is cancelled; a stop with work still active keeps it, so the
actor wakes by itself and Pi resumes the run.

A new test runs the agent in a child process, kills it with its engine
while a tool runs, and checks that the run finishes with no call to the
actor.
@NathanFlurry
NathanFlurry force-pushed the stack/fix-pi-schedule-a-recovery-wake-while-pi-work-is-active-ponmmwro branch from 6a1924b to 60487f3 Compare November 16, 2026 09:33
A commit that fails while a run is going, with no call in flight, must
reopen Pi Durable at once so the run finishes. In 0.5.7-rc.1 closing the
failed harness asked it for its wake, which it refuses, so the reopen
failed and the run waited for the recovery wake about 15 seconds later.
The new test has a replay-safe tool whose first run commits a document
that storage rejects, and checks that the tool reruns within 10 seconds
and the run ends done. It fails on rc.1's runtime and passes on this
stack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eersnington
eersnington force-pushed the stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk branch from e0ab6a0 to 7ec7030 Compare November 16, 2026 12:30
@NathanFlurry

Copy link
Copy Markdown
Member Author

Superseded by #402: this PR's two commits are at the bottom of the restacked stack as 890cf76 and f2d1260 (identical patches), and #402 builds on them. #401 now stacks on #400.

@eersnington
eersnington deleted the stack/fix-pi-schedule-a-recovery-wake-while-pi-work-is-active-ponmmwro branch November 16, 2026 13:04
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