Skip to content

bb's own outbound fetch() ignores HTTP_PROXY/HTTPS_PROXY: provider usage and Codex subscription calls fail (HTTP 403) behind a mandatory proxy #3239

Closed

Description

@dkarelov

Summary

Every outbound HTTP call bb makes itself uses Node's global fetch with no dispatcher, so it silently ignores HTTP_PROXY / HTTPS_PROXY / NO_PROXY. Behind a mandatory proxy this breaks Settings → Usage limits for all three providers and every bb-owned ChatGPT/OpenAI call (thread titles, transcription, manager calls) — in a region where OpenAI and Anthropic block the IP, those requests come back HTTP 403. Agent turns mostly still work, because they run through the spawned provider CLI (codex, claude), which does its own proxying — which is what makes this look intermittent rather than total.

I expected bb to route its own requests through the proxy the environment declares, the way the push-notifications plugin already does with undici's EnvHttpProxyAgent.

Versions and environment

  • bb 0.42.1, run with npx bb-app@latest (matches npm view bb-app version = 0.42.1); source read at main @ 06aeaa994942ae7527dc49d2268c1f801e8542a0
  • Ubuntu 24.04.1 LTS on WSL2 (kernel 6.6.87.2-microsoft-standard-WSL2), Windows host
  • Node v24.14.1
  • Providers: codex (codex-cli 0.153.4, ChatGPT subscription auth), claude-code (Claude Code 2.1.263), acp-cursor
  • Mandatory local HTTP proxy at http://127.0.0.1:10808, exported as HTTP_PROXY/HTTPS_PROXY, with NO_PROXY=localhost,127.0.0.1. The proxy vars are present in the environment of every bb process (verified via /proc/<pid>/environ for npm exec bb-app, the server, and the host daemon).

Steps to reproduce

A. Universal repro — no blocked region needed. Point the proxy variables at a dead port. If bb honored them, every outbound request would fail with ECONNREFUSED; instead they succeed, proving the proxy is never consulted.

# 1. Proxy is ignored: request succeeds despite the proxy being unreachable
HTTPS_PROXY=http://127.0.0.1:1 HTTP_PROXY=http://127.0.0.1:1 \
  node -e 'fetch("https://chatgpt.com/backend-api/wham/usage",{signal:AbortSignal.timeout(15000)}).then(r=>console.log("status",r.status)).catch(e=>console.log("ERR",e.cause?.code))'
# -> status 403      (a direct connection was made; in an unblocked region you get 401)

# 2. Same request with a dispatcher wired up: the proxy IS used
HTTPS_PROXY=http://127.0.0.1:1 NODE_USE_ENV_PROXY=1 \
  node -e 'fetch("https://chatgpt.com/backend-api/wham/usage",{signal:AbortSignal.timeout(15000)}).then(r=>console.log("status",r.status)).catch(e=>console.log("ERR",e.cause?.code))'
# -> ERR ECONNREFUSED

# 3. For contrast, curl honours the same variable
HTTPS_PROXY=http://127.0.0.1:1 curl --max-time 10 https://chatgpt.com/backend-api/wham/usage
# -> exit 7, connection refused

B. The user-visible symptom, on a network where chatgpt.com / api.anthropic.com / api2.cursor.sh reject the direct IP but the proxy is allowed:

export HTTP_PROXY=http://127.0.0.1:10808 HTTPS_PROXY=http://127.0.0.1:10808
npx bb-app@latest
bb settings usage        # or Settings -> Usage limits in the UI

Did not reproduce with: the codex CLI itself (it proxies via its own [features.network_proxy] config); loopback traffic to bb's own ports; a clean data dir (unrelated).

Expected vs actual

Actual — bb settings usage, with a working proxy exported and reachable (account emails redacted):

{
  "codex": {
    "status": "error",
    "message": "Codex usage request failed (HTTP 403).",
    "planLabel": null,
    "accountEmail": "<redacted>"
  },
  "claude-code": {
    "status": "error",
    "message": "Claude usage request failed (HTTP 403).",
    "planLabel": "Max (5x)",
    "accountEmail": "<redacted>"
  },
  "acp-cursor": {
    "status": "error",
    "message": "Cursor usage request failed (HTTP 403).",
    "planLabel": null,
    "accountEmail": null
  }
}

Expected: the same usage payload the endpoint returns when the request actually goes through the proxy. With identical credentials and identical headers, curl through that same proxy returns real data:

$ curl -x http://127.0.0.1:10808 -H "Authorization: Bearer $ACCESS_TOKEN" \
    -H "chatgpt-account-id: $ACCOUNT_ID" -H "originator: bb" \
    -H "User-Agent: bb-provider-codex" -H "Accept: application/json" \
    https://chatgpt.com/backend-api/wham/usage
200
{"user_id":"user-…","account_id":"…","email":"…","plan_type":"prolite","rate_limit":{"allowed":…}}

Confirmed the fix at the network layer by replaying bb's exact fetchCodexUsage request from Node with a dispatcher enabled: NODE_USE_ENV_PROXY=1 → HTTP 200, plan_type: prolite, all four rate_limit windows present.

Evidence

Direct vs. proxied, same machine, same moment:

Endpoint direct via proxy
chatgpt.com/backend-api/wham/usage (authenticated) 403 200 + payload
api.anthropic.com/api/oauth/usage (unauth) 403 429
api2.cursor.sh/aiserver.v1.DashboardService/… (unauth) 403 415
api.openai.com/v1/models (unauth) 403 401

The 403s are edge rejections of the direct IP; every proxied response is a real application-layer response.

Call sites that use bare global fetch and therefore never see the proxy (permalinks at 06aeaa99):

The one place that gets it right, and the precedent for a fix: plugins/push-notifications/sender.ts#L507 builds an EnvHttpProxyAgent and passes it as a per-request dispatcher. grep for setGlobalDispatcher|ProxyAgent|EnvHttpProxyAgent across apps, packages and plugins returns that file and nothing else outside tests, so no global dispatcher is installed anywhere.

Environment inheritance is not the problem: sanitizeInheritedChildProcessEnv strips only NODE_ENV and BB_*, so the proxy variables do reach the plugin host worker where provider-codex runs. They are simply never read.

Partial workaround, and why it is not enough: exporting NODE_USE_ENV_PROXY=1 before launching bb makes Node honour the variables process-wide. Verified on Node 24.14.1: bb's loopback traffic is unaffected (127.0.0.1:38886 and localhost:38886 health endpoints still return 200, given localhost,127.0.0.1 in NO_PROXY), and the usage request returns 200.

But that flag only exists in Node 24, while bb's baseline is older — package.json declares "node": ">=22.19.0" and .nvmrc pins 22.19.0. On that pinned version the escape hatch is simply absent:

$ npx -y [email protected] --use-env-proxy -e 'console.log("ok")'
node: bad option: --use-env-proxy

$ HTTPS_PROXY=http://127.0.0.1:1 NODE_USE_ENV_PROXY=1 npx -y [email protected] \
    -e 'fetch("https://chatgpt.com/backend-api/wham/usage").then(r=>console.log("status",r.status))'
status 403      # variable ignored, request still went direct

So on bb's own supported Node version there is no user-side workaround at all, and the packaged desktop app gives the user no place to set it either.

Suggested fix: install a global undici dispatcher once at server and host-daemon startup, e.g. setGlobalDispatcher(new EnvHttpProxyAgent()) when any proxy variable is set. That covers every current and future fetch call site in one place, keeps NO_PROXY semantics, and works regardless of Node version. Happy to open the PR for this once approved per CONTRIBUTING.md.

What you ruled out

  • Not a duplicate of Transcription often fails with HTTP 403 due to cloudflare when using codex subscription #1587 ("Transcription often fails with HTTP 403 due to cloudflare when using codex subscription"). That one is Cloudflare bot mitigation on a direct connection, and the fix for it was the cf-cookie retry in chatgpt-fetch.ts. Here cf-mitigated is absent on the 403 and the retry cannot help, because the request never leaves through the proxy at all.
  • Not a credentials problem: the same access token and headers return 200 through the proxy and 403 direct.
  • Not environment inheritance: proxy variables are present in /proc/<pid>/environ for every bb process, and the env sanitizer does not strip them.
  • Not a NO_PROXY misconfiguration: the dead-port repro above shows the proxy is ignored for external hosts even when nothing excludes them.
  • Not specific to one provider: Codex, Claude and Cursor usage all fail identically, and all three endpoints reject the direct IP.
  • Not the provider CLIs: codex and claude proxy correctly on this machine, which is why agent turns keep working while bb's own calls fail.
  • Still present on main @ 06aeaa994942ae7527dc49d2268c1f801e8542a0 by code inspection; reproduced at runtime on the matching 0.42.1 release.

Suggested priority and effort

Medium–High — hits every user behind a mandatory proxy: corporate networks, and users in regions where OpenAI/Anthropic reject direct connections, for whom bb's own AI features fail outright. No workaround on bb's declared Node baseline (22.19.0) or on the desktop app; partial one on Node 24. Effort probably Low: one dispatcher installed at two startup paths.

Checks

  • I reproduced this on the latest release (0.42.1) and read the code on main @ 06aeaa99.
  • I searched open and closed issues for the same problem.
  • This was written by an agent; the body ends with the marker below.

AGENT GENERATED

Activity

  1. added theissue type on Sep 8, 2026
  2. added
    providers
    provider-codex
    provider-claude-code
    provider-acp
    on Sep 8, 2026
  3. dkarelov commented on Sep 8, 2026

    @dkarelov
    Author

    Follow-up findings from prototyping the fix locally. Three of them change what the fix has to look like, so posting them here rather than leaving them implicit.

    1. The one-line fix I suggested above is not safe — it would break bb.

    setGlobalDispatcher(new EnvHttpProxyAgent()) routes everything through the proxy, and bb's own inter-process traffic is HTTP on loopback (launcher → server health checks, server ↔ host daemon, CLI → server). A user who sets HTTP_PROXY without listing loopback in NO_PROXY — which is the common case, since nothing today tells them they need to — would have that internal traffic sent to their proxy. Against a dead proxy:

    http://127.0.0.1:38886/health -> ERR ECONNREFUSED
    

    Node's own --use-env-proxy behaves identically, so this is not an undici quirk to route around. Whatever installs the dispatcher should force loopback into the no-proxy set rather than trusting the environment, and preserve a bare * unchanged (undici only honours the wildcard as an exact value, so appending to it silently disables it).

    2. An IPv6 loopback entry needs its brackets.

    undici parses no-proxy entries with /^(.+):(\d+)$/, so a bare ::1 becomes hostname : with port 1 and never matches anything. [::1] is the form that works — matching the bracketed host undici compares against. Worth knowing for anyone who currently has ::1 in NO_PROXY and assumes it is doing something.

    3. undici tunnels proxied requests with CONNECT even for plain http:// origins.

    A test double that is only an HTTP server will hang rather than fail, because it never answers the CONNECT. This cost me a confusing timeout; noting it so the next person writing a test for this does not repeat it.

    Where the dispatcher has to go. One installation per process, and there are four processes that make outbound requests, not one:

    • apps/server — voice transcription, marketplace stats
    • apps/host-daemon
    • the plugin host worker — where plugins/provider-codex/src/host.ts makes bb's own ChatGPT Responses calls
    • the provider bridge worker — where bridge.ts runs the usage requests this issue is about

    One implementation trap. apps/host-daemon/src/plugin-host-worker.ts currently imports nothing but node: builtins, and it is forked as raw TypeScript (relying on Node's type stripping) in dev and in plugin-host-worker.test.ts. Importing a workspace package whose index re-exports ./something.js breaks it there with ERR_MODULE_NOT_FOUND, because type stripping does not rewrite the extension. A subpath export whose target has no relative imports works; the package root does not.

    I have a local patch along these lines with tests, but per CONTRIBUTING.md I am not on the approved-contributor list, so I am not opening a PR. Happy to hand it over or to go through the Discord approval step first — whichever the maintainers prefer.

    AGENT GENERATED

  4. added
    confirmed-repro
    on Sep 8, 2026
  5. bb-slop-cop commented on Sep 8, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classification: Bug · Priority Medium · Effort Low

    Labels: providers, provider-codex, provider-claude-code, provider-acp, confirmed-repro

    Report: https://get-bb.github.io/reports/issues/3239.html

    Verdict: REPRODUCED · Confidence: high

    Root cause: bb-owned provider and server request paths call Node's default fetch without a proxy-aware dispatcher. Provider host code also runs in a separately forked process, so parent-process dispatcher state would not cover it.

    Reproduction: a deterministic local Vitest pointed the proxy variables at a closed loopback port and invoked bb's Codex fetch wrapper; it reached the origin and returned HTTP 200 in both the primary and second clean trusted checkouts.

    Pull request: not opened because a complete fix crosses the server and forked plugin-host subsystems and requires deciding proxy-agent dependency ownership, which fails the simple-fix and no-new-dependency gates.

  6. lebryk commented on Oct 5, 2026

    @lebryk

    Related, filed separately as #4957: the host daemon's own ws and node:http(s) connections (server WebSocket, bb connect tunnel, machine auth proxy) ignore the proxy variables even with NODE_USE_ENV_PROXY=1, so a global dispatcher fix here would not cover them. The prototype linked there always connects loopback directly, in line with your first follow-up finding.

    AGENT GENERATED

  7. ymichael commented on Nov 17, 2026

    @ymichael
    Collaborator

    Fixed by #6194: the server, daemon and workers now honour HTTP(S)_PROXY. This needs Node 22.21+ or 24.5+. Closing.

    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

    confirmed-reproprovider-acpprovider-claude-codeprovider-codexproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions