Skip to content

feat(pi): add optional native RPC subprocess sessions - #465

Merged
stamp-build[bot] merged 8 commits into
mainfrom
agent/otter/pi-rpc
Oct 26, 2026
Merged

stamp-build[bot] merged 8 commits into
mainfrom
agent/otter/pi-rpc

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Otter from open-agent-runtime opened this pull request through Stamp
View in Stamp →


Hosts can choose createPiRuntime({ execution: "subprocess" }) to run each Pi session in Pi's own RPC process. The existing in-process SDK remains the default. The same options object configures execution, project trust and package installation. A host can supply an executable and literal prefix arguments for its own Pi subcommand; opening checks the selected Pi version against OAR's dependency before starting the session.

The adapter reuses Pi's event projection, reads native context usage after every settled turn, keeps withdrawable inputs in OAR, resumes by the full native session path, and loads session MCP servers through a private native extension. The extension is materialized from bundled source so a single-file host needs no adjacent OAR files. MCP credentials never enter argv. Provider redaction keys travel over a private fd 3 pipe; the native hook waits for the parent to register each key before allowing provider output. Keys never pass through a temporary file or RPC stdout. Disposal gives stdin EOF time to run native shutdown hooks before bounded process-tree cleanup.

Both execution modes use the same project-package preflight and typed refusal. Missing packages that would require an unapproved installation reject before either the RPC version probe or session process starts. The preflight uses the SDK already needed to resolve native session paths; it does not load or execute extensions in the host. Native --approve and --no-approve select trust for this process without changing the persistent trust store. RPC also passes --offline by default as protection against package-store changes after preflight. Explicit allowProjectPackageInstall: true removes that forced flag; it does not override a native PI_OFFLINE policy. Documentation distinguishes the host preflight environment from child-only environment overrides.

Both locations reset builtins to current defaults and honor current exclusions. Resume accepts the supplied cwd and its physical path within the same session directory, preserving native RPC sessions when a subprocess resolves a directory symlink, including macOS /var. Native RPC still differs when restoring default-inactive extension tools and unresolved historical names; the documentation and regression tests state those limits explicitly. Installation and independent inventories still describe the bundled SDK. Arbitrary RPC launch flags are refused. A single-file host without a resolvable bundled entry receives an actionable error requesting an explicit command. The same PR adds the Placement design rationale to system.md.

Validation on Linux with Pi 1.4.0 and local scripted providers, without account use:

  • Complete check and build pass. The final combined revision passes 2,046 unit tests and 19 mock behavior cases.
  • All eight shared behavior backends pass, including Qwen, Qoder and Pi RPC.
  • All 69 applicable RPC vendor tests pass. The 20 project-policy and package-resolution cases also pass through the SDK. These cover missing-package refusal, untrusted installed packages, default no-install behavior and unchanged trust files. The untrusted-project case failed before the integration fix and passed afterward.
  • Earlier RPC validation passed all 63 applicable SDK vendor cases and proved that a session created through a linked cwd resumes through both RPC and the SDK.
  • A bundled host outside the repository opened the selected native CLI, completed a turn and read native context usage without adjacent dependencies. This tests a JavaScript bundle, not a Node-free operating system.

Original failures remain part of the evidence. macOS first exposed a physical-cwd session-header mismatch, reproduced locally before the fix. Windows then exposed a test assumption about junction and short-path resolution; the regression now compares with the cwd reported by an actual child. A clean-install run failed with npm ECONNRESET. The first fd 3 implementation hung on Windows; Node's documented overlapped handle and stderr-bearing startup errors fixed that, with Windows native and behavior checks passing on the corrected revision. The previous head also encountered the Claude MCP-catalog test race, subsequently addressed by the separately merged test change. None of those failures is treated as evidence that an unrun platform passed.

The first local combined-policy attempt inherited Raft's PI_PACKAGE_DIR and reported its host package version instead of Pi's version. That failure was retained; the Pi-specific rerun removed the host override without changing the product version check. Cross-platform CI must validate the final rebased head.

The native probe is reproducible under experiments/pi-rpc-native/, with source observations pinned to upstream Pi v1.4.0 (4a080252). The project-policy suites are shared by both execution modes. Pi RPC system-prompt transport through private files remains the separately requested follow-up after this PR merges.

Rebased onto main 7d4e4f1, including the merged Windows auxiliary process cleanup in #486. The only manual conflict was the experiment index; both entries are retained. The process-tree exit guard and hidden taskkill window remain intact. The combined head passed the full check, build, all eight behavior backends and all 69 applicable RPC vendor cases again. The first combined lint run reported a 301-line process helper; shortening its comment restored the 300-line limit without changing behavior. Current head: 990ebd77b4538dc66406d0f7aef7fe669150b3e8; renewed exact-head review and final CI are required.

@stamp-build
stamp-build Bot force-pushed the agent/otter/pi-rpc branch 3 times, most recently from 1bb02ea to c661fcd Compare October 23, 2026 20:12
stamp-build Bot added a commit that referenced this pull request Oct 23, 2026
<!-- stamp:review:v1 -->
<sup><img
src="https://cdn.slock.ai/avatars/6aabf32c-20bc-4cba-b55a-2aa72b60999b/8ba4452ceb890f1930886ef4286fdb99.webp"
width="16" height="16" align="absmiddle" alt=""> <b>Otter</b> from
open-agent-runtime opened this pull request through
Stamp</sup><br><sup><a
href="https://stamp.build/review?receipt=prc_8f30a5411a7b6a3069f525c9e38e2310"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp
→</a></sup>

---
<!-- /stamp:review:v1 -->

The Claude MCP vendor test waited until the server received tools/list,
then assumed the client had already applied its response. On Windows in
PR #465, the next model request still carried the old searchable catalog
while the later beta call succeeded. The original failure is retained at
https://github.com/botiverse/oar/actions/runs/40017462477/job/120633113380.

The test now waits for the model-visible replacement catalog through
bounded probe turns. Every request and observed catalog remains
available as evidence, and a failed native turn fails immediately. The
existing assertions for search results, loaded schemas, removal and
actual host calls are unchanged. The runtime documentation distinguishes
server receipt from client application. There is no adapter wait or
retry.

Validation: the native test passes with Claude 2.1.309; full check and
build pass on current main c6a2ca7. This independent test fix will be
merged before rebasing PR #465.

Co-authored-by: Otter <[email protected]>
stamp-build Bot added a commit that referenced this pull request Oct 26, 2026
…ly (#473)

<!-- stamp:review:v1 -->
<sup><img
src="https://cdn.slock.ai/avatars/6aabf32c-20bc-4cba-b55a-2aa72b60999b/8ba4452ceb890f1930886ef4286fdb99.webp"
width="16" height="16" align="absmiddle" alt=""> <b>Otter</b> from
open-agent-runtime opened this pull request through
Stamp</sup><br><sup><a
href="https://stamp.build/review?receipt=prc_660e05b2159d8a49ddb6bbe6074f6522"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp
→</a></sup>

---
<!-- /stamp:review:v1 -->

Pi session startup currently records persistent project trust and can
install configured packages without a host decision. Claude also passes
explicit system prompts in argv, exposing their contents and exceeding
Windows command-line limits for long prompts.

**Breaking:** Pi now preflights native package resolution. When it
reports installation or replacement is needed, opening fails with
`RuntimeFailureError`, `failure: "invalid_request"`, and `code:
"project_packages_blocked"`. The reason lists the packages and two
remedies: start the host with native `PI_OFFLINE=1`, or explicitly
permit installation with `createPiRuntime({ allowProjectPackageInstall:
true })`. This is never a `cwd` or missing-session refusal. Installed
compatible packages continue to load normally.

`createPiRuntime({ projectTrusted, allowProjectPackageInstall })`
applies the same policy to sessions, model listing and inventories.
Trust is local to each operation; OAR never writes `trust.json`. Native
untrusted mode suppresses project settings, packages and extensions. The
native preflight callback has no scope, so the conservative rule covers
the full native package list, including unrelated user packages. OAR
neither duplicates Pi's resolver nor changes the host environment. Pi
1.4.0 exposes no per-load offline mode in its SDK: the preflight does
not lock the package store against concurrent changes. Native offline
mode is the stronger no-install guarantee. Public option types live
separately so #465 can combine execution and project options in one
factory object.

Claude uses native prompt-file flags with private temporary files and
cleanup on exit or startup failure. Explicit empty prompts are
preserved. A real-runtime regression verifies both multiline prompts
above the Windows command-line limit in the actual provider request.

Validation: 19 Pi policy and resolution cases pass, including installed
compatible/incompatible versions, missing packages, all three policies,
user-package inheritance, conservative user-package refusal, untrusted
inventories and exact native offline parsing. A direct native probe
confirms that an existing directory with an incompatible version still
triggers installation; the public preflight detects it without executing
extensions. The revised behavior regressions fail on the prior PR head.
The full Pi vendor suite passes (82 tests); the unchanged Claude native
suite passed earlier (52 tests), including long prompt transmission.
After rebasing onto main `d74c409`, the 20 directly affected native
regressions, all seven behavior backends, `CI=1 pnpm run check`, and
build pass. CI at `39d1563` initially passed 22 of 23 jobs; Windows
Qoder timed out during native initialize. That failure remains recorded
in the run history.

The Pi RPC portion follows #465. No release or version bump.

Rebased onto main `ef54cd6` as `b3f99ce`, incorporating the merged Qoder
initialization fix. Both topic patches are unchanged. The complete local
check passed again (2,036 unit tests and 19 mock behavior cases); CI is
running for this head.

---------

Co-authored-by: Otter <[email protected]>
@stamp-build
stamp-build Bot force-pushed the agent/otter/pi-rpc branch from c661fcd to 990ebd7 Compare October 26, 2026 12:29
@stamp-build
stamp-build Bot merged commit 5ebed50 into main Oct 26, 2026
27 checks passed
@stamp-build
stamp-build Bot deleted the agent/otter/pi-rpc branch October 26, 2026 12:43
@stamp-build stamp-build Bot mentioned this pull request Oct 26, 2026
stamp-build Bot added a commit that referenced this pull request Oct 26, 2026
<!-- stamp:review:v1 -->
<sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg"
width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from
open-agent-runtime opened this pull request through
Stamp</sup><br><sup><a
href="https://stamp.build/review?receipt=prc_48e1b9abd98c4e88cea55ad400f97394"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp
→</a></sup>

---
<!-- /stamp:review:v1 -->

## Breaking changes

### Resume no longer accepts prompts the runtime ignores (#469)
Measured on Claude 2.1.309 and Codex 0.164.0: when resuming, Claude
ignores `systemPrompt` and `appendSystemPrompt`, and Codex ignores
`appendSystemPrompt` (a replacement `systemPrompt` does take effect on
Codex). OAR used to send them anyway, so the prompt was silently
dropped. These cases now fail with `UnsupportedOptionError` before any
process starts, for any explicit value, including the same text the
session was created with and `""`.

**Host note:** on resume, omit the refused options; the session keeps
the prompt it was created with. To change it, open a new session, or
deliver the change as input. Codex resume still accepts `systemPrompt`.

### Cursor: OAR no longer changes `process.env` (#469)
OAR used to set `CURSOR_TREE_SITTER_VENDOR_DIR` and
`CURSOR_RIPGREP_PATH` in the host's process environment before loading
the Cursor SDK. It no longer does. The new `cursorNativeEnvironment()`
returns those two absolute paths (or null) without changing anything.

**Host note:** with a non-hoisted layout (pnpm, a bundled entry), apply
it before loading the SDK, for example `Object.assign(process.env,
cursorNativeEnvironment() ?? {})`, or set the two paths yourself.
Without them the SDK's shell parsing degrades and its ripgrep lookups
can fail with `Ripgrep path not configured`.

### Cursor: `authStatus()` is `unknown` while `CURSOR_API_KEY` is set
(#477)
Cursor's status call describes only the SDK's stored login, but sessions
use `CURSOR_API_KEY` when it is set. `authStatus()` now returns
`unknown` in that case, with a detail saying so, instead of reporting
the stored login's state and identity. It neither reads nor validates
the environment key.

### Pi: no silent package installs, no persistent trust (#473)
Opening a Pi session no longer writes a trust grant into the user's Pi
`trust.json`; project trust lasts for that open only. When Pi's own
preflight reports that its configured package list (project or user)
would install or replace packages, opening now fails with
`RuntimeFailureError` code `project_packages_blocked` and lists those
packages, instead of installing them from the network inside the host
process. The same check makes Pi's `listModels` answer `unsupported` and
its inventories `query_failed`, with the blocked-package reason. The
rule is deliberately conservative, and it is the same for in-process and
subprocess (`execution: "subprocess"`, #465) sessions; subprocess
sessions also start Pi with `--offline` unless installation is allowed.
With `PI_OFFLINE` set, OAR emits an `OAR_PI_PACKAGE_MISSING` process
warning for each configured project package it cannot locate.

**Host note:** start the host with `PI_OFFLINE=1`, or create the runtime
with `createPiRuntime({ allowProjectPackageInstall: true })`.
`createPiRuntime({ projectTrusted: false })` opens without loading
project configuration or extensions, for directories you do not trust.

### Pi: an empty `systemPrompt` is refused (#488)
`systemPrompt: ""` used to open and silently got Pi's default prompt,
because Pi treats an empty custom prompt as absent. It now fails with
`UnsupportedOptionError`, in process and in a subprocess.
Whitespace-only prompts still replace the base prompt, and
`appendSystemPrompt: ""` is unaffected.

### TypeScript: `DeliverOptions` and `DeliverWhen` (#467)
`DeliverWhen` gained `"interrupt"`, and `DeliverOptions` is now a union
type alias rather than an interface. Code that passes a variable of type
`DeliverWhen` as `when` must also handle `maxWaitMs` for the interrupt
case, and an `interface ... extends DeliverOptions` must become an
intersection type.

## New

### Qwen Code runtime (#464)
`qwen` joins `defaultRuntimes`, driven through Qwen Code's native
stream-json control protocol (the interface its own SDKs use). Model
readback from each turn's init, effort only as Qwen reports it, explicit
full-auto approval mode, session MCP over the initialize request (never
on the command line), resume, system prompts. No steer (mid-turn input
is queued by OAR, so withdraw works), text-only input, `outputSchema`,
`serviceTier` and `name` refused. No login member, because Qwen removed
its native auth command: configure a provider through environment
variables such as `OPENAI_API_KEY`, `OPENAI_BASE_URL` and
`OPENAI_MODEL`. Usage after a resume is reported as unknown, because
Qwen reports cumulative totals with no session baseline. New entry point
`@botiverse/oar/runtimes/qwen`.

**Known native limit:** several Qwen sessions in the same home contend
for its extension-store lock; a first turn can wait or fail with
`Extension store is busy`. See the Qwen runtime docs.

### Qoder CLI runtime (#466)
`qoder` joins `defaultRuntimes`, driven through Qoder's native
stream-json control protocol. Installation through Qoder's own
installer, login through `qodercli login` (the link is handed to the
host; `openBrowser: false` supported), status through `qodercli status`,
model and effort readback (effort through `get_settings`), full-auto
permission mode, resume (new prompts on resume take effect), session MCP
and system prompts through private files, credits-exhausted errors
classified as billing. Account details from private responses never
enter records. Steer through native `priority: next` user messages
(joins at a tool boundary, or follows a text-only turn), with
`--replay-user-messages` echoing each input's id (#478). Session
`initialize` gets 60 seconds on every platform, because Qoder
initializes its built-in plugins on every open: measured 7 to 25 seconds
per session open (#476). Verified with the real `qodercli` binary and
its native fake-response reader; a real successful turn against Qoder's
service is still pending account credits. Any `qodercli` command,
including OAR's version probe, can unpack Qoder's native files under
`~/.qoder`. New entry point `@botiverse/oar/runtimes/qoder`.

Hosts using the default registry now also probe for `qwen` and
`qodercli`.

### Qwen installation (#470)
`install` and `installPlan` for Qwen use Qwen's official standalone
installer without editing shell profiles; the installation probe uses
`qwen --version`. On Windows, Qwen's and Qoder's `installPlan` return
the vendor's instructions instead of running an installer.

### Pi out of process (#465, #487)
`createPiRuntime({ execution: "subprocess" })` runs each Pi session in
its own process through Pi's native RPC mode, with the same bundled Pi
version (checked at every open). A single-executable host passes
`command` and `args` for its own Pi subcommand. Per-turn context usage
comes from Pi's `get_session_stats`. Session MCP configuration goes
through a private file, never the command line; provider keys travel
over a private pipe and never touch the command line or disk; system
prompts go through private files that OAR reads back before starting the
process (#487). Subprocess sessions refuse `launchArgs`. Pi's
`installation`, `listModels` and inventories still inspect the bundled
SDK. The in-process SDK remains the default. Resume in both modes also
finds sessions stored under the symlink-resolved working directory. The
design rationale is in docs/design/system.md, "Placement".

### Sessions without the user's own configuration (#475)
`SessionOptions.userConfiguration: "exclude"` opens a session that skips
user-level plugins, skills, commands, agents, MCP servers, hooks, memory
and settings, while keeping the user's existing login and native session
history. Host-provided options (MCP servers, prompts, directories) still
apply. Supported on Claude (native setting sources, strict MCP, memory
exclusion; login and token refresh verified, sessions resume across both
modes) and Cursor (the SDK reads no user configuration). On Claude,
`exclude` refuses `launchArgs` that set `--setting-sources`,
`--settings` or `--strict-mcp-config`, and refuses working directory and
home combinations whose symlink or junction resolution would load user
files as project files. Every other runtime refuses `exclude` with
`UnsupportedOptionError`: Codex and Kimi keep history in the same home
as configuration, and a separate home breaks resume or splits history.
The default, `include`, is unchanged.

### Orientation (#477)
`orient(registry, { depth, runtimes, include, timeoutMs, signal })`
reads installation, login status, provider metadata, account usage and
model lists in one bounded snapshot (60 seconds by default), without
opening a session or submitting a prompt. `include: ["customization"]`
adds user skill, command, MCP and tool counts. `usability(snapshot, {
minVersions })` from `@botiverse/oar/observe` turns that snapshot into a
per-runtime yes or no with a reason; version floors are the host's to
supply. CLI: `oar orient [runtime...] --depth --json --customization
--timeout`.

`local` (the default depth) runs only auth readers declared not to touch
the network, refresh credentials or run key commands
(`AuthStatusReader.localOnly`). Today that is Cursor; Claude, Codex and
Qoder login status is reported as skipped at `local` and read at
`account`. `account` can refresh native credentials and run a configured
`apiKeyHelper`; `models` can start native processes. See
docs/spec/orientation.md.

Supporting additions: `Runtime.providers` (Pi's stored provider
metadata), `ProviderAuthFacade.listProviders({ resolve: false })` to
read it without resolving credentials, and `LoginAccount.credential`
(`account` or `api_key`) and `metering` (`plan` or `usage`), filled in
by Claude, Codex and Cursor. Codex `authStatus` now also recognizes its
`API key configured` output.

### Interrupt delivery for runtimes without steer (#467)
`session.deliver(input, { when: "interrupt", maxWaitMs, merge })` steers
when the runtime can. Otherwise it waits for running root tools (up to
`maxWaitMs`), takes back every held input, aborts, waits for the
runtime's own turn end, and sends one merged prompt (default merge:
inputs joined by a blank line). The result lists `mergedInputIds`, or
returns every input in `undeliveredInputIds` on failure. The merged
prompt record lists the earlier inputs it delivers in `carries`;
conversation views show each input once in that turn. `prompt({ carries
})` is validated: every carried input must be a withdrawn input of the
same session and agent. While an interrupt batch is pending, other
`deliver()` calls on that session wait for it.

## Behavior changes
- Records a session appends from inside a record observer's callback are
now delivered to observers after the current record, in sequence order,
instead of immediately inside that callback (#467).

## Fixes
- Claude: system prompts are passed through private files (0600 on
POSIX) instead of the command line, so they are not visible in process
lists and are not limited by the Windows command-line length (#473).
- Claude `listModels` no longer starts the user's hooks or MCP servers;
claude.ai connectors also stay off during listing (#485, carrying #483
by Oscar-Williams; issue #480).
- Windows: stopping an executable probe, an ACP terminal or an owned
Morph console now ends the whole process tree (#486, carrying #459 by
Oscar-Williams; issue #352).
- Pi: `dispose()` always settles; native abort and extension shutdown
share a 10 second bound (#469).
- Pi Durable: a missing conversation is a `SessionNotFoundError`, like
other runtimes (#469).

## Internal
- The stream-json control protocol is now one shared core used by
Claude, Qwen and Qoder; Claude's records are unchanged frame for frame
(#463).
- CI runs 26 checks (new Qwen, Qoder and Pi RPC behavior backends on all
three platforms).

Co-authored-by: Cindy <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

0 participants