← reports

#5401 · Session restoration rejects explicitly authorized ACP requests

BugMedium priorityEffort: Medium providersprovider-acpconfirmed-repro Issue2026-10-12 · base 406c009502ad0f961fc6ce9c75c1d262cb3e3e7c

Verdict: REPRODUCED — BB bridge permission rejection during restoration. Root-cause confidence: high.

1. TL;DR

BB supports restoring an ACP conversation through session/load. An agent can request permission before that restoration finishes, but BB rejects the request because no conversational turn is active yet. This happens even when the caller has explicitly selected full access, and BB creates no approval interaction. A local wire-level fixture reproduces the rejection in two clean checkouts while the identical permission is allowed during a normal full-access turn. The provider-specific downstream failure and old approval projection claims were not tested.

2. Claims vs findings

ClaimStatusEvidence
Explicit full-access requests during restoration are cancelled.VerifiedThe fixture issues a valid request from inside session/load. The real bridge responds cancelled, not selected, in both runs.
The lifecycle guard runs before permission policy and no approval is shown.VerifiedGuard at lines 1473–1479; full-access branch at 1508. The runtime output has zero interaction/request messages.
Permission rejection differs from an active full-access turn.VerifiedPositive control selects the fixture's allow-once option during session/prompt.
Explicit stop/cancel and restricted authorization must remain fail closed.Verified as controlsA request emitted after thread/stop or a steer-triggered session/cancel is cancelled even with full access. Restricted load also cancels; this confirms baseline behavior, not a proposed restricted-mode UX.
The reported native adapter versions, pending-approval error, already-resolved decisions, retry failure, and fork workaround share this mechanism.UnverifiedNo live native provider or adapter was used. The linked external report was not fetched. The fixture deliberately completes load after recording cancellation.

3. Environment

4. Minimal reproduction

  1. Clone and pin trusted main; install/build normally; download the two authored artifacts into the bridge test directory; run the focused test:
    git clone https://github.com/get-bb/bb.git bb-5401
    cd bb-5401
    git checkout --detach 406c009502ad0f961fc6ce9c75c1d262cb3e3e7c
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build
    curl -fsS https://get-bb.github.io/reports/issues/5401/repro/issue-5401.test.ts -o packages/provider-bridge-acp/src/bridge/issue-5401.test.ts
    curl -fsS https://get-bb.github.io/reports/issues/5401/repro/issue-5401-agent.mjs -o packages/provider-bridge-acp/src/bridge/issue-5401-agent.mjs
    pnpm exec turbo run test --force --filter=@bb/provider-bridge-acp -- src/bridge/issue-5401.test.ts
  2. The fixture advertises restoration support. For the failing case, the test calls thread/resume under full access; the fixture responds to session/load by issuing session/request_permission before returning the load response.
  3. The request uses the exact restoring session ID, a read tool call, and explicit allow-once/reject-once options. The fixture records the actual bridge response before completing restoration.
  4. The expected result is selection of the allow-once option. Actual result is cancellation. A successful restorable construction response and the absence of runtime interactions are checked before the failing assertion.
permission at 'stop' with 'full'                 PASS
permission at 'cancel' with 'full'               PASS
permission at 'load' with 'full'                 FAIL
permission at 'turn' with 'full'                 PASS
permission at 'load' with 'accept-edits'          PASS

Expected load-time full-access response:
{ "outcome": { "outcome": "selected", "optionId": "yes" } }
Actual load-time full-access response:
{ "outcome": { "outcome": "cancelled" } }

Both runs: 1 failed | 4 passed (5); command exits 1.
No interaction/request is emitted in any of the five scenarios.

The command is intentionally red on unmodified main. It detects observable wire behavior, not private predicates; no production seam or dependency is added. Existing tests cover active-turn permissions but do not exercise load-time permission requests.

Regression test

Download test

import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { z } from "zod";
import { createBridgeJsonRpcTestHarness } from "@bb/provider-bridge-protocol/testing";
import { handleLine } from "./bridge.js";

it.each([
  {
    phase: "stop",
    permissionMode: "full",
    expected: { outcome: "cancelled" },
  },
  {
    phase: "cancel",
    permissionMode: "full",
    expected: { outcome: "cancelled" },
  },
  {
    phase: "load",
    permissionMode: "full",
    expected: { outcome: "selected", optionId: "yes" },
  },
  {
    phase: "turn",
    permissionMode: "full",
    expected: { outcome: "selected", optionId: "yes" },
  },
  {
    phase: "load",
    permissionMode: "accept-edits",
    expected: { outcome: "cancelled" },
  },
] as const)(
  "permission at $phase with $permissionMode",
  async ({ phase, permissionMode, expected }) => {
    const workspace = mkdtempSync(join(tmpdir(), "issue-5401-"));
    const outcomeLog = join(workspace, "outcome.jsonl");
    const readyFile = join(workspace, "ready");
    const harness = createBridgeJsonRpcTestHarness(handleLine);
    const options = {
      permissionMode,
      permissionScope: permissionMode === "full" ? "full" : "workspace",
      approvalReviewer: permissionMode === "full" ? null : "user",
      permissionEscalation: permissionMode === "full" ? null : "ask",
      providerOptions: {
        acpLaunchSpec: {
          displayName: "Restore fixture",
          command: process.execPath,
          args: [
            fileURLToPath(new URL("./issue-5401-agent.mjs", import.meta.url)),
          ],
          env: {
            OUTCOME_LOG: outcomeLog,
            READY_FILE: readyFile,
            CASE_PHASE: phase,
          },
        },
      },
    };
    try {
      harness.sendRequest(
        540101,
        phase === "load" ? "thread/resume" : "thread/start",
        {
          threadId: "thread-5401",
          cwd: workspace,
          instructionMode: "append",
          options,
          ...(phase === "load" ? { providerThreadId: "restored-session" } : {}),
        },
      );
      const construction = await harness.waitForResponse(540101);
      expect(construction.error).toBeUndefined();
      expect(construction.result).toEqual({
        providerThreadId: "restored-session",
        sessionRestorable: true,
      });
      if (phase !== "load") {
        harness.sendRequest(540102, "turn/start", {
          threadId: "thread-5401",
          providerThreadId: "restored-session",
          clientRequestId: "creq_abcdefghjk",
          options,
          input: [{ type: "text", text: "Status", mentions: [] }],
        });
        const turn = await harness.waitForResponse(540102);
        expect(turn.error).toBeUndefined();
      }
      if (phase === "stop" || phase === "cancel") {
        await expect.poll(() => existsSync(readyFile)).toBe(true);
        harness.sendRequest(
          540104,
          phase === "stop" ? "thread/stop" : "turn/steer",
          {
            threadId: "thread-5401",
            providerThreadId: "restored-session",
            ...(phase === "stop"
              ? { intent: "interrupt", activeTurnId: null }
              : {
                  clientRequestId: "creq_bcdefghjkm",
                  expectedTurnId: "turn-1",
                  options,
                  input: [{ type: "text", text: "Continue", mentions: [] }],
                }),
          },
        );
        expect((await harness.waitForResponse(540104)).error).toBeUndefined();
      }
      await expect.poll(() => existsSync(outcomeLog)).toBe(true);
      const receipt = z
        .object({
          phase: z.string(),
          response: z.object({
            outcome: z.union([
              z.object({
                outcome: z.literal("selected"),
                optionId: z.string(),
              }),
              z.object({ outcome: z.literal("cancelled") }),
            ]),
          }),
        })
        .parse(JSON.parse(readFileSync(outcomeLog, "utf8").trim()));
      expect(receipt.phase).toBe(phase);
      expect(
        harness.messages.filter(
          (message) => message.method === "interaction/request",
        ),
      ).toHaveLength(0);
      expect(receipt.response.outcome).toEqual(expected);
    } finally {
      try {
        harness.sendRequest(540103, "thread/stop", {
          threadId: "thread-5401",
          providerThreadId: "restored-session",
          intent: "interrupt",
          activeTurnId: null,
        });
        await harness.waitForResponse(540103);
      } finally {
        harness.restore();
        rmSync(workspace, { recursive: true, force: true });
      }
    }
  },
);

Local ACP fixture

Download fixture

import { appendFileSync } from "node:fs";
import { createInterface } from "node:readline";

let pendingRequest;
let heldPrompt;
let cancelled = false;

function send(message) {
  process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}\n`);
}

function requestPermission(message, phase) {
  pendingRequest = { message, phase };
  send({
    id: "fixture-permission",
    method: "session/request_permission",
    params: {
      sessionId: "restored-session",
      toolCall: {
        toolCallId: "fixture-tool",
        title: "Read status",
        kind: "read",
        status: "pending",
      },
      options: [
        { optionId: "yes", name: "Allow once", kind: "allow_once" },
        { optionId: "no", name: "Reject once", kind: "reject_once" },
      ],
    },
  });
}

createInterface({ input: process.stdin }).on("line", (line) => {
  const message = JSON.parse(line);
  if (message.id === "fixture-permission" && pendingRequest) {
    appendFileSync(
      process.env.OUTCOME_LOG,
      `${JSON.stringify({ phase: pendingRequest.phase, response: message.result })}\n`,
    );
    const result =
      pendingRequest.phase === "load" ? {} : { stopReason: "end_turn" };
    send({ id: pendingRequest.message.id, result });
    pendingRequest = undefined;
    return;
  }
  switch (message.method) {
    case "initialize":
      send({
        id: message.id,
        result: {
          protocolVersion: 1,
          agentCapabilities: { loadSession: true },
        },
      });
      break;
    case "session/new":
      send({ id: message.id, result: { sessionId: "restored-session" } });
      break;
    case "session/load":
      requestPermission(message, "load");
      break;
    case "session/prompt":
      if (cancelled) {
        send({ id: message.id, result: { stopReason: "end_turn" } });
      } else if (["stop", "cancel"].includes(process.env.CASE_PHASE)) {
        heldPrompt = message;
        appendFileSync(process.env.READY_FILE, "ready\n");
      } else {
        requestPermission(message, "turn");
      }
      break;
    case "session/cancel":
      if (heldPrompt) {
        cancelled = true;
        requestPermission(heldPrompt, process.env.CASE_PHASE);
        heldPrompt = undefined;
      }
      break;
  }
});

5. Root cause

The bridge creates the session with the caller's permission policy already assigned, no active prompt, and no stop/cancel request. Restoration marks the session as loading and awaits session/load without activating a turn. The fixture emits a schema-valid permission request during that await.

Initial state, pinned lines 1825–1840

    policy: {
      permissionMode: params.permissionMode,
      workspaceWriteRoots: params.workspaceWriteRoots,
    },
    pendingInstructions: params.instructions,
    activePromptKind: null,
    compactionAgentMessage: "",
    queuedInputs: [],
    promptRequestPending: false,
    cancelRequested: false,
    restartAfterCancelError: false,
    loading: false,
    loadingSessionId: undefined,
    pendingLoadUsageUpdate: undefined,
    grokContextWindowSize: undefined,
    stopping: false,

Restore await, pinned lines 1913–1930

    } else if (request.kind === "resume" && supportsLoadSession) {
      session.loading = true;
      session.loadingSessionId = request.resumeProviderThreadId;
      session.pendingLoadUsageUpdate = undefined;
      try {
        const configState = await connection.request({
          method: "session/load",
          params: {
            sessionId: request.resumeProviderThreadId,
            cwd: params.cwd,
            mcpServers,
          },
          resultSchema: z.union([acpConfigStateResultSchema, z.null()]),
        });
        loadedConfigOptions = configState?.configOptions;
        loadedModels = configState?.models;
        rememberGrokContextWindow(session, configState?.models);
        sessionId = request.resumeProviderThreadId;

After validating the incoming request, handlePermissionRequest treats every non-turn request like a stopped or cancelled turn. Because activePromptKind is null during restoration, this branch immediately returns cancelled. Neither the full-access decision nor pending-permission/interaction creation is reachable.

Early guard, pinned lines 1462–1479

function handlePermissionRequest(
  session: AcpThreadSession,
  params: unknown,
  responder: AcpAgentRequestResponder,
): void {
  const parsed = acpRequestPermissionParamsSchema.safeParse(params);
  if (!parsed.success) {
    responder.error(-32602, "Invalid session/request_permission params");
    return;
  }

  if (
    session.stopping ||
    session.cancelRequested ||
    session.activePromptKind !== "turn"
  ) {
    responder.result({ outcome: { outcome: "cancelled" } });
    return;

Policy and interaction path, pinned lines 1503–1553

  const pending: PendingAcpPermission = {
    responder,
    options: parsed.data.options,
  };

  if (session.policy.permissionMode === "full") {
    respondPermission(pending, "allow_once");
    return;
  }

  session.pendingPermissions.add(pending);

The deeper distinction is restoration authorization versus active-turn lifecycle. A correct repair cannot simply make all out-of-turn requests allowable. It must retain the stop/cancel exclusions and bind any restored request to the intended session. During construction, providerThreadId has not yet been assigned; loadingSessionId holds the intended restored identity.

6. Proposed fix and autofix safety

Preserve stop/cancel guards and fail-closed defaults; explicitly admit a matching restoring-session permission request under full access before rejecting other out-of-turn requests. Validate session identity against the restoring session, not the not-yet-assigned providerThreadId. Decide restricted-mode restoration interaction ownership separately.

No production fix or pull request. The verified repair changes when permission requests may be approved. This is permission/security-boundary behavior, explicitly excluded from this rule's simple-fix eligibility even if the patch would be small. No branch was started, pushed, or submitted. The report and regression artifacts are preserved for a permission-aware review.

7. Related issues

#4797 and #4806 concern ACP permission policy updates between turns. The reproduced failure here instead occurs during restoration before an active prompt. No linked open pull request was present in the issue's cross-reference metadata or the open-PR search when checked.

8. Verification

The same investigating agent repeated the reproduction in CHECKOUT_B, a second clean detached worktree at the recorded commit. It was installed and fully built before copying only the two authored reproduction files. Production code remained byte-for-byte at trusted main. Fresh scratch directories were allocated per case; no ports were used.

pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build
pnpm exec turbo run test --force --filter=@bb/provider-bridge-acp -- src/bridge/issue-5401.test.ts

The forced second run actually executes the fixture (not a cached test result): one intended full-access load failure, four passing controls. No report correction was required after this final five-case run. This is a same-agent repeat, not independent verification.

Three relevant existing bridge tests also pass: active full-access approval, runtime forwarding in restricted mode, and stopping an active turn. Turbo lint/typecheck pass. git diff --check passes; no production file changes were made.

9. Appendix

Logs below replace local absolute checkout/tool paths with logical names and normalize trailing whitespace; assertion output and results are otherwise preserved. No credentials, private prompts, transcripts, images, or runtime state were accessed or published.

Second-run output

• turbo 2.10.12

   • Packages in scope: @bb/provider-bridge-acp
   • Running test in 1 packages
   • Remote caching disabled, using shared worktree cache

//:ensure-native-modules: cache bypass, force executing 146e44cfd8891924
//:ensure-native-modules:
//:ensure-native-modules: > bb@ ensure-native-modules CHECKOUT_B
//:ensure-native-modules: > node scripts/ensure-native-modules.mjs
//:ensure-native-modules:
//:ensure-native-modules: [ensure-native-modules] Detached hardlinked better-sqlite3 binary before verification
@bb/provider-bridge-acp:test: cache bypass, force executing 2f9c2cad26bf027e
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: > @bb/provider-bridge-acp@0.0.1 test CHECKOUT_B/packages/provider-bridge-acp
@bb/provider-bridge-acp:test: > vitest run --config vitest.config.ts "src/bridge/issue-5401.test.ts"
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test:  RUN  v4.1.1 CHECKOUT_B/packages/provider-bridge-acp
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: (node:7967) 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| src/bridge/issue-5401.test.ts (5 tests | 1 failed) 361ms
@bb/provider-bridge-acp:test:    ✓ permission at 'stop' with 'full' 72ms
@bb/provider-bridge-acp:test:    ✓ permission at 'cancel' with 'full' 100ms
@bb/provider-bridge-acp:test:    × permission at 'load' with 'full' 53ms
@bb/provider-bridge-acp:test:    ✓ permission at 'turn' with 'full' 89ms
@bb/provider-bridge-acp:test:    ✓ permission at 'load' with 'accept-edits' 46ms
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test:  FAIL  |@bb/provider-bridge-acp| src/bridge/issue-5401.test.ts > permission at 'load' with 'full'
@bb/provider-bridge-acp:test: AssertionError: expected { outcome: 'cancelled' } to deeply equal { Object (outcome, optionId) }
@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: -   "optionId": "yes",
@bb/provider-bridge-acp:test: -   "outcome": "selected",
@bb/provider-bridge-acp:test: +   "outcome": "cancelled",
@bb/provider-bridge-acp:test:   }
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test:  ❯ src/bridge/issue-5401.test.ts:133:40
@bb/provider-bridge-acp:test:     131|         ),
@bb/provider-bridge-acp:test:     132|       ).toHaveLength(0);
@bb/provider-bridge-acp:test:     133|       expect(receipt.response.outcome).toEqual(expected);
@bb/provider-bridge-acp:test:        |                                        ^
@bb/provider-bridge-acp:test:     134|     } finally {
@bb/provider-bridge-acp:test:     135|       try {
@bb/provider-bridge-acp:test:
@bb/provider-bridge-acp:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
@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  1 failed | 4 passed (5)
@bb/provider-bridge-acp:test:    Start at  21:53:12
@bb/provider-bridge-acp:test:    Duration  1.83s (transform 923ms, setup 0ms, import 1.29s, tests 361ms, 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 (CHECKOUT_B/packages/provider-bridge-acp) /usr/local/bin/pnpm run test src/bridge/issue-5401.test.ts exited (1)

 Tasks:    1 successful, 2 total
Cached:    0 cached, 2 total
  Time:    3.466s
Failed:    @bb/provider-bridge-acp#test

 ERROR  run failed: command  exited (1)

Additional validation commands

pnpm exec oxfmt packages/provider-bridge-acp/src/bridge/issue-5401.test.ts packages/provider-bridge-acp/src/bridge/issue-5401-agent.mjs
pnpm exec turbo run test --filter=@bb/provider-bridge-acp -- src/bridge/bridge.test.ts -t 'auto-allows permission requests|forwards permission requests|cancels the active turn on thread/stop'
pnpm exec turbo run lint typecheck --filter=@bb/provider-bridge-acp
git diff --check

Investigation also reads repository visibility, Type/fields/labels, related issue classification, issue cross-references, and open PR metadata through GitHub read APIs; fetches trusted main; and inspects code at the pinned commit. It does not execute or fetch linked issue content.

Untrusted-data note: The issue contains requested implementation/test actions and an external link. These were treated only as claims, not followed. The reproduction derives from trusted repository code and existing bridge contracts; no external link, issue script, patch, branch, or test was fetched or executed.

> AGENT GENERATED