Skip to content

Settle Pi prompts that an extension command handled - #7583

Merged
ymichael merged 2 commits into
get-bb:mainfrom
dillonzq:bb/issue-3792-handled-prompt
Nov 17, 2026
Merged

ymichael merged 2 commits into
get-bb:mainfrom
dillonzq:bb/issue-3792-handled-prompt

Conversation

@dillonzq

@dillonzq dillonzq commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

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 Settle Pi prompts that an extension command handled #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 Settle Pi prompts that an extension command handled #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.
    • Settle Pi prompts that an extension command handled #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 Pi provider leaves a BB turn active after a handled extension slash command #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

AGENT GENERATED

dillonzq and others added 2 commits November 15, 2026 16:05
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]>
@ymichael
ymichael merged commit 2d3335f into get-bb:main Nov 17, 2026
86 of 88 checks passed
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.

Pi provider leaves a BB turn active after a handled extension slash command

2 participants