Skip to content

Connect's 30s response-header timeout breaks model calls for large-context threads #4832

Closed

Description

@brsbl

Summary

A bb thread whose context has grown large (about 841k of 1M tokens) fails every turn with:

API Error: 504 bb connect: timed out waiting for the tunnel client.

Model calls from the host go through the Account Pool proxy on the bb server, and they reach it through the bb Connect relay. The relay gives up when response headers haven't arrived 30 seconds after it opens the stream. A large model request can't return headers in that time, so the thread can never complete another turn. Small requests on the same path work.

Evidence

  • Request path. The Claude Code session environment sets ANTHROPIC_BASE_URL=http://127.0.0.1:<port>/api/v1/plugins/account-pool/http, so every model call goes to the Account Pool plugin on the bb server. In the affected setup the server runs remotely, so that call crosses the Connect relay.
  • The timeout. proxyHttp arms a RESP_HEAD_TIMEOUT_MS = 30_000 timer when it opens the stream. That is before pumpRequestBody uploads the body, so the upload time counts against the 30 seconds.
  • Work before headers. After the body arrives, the Account Pool parses the whole request and may wait up to MAX_INLINE_HOLD_MS = 20_000 for quota. Only then does it call Anthropic and wait for upstream headers.
  • Observed. On one thread at about 841k estimated context tokens, 4 consecutive turns each ran 6–9 minutes and ended with the 504 above, which fits Claude Code retrying the 504 several times. A fresh thread on the same project, host and pool works normally.

Not yet measured: the actual time to response headers for a request this size. The causal link to context size is strongly supported but not proven.

Impact

  • Once a thread is this large, it can't run any more turns. "Continue" and retry fail the same way.
  • Compaction doesn't help: it sends the same large context through the same path and hits the same timeout. The only workaround is to abandon the thread and start a new one.
  • The error text calls it a temporary server-side issue and points to status.claude.com, so users keep retrying something that will never succeed.

Suggested fix

  1. In Connect, start the response-header timer only after the request body has finished uploading, so upload time doesn't count against it.
  2. Give long-running model-API traffic (the Account Pool HTTP route) a much longer header timeout than 30 seconds, or none, since a model API can legitimately take longer than that to start responding.
  3. Open question: should the host's model traffic go through the remote relay at all? Talking to the pool or to the provider more directly would remove this failure mode. This is an architecture decision, separate from the two changes above.

Related

BB-Thread-ID: thr_d58s3peww2

Activity

  1. added
    bug
    remote
    connect
    on Oct 4, 2026
  2. added theissue type on Oct 4, 2026
  3. added
    partial-repro
    on Oct 4, 2026
  4. bb-slop-cop commented on Oct 4, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority: High · Effort: Medium. Added the missing properties; preserved bug, remote, and connect.
    • Report: https://get-bb.github.io/reports/issues/4832.html
    • Verdict: PARTIALLY REPRODUCED · Confidence: high for the transport mechanism. Applied partial-repro.
    • Root cause: Both Connect HTTP paths start a fixed 30-second response-header deadline before request upload. Slow uploads and delayed post-upload headers return the exact gateway 504. Actual large-context model timing remains unmeasured.
    • Verification: Two clean checkouts of trusted main reproduce four expected-200/actual-504 failures and two successful controls. All 192 existing Connect tests pass.
    • No PR: A model-route timeout budget requires a product-policy decision; moving the timer alone leaves the delayed-header failure unresolved.

    AGENT GENERATED

  5. sms-yui commented on Oct 20, 2026

    @sms-yui
    Contributor

    Another symptom with the same root cause: GPT Image 2 never works through the Account Pooler from a remote machine. Unlike the large-context case, it doesn't depend on request size; every image edit fails.

    What happens

    A Codex thread on a remote macOS host calls the built-in image_gen tool. Codex routes it through the Account Pooler (model_provider = "bb-account-pool", base URL …/api/v1/plugins/account-pool/http/v1), and that call crosses bb Connect to reach the bb server. Every call fails:

    image generation failed: http 504 Gateway Timeout: Some("bb connect: timed out waiting for the tunnel client (stage: response-head)\n")
    
    • In two threads, all 8 image_gen calls failed after 139–154 s each. That fits Codex retrying several 30 s failures. No call produced an image.
    • On the same host, the same edit (same 1920×1080 reference image and prompt) run with the host's own Codex login, which bypasses the Account Pooler and Connect, produced an image in 52 s.

    Why

    • The hub proxies POST /v1/images/generations and /v1/images/edits (server.ts#L440-L452).
    • These responses aren't streamed: upstream sends response headers only when the image is finished, so a high-quality edit takes longer than 30 s to produce headers.
    • Connect's deadline is a fixed RESP_HEAD_TIMEOUT_MS = 30_000. Voice transcription is the only exception (90 s, Allow Codex voice requests to use the transcription budget #5020).
    • /v1/responses streams, so it returns headers quickly and normal turns work. That's why most pooled traffic doesn't hit this.
    • Outside Connect, the hub's own upstream limit is undici's default headersTimeout of 300 s (upstream-transport.ts#L4). I found no other timeout under 300 s on this path (host-daemon proxy, tunnel client, server).

    Options for the timeout-budget decision

    I prototyped two fixes on a fork. Neither has run against a deployed gateway, but they may help scope the decision:

    1. Path budget (sms-yui:scott/connect-image-head-timeout): 360 s for POST to the two pooled image routes. It's small, but it hardcodes a plugin route into Connect. Hub failover across accounts can still exceed it, and the relay socket sits silent for minutes.
    2. Liveness frames (sms-yui:scott/connect-head-pending):
      • For plugin HTTP routes, the tunnel client sends a new head-pending frame every 10 s while it waits for the origin's response head.
      • Each frame moves the gate and relay deadlines to 30 s after that frame, capped at 15 min.
      • Support is negotiated both on the tunnel's 101 and per relay, so old clients and gateways keep today's behavior.
      • This would also cover the large-context case here for pooled routes, but it changes the tunnel protocol.
    3. Not prototyped: have the hub send response headers early for image routes, the way streamToolCallResponse does for plugin tools (Keep interactive plugin tools past the Connect timeout #1084, tool-calls.ts#L25). It needs no Connect change, but an upstream error that arrives after the early headers can no longer return its real status code.

    Workaround: bb pool bypass <thread> on the image thread routes it with the host's own provider login and avoids Connect.

    Environment

    • bb 0.46.0. The server runs on Linux; the remote host is macOS and reaches the server through bb Connect.
    • Codex CLI 0.163.0, ChatGPT login, Account Pooler routing enabled for Codex.
    • Evidence comes from the threads' Codex rollouts and bb thread log. I didn't reproduce this on main, but the code paths cited are unchanged at 0eac33e06.

    BB-Thread-ID: thr_5dph4qkdqg

    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

    bugconnectpartial-reproremote

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions