#6912 · ACP pending-session cancellation gap
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
Stop can acknowledge success while an ACP session is still being constructed, yet that construction continues and becomes live. During a settings-driven replacement, the same gap allows the pending message to reach the replacement agent and finish normally. The stop handler only sees registered sessions; the constructing replacement is not yet registered. Two newly authored bridge-level tests exercise the real bridge and its repository-owned fake ACP subprocess, and both fail with the claimed behavior in two separate clean checkouts. No UI interaction or third-party agent was tested.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Stop can miss a fresh session before registration. | Verified | The stop response is {ok:true}, but the agent launches and start resolves ready. No model-list command is needed for this reproduction. |
| Stop can miss a settings-driven rebuild and the message still completes. | Verified | A permission-CLI change forces relaunch; the fake agent logs the message and the bridge reports normal completion despite the acknowledged stop. |
| All launch-time setting variants and real-agent/UI timing behave identically. | Not individually verified | Permission-CLI relaunch was executed; other settings share the inspected rebuild path. UI, macOS, and third-party agents were not exercised. |
| The stop handler cannot address an unregistered construction. | Verified | Source and the two live subprocess reproductions agree. |
3. Environment
- Public repository get-bb/bb; fetched trusted main at
dbb247c60f46494579adb40b80efa7c8a861b35cbefore both checkouts. - Linux 4.19.0-gvisor x86_64; Node v22.19.0; pnpm 9.15.0; ACP SDK 1.7.0 from the frozen lockfile.
- Two separate temporary clones, named
firstandsecond, each installed with the frozen lockfile and built through the package-filtered Turbo dependency graph. - Both execute the repository fake ACP agent, not code supplied by the issue or a pull request. Each test creates a new temporary workspace through the existing harness and cleans its subprocesses afterward.
- No development server, shared product data, external provider credentials, browser, or application listening ports were used.
4. Minimal reproduction
The complete test block below is newly authored from trusted main, not copied from the issue or linked PR. Add it to the existing bridge test harness. It changes no production file and adds no dependency. Tests and raw logs are embedded here; they are not committed as separate files, in accordance with this public report repository's policy.
- Create a fresh trusted clone:
git clone https://github.com/get-bb/bb.git bb-stop-repro cd bb-stop-repro git checkout --detach dbb247c60f46494579adb40b80efa7c8a861b35c pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@bb/provider-bridge-acp
- Insert the complete new test block below immediately before the existing
describe("acp bridge", () => {inpackages/provider-bridge-acp/src/bridge/bridge.test.ts. Existing imports and helpers supply every dependency. Then run:git diff --check
- Run only the two new cases:
pnpm exec turbo run test --filter=@bb/provider-bridge-acp -- src/bridge/bridge.test.ts -t 'stop admission regression'
Expected: interrupted initial construction is cancelled without launching the agent; the interrupted replacement does not deliver a prompt or complete normally. Observed: both expectations fail on unchanged production code.
- "launched": false, - "outcome": "cancelled", + "launched": true, + "outcome": "ready", - "completedNormally": false, - "deliveredPrompts": [], + "completedNormally": true, + "deliveredPrompts": [ + "cancellation probe", + ], Tests 2 failed | 207 skipped (209)
In both snapshots the stop response was {"ok":true}. Complete assertion output from both runs is embedded in the appendix.
Complete new test block (77 added lines including insertion spacing)
describe("stop admission regression", () => {
it("does not admit an initial session after acknowledging interruption", async () => {
const launchFile = join(workspaceDir, "initial-session-launches.txt");
const starting = startThread({
envVars: { FAKE_ACP_LAUNCH_LOG: launchFile },
});
const threadId = `thread-${nextThreadSerial}`;
const stopping = sendRequest("thread/stop", {
threadId,
providerThreadId: threadId,
intent: "interrupt",
activeTurnId: null,
});
const stopResult = await waitForResponse(stopping);
const outcome = await starting.then(
() => "ready",
() => "cancelled",
);
expect({
acknowledged: stopResult.result,
outcome,
launched: existsSync(launchFile),
}).toEqual({
acknowledged: { ok: true },
outcome: "cancelled",
launched: false,
});
});
it("does not deliver a turn overtaken by interruption during permission relaunch", async () => {
const promptFile = join(workspaceDir, "permission-relaunch-prompts.txt");
const launch = {
envVars: {
FAKE_ACP_LOAD_SESSION: "1",
FAKE_ACP_PROMPT_LOG: promptFile,
},
permissionCli: {
full: ["--unrestricted"],
workspaceWrite: ["--workspace-only"],
insertAfterArgs: 1,
},
};
const thread = await startThread(launch);
const pendingTurn = sendTurnRequest("turn/start", thread.providerThreadId, {
input: [{ type: "text", text: "cancellation probe", mentions: [] }],
options: executionOptions({
permissionMode: "accept-edits",
providerOptions: launchProviderOptions(launch),
}),
});
const stopping = sendRequest("thread/stop", {
threadId: thread.bbThreadId,
providerThreadId: thread.providerThreadId,
intent: "interrupt",
activeTurnId: null,
});
const stopResult = await waitForResponse(stopping);
const turnResult = await waitForResponse(pendingTurn);
if (!turnResult.error) {
await waitForTurnCompleted();
}
expect({
acknowledged: stopResult.result,
deliveredPrompts: loggedPrompts(promptFile),
completedNormally: threadEventsOfType("turn/completed").some(
(event) => event.status === "completed",
),
}).toEqual({
acknowledged: { ok: true },
deliveredPrompts: [],
completedNormally: false,
});
});
});
5. Root cause
Construction first awaits shutdown of an existing session before the replacement has an identity in the session map:
async function startAgentSession(
request: AcpSessionStartRequest,
): Promise<AcpThreadSession> {
const params = request.params;
const bbThreadId = params.threadId;
const existing = sessionsByBbThreadId.get(bbThreadId);
if (existing) {
await stopSession(existing);
}
It also awaits launch-argument resolution before creating the agent connection and before registering the replacement:
const launch = await resolveAgentLaunchArgs(params);
if (launch.warning) {
emitStartNotification(ACP_WARNING_METHOD, {
threadId: bbThreadId,
summary: launch.warning,
});
}
awaitingFirstPrompt: true,
};
sessionsByBbThreadId.set(bbThreadId, session);
try {
Stop only looks up the registered session and always acknowledges success even when no session is found:
case "thread/stop": {
const session = sessionsByBbThreadId.get(request.params.threadId);
if (session) {
if (request.params.intent === "release") {
await releaseSession(session);
} else {
await stopSession(session);
}
}
sendResult(request.id, { ok: true });
return;
}
On initial start, the lookup is empty. During rebuild, it can still reference the old session, whose stop operation already has its stopping flag set and returns immediately to a second stop. No per-thread pending-construction cancellation state carries that request forward. The replacement therefore resumes after its await, launches, registers, and receives the pending turn. The late session.stopping guard cannot help because it checks the new object, not the old object that stop saw.
This is a lifecycle/admission ordering gap, not agent refusal to honor session/cancel. The fresh-start test proves the gap without dynamic model discovery; an asynchronous launch-resolution boundary alone suffices.
6. Proposed fix
Track pending session constructions by bb thread before the first await. Stop should mark those constructions cancelled as well as stop any registered session. Check the cancellation state after awaited shutdown and launch-argument resolution, before launching/registering a replacement, and remove pending entries in a finally block. Preserve existing cancellation once a session is registered. Validate fresh start, settings relaunch, failed construction cleanup, and concurrent starts for the same thread.
No production fix was applied here: an open pull request already links this issue, so the autopilot duplicate-PR gate prevents creating another.
7. Linked PR review
PR #6913 — static review only
GitHub metadata showed an open PR targeting main with Fixes #6912. Its untrusted diff adds a set of pending-start cancellation records per thread, wraps construction with finally-based cleanup, checks cancellation after the two pre-registration waits, and marks pending records from the stop handler.
Assessment: the proposed mechanism targets the reproduced root cause, rather than merely changing the acknowledgement. No obvious blocker was identified in that narrow static inspection. This is not runtime validation or approval of the PR: its branch, tests, binaries, and patches were never checked out or run. Tests executed for this report are only the newly authored reproduction and existing controls on trusted main.
8. Related coverage and limits
Existing bridge tests for stopping an already active turn and for rebuilding with changed environment both pass on the same main checkout. They cover each operation separately but do not cover stop overtaking pending construction. A small repository issue search did not establish a different duplicate; the explicit linked PR is the actionable existing fix path.
9. Verification
The same agent repeated the reproduction, not an independent reviewer. The second checkout was a separate clean clone at the exact base commit with a fresh install, separate node_modules and new test-created temporary workspaces. Only the newly authored test block was then added; production code remained byte-for-byte at main.
pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@bb/provider-bridge-acp pnpm exec turbo run test --filter=@bb/provider-bridge-acp -- src/bridge/bridge.test.ts -t 'stop admission regression' Second run: exit 1; 2 failed | 207 skipped (209). First run: exit 1; 2 failed | 207 skipped (209). Both failures are the intended lifecycle assertions, not setup errors.
A preliminary permission test placed CLI flags before the Node script and failed during fixture setup. The authored test was corrected to use the harness-supported insertAfterArgs: 1 before the two reported runs. The fresh-start test additionally demonstrates that model-list discovery is unnecessary. These are the only investigation corrections; no production change was made.
Existing controls:
pnpm exec turbo run test --filter=@bb/provider-bridge-acp -- src/bridge/bridge.test.ts -t 'cancels the active turn on thread/stop|rebuilds the agent with environment from a later turn' Exit 0; 2 passed | 207 skipped (209).
10. Appendix
First reproduction assertion output
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: FAIL |@bb/provider-bridge-acp:isolated| src/bridge/bridge.test.ts > stop admission regression > does not admit an initial session after acknowledging interruption
@bb/provider-bridge-acp:test: AssertionError: expected { acknowledged: { ok: true }, …(2) } to deeply equal { acknowledged: { ok: true }, …(2) }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: - Expected
@bb/provider-bridge-acp:test: + Received
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: {
@bb/provider-bridge-acp:test: "acknowledged": {
@bb/provider-bridge-acp:test: "ok": true,
@bb/provider-bridge-acp:test: },
@bb/provider-bridge-acp:test: - "launched": false,
@bb/provider-bridge-acp:test: - "outcome": "cancelled",
@bb/provider-bridge-acp:test: + "launched": true,
@bb/provider-bridge-acp:test: + "outcome": "ready",
@bb/provider-bridge-acp:test: }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ❯ src/bridge/bridge.test.ts:731:8
@bb/provider-bridge-acp:test: 729| outcome,
@bb/provider-bridge-acp:test: 730| launched: existsSync(launchFile),
@bb/provider-bridge-acp:test: 731| }).toEqual({
@bb/provider-bridge-acp:test: | ^
@bb/provider-bridge-acp:test: 732| acknowledged: { ok: true },
@bb/provider-bridge-acp:test: 733| outcome: "cancelled",
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: FAIL |@bb/provider-bridge-acp:isolated| src/bridge/bridge.test.ts > stop admission regression > does not deliver a turn overtaken by interruption during permission relaunch
@bb/provider-bridge-acp:test: AssertionError: expected { acknowledged: { ok: true }, …(2) } to deeply equal { acknowledged: { ok: true }, …(2) }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: - Expected
@bb/provider-bridge-acp:test: + Received
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: {
@bb/provider-bridge-acp:test: "acknowledged": {
@bb/provider-bridge-acp:test: "ok": true,
@bb/provider-bridge-acp:test: },
@bb/provider-bridge-acp:test: - "completedNormally": false,
@bb/provider-bridge-acp:test: - "deliveredPrompts": [],
@bb/provider-bridge-acp:test: + "completedNormally": true,
@bb/provider-bridge-acp:test: + "deliveredPrompts": [
@bb/provider-bridge-acp:test: + "cancellation probe",
@bb/provider-bridge-acp:test: + ],
@bb/provider-bridge-acp:test: }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ❯ src/bridge/bridge.test.ts:777:8
@bb/provider-bridge-acp:test: 775| (event) => event.status === "completed",
@bb/provider-bridge-acp:test: 776| ),
@bb/provider-bridge-acp:test: 777| }).toEqual({
@bb/provider-bridge-acp:test: | ^
@bb/provider-bridge-acp:test: 778| acknowledged: { ok: true },
@bb/provider-bridge-acp:test: 779| deliveredPrompts: [],
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: Test Files 1 failed (1)
@bb/provider-bridge-acp:test: Tests 2 failed | 207 skipped (209)
@bb/provider-bridge-acp:test: Start at 15:51:31
@bb/provider-bridge-acp:test: Duration 5.44s (transform 4.16s, setup 0ms, import 4.79s, tests 356ms, environment 0ms)
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ELIFECYCLE Test failed. See above for more details.
@bb/provider-bridge-acp#test: ERROR command (SCRATCH/first/packages/provider-bridge-acp) /usr/local/bin/pnpm run test src/bridge/bridge.test.ts -t stop admission regression exited (1)
Tasks: 2 successful, 3 total
Cached: 1 cached, 3 total
Time: 7.618s
Failed: @bb/provider-bridge-acp#test
ERROR run failed: command exited (1)
Second reproduction assertion output
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: FAIL |@bb/provider-bridge-acp:isolated| src/bridge/bridge.test.ts > stop admission regression > does not admit an initial session after acknowledging interruption
@bb/provider-bridge-acp:test: AssertionError: expected { acknowledged: { ok: true }, …(2) } to deeply equal { acknowledged: { ok: true }, …(2) }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: - Expected
@bb/provider-bridge-acp:test: + Received
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: {
@bb/provider-bridge-acp:test: "acknowledged": {
@bb/provider-bridge-acp:test: "ok": true,
@bb/provider-bridge-acp:test: },
@bb/provider-bridge-acp:test: - "launched": false,
@bb/provider-bridge-acp:test: - "outcome": "cancelled",
@bb/provider-bridge-acp:test: + "launched": true,
@bb/provider-bridge-acp:test: + "outcome": "ready",
@bb/provider-bridge-acp:test: }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ❯ src/bridge/bridge.test.ts:731:8
@bb/provider-bridge-acp:test: 729| outcome,
@bb/provider-bridge-acp:test: 730| launched: existsSync(launchFile),
@bb/provider-bridge-acp:test: 731| }).toEqual({
@bb/provider-bridge-acp:test: | ^
@bb/provider-bridge-acp:test: 732| acknowledged: { ok: true },
@bb/provider-bridge-acp:test: 733| outcome: "cancelled",
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: FAIL |@bb/provider-bridge-acp:isolated| src/bridge/bridge.test.ts > stop admission regression > does not deliver a turn overtaken by interruption during permission relaunch
@bb/provider-bridge-acp:test: AssertionError: expected { acknowledged: { ok: true }, …(2) } to deeply equal { acknowledged: { ok: true }, …(2) }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: - Expected
@bb/provider-bridge-acp:test: + Received
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: {
@bb/provider-bridge-acp:test: "acknowledged": {
@bb/provider-bridge-acp:test: "ok": true,
@bb/provider-bridge-acp:test: },
@bb/provider-bridge-acp:test: - "completedNormally": false,
@bb/provider-bridge-acp:test: - "deliveredPrompts": [],
@bb/provider-bridge-acp:test: + "completedNormally": true,
@bb/provider-bridge-acp:test: + "deliveredPrompts": [
@bb/provider-bridge-acp:test: + "cancellation probe",
@bb/provider-bridge-acp:test: + ],
@bb/provider-bridge-acp:test: }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ❯ src/bridge/bridge.test.ts:777:8
@bb/provider-bridge-acp:test: 775| (event) => event.status === "completed",
@bb/provider-bridge-acp:test: 776| ),
@bb/provider-bridge-acp:test: 777| }).toEqual({
@bb/provider-bridge-acp:test: | ^
@bb/provider-bridge-acp:test: 778| acknowledged: { ok: true },
@bb/provider-bridge-acp:test: 779| deliveredPrompts: [],
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: Test Files 1 failed (1)
@bb/provider-bridge-acp:test: Tests 2 failed | 207 skipped (209)
@bb/provider-bridge-acp:test: Start at 15:52:29
@bb/provider-bridge-acp:test: Duration 5.36s (transform 4.09s, setup 0ms, import 4.72s, tests 339ms, environment 0ms)
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ELIFECYCLE Test failed. See above for more details.
@bb/provider-bridge-acp#test: ERROR command (SCRATCH/second/packages/provider-bridge-acp) /usr/local/bin/pnpm run test src/bridge/bridge.test.ts -t stop admission regression exited (1)
Tasks: 2 successful, 3 total
Cached: 0 cached, 3 total
Time: 7.636s
Failed: @bb/provider-bridge-acp#test
ERROR run failed: command exited (1)
Existing-control output
@bb/provider-bridge-acp:test: @bb/provider-bridge-acp:test: (node:3782) ExperimentalWarning: SQLite is an experimental feature and might change at any time @bb/provider-bridge-acp:test: (Use `node --trace-warnings ...` to show where the warning was created) @bb/provider-bridge-acp:test: ✓ |@bb/provider-bridge-acp:isolated| src/bridge/bridge.test.ts (209 tests | 207 skipped) 316ms @bb/provider-bridge-acp:test: @bb/provider-bridge-acp:test: Test Files 1 passed (1) @bb/provider-bridge-acp:test: Tests 2 passed | 207 skipped (209) @bb/provider-bridge-acp:test: Start at 15:53:13 @bb/provider-bridge-acp:test: Duration 5.15s (transform 3.89s, setup 0ms, import 4.53s, tests 316ms, environment 0ms) @bb/provider-bridge-acp:test: Tasks: 3 successful, 3 total Cached: 0 cached, 3 total Time: 7.376s
Git metadata, issue properties, labels, and linked-PR metadata/diff were inspected through GitHub reads. Trusted source was fetched from get-bb/bb main, cloned twice, installed frozen, built with filtered Turbo, and exercised with the commands above. Both local diffs passed git diff --check. No third-party agent or UI behavior is claimed verified.
Untrusted-data note: Issue content and linked-PR diff were treated only as claims/static evidence. No issue-supplied command, test, patch, branch, external URL, or binary was executed. The reproduction is newly authored from the trusted repository harness.
> AGENT GENERATED