Skip to content

fix(pi): give c.pi to onAnswer and the remaining actor hooks - #400

Merged
eersnington merged 3 commits into
mainfrom
stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk
Nov 17, 2026
Merged

eersnington merged 3 commits into
mainfrom
stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk

Conversation

@NathanFlurry

@NathanFlurry NathanFlurry commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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.

onRequest, onWebSocket, and onBeforeActionResponse now run with c.pi like
the other lifecycle hooks, and are typed with it. run gets c.pi too, as a
getter only: onWake opens Pi Durable before run starts, and run is not
counted as a call, so a run that waits on Pi never holds a sleep's drain. A
workflow's run function keeps its symbol-keyed config. A workflow() body
gets its own ctx, without c.pi. onStateChange, which RivetKit 3 deprecates,
is unchanged. Hooks that run before Pi Durable can open (onCreate,
onMigrate, onBeforeConnect, and the create* hooks) are unchanged.

Every context's c.pi is one getter that reads the generation's open harness from PiRuntime, or throws why there is none:

get: () => {
  if (unavailable !== undefined) throw unavailable;
  if (runtime.status !== "open") throw piClosed(runtime.status);
  if (runtime.pi) return runtime.pi;
  throw runtime.piError ?? harnessNotOpen();
}

The getter never reads another context's c.pi, so every reader gets the same harness, also after a reopen.


This is part 5 of 6 in a stack:

NathanFlurry commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Stack for rivet-dev/agents

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

change ouynwsuk

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

📟 Pip-Boy · 08f8838

📦 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.6 MB 392.6 MB 392.6 MB +6.8 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
zizmor 18s checkout · 10s
changes 19s checkout · 13s
footprint 3m25s Run pnpm --dir sandbox-agent install --frozen-lockfile · 1m14s
⏭ hygiene — skipped
⏭ self-test — skipped
⏭ native · ${{ matrix.platform }} — skipped
report 26s checkout · 14s
🔭 Full CI trace for this commit

One OpenTelemetry trace of CI and Pip-Boy for 08f8838: 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 08f8838252503d98baaf2a35565db77ce9328ad7

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.

@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 changed the title fix(pi): type onAnswer's context with c.pi and the actor's state fix(pi): give c.pi to onAnswer and the remaining actor hooks Nov 16, 2026
@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
@eersnington
eersnington force-pushed the stack/feat-pi-define-tools-and-hooks-like-actions-with-the-actor-s-context-lsnzrvrm branch from 1a1207d to 3c425ed Compare November 16, 2026 12:30
@eersnington
eersnington force-pushed the stack/feat-pi-define-tools-and-hooks-like-actions-with-the-actor-s-context-lsnzrvrm branch from 3c425ed to 63fcdd4 Compare November 17, 2026 14:12
@eersnington
eersnington force-pushed the stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk branch from 7ec7030 to b0ed8a4 Compare November 17, 2026 14:12
@eersnington
eersnington force-pushed the stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk branch from b0ed8a4 to 27e5cb7 Compare November 17, 2026 16:14
Base automatically changed from stack/feat-pi-define-tools-and-hooks-like-actions-with-the-actor-s-context-lsnzrvrm to main November 17, 2026 17:06
Nathaneil Flurry and others added 3 commits November 17, 2026 21:07
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.
A tool that wrote c.state ran onStateChange with the context tools share.
withOpenPi then gave that context a pi getter that read itself, and every
later c.pi read overflowed the stack.

- Every context's c.pi is now one getter that reads the generation's open
  harness, or throws why there is none.
- withOpenPi and withUnavailablePi are gone.
- run gets only the c.pi getter. As a counted call it lasted the whole
  generation, so a run that waits on Pi held every sleep until the drain
  deadline.
- onStateChange no longer gets c.pi support. RivetKit 3 deprecates it, and
  the context that wrote the state already has c.pi.
- The onAnswer typing test checks c.vars instead of the deprecated c.state.
@eersnington
eersnington force-pushed the stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk branch from 27e5cb7 to 08f8838 Compare November 17, 2026 17:07
@eersnington
eersnington merged commit ce882b8 into main Nov 17, 2026
11 checks passed
@eersnington
eersnington deleted the stack/fix-pi-type-onanswer-s-context-with-c-pi-and-the-actor-s-state-ouynwsuk branch November 17, 2026 18:09
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.

2 participants