Skip to content

ACP: thread/stop answers { ok: true } but the turn still runs when it arrives during a session start or settings rebuild #6912

Open

Description

@Willhong

Summary

On an ACP thread, if I change an execution setting that forces an agent restart (permission mode, launch-time model/reasoning, or env vars) and press Stop right after sending the message, the stop is acknowledged but the agent still receives the message and finishes the turn. The same gap exists for a brand-new thread: a stop sent while thread/start is still launching the agent is acknowledged, and the thread comes back with a live agent. I expected the stop to cancel the pending turn or start.

Versions and environment

  • bb from source at main dbb247c60f46494579adb40b80efa7c8a861b35c (installed app: bb 0.48.1)
  • macOS 26.6.2, Node v25.9.0
  • Provider: any ACP agent through @bb/provider-bridge-acp. Reproduced with the bridge test suite's fake-acp-agent.mjs, not with a specific third-party agent.

Steps to reproduce

Bridge-level reproduction (deterministic):

  1. git checkout dbb247c60f46494579adb40b80efa7c8a861b35c && pnpm install
  2. Add the two tests from the details block below to packages/provider-bridge-acp/src/bridge/bridge.test.ts (inside describe("acp bridge", …)). They use only helpers and fake-agent env vars that already exist on main.
  3. pnpm exec turbo run test --filter=@bb/provider-bridge-acp (or, once that has built the dependencies, cd packages/provider-bridge-acp && pnpm exec vitest run --config vitest.config.ts src/bridge/bridge.test.ts -t "thread/stop answer" to run only these two)

User-level path (the same code path; I have not reproduced it through the UI, because the window is the agent restart time and needs precise timing):

  1. Open a thread on an ACP provider whose agent supports session/load.
  2. Change the permission mode (for example Full → Accept Edits) or a launch-time model setting.
  3. Send a message and press Stop immediately, while the bridge is still restarting the agent.
Reproduction tests
  it("sends no prompt after thread/stop answers during a session rebuild", async () => {
    const promptLog = join(workspaceDir, "rebuild-stop-prompts.log");
    const envVars = { FAKE_ACP_LOAD_SESSION: "1" };
    const { bbThreadId, providerThreadId } = await startThread({ envVars });

    const turnId = sendTurnRequest("turn/start", providerThreadId, {
      input: [{ type: "text", text: "after stop", mentions: [] }],
      options: executionOptions({
        envVars: { FAKE_ACP_PROMPT_LOG: promptLog },
        providerOptions: { acpLaunchSpec: acpLaunchSpec({ envVars }) },
      }),
    });
    const stopId = sendRequest("thread/stop", {
      threadId: bbThreadId,
      providerThreadId,
      intent: "interrupt",
      activeTurnId: null,
    });
    const stopResponse = await waitForResponse(stopId);
    expect(stopResponse.result).toEqual({ ok: true });
    const stopIndex = output.messages.indexOf(stopResponse);
    await waitForResponse(turnId);
    await new Promise((resolveTick) => realSetTimeout(resolveTick, 500));
    const acceptedIndex = output.messages.findIndex((message) =>
      deltaKindsOf(message).includes("input.accepted"),
    );

    expect({
      inputAcceptedAfterStopAnswer: acceptedIndex > stopIndex,
      promptsAfterStop: loggedPrompts(promptLog),
      turnCompleted: threadEventsOfType("turn/completed").map((e) => e.status),
    }).toEqual({
      inputAcceptedAfterStopAnswer: false,
      promptsAfterStop: [],
      turnCompleted: expect.not.arrayContaining(["completed"]),
    });
  });

  it("fails a thread/start that thread/stop answered before the session was registered", async () => {
    chmodSync(FAKE_AGENT_PATH, 0o755);
    const launchLog = join(workspaceDir, "fresh-start-stop-launches.log");
    const launch = {
      agent: { command: FAKE_AGENT_PATH, args: [] },
      modelListArgs: ["--list-models", "--fresh-start-stop"],
      selectFlag: "--model",
      envVars: {
        FAKE_ACP_LAUNCH_LOG: launchLog,
        FAKE_ACP_MODEL_LINES:
          "pinme - Pin Me\npinme-extra-high - Pin Me Extra High",
      },
    };
    nextThreadSerial += 1;
    const bbThreadId = `thread-${nextThreadSerial}`;
    const startId = sendRequest("thread/start", {
      threadId: bbThreadId,
      cwd: workspaceDir,
      instructionMode: "append",
      options: executionOptions({
        model: "pinme",
        reasoningLevel: "xhigh",
        providerOptions: launchProviderOptions(launch),
      }),
    });
    const stopId = sendRequest("thread/stop", {
      threadId: bbThreadId,
      providerThreadId: bbThreadId,
      intent: "interrupt",
      activeTurnId: null,
    });

    expect((await waitForResponse(stopId)).result).toEqual({ ok: true });
    const startResponse = await waitForResponse(startId);
    expect({
      startError: startResponse.error?.message,
      agentLaunched: existsSync(launchLog),
    }).toEqual({
      startError: `ACP session for thread "${bbThreadId}" was released during construction`,
      agentLaunched: false,
    });
  }, 20_000);

Expected vs actual

Expected: once thread/stop answers { ok: true }, the stopped message is never
prompted to the agent and the turn does not complete; a thread/start that the
stop overtook fails instead of launching an agent.

Actual on main dbb247c60f:

FAIL  src/bridge/bridge.test.ts > acp bridge > sends no prompt after thread/stop answers during a session rebuild
- Expected
+ Received
  {
-   "inputAcceptedAfterStopAnswer": false,
-   "promptsAfterStop": [],
+   "inputAcceptedAfterStopAnswer": true,
+   "promptsAfterStop": [
+     "after stop",
+   ],
    "turnCompleted": [
      "completed",
    ],
  }

FAIL  src/bridge/bridge.test.ts > acp bridge > fails a thread/start that thread/stop answered before the session was registered
- Expected
+ Received
  {
-   "agentLaunched": false,
-   "startError": "ACP session for thread \"thread-2\" was released during construction",
+   "agentLaunched": true,
+   "startError": undefined,
  }

Tests  2 failed | 207 skipped (209)

Evidence

Observed cause: startAgentSession registers the new session in sessionsByBbThreadId only after two awaits:

The thread/stop handler only looks in sessionsByBbThreadId. Between those awaits it finds no session (fresh start) or the old session that is already stopping (rebuild via reconcileExecutionSettings → rebuildAgentSession), answers { ok: true }, and nothing tells the in-flight start that it was stopped. The existing session.stopping check at the end of construction only catches stops that arrive after the session is registered.

How it was found: a TLA+ model of the per-thread session lifecycle (one start, one stop, every interleaving) produced both interleavings as counterexamples. The tests above replay them against the real bridge with the fake ACP agent. The investigation ran in a local bb thread (thr_ydkdbumzvc, not on a shared server).

What you ruled out

Suggested priority and effort

Medium: it needs a stop pressed during the agent restart or launch window, but when it hits, a turn the user stopped runs to completion with the agent's tools. I have not verified a workaround. Effort low (fix in the linked PR: one source file plus the two tests).

AGENT GENERATED

Activity

  1. added theissue type on Nov 3, 2026
  2. added
    providers
    provider-acp
    confirmed-repro
    on Nov 3, 2026
  3. bb-slop-cop commented on Nov 3, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    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-acpproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions