Skip to content

Fix Pi turns staying active after handled extension commands - #4066

Closed
dillonzq wants to merge 3 commits into
get-bb:mainfrom
dillonzq:fix/pi-command-settlement
Closed

dillonzq wants to merge 3 commits into
get-bb:mainfrom
dillonzq:fix/pi-command-settlement

Conversation

@dillonzq

@dillonzq dillonzq commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Pi acknowledges handled extension commands and intercepted input without starting an agent run. BB nevertheless waited for agent_end, leaving commands such as /ponytail lite permanently Working even though the mode change had already been persisted. Reproduced on upstream main 18960354e462d514c0d6071ba1ed0f8f2acd625c; investigation evidence is in #3792.

What changed

After a successful, non-queued Pi prompt preflight, query Pi's existing get_state RPC. If Pi reports neither streaming nor compaction, finish that specific outstanding settlement. Await already-received event delivery first so an actual agent completion/error retains its outcome. The state probe races the run settlement so a hanging probe cannot delay an already-completed turn. A failed state probe preserves event-based completion instead of treating an accepted prompt as failed. Active runs and queued inputs retain their existing completion path; remove settlements by identity so an asynchronous probe cannot discard another dispatch.

Added a real Pi subprocess regression with an isolated agent directory and an in-process fixture model. It covers repeated handled commands, intercepted input, delayed normal preflight, an active model run with an injected status-probe rejection, a completed run with a deliberately unresolved probe, and queued follow-up input without making model API calls. Added an ACP regression for a plain prompt that returns only stopReason, without activity notifications.

No server/daemon wire fields, public SDK, CLI, or configuration contracts change; no host protocol version bump is required.

How you verified

  • Before the fix, the real Pi 0.84.0 subprocess regression fails with expected 'pending' to deeply equal {}. It passes with the fix.
  • Isolated source BB server/daemon with installed Pi 0.87.0: main receives ponytail-mode: lite, remains active, and emits provider_turn_start_timeout. After applying the fix and stopping/retrying the same synthetic thread, the same command produces turn/started, turn/input/accepted, and turn/completed, and the thread returns to idle. A subsequent mode change also completes. Original production threads were not modified.
  • The probe-failure regression fails before the follow-up fix because settlement completes while Pi is still streaming; after the fix it stays pending until agent_end, without invoking the session failure callback. A separate hanging-probe check fails before the follow-up race fix and now completes before the probe is released; another command then completes normally.
  • pnpm exec turbo run test typecheck --filter=bb-plugin-provider-pi: 169 tests passed, typecheck passed.
  • pnpm exec turbo run test typecheck --filter=@bb/provider-bridge-acp: 326 tests passed, typecheck passed, including the new no-activity regression.
  • pnpm exec turbo run test --filter=bb-plugin-provider-codex --filter=bb-plugin-provider-claude-code -- --run bridge.conformance.test.ts bridge.zero-work-turn.test.ts: Codex 24 tests and Claude Code's canonical protocol suite passed. Claude's suite explicitly exercises result-only completion; Codex exercises zero-work turns.

Checks ran on Node 22.23.2 / macOS 27.0. An initial broad ACP run hit the existing missing-executable test's EACCES versus ENOENT expectation with the inherited PATH; rerunning with a clean executable PATH passed. Other-provider checks use their protocol fixtures, not a claim that every external ACP agent or live Claude/Codex version was exercised. No UI code changed; full-app verification used the source CLI and persisted thread events.

Fixes #3792

AGENT GENERATED

@dillonzq
dillonzq marked this pull request as ready for review September 22, 2026 09:00
Copilot AI lite review requested due to automatic review settings September 22, 2026 09:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

A critical probe-error path can prematurely settle an active Pi run and lose its eventual completion.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes Pi turns that remain active after handled commands or intercepted input.

Changes:

  • Adds identity-safe state-based settlement.
  • Adds Pi subprocess regression coverage.
  • Adds ACP result-only completion coverage.
File Description
plugins/​provider-pi/​src/​bridge/​rpc-session.ts Implements fallback settlement logic.
plugins/​provider-pi/​src/​bridge/​rpc-session.command.test.ts Tests Pi command and queue settlement behavior.
packages/​provider-bridge-acp/​src/​bridge/​bridge.test.ts Tests ACP stopReason-only completion.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

A hanging state probe can delay an already completed turn for 30 seconds.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Race get_state probe with settlement to avoid delaying completed turns

plugins/​provider-pi/​src/​bridge/​rpc-session.ts:358

An unresponsive get_state probe now delays an otherwise completed agent turn for the full 30-second default RPC timeout: this callback cannot reach await settlement until the probe finishes, even when agent_end has already resolved the settlement. Race the probe against settlement so event-based completion remains immediate when the status RPC hangs; the existing identity check still makes the late probe safe.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The settlement race is handled safely and the relevant edge cases have comprehensive regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@dillonzq dillonzq closed this by deleting the head repository Oct 5, 2026
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