Repository navigation
Settle Pi prompts that an extension command handled - #7583
Merged
Merged
Conversation
Pi 0.99+ replies to an RPC prompt with disposition "handled" when an extension command or input handler consumed it. BB waited for agent_end, so a command that started no run left the thread Working until the 120s start timeout. A handler can also start a run without awaiting it, and that run's agent_start reaches BB after the handled reply. After a handled reply, ask Pi for get_state and settle the prompt only when no run started and Pi is not streaming; otherwise wait for the run. Fixes #3792 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pi before 0.99.0 replies to an RPC prompt without a disposition, so a prompt an extension command or input handler consumed still left the thread Working on Pi 0.84-0.87. Run the get_state idle check for any reply that does not say Pi started or queued a run. Every supported Pi (0.84.0-0.87.1) sets the run active synchronously right after it writes the prompt reply, so a started run reports isStreaming: true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asdata.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_startRunawaits_prepareRunbefore it emitsagent_start, so thehandledreply reaches BB before the run'sagent_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 sayshandled, or has no disposition (Pi before 0.99), BB asks Pi forget_state. It settles the prompt at once only when noagent_startarrived since dispatch andisStreamingis false; then it removes that prompt's own settlement by identity, clears processing, delivers the events already received, and settles as completed._startRunsets the run active synchronously, so a run the handler started reportsisStreaming: trueand the turn settles at that run's end as before. Ifget_statefails, BB keeps waiting for the run as before.pi.sendUserMessage()reaches_startRunonly after Pi's async input handlers and auth check, andget_statedoes not report that preflight. If it outlasts theget_stateround trip, the turn settles before that run starts. Not reproduced.main, and follows its review: use the explicit disposition plusget_stateisStreaming, instead of a timing guess. Pi versions older than 0.99.0 send no disposition, so BB runs the sameget_statecheck for any reply that does not saystartedorqueued. 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_isAgentRunActivebefore its first await), so a prompt that started a run still reportsisStreaming: true.HOST_DAEMON_PROTOCOL_VERSIONbump.How you verified
rpc-session.settlement.test.ts:isStreaming: falsesettles, with and without extension settlement support, and a later normal run still settles at its own end.handledbefore the command'sagent_start(isStreaming: true), when the run started before the reply, when the run starts and ends while Pi answersget_state, whenget_statefails, and when the reply has no disposition.handledcheck, both of those cases time out.main, both handled-prompt cases time out. With Settle Pi prompts that an extension command handled #6631's logic (noisStreamingcheck), the "reply beforeagent_start" case settles{}while the run is active.PiRpcSession.start()with an isolatedPI_CODING_AGENT_DIR, a local OpenAI-compatible stub model, and an extension with/return-now(onlypi.appendEntry) and/start-run(pi.sendMessage(..., { triggerTurn: true })), run as a temporary uncommitted vitest file:main: each prompt is still pending after 10s.handledreply for/start-runbeforeagent_start. The prompt settles{}at once, and the run's settlement then resolves the next/return-nowinstead./return-nowsettles{}afterget_statereportsisStreaming: false./start-rungetsisStreaming: trueand settles{"boundaryDelivered":true}afteragent_endandagent_settled. The next/return-nowsettles{}.BB_PI_BRIDGE_COMMANDpointing at Pi 0.85.1 (the version in Pi provider leaves a BB turn active after a handled extension slash command #3792) and the same extension: with only thehandledcheck,/return-nowstays Working. With this change it settles within 2s,/start-runwaits for its run and showsstarted-by-command, a plain prompt repliesok, and a second/return-nowsettles; 4 turns started and 4 completed.pnpm exec turbo run test typecheck --filter=bb-plugin-provider-pi: 359 tests passed, 5 skipped; typecheck passed.lintandlint:type-awarepassed.Fixes #3792
🤖 Generated with Claude Code