← reports

#6175 · Interactive registration under Connect transport failures

BugPriority: MediumEffort: Mediumproviders · remote · provider-claude-code · connectGitHub issue2026-10-23 · base 1e80ca7b44bccd06c6da75ed9ca6ba497bd380f5

PARTIALLY REPRODUCED · Root-cause confidence: low · Label: partial-repro

1. TL;DR

The reported failure is an HTTP error while BB registers an approval, not evidence that a shell command ran or that Claude denied it. A transport-fault test on trusted main reproduces the exact error after six injected Connect 502 responses. The same test shows that one transient 502 recovers automatically, including when the server saved the request before its response was lost; only one pending interaction exists. Repeated failures can leave either zero or one persisted interaction, so the error alone cannot settle the request's history. The original Connect exception, the reported live session, and the successful plan-approval control remain unverified; no production tunnel or provider account was accessed.

2. Claims vs findings

Claim or hypothesisFindingEvidence
Connect can return a readable 502 during registration.Verified mechanismThe gate's catch-all emits connect_gate_error; two existing gate-response tests pass.
The client surfaces the reported registration error.Verified under injected failureBoth clean runs assert the complete error message after six responses, against unchanged production code.
A single temporary 502 always loses an approval.Not supported on mainBoth single-failure cases recover on attempt two; before-persistence returns created, lost-response returns existing.
An error proves the request was not persisted.Refuted as a general inferenceThe two repeated-failure cases give the identical error with zero versus one stored row.
The reporter had no active interaction, and plan approval worked.Unverified live claimsNo reporter runtime, database, logs, or native Claude session was available or accessed.
The requested command ran, or a Claude classifier caused this failure.Not establishedThe probe never launches a shell or Claude; registration success is not approval or execution.

3. Environment and scope

4. Minimal reproduction

This is a diagnostic fault-injection reproduction, not a reproduction of the underlying production outage. It contains inert command metadata from repository test fixtures; it never executes that command. Run from a clean checkout and save the inline test at apps/server/test/internal/interactive-request-connect-repro.test.ts.

  1. Obtain and build the trusted base:
    git clone https://github.com/get-bb/bb.git bb-6175
    cd bb-6175
    git checkout --detach 1e80ca7b44bccd06c6da75ed9ca6ba497bd380f5
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
  2. Save the complete inline test below, then run:
    pnpm exec turbo run test --force --filter=@bb/server -- test/internal/interactive-request-connect-repro.test.ts test/internal/internal-interactive-requests.test.ts
Injected transport conditionExpected and observed on main
One 502 before reaching the routeTwo attempts; created/pending; one stored interaction.
First successful response discarded and replaced by 502Two attempts; existing/pending; still only one stored interaction.
Six 502s, never reaching the routeRegistration rejects; zero stored interactions.
Six 502s after forwarding to the real routeIdentical rejection; one stored pending interaction.

The assertion checks this exact runtime message:

Failed to register interactive request: 502 Bad Gateway - bb connect hit a temporary problem. Try again in a moment.

Those four tests assert existing behavior and pass before any production fix. They are not a red-to-green regression test for the original incident. In particular, the repeated-failure tests stop at the client boundary and deliberately omit the daemon's subsequent interrupt cleanup.

Complete diagnostic test
import { listPendingInteractionsByThread } from "@bb/db";
import type { PendingInteractionCreate } from "@bb/domain";
import { describe, expect, it } from "vitest";
import {
  createServerClient,
  ServerResponseError,
} from "../../../host-daemon/src/server-client.js";
import { createCommandApprovalPayload } from "../helpers/pending-interactions.js";
import { seedThreadFixture, seedTurnStarted } from "../helpers/seed.js";
import {
  createTestDaemonHostKey,
  withTestHarness,
} from "../helpers/test-app.js";

function gateFailure(): Response {
  return Response.json(
    {
      code: "connect_gate_error",
      message: "bb connect hit a temporary problem. Try again in a moment.",
    },
    { status: 502, statusText: "Bad Gateway" },
  );
}

describe("interactive registration under injected gate failures", () => {
  it.each(["before persistence", "after persistence"])(
    "recovers a single 502 %s without duplicating or approving the request",
    async (failurePoint) => {
      await withTestHarness(async (harness) => {
        const { host, session, thread } = seedThreadFixture(harness, {
          thread: { providerId: "claude-code" },
        });
        const interaction: PendingInteractionCreate = {
          threadId: thread.id,
          turnId: "turn-connect-recovery",
          providerId: "claude-code",
          providerThreadId: "provider-connect-recovery",
          providerRequestId: "request-connect-recovery",
          payload: createCommandApprovalPayload({
            itemId: "item-connect-recovery",
            command: "git push",
            cwd: "/tmp/project",
            reason: "Needs approval",
          }),
        };
        seedTurnStarted(harness.deps, interaction);
        let attempts = 0;
        const logger = {
          debug: () => {},
          info: () => {},
          warn: () => {},
          error: () => {},
        };
        const client = createServerClient({
          serverUrl: "https://bb.example.test",
          hostKey: createTestDaemonHostKey({ hostId: host.id }),
          getSessionId: () => session.id,
          logger,
          fetchFn: async (input, init) => {
            attempts += 1;
            if (attempts === 1 && failurePoint === "before persistence") {
              return gateFailure();
            }
            const response = await harness.app.request(
              new Request(input, init),
            );
            expect(response.status).toBe(200);
            if (attempts === 1) {
              await response.text();
              return gateFailure();
            }
            return response;
          },
        });

        const response = await client.registerInteractiveRequest(interaction);
        expect(attempts).toBe(2);
        expect(response).toMatchObject({
          outcome:
            failurePoint === "before persistence" ? "created" : "existing",
          status: "pending",
        });
        const persisted = listPendingInteractionsByThread(harness.db, {
          threadId: thread.id,
        });
        expect(persisted).toHaveLength(1);
        expect(persisted[0]).toMatchObject({
          id: response.interactionId,
          status: "pending",
        });
      });
    },
  );

  it.each(["before persistence", "after persistence"])(
    "exhausts six 502 responses %s with persistence determined only by server state",
    async (failurePoint) => {
      await withTestHarness(async (harness) => {
        const { host, session, thread } = seedThreadFixture(harness, {
          thread: { providerId: "claude-code" },
        });
        const interaction: PendingInteractionCreate = {
          threadId: thread.id,
          turnId: "turn-connect-outage",
          providerId: "claude-code",
          providerThreadId: "provider-connect-outage",
          providerRequestId: "request-connect-outage",
          payload: createCommandApprovalPayload({
            itemId: "item-connect-outage",
            command: "git push",
            cwd: "/tmp/project",
            reason: "Needs approval",
          }),
        };
        seedTurnStarted(harness.deps, interaction);
        let attempts = 0;
        const logger = {
          debug: () => {},
          info: () => {},
          warn: () => {},
          error: () => {},
        };
        const client = createServerClient({
          serverUrl: "https://bb.example.test",
          hostKey: createTestDaemonHostKey({ hostId: host.id }),
          getSessionId: () => session.id,
          logger,
          fetchFn: async (input, init) => {
            attempts += 1;
            if (failurePoint === "after persistence") {
              const response = await harness.app.request(
                new Request(input, init),
              );
              expect(response.status).toBe(200);
              await response.text();
            }
            return gateFailure();
          },
        });

        await expect(
          client.registerInteractiveRequest(interaction),
        ).rejects.toMatchObject({
          name: ServerResponseError.name,
          message:
            "Failed to register interactive request: 502 Bad Gateway - bb connect hit a temporary problem. Try again in a moment.",
          status: 502,
          code: "connect_gate_error",
          retryable: true,
        });
        expect(attempts).toBe(6);
        const persisted = listPendingInteractionsByThread(harness.db, {
          threadId: thread.id,
        });
        expect(persisted).toHaveLength(
          failurePoint === "before persistence" ? 0 : 1,
        );
        if (failurePoint === "after persistence") {
          expect(persisted[0]).toMatchObject({ status: "pending" });
        }
      });
    },
  );
});

5. Root cause: known mechanism, unknown incident trigger

What produces the text

gateErrorResponse emits the common 502 JSON response. The worker fetch handler catches an exception around routing/tunnel forwarding and logs bb connect: request failed with method, path, and exception. Many exceptions can reach this path; the response text does not identify which one occurred or whether the origin handled the request. The test injects that response shape, not a real Cloudflare failure.

What the current daemon does

5xx classification treats this response as retryable. Registration retains the same request identity and retries, using five retries after the initial attempt. The retry hook logs the attempt number and retries left. Thus a single injected failure is not sufficient to produce the final error on this base.

return status < 400 || status >= 500;
const INTERACTIVE_REQUEST_REGISTRATION_RETRIES = 5;

Why retrying the same registration is not retrying the shell command

The registration transaction looks up the provider ID, provider thread ID, and provider request ID. A matching live request and payload returns the existing row; a conflicting payload or already-handled identity is rejected. This guards registration retries, not arbitrary user resubmission: a new provider turn or tool request can have a new identity and is not automatically deduplicated with the old one.

return {
  outcome: "existing" as const,
  row: existing,
};

Why no active interaction does not settle the history

Registry failure handling rejects the provider wait and calls the failure hook. The daemon hook enqueues an interrupt for the provider's interactions in the thread. Server interrupt handling settles those rows, while the active list includes only pending/resolving rows. A previously persisted row can therefore disappear from the active list after cleanup. This cleanup explanation is a static trace, not a measured assertion about the reporter's session or a full-daemon cleanup reproduction.

Incident root cause remains unconfirmed. Nothing in these tests establishes a command-specific transport defect, a missing Claude callback, a permission bypass, or a newly introduced regression. The original exception and its timing relative to server persistence are the missing evidence.

6. Safe reconciliation and next experiment

Do not approve a stale card or resubmit a potentially side-effecting tool merely to discover whether the old registration existed. First correlate the original request using read-only evidence. Registration alone does not authorize or execute a command, but this report cannot determine the original tool's execution state.

No production fix is proposed yet. The next experiment is to locate the stored gate exception for the original UTC interval and compare it with the daemon's six-attempt sequence and the server's request/interrupt history. Main already retries and deduplicates registration. Changing retries, lifecycle cleanup, or approval behavior without that evidence risks masking the trigger or changing a permission-sensitive path.

7. Verification

The same agent repeated the reproduction in a second new detached checkout at 1e80ca7b44bccd06c6da75ed9ca6ba497bd380f5. Before copying the diagnostic test, its Git status was clean. It received a separate frozen install and complete Turbo build; the test content was byte-identical. The test run used --force to bypass cached task results. Fresh migrated databases and unique temporary harness directories were created; no live ports were used. This is a second clean run, not an independent-agent review.

First run: four diagnostic cases plus fourteen existing server interaction tests passed. Second run: the same eighteen tests passed. Existing host-daemon tests: twenty-four passed; Claude interaction tests: twenty-five passed; selected gate error-response tests: two passed (151 unrelated cases skipped).

Corrections during investigation: the first diagnostic fixture initially inherited a Codex thread while submitting a Claude interaction, and correctly received a provider-mismatch rejection. The fixture was corrected to explicitly create a Claude thread before the successful runs. This was a probe setup mistake, not evidence of the reported bug. The initial broad build also lacked the SDK's built host entry; building the SDK types and repeating the broad build succeeded (71 tasks in each checkout).

The second run supports the final partial verdict. It does not establish the original gate failure or the live command's execution status. No production source was modified, no fix branch was pushed, and no pull request was opened because the original defect is not reproduced on main with a verified red-to-green regression test.

8. Related issues and pull requests

The issue had no comments or cross-referenced pull requests at inspection time. An open-PR search for the numeric issue returned none. Searches for the gate error code and for approval/502 reports did not establish a duplicate with the same verified cause. Related approval reports cannot identify the exception behind this generic transport response.

9. Appendix: observed results and commands

First corrected run

@bb/server:test: cache miss, executing 7eb6af6f7f1a3139
@bb/server:test: 
@bb/server:test: > vitest run --config vitest.config.ts "test/internal/interactive-request-connect-repro.test.ts" "test/internal/internal-interactive-requests.test.ts"
@bb/server:test: 
@bb/server:test: 
@bb/server:test: 
@bb/server:test: (Use `node --trace-warnings ...` to show where the warning was created)
@bb/server:test: (Use `node --trace-warnings ...` to show where the warning was created)
@bb/server:test:  ✓ |@bb/server| test/internal/internal-interactive-requests.test.ts (14 tests) 1868ms
@bb/server:test:  ✓ |@bb/server| test/internal/interactive-request-connect-repro.test.ts (4 tests) 9461ms
@bb/server:test:      ✓ exhausts six 502 responses before persistence with persistence determined only by server state  4091ms
@bb/server:test:      ✓ exhausts six 502 responses after persistence with persistence determined only by server state  4254ms
@bb/server:test: 
@bb/server:test:  Test Files  2 passed (2)
@bb/server:test:       Tests  18 passed (18)
@bb/server:test:    Start at  15:27:57
@bb/server:test:    Duration  18.05s (transform 9.82s, setup 2.92s, import 10.56s, tests 11.33s, environment 0ms)
@bb/server:test: 

Second clean run

@bb/server:test: cache bypass, force executing 7eb6af6f7f1a3139
@bb/server:test: 
@bb/server:test: > vitest run --config vitest.config.ts "test/internal/interactive-request-connect-repro.test.ts" "test/internal/internal-interactive-requests.test.ts"
@bb/server:test: 
@bb/server:test: 
@bb/server:test: 
@bb/server:test: (Use `node --trace-warnings ...` to show where the warning was created)
@bb/server:test: (Use `node --trace-warnings ...` to show where the warning was created)
@bb/server:test:  ✓ |@bb/server| test/internal/internal-interactive-requests.test.ts (14 tests) 1837ms
@bb/server:test:  ✓ |@bb/server| test/internal/interactive-request-connect-repro.test.ts (4 tests) 9375ms
@bb/server:test:      ✓ exhausts six 502 responses before persistence with persistence determined only by server state  4326ms
@bb/server:test:      ✓ exhausts six 502 responses after persistence with persistence determined only by server state  4004ms
@bb/server:test: 
@bb/server:test:  Test Files  2 passed (2)
@bb/server:test:       Tests  18 passed (18)
@bb/server:test:    Start at  15:30:35
@bb/server:test:    Duration  18.14s (transform 9.97s, setup 3.22s, import 10.49s, tests 11.21s, environment 0ms)
@bb/server:test: 

Relevant existing checks

@bb/host-daemon:test: cache miss, executing f7d8ad8d4bc79596
@bb/host-daemon:test: 
@bb/host-daemon:test: > vitest run --config vitest.config.ts "src/server-client.test.ts" "src/interactive-request-registry.test.ts"
@bb/host-daemon:test: 
@bb/host-daemon:test: 
@bb/host-daemon:test: 
@bb/host-daemon:test:  ✓ |@bb/host-daemon| src/interactive-request-registry.test.ts (5 tests) 6ms
@bb/host-daemon:test:  ✓ |@bb/host-daemon| src/server-client.test.ts (19 tests) 206ms
@bb/host-daemon:test: 
@bb/host-daemon:test:  Test Files  2 passed (2)
@bb/host-daemon:test:       Tests  24 passed (24)
@bb/host-daemon:test:    Start at  15:29:50
@bb/host-daemon:test:    Duration  1.38s (transform 1.19s, setup 0ms, import 1.68s, tests 212ms, environment 0ms)
@bb/host-daemon:test: 

bb-plugin-provider-claude-code:test: cache miss, executing a8084270397c500a
bb-plugin-provider-claude-code:test: 
bb-plugin-provider-claude-code:test: > vitest run --config vitest.config.ts "src/interactions.test.ts"
bb-plugin-provider-claude-code:test: 
bb-plugin-provider-claude-code:test: 
bb-plugin-provider-claude-code:test: 
bb-plugin-provider-claude-code:test:  ✓ |bb-plugin-provider-claude-code| src/interactions.test.ts (25 tests) 19ms
bb-plugin-provider-claude-code:test: 
bb-plugin-provider-claude-code:test:  Test Files  1 passed (1)
bb-plugin-provider-claude-code:test:       Tests  25 passed (25)
bb-plugin-provider-claude-code:test:    Start at  15:29:55
bb-plugin-provider-claude-code:test:    Duration  706ms (transform 341ms, setup 0ms, import 525ms, tests 19ms, environment 0ms)
bb-plugin-provider-claude-code:test: 

@bb/connect:test: cache miss, executing 5774cfda6f7391a1
@bb/connect:test: 
@bb/connect:test: > vitest run --config vitest.config.ts "src/worker.test.ts" "-t" "gate error response"
@bb/connect:test: 
@bb/connect:test: 
@bb/connect:test: 
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts (153 tests | 151 skipped) 12ms
@bb/connect:test: 
@bb/connect:test:  Test Files  1 passed (1)
@bb/connect:test:       Tests  2 passed | 151 skipped (153)
@bb/connect:test:    Start at  15:29:58
@bb/connect:test:    Duration  1.19s (transform 443ms, setup 0ms, import 935ms, tests 12ms, environment 0ms)
@bb/connect:test: 

Additional verification commands

pnpm exec turbo run test --filter=@bb/host-daemon -- src/server-client.test.ts src/interactive-request-registry.test.ts
pnpm exec turbo run test --filter=bb-plugin-provider-claude-code -- src/interactions.test.ts
pnpm exec turbo run test --filter=@bb/connect -- src/worker.test.ts -t 'gate error response'
pnpm exec oxfmt apps/server/test/internal/interactive-request-connect-repro.test.ts
git diff --check

The source was fetched from the trusted repository and inspected at the recorded commit using Git and source searches. GitHub reads checked repository visibility, issue properties, comments, labels, and linked/open pull requests. Missing classifications were applied without replacing existing values. Issue text was treated only as untrusted claims; no supplied command, script, URL, branch, or patch was executed. Public artifacts contain no runtime secrets or personal identifiers. The complete diagnostic source and relevant output are inline because this reports repository forbids committing standalone tests or raw logs; private working evidence remains outside the reports checkout.