Repository navigation
Conversation
Pi 0.99+ replies to an RPC prompt with disposition "handled" when an extension command or input handler consumed it without starting a run. BB waited for agent_end, so the thread stayed Working until the 120s start timeout. Settle the prompt on that reply unless the handler itself started a run, which still settles the turn. Fixes #3792 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This is an automated message. We have closed this pull request because it has been open for more than two weeks. |
|
Thank you for this, and for using Pi's explicit disposition. One case still ends the turn too early. The PR says a run started by the command reaches bb before the
|
## Human comments ## What was wrong `PiRpcSession.prompt()` settles a BB turn only when an agent run ends (`agent_end`, or `agent_settled` through the BB extension). When an extension command or an `input` handler consumes the prompt, Pi starts no run and emits neither event, so the settlement never resolves. The thread stays Working until `provider_turn_start_timeout` (120s), and stopping it kills Pi along with the command's in-memory state. Since Pi 0.99.0 the RPC `prompt` reply states this outcome as `data.disposition: "handled"` (`"queued"`/`"started"` otherwise), but BB discarded the reply data. Reported in #3792. A handled reply alone does not mean no run follows. A command handler that calls `pi.sendMessage(..., { triggerTurn: true })` does not await it, and `_startRun` awaits `_prepareRun` before it emits `agent_start`, so the `handled` reply reaches BB before the run's `agent_start` (Pi 1.5.2, `core/extensions/loader.js:311`, `core/agent-session.js:1487`). ## What changed - `plugins/provider-pi/src/bridge/rpc-session.ts`: the prompt dispatch helpers return Pi's reply data. When the reply says `handled`, or has no disposition (Pi before 0.99), BB asks Pi for `get_state`. It settles the prompt at once only when no `agent_start` arrived since dispatch and `isStreaming` is false; then it removes that prompt's own settlement by identity, clears processing, delivers the events already received, and settles as completed. `_startRun` sets the run active synchronously, so a run the handler started reports `isStreaming: true` and the turn settles at that run's end as before. If `get_state` fails, BB keeps waiting for the run as before. - Known limit: a handler that calls `pi.sendUserMessage()` reaches `_startRun` only after Pi's async input handlers and auth check, and `get_state` does not report that preflight. If it outlasts the `get_state` round trip, the turn settles before that run starts. Not reproduced. - This replaces #6631 (closed by the stale bot), rebased on current `main`, and follows its review: use the explicit disposition plus `get_state` `isStreaming`, instead of a timing guess. Pi versions older than 0.99.0 send no disposition, so BB runs the same `get_state` check for any reply that does not say `started` or `queued`. Every supported version before 0.99 (0.84.0–0.87.1) writes the prompt reply and then sets the run active synchronously (`preflightResult(true)` followed by `_runAgentPrompt`, which sets `_isAgentRunActive` before its first await), so a prompt that started a run still reports `isStreaming: true`. - No server/daemon wire fields, SDK, CLI, or configuration change; no `HOST_DAEMON_PROTOCOL_VERSION` bump. ## How you verified - New tests in `rpc-session.settlement.test.ts`: - A handled prompt with `isStreaming: false` settles, with and without extension settlement support, and a later normal run still settles at its own end. - The turn waits for the run when Pi replies `handled` before the command's `agent_start` (`isStreaming: true`), when the run started before the reply, when the run starts and ends while Pi answers `get_state`, when `get_state` fails, and when the reply has no disposition. - The same settle test with a reply that has no disposition (Pi before 0.99). With only the `handled` check, both of those cases time out. - On `main`, both handled-prompt cases time out. With #6631's logic (no `isStreaming` check), the "reply before `agent_start`" case settles `{}` while the run is active. - A real Pi 1.5.2 subprocess, driving `PiRpcSession.start()` with an isolated `PI_CODING_AGENT_DIR`, a local OpenAI-compatible stub model, and an extension with `/return-now` (only `pi.appendEntry`) and `/start-run` (`pi.sendMessage(..., { triggerTurn: true })`), run as a temporary uncommitted vitest file: - `main`: each prompt is still pending after 10s. - #6631's logic: Pi sends the `handled` reply for `/start-run` before `agent_start`. The prompt settles `{}` at once, and the run's settlement then resolves the next `/return-now` instead. - This change: `/return-now` settles `{}` after `get_state` reports `isStreaming: false`. `/start-run` gets `isStreaming: true` and settles `{"boundaryDelivered":true}` after `agent_end` and `agent_settled`. The next `/return-now` settles `{}`. - Live, in a source dev app with `BB_PI_BRIDGE_COMMAND` pointing at Pi 0.85.1 (the version in #3792) and the same extension: with only the `handled` check, `/return-now` stays Working. With this change it settles within 2s, `/start-run` waits for its run and shows `started-by-command`, a plain prompt replies `ok`, and a second `/return-now` settles; 4 turns started and 4 completed. - `pnpm exec turbo run test typecheck --filter=bb-plugin-provider-pi`: 359 tests passed, 5 skipped; typecheck passed. `lint` and `lint:type-aware` passed. Fixes #3792 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Michael Yong <[email protected]>
Human comments
What was wrong
PiRpcSession.prompt()settles a BB turn only when an agent run ends (agent_end, oragent_settledthrough the BB extension). When an extension command or aninputhandler consumes the prompt, Pi starts no run and emits neither event, so the settlement never resolves. The thread stays Working untilprovider_turn_start_timeout(120s), and stopping it kills Pi along with the command's in-memory state. Since Pi 0.99.0 the RPCpromptreply states this outcome explicitly asdata.disposition: "handled"("queued"/"started"otherwise), but BB discarded the reply data. Reported in #3792; real Pi 1.4.0 RPC output for a handled command is{"type":"entry_appended",...}followed by{"type":"response","command":"prompt","success":true,"data":{"disposition":"handled"}}, with no agent events.What changed
plugins/provider-pi/src/bridge/rpc-session.ts: the prompt dispatch helpers return Pi's reply data. When the reply sayshandledand noagent_startarrived since dispatch, that prompt's own settlement is removed by identity, processing is cleared, already-received events are delivered, and the prompt settles as completed. If the command handler started a run itself (for examplepi.sendMessage(..., { triggerTurn: true })), that run's start precedes the reply, so the turn still settles at the run's end as before.get_stateprobe, unlike the closed Fix Pi turns staying active after handled extension commands #4066. Pi versions older than 0.99.0 send no disposition and keep the existing behavior, so this bug remains on them (the repo pins 0.84.0 as the minimum supported).HOST_DAEMON_PROTOCOL_VERSIONbump.How you verified
rpc-session.settlement.test.ts: a handled prompt settles with and without extension settlement support, followed by a normal run that settles at its own end. A handled command that started a run, and a reply without a disposition, both still wait for the run. Before the fix, both handled-prompt cases time out with the settlement pending; after the fix they pass.PI_CODING_AGENT_DIRwith an extension whose/return-nowhandler only callspi.appendEntry), driving the actualPiRpcSession.start()andprompt("/return-now")twice. Unfixed code fails withexpected 'pending' to deeply equal {}; with the fix both prompts settle as{}. This was a temporary local test run directly with vitest, because Turbo strips the agent-dir env var; it was not committed.pnpm exec turbo run test typecheck --filter=bb-plugin-provider-pi: 331 tests passed, 8 skipped, typecheck passed.Fixes #3792
🤖 Generated with Claude Code