← reports

#6450 · Connect gate failures and thread-loading delays

BugHighEffort: Mediumremote · connect · perfGitHub issue2026-10-28 · base f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7

Verdict: PARTIALLY REPRODUCED · Root-cause confidence: low for the reported production incident. Confidence is high only in the verified exception-to-502 mechanism.

1. TL;DR

The reported error text is generated by the Connect gate when request processing throws, not by the local thread API. Existing trusted-main tests reproduce that exact JSON 502 by injecting a failed gate label lookup; separate tests show unreachable or overloaded tunnel objects also produce 502 responses. A stalled request instead produces a stage-specific 504 after the gate deadline. These are controlled failure injections, not a reproduction of normal thread browsing becoming slow or unreliable. The production trigger, frequency, and affected population remain unverified; no infrastructure-capacity diagnosis or safe production fix follows from the message alone.

2. Claims vs findings

ClaimFindingEvidence and limits
The temporary-problem response can appear on thread API requests.Verified under fault injectionThe existing gate error response test rejects label resolution and observes HTTP 502 with code connect_gate_error on a thread child-summary GET.
Thread browsing is routinely slow and fails many times per day.UnverifiedNo affected account, request trace, incident timestamp, or production telemetry was used. Tests do not model the reporter's network or workload.
Empty local logs prove relay capacity is the problem.Not establishedA gate lookup can fail before forwarding anything to the host, but the same catch handles many other exceptions. Local log absence cannot identify the failed dependency.
This is distinct from an ordinary response-head timeout.Mechanism distinguishedThe generic message is HTTP 502; deadline expiry is HTTP 504 with a stage-specific plain-text body. No reporter response headers were available to correlate an actual request.
All remote users are affected.UnverifiedNo fleet-wide data was collected. Priority High reflects the reported recurring work block, not a verified global outage.

3. Environment

4. Minimal reproduction

Scope: reproduce the gate's failure response and distinguish it from deadline expiry. This does not reproduce spontaneous failures during normal browsing.

  1. Create a clean checkout at the exact trusted commit and install existing dependencies:
    git clone https://github.com/get-bb/bb.git checkout-A
    cd checkout-A
    git checkout --detach f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7
    pnpm install --frozen-lockfile --prefer-offline
  2. Run the existing owning-boundary tests through Turbo. No new test or dependency is required:
    pnpm exec turbo run test --filter=@bb/connect --force -- --reporter=verbose -t 'gate error response|gate request deadline|gate replays through a tunnel object restart|gate lookup caches'
  3. The selected error-response test rejects gate label resolution with a synthetic D1 overload error and calls the worker on a thread API GET. Expected and actual are identical:
    HTTP 502
    {"code":"connect_gate_error","message":"bb connect hit a temporary problem. Try again in a moment."}
    Gate console.error records the originating exception.
    The HTML-navigation variant has an automatic refresh interval of 5 seconds.

    Those response values are asserted in the existing tests; they are not claimed to be a captured production HTTP transcript. The distinct stalled-tunnel test asserts HTTP 504 and the body fragment (stage: tunnel-object).

Repeatable runner

Save this as reproduce.sh outside the source checkout and invoke bash reproduce.sh checkout-A. It also works against checkout-B.

#!/usr/bin/env bash
set -euo pipefail
checkout=${1:?Pass the path to a clean trusted checkout}
cd "$checkout"
test "$(git rev-parse HEAD)" = f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7
git diff --quiet
git diff --cached --quiet
pnpm exec turbo run test --filter=@bb/connect --force -- --reporter=verbose -t 'gate error response|gate request deadline|gate replays through a tunnel object restart|gate lookup caches'

Existing failure-response test

Excerpt of apps/connect/src/worker.test.ts:3370. Only the synthetic hostname has been anonymized; run the original source test using the command above rather than treating this excerpt as a standalone test file.

describe("gate error response", () => {
  beforeEach(() => {
    vi.clearAllMocks();
    mockResolveLabel.mockRejectedValue(
      new Error("D1_ERROR: D1 DB is overloaded. Requests queued for too long."),
    );
  });

  it("answers an API caller with a readable JSON 502 and logs the failure", async () => {
    const logged = vi.spyOn(console, "error").mockImplementation(() => {});
    const { env, ctx } = makeEnv(() => new Response("origin"));
    const response = await worker.fetch(
      visitorRequest("HOST.getbb.app", "/api/v1/threads/thr_x/child-summary"),
      env as never,
      ctx,
    );
    expect(response.status).toBe(502);
    expect(await response.json()).toEqual({
      code: "connect_gate_error",
      message: "bb connect hit a temporary problem. Try again in a moment.",
    });
    expect(logged).toHaveBeenCalledWith(
      "bb connect: request failed",
      expect.objectContaining({
        method: "GET",
        path: "/api/v1/threads/thr_x/child-summary",
        error:
          "Error: D1_ERROR: D1 DB is overloaded. Requests queued for too long.",
      }),
    );
    logged.mockRestore();
  });

  it("gives a browser navigation a page that retries itself", async () => {
    const logged = vi.spyOn(console, "error").mockImplementation(() => {});
    const { env, ctx } = makeEnv(() => new Response("origin"));
    const response = await worker.fetch(
      visitorRequest("HOST.getbb.app", "/", {
        headers: { accept: "text/html" },
      }),
      env as never,
      ctx,
    );
    expect(response.status).toBe(502);
    expect(response.headers.get("content-type")).toContain("text/html");
    const body = await response.text();
    expect(body).toContain("bb connect hit a temporary problem");
    expect(body).toContain('http-equiv="refresh" content="5"');
    logged.mockRestore();
  });
});

Observed selected-test output, checkout-A

@bb/connect:test:  ✓ |@bb/connect:isolated| src/session.test.ts > gate lookup caches > runs one D1 lookup for a burst of concurrent requests 24ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate replays through a tunnel object restart > does not add load to an unreachable object 3ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate replays through a tunnel object restart > does not replay onto an overloaded object 1ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > answers 504 naming the stage when the tunnel object never answers 6ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > records the tunnel's heartbeat age with a stall ('connected', 95000) 3ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > records the tunnel's heartbeat age with a stall ('connected', -1) 2ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > records the tunnel's heartbeat age with a stall ('disconnected', -1) 2ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > answers 504 when routing never finishes 2ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > answers 504 naming the body stage when a relayed upload never ends 5ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > answers 504 naming the head stage when a relayed request gets no response 3ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > disposes a late HTTP response after the deadline answered 1ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > disposes a late WebSocket response after the deadline answered 1ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > marks a tunnel dial still waiting on the tunnel object after three seconds 3ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate request deadline > records nothing for a request that answers in time 1ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate error response > answers an API caller with a readable JSON 502 and logs the failure 2ms
@bb/connect:test:  ✓ |@bb/connect:isolated| src/worker.test.ts > gate error response > gives a browser navigation a page that retries itself 1ms

This is a transport/error-path investigation, not a layout defect; screenshots would not identify the failed dependency, and none were fabricated.

5. Root cause and limits

Verified mechanism

Gate label resolution awaits a database-backed routing lookup before forwarding to a tunnel. A rejected lookup escapes to the outer worker catch, which records a gate-side exception and returns gateErrorResponse:

export function gateErrorResponse(request: Request): Response {
  if (wantsHtml(request)) {
    return gatePage(
      `<h1>bb connect hit a temporary problem</h1>
       <p>This page retries automatically in a few seconds.</p>
       <button class="btn" onclick="location.reload()">Retry now</button>`,
      502,
      5,
    );
  }
  return Response.json(
    {
      code: "connect_gate_error",
      message: "bb connect hit a temporary problem. Try again in a moment.",
    },
    { status: 502 },
  );
}

That exception handler is a many-to-one mapping: the error text is not a unique signature for D1 overload or an overloaded relay. The existing unreachable/overloaded object tests demonstrate other failure sources. Tunnel replay policy intentionally avoids adding retry load to unreachable or overloaded objects; blindly retrying those cases is not a demonstrated safe fix.

withGateDeadline separately caps waiting and reports the progress stage, returning 504 rather than the generic 502. The ordinary limit is 30,000 ms. This bounds a stall; it does not establish the cause of the reported multi-second delays.

Production root cause remains unknown

The tests deliberately inject failures. They cannot establish that the reporter encountered D1 overload, a Durable Object reset, an unreachable tunnel, an origin exception, or a different dependency failure. Empty host logs are consistent with a pre-forwarding gate error, but do not prove it. No production telemetry was accessed.

Trusted history already contains commit 6b3fa9d0f444ef5fd1e7ae0ee141bd5c92e6d55b, merged October 20, 2026, coalescing concurrent gate lookups (SettledLookupCache). The existing 20-request burst test passes and performs one database select. That commit is also an ancestor of the desktop-v0.47.1 tag dated October 23, 2026. Neither the client tag nor the existing mitigation proves what code the hosted gate deployed or that this incident is already fixed.

6. Proposed fix / next experiment

Not confident enough to propose a production code change. First correlate one failing thread request's exact UTC time, request path, HTTP status/body, and edge request identifier with stored gate Workers Logs and existing stall/tunnel metrics. Distinguish a caught 502 exception from a 504 deadline and record whether the host received the request. Use an isolated staging deployment to reproduce the observed dependency failure before designing a regression test. Never attach a production Wrangler tail or dashboard live log stream: that can reset tunnel Durable Objects.

No open pull request linking this issue was found in its cross-reference timeline or the open-PR body search. No fix branch or PR was created: a production regression under normal conditions has not been reproduced, so the mandatory failing-before/passing-after simple-fix condition cannot be met safely.

7. Verification

The same agent created a second clean detached checkout at the recorded base, installed from the frozen lockfile again, and reran both the complete Connect suite and the exact focused runner with --force, preventing Turbo from substituting cached test execution. No new ports or app data were needed in either run. This is a repeated clean check, not an independent review.

Checkcheckout-Acheckout-B
Focused failure, deadline, replay, cache checks30 passed; 268 deliberately skipped30 passed; 268 deliberately skipped
Complete Connect suite298 passed in 10 files298 passed in 10 files
Tracked production changesNoneNone

The second run supports only the same controlled error-path conclusions. No correction or escalation to REPRODUCED was warranted.

checkout-A, full suite:
@bb/connect:test:  Test Files  10 passed (10)
@bb/connect:test:       Tests  298 passed (298)
@bb/connect:test:    Duration  5.27s (transform 4.64s, setup 0ms, import 9.88s, tests 6.75s, environment 1ms)
Cached:    0 cached, 2 total
  Time:    6.517s 

checkout-B, full suite:
@bb/connect:test:  Test Files  10 passed (10)
@bb/connect:test:       Tests  298 passed (298)
@bb/connect:test:    Duration  5.38s (transform 4.51s, setup 0ms, import 9.19s, tests 8.95s, environment 1ms)
Cached:    0 cached, 2 total
  Time:    6.556s 

checkout-A, focused:
@bb/connect:test:  Test Files  2 passed | 8 skipped (10)
@bb/connect:test:       Tests  30 passed | 268 skipped (298)
@bb/connect:test:    Duration  2.61s (transform 5.02s, setup 0ms, import 9.68s, tests 630ms, environment 1ms)
Cached:    0 cached, 2 total
  Time:    3.907s 

checkout-B, focused:
@bb/connect:test:  Test Files  2 passed | 8 skipped (10)
@bb/connect:test:       Tests  30 passed | 268 skipped (298)
@bb/connect:test:    Duration  2.51s (transform 4.91s, setup 0ms, import 9.53s, tests 624ms, environment 1ms)
Cached:    0 cached, 2 total
  Time:    3.781s 

8. Related repository evidence

Merged PR #5884 is relevant history for gate lookup coalescing, not a linked open fix for this issue. Trusted main already includes it; its branch was not checked out or executed. Existing trusted tests are stronger evidence than assuming the older lookup stampede is still occurring.

9. Appendix

Investigation commands: GitHub reads of issue type/fields/labels/comments/cross-references, valid repository classifications, similar Connect issue metadata and open PR links; git fetch origin main; upstream main SHA comparison; detached worktree creation; frozen installs; initial pnpm exec turbo run build; complete pnpm exec turbo run test --filter=@bb/connect in each checkout (second with --force); focused runner above in each checkout; trusted source/history reads; tag ancestry check. Reproduction scripts and raw evidence remain local; the public report embeds the complete runner and relevant output rather than exposing runtime dumps or machine-specific paths.

Trust boundary: issue text was treated only as untrusted claims. Its feature suggestions were not followed, no supplied URL was fetched, no issue-provided code was executed, and no linked PR branch was used.

> AGENT GENERATED