Skip to content

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

Closed

Description

@IlyaM

Summary

A Pi extension slash command that completes without starting Pi's main agent run leaves its BB thread active indefinitely. Subsequent input, including a command intended to cancel the extension's background work, remains blocked behind that active turn.

Pi's extension-command contract permits this command shape, so BB should settle the submitted turn after a handled command rather than requiring an agent_end event that will not occur.

Versions and environment

  • bb 0.43.0, managed installation
  • Pi 0.85.1
  • Ubuntu 26.04 LTS (x86_64), Node v22.22.1
  • Pi provider in a local project environment
  • Source inspection also checked upstream main at c024ceac524882b7bf9fbef41c14c4911919de4c

Steps to reproduce

The behavior was observed in an existing BB Pi thread. A clean, standalone reproduction on the latest main has not been run, so the following minimal fixture is unverified.

  1. In a project used by a BB Pi thread, load a Pi extension that registers a slash command whose handler completes without starting the main Pi agent run, for example:

    pi.registerCommand("return-now", {
      description: "Return without an agent turn",
      handler: async (_args, ctx) => {
        ctx.ui.notify("command handled", "info");
      },
    });
  2. Send /return-now to the BB Pi thread.

  3. Send another prompt or another extension command.

Expected vs actual

Expected: Once Pi has handled /return-now, BB marks that submitted turn complete. The next prompt or extension command can be dispatched normally.

Actual: The BB thread remains active after the command handler returns. A later command is blocked behind the active turn, so it cannot be used to control or cancel the extension's background work.

No public-safe terminal or server-log excerpt was captured for this report; the observed symptom is the persistent active turn and blocked follow-up input.

Evidence

At upstream main commit c024ceac524882b7bf9fbef41c14c4911919de4c, PiRpcSession.prompt() creates a pending run settlement before it sends Pi the RPC prompt request:

  • this.isProcessing = true;
    const tracked = this.trackPendingInputConsumption("followUp");
    const settlement = new Promise<PiPromptRunOutcome>((resolve) => {
    this.pendingRunSettlements.push({ resolve });
    });
    const settled = this.dispatchWithTransientAuthRetry(
    child,
    {
    type: "prompt",
    message: text,
    ...(images && images.length > 0 ? { images } : {}),
    streamingBehavior: "followUp",
    },
    NO_REQUEST_TIMEOUT,
    ).then(
    async (): Promise<PiPromptRunOutcome | null> => {
    if (tracked.pending.queuedText !== null) {
    this.dropRunSettlement();
    return null;
    }
    this.resolvePendingInputConsumption(tracked.pending);
    const outcome = await settlement;
    return outcome;
    },
    (error: unknown): PiPromptRunOutcome | null => {
    this.isProcessing = false;

The bridge reports the prompt settled only after that settlement resolves:

  • function startPiPrompt(
    threadSession: ThreadSession,
    threadId: string,
    text: string,
    images: ImageContent[],
    ): Promise<void> {
    const dispatch = threadSession.session.prompt(
    text,
    images.length > 0 ? images : undefined,
    );
    void dispatch.settled.then((outcome) => {
    if (outcome === null) {
    return;
    }
    reportPromptSettled({
    ...(outcome.error !== undefined ? { error: outcome.error } : {}),
    sessionSerial: threadSession.sessionSerial,
    threadId,
    });

The pending settlement is resolved in the agent_end event path:

  • if (event.type === "agent_end") {
    this.deliverInOrder(async () => {
    const leafId = await this.takeAgentEndLeaf();
    if (leafId !== null) {
    this.lastKnownLeafId = leafId;
    }
    this.onEvent({
    ...event,
    ...(this.lastKnownLeafId === null
    ? {}
    : { providerCheckpointId: this.lastKnownLeafId }),
    });
    this.settleRun(event);
    });
    return;

Pi documents agent_end as the end of a low-level agent run, while extension commands are a separate API; it also documents command handlers that call ctx.waitForIdle() and then return:

No public-safe investigation link is available.

Suggested fix

Add an explicit completion path for a Pi RPC prompt that Pi handled as an extension command and that therefore does not produce an agent run. The bridge should resolve the corresponding BB turn without waiting for agent_end. The completion signal should be explicit rather than inferred from timing, so a normal slow-starting agent run is not settled prematurely.

What you ruled out

  • This is not caused by ctx.waitForIdle() itself: Pi documents it for command handlers, and it returns immediately when no agent or compaction run is active.
  • This is distinct from closed issue Pi extension-triggered turn stays working after agent_end #1633: that issue concerned a valid agent_end event rejected by message-schema validation. Here the command intentionally produces no agent run and thus no agent_end event.
  • Searches of open and closed issues for agent_end, Pi extension commands, and Pi bridge command handling found no issue for this no-agent_end command-completion path.

Suggested priority and effort

Medium — affects any BB Pi extension whose slash command returns without starting Pi's main agent run. There is no in-thread workaround once the command has been invoked; stopping the thread is the practical recovery.

Checks

  • I reproduced the symptom in an existing BB Pi thread and clearly note that a clean reproduction on latest main is unverified.
  • I searched open and closed issues for the same command-completion path.

AGENT GENERATED

Activity

  1. added theissue type on Sep 16, 2026
  2. added
    providers
    provider-pi
    confirmed-repro
    on Sep 16, 2026
  3. bb-slop-cop commented on Sep 16, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classified as Bug · Medium priority · Medium effort; added providers, provider-pi, and confirmed-repro.

    Reproduction and root-cause report: REPRODUCED, high root-cause confidence. In two clean checkouts of trusted main, a real Pi command completed with no agent events, but BB’s settlement remained pending. The embedded regression test fails with expected 'pending' to be 'settled'.

    BB waits for agent_end, while Pi acknowledges handled commands without starting an agent run. Tested the repository’s pinned Pi 0.84.0; Pi 0.85.1 and the browser follow-up queue were not exercised.

    No PR: safely distinguishing command completion from ordinary prompt preflight requires completion-contract/design work outside this rule’s simple-fix limits.

  4. dillonzq commented on Sep 22, 2026

    @dillonzq
    Contributor

    Reproduced again on current upstream main at 18960354e462d514c0d6071ba1ed0f8f2acd625c using a real Pi 0.84.0 subprocess (the repository-pinned dependency), Node 22.23.2, and macOS 27.0. The regression uses an isolated Pi agent directory and a local extension; no model API request or Mane Control installation is needed.

    The extension registers /return-now, whose handler only calls pi.appendEntry("command-handled", {}). The test calls the actual PiRpcSession.start() and prompt("/return-now"), awaits dispatch.consumed, and then checks dispatch.settled:

    AssertionError: expected 'pending' to deeply equal {}
    

    Pi successfully acknowledges the command but emits neither agent_start nor agent_end. The unmodified bridge keeps the settlement pending. This is a subprocess/bridge reproduction, not a fresh full-UI reproduction on main.

    Separately, the same symptom occurred twice in installed BB 0.43.3 with Pi 0.87.0 and Mane Control 0.1.2. In investigation thread thr_v5vxuwc38u, /ponytail lite was followed by entry_appended with customType: "ponytail-mode" and data: { "mode": "lite" }, then:

    The provider accepted a turn but did not start it within 120s. The request may be stalled; stopping the thread interrupts it.
    

    Stopping and submitting the same command reproduced the failure. This rules out Mane Control as a necessary cause and distinguishes the issue from stalled model inference: the mode change already completed.

    Current-main code still creates a settlement and waits after the prompt acknowledgement; the normal settlement path requires agent_end.

    I am testing a fix and will link a PR, including checks that ordinary preflight acknowledgements and queued inputs are not treated as completed runs.

    AGENT GENERATED

  5. cameronm123 commented on Oct 11, 2026

    @cameronm123

    Related final-settlement contract evidence from installed BB 0.46.0 with Pi 1.1.0. This is source inspection, not a reproduction of premature completion or of this issue's handled-command symptom.

    Pi's installed RPC documentation distinguishes the events:

    agent_end marks the end of one low-level agent run, but retries, overflow recovery, compaction, steering, or follow-up work can still follow. Wait for agent_settled when the client needs to know Pi will not continue automatically.

    The installed BB Pi bridge resolves pending settlements in the agent_end path. The relevant extracted behavior is:

    if (n.type === "agent_end") {
      this.deliverInOrder(async () => {
        // Checkpoint delivery precedes settlement.
        this.onEvent(n);
        this.settleRun(n);
      });
      return;
    }
    
    settleRun(t) {
      if (t.willRetry === true) return;
      const pending = this.pendingRunSettlements.shift();
      if (!pending) return;
      // The full implementation also propagates a final assistant error.
      pending.resolve({});
    }

    The excerpt above omits checkpoint lookup and error propagation for clarity. Separately, trackProcessingState clears processing on agent_end when willRetry !== true.

    The handled-command fix and normal-run completion need distinct contracts. A prompt can complete without an agent run, as demonstrated in this issue. A low-level run can also finish before Pi has settled all continuation work. Checking only willRetry does not cover the documented continuation cases.

    For Pi versions that expose agent_settled, please consider making that event the owner of final run completion while retaining agent_end checkpoints. Bind legacy behavior to an explicit supported version or capability. This report does not claim that current upstream main still has the installed-bundle behavior.

    Suggested acceptance cases are ordinary completion, retry, overflow recovery, automatic and manual compaction, extension continuation, queued steering and follow-up work, handled input with no run, cancellation, and session shutdown. Each submitted input should produce exactly one final settlement, with no intermediate completion forwarded to automatic judges.

    No installed bundle was patched and no live failure injection was performed.

    AGENT GENERATED

  6. mlegls commented on Oct 25, 2026

    @mlegls

    Still occurs on installed BB 0.47.0 with Pi 1.4.0 (Linux). An extension command (`/edit-here`, which only sets in-memory state and calls `pi.appendEntry`) left the thread on Working until it hit `provider_turn_start_timeout` after 120s. Stopping the thread killed the Pi process, so the command's in-memory effect was also lost.

    Pi 1.4.0 already reports when no run will follow. The RPC `prompt` reply now carries a `disposition`, emitted from `AgentSession.prompt`'s `preflightResult` callback (`dist/modes/rpc/rpc-mode.js`, `dist/core/agent-session.js`):

    • `"handled"`: an extension command ran, or an `input` handler consumed the text. No agent run starts.
    • `"queued"`: queued as steer or follow-up behind a running agent.
    • `"started"`: a new run started.

    When the prompt reply's `data.disposition === "handled"`, the bridge could resolve the settlement immediately instead of waiting for `agent_end`/`agent_settled`. That separates a handled command from a normal preflight acknowledgement without any guessing on BB's side.

    Workaround for extension authors until then: have the command start a turn under BB, for example `pi.sendMessage({...}, { triggerTurn: true })`.

    AGENT GENERATED

  7. mlegls commented on Nov 13, 2026

    @mlegls

    Additional input-event case on installed bb 0.48.1: an extension consumes the first prompt with { action: "handled" } and calls pi.sendMessage({ customType, content, display: true }). The thread stayed active with no displayed response for 45 seconds; the Pi transcript retained the custom message. This appears to be the same no-agent-run settlement gap as the slash-command case, with an additional custom-message display symptom.

    Versions and environment

    • bb 0.48.1, managed installation; remote Linux worktree environment.
    • The incident did not retain the provider's exact Pi version or desktop-client OS version; these are unknown.
    • No-paid scripted provider, not a stalled live-model inference.
    • This is retained incident evidence, not a fresh reproduction against latest release or upstream main.

    Minimal fixture (unverified standalone reduction)

    Load this extension in a bb Pi project's .pi/extensions/handled.ts, then send "handled-input-repro":

    export default function (pi) {
      pi.on("input", (event) => {
        if (event.text !== "handled-input-repro") return;
        pi.sendMessage({
          customType: "handled-input-repro",
          content: "Handled without starting an agent run",
          display: true,
        });
        return { action: "handled" };
      });
    }

    Expected: display the custom message and settle the input without starting a model run.
    Observed in the original extension: no visible message and no idle transition within 45 seconds. Disposable thread thr_urdf59vqwg contained only provisioning and identity events until manual stop; its Pi transcript retained the custom message. No public-safe raw event dump was retained, so this is an observation summary rather than a verbatim log.

    Workaround and limits

    For our terminal Learn-entry refusal only, writing the refusal to stderr and calling ctx.shutdown() from the handled input makes bb record turn/failed and an Error containing the refusal. That recovers a visible terminal error, not normal completion of a handled prompt. Ordinary handled prompts still need to settle and display their response.

    No agent run is intended in this case; waiting for model output cannot resolve it. Please include input-event handlers alongside slash commands when fixing #3792. We saw #6631 closed unmerged; no claim is made here about a fix in current upstream main.

    Origin: Common Concept implementation thread thr_8f7ufg5cff; affected disposable thread thr_urdf59vqwg; reporting thread thr_53bf96e8r2. Concept source base for this report: e04f9831c577a081bc7150f818b7b466ef0db28d (not a bb source commit). No new model call or reproduction thread was started for this comment.

    AGENT GENERATED

  8. mlegls commented on Nov 24, 2026

    @mlegls

    Retested the standalone input fixture from the earlier comment on BB 0.50.1 (npm install, Linux execution host), with a local scripted Pi model. Settlement works; the displayed custom reply is still missing from the BB conversation.

    1. In a trusted disposable project, load that exact .pi/extensions/handled.ts fixture and send handled-input-repro as the first prompt. BB records turn/started, turn/input/accepted, and turn/completed (status: completed) and returns to idle. The scripted provider received no request on this turn.
    2. bb thread log <id> --all --format minimal shows the user's prompt with no response. The first-turn raw event log has no message item. Pi's session contains {"type":"custom_message","customType":"handled-input-repro","display":true,"content":"Handled without starting an agent run"} (project/session metadata omitted).
    3. Send an ordinary follow-up without stopping the runtime. It produces a visible scripted assistant reply and completes on the same Pi session. This was the only model request, handled entirely in-process by the fixture.

    So #7583 fixes the stuck-turn part of this input-handler case in 0.50.1. The remaining result here is a reply retained by Pi but absent from BB's conversation timeline. The observations above are from BB's CLI timeline and event log, not a desktop UI inspection.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproprovider-piproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions