#7879 · Plugin command transport bypasses configured proxies
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
Plugin command execution selects a dedicated HTTP dispatcher that does not read proxy environment variables. On a network where the server name is resolvable only by a configured proxy, the command therefore fails with fetch failed. A real local HTTP origin and CONNECT proxy reproduce the failure without a bb server, user credentials, or a sandbox. Repeating the same test in a second clean checkout gives the same DNS failure; direct and proxy-bypass controls pass. Replacing only the dispatcher implementation with the already-installed environment-aware agent fixes both uppercase and lowercase proxy settings while retaining the long command timeout.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Plugin command POSTs ignore configured proxies. | Verified | Uppercase and lowercase HTTP proxy cases both fail with direct DNS lookup on trusted main; both pass after the dispatcher replacement. |
| The custom dispatcher is responsible. | Verified | The POST supplies a plain Agent. A two-line replacement makes the same real-network cases pass without changing the destination, environment, or proxy. |
| Discovery and core requests can use Node's default proxy routing. | Supported by source; not exercised under Node's built-in proxy flag here. | Discovery calls cliFetch without a dispatcher; cliFetch delegates to global fetch. The reproduction host runs Node 22.19.0, below the documented built-in proxy support version. |
| The original macOS sandbox has this exact failure. | Unverified environment | No macOS sandbox was used. The underlying proxy-only reachability failure is reproduced on Linux. |
| HTTPS proxy routing is affected too. | Supported by shared source path; not separately network-tested | The same explicit dispatcher is used for HTTP and HTTPS command URLs. The chosen library agent implements both schemes. |
3. Environment
- Trusted public repository: get-bb/bb, origin/main at
9f4c15646d3d7d9320191d4a2cd76199471a1ddc. - Linux 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.12; existing undici 7.30.2.
- Two separate source checkouts at the identical commit. Each test invocation allocates fresh OS-selected loopback ports with
listen(0), closes the servers and tunnel sockets, and restores proxy environment variables. - No product instance, provider, persistent data directory, real server endpoint, or credentials are required. The reserved
.invaliddestination cannot resolve directly; the local proxy connects it to the loopback origin. - Frozen install and scoped CLI build succeeded. The initial whole-repository build hit missing generated Plugin SDK exports in an unrelated plugin; building the existing SDK types with Turbo repaired that preparation step. CLI build, typecheck, and tests then completed successfully.
4. Minimal reproduction
- Clone the public target repository, check out the recorded trusted main commit, and prepare the CLI:
git clone https://github.com/get-bb/bb.git bb-proxy-repro cd bb-proxy-repro git checkout 9f4c15646d3d7d9320191d4a2cd76199471a1ddc pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=@bb/cli
- Save the attached, independently authored regression test as
apps/cli/src/__tests__/plugin-cli-env-proxy.test.ts. It exercises the real production function and real HTTP sockets, not a mocked fetch or copied issue script. - Run:
pnpm exec turbo run test --filter=@bb/cli -- plugin-cli-env-proxy.test.ts
Expected: all five cases pass. For configured proxies, the POST is delivered through a CONNECT tunnel and prints the origin's command result. NO_PROXY and no-proxy-configured controls connect directly.
Actual on trusted main, both runs:
FAIL routes plugin command POSTs according to 'HTTP_PROXY' FAIL routes plugin command POSTs according to 'http_proxy' AssertionError: promise rejected "TypeError: fetch failed" instead of resolving Caused by: Error: getaddrinfo ENOTFOUND bb-proxy-regression.invalid Tests 2 failed | 3 passed (5) process exit: 1
Complete regression test
import { createServer, type Server } from "node:http";
import { connect } from "node:net";
import { Writable, type Duplex } from "node:stream";
import { afterEach, expect, it, vi } from "vitest";
afterEach(() => {
vi.unstubAllEnvs();
});
async function listen(server: Server): Promise<number> {
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const address = server.address();
if (address === null || typeof address === "string") {
throw new Error("Expected a TCP server address");
}
return address.port;
}
it.each([
{ name: "HTTP_PROXY", proxyKey: "HTTP_PROXY", bypassKey: undefined },
{ name: "http_proxy", proxyKey: "http_proxy", bypassKey: undefined },
{ name: "NO_PROXY", proxyKey: "HTTP_PROXY", bypassKey: "NO_PROXY" },
{ name: "no_proxy", proxyKey: "http_proxy", bypassKey: "no_proxy" },
{ name: "no proxy configured", proxyKey: undefined, bypassKey: undefined },
])(
"routes plugin command POSTs according to $name",
async ({ proxyKey, bypassKey }) => {
vi.resetModules();
for (const key of [
"HTTP_PROXY",
"HTTPS_PROXY",
"http_proxy",
"https_proxy",
"NO_PROXY",
"no_proxy",
]) {
vi.stubEnv(key, undefined);
}
const requests: string[] = [];
const tunnels: string[] = [];
const sockets = new Set<Duplex>();
const origin = createServer((request, response) => {
requests.push(`${request.method} ${request.url}`);
request.resume();
response.setHeader("content-type", "application/json");
response.end(
JSON.stringify({ exitCode: 0, stdout: "proxied command result" }),
);
});
const proxy = createServer();
try {
const originPort = await listen(origin);
proxy.on("connect", (request, downstream, head) => {
tunnels.push(request.url ?? "");
const upstream = connect(originPort, "127.0.0.1", () => {
downstream.write("HTTP/1.1 200 Connection Established\r\n\r\n");
upstream.write(head);
upstream.pipe(downstream);
downstream.pipe(upstream);
});
sockets.add(downstream);
sockets.add(upstream);
downstream.on("error", () => upstream.destroy());
upstream.on("error", () => downstream.destroy());
});
const proxyPort = await listen(proxy);
if (proxyKey !== undefined) {
vi.stubEnv(proxyKey, `http://127.0.0.1:${proxyPort}`);
}
if (bypassKey !== undefined) {
vi.stubEnv(bypassKey, "127.0.0.1");
}
const shouldProxy = proxyKey !== undefined && bypassKey === undefined;
const hostname = shouldProxy
? "bb-proxy-regression.invalid"
: "127.0.0.1";
const writes: string[] = [];
const stream = new Writable({
write(chunk, _encoding, callback) {
writes.push(chunk.toString());
callback();
},
});
const { runPluginCliCommand } = await import("../plugin-cli-proxy.js");
await expect(
runPluginCliCommand(
`http://${hostname}:${originPort}`,
"transport-fixture",
["inspect"],
{ stdout: stream, stderr: stream },
),
).resolves.toBe(0);
expect(writes).toEqual(["proxied command result\n"]);
expect(requests).toEqual(["POST /api/v1/plugins/transport-fixture/cli"]);
expect(tunnels).toEqual(shouldProxy ? [`${hostname}:${originPort}`] : []);
} finally {
for (const socket of sockets) socket.destroy();
origin.closeAllConnections();
proxy.closeAllConnections();
await Promise.all(
[origin, proxy].map(
(server) =>
new Promise<void>((resolve) => server.close(() => resolve())),
),
);
}
},
);
5. Root cause
getPluginCliDispatcher constructs and caches a plain undici.Agent with a 65-minute headers timeout. That agent handles direct connections; it does not consume proxy environment settings. runPluginCliCommand supplies it explicitly on the POST, overriding any global fetch dispatcher. cliFetch forwards the dispatcher unchanged to fetch.
pluginCliDispatcher ??= new Agent({
headersTimeout: PLUGIN_CLI_HEADERS_TIMEOUT_MS,
});
...
dispatcher: getPluginCliDispatcher(),
This explains the observed direct DNS error: the proxy can route the reserved destination, but the explicit direct agent attempts local DNS first. This is a transport-policy inconsistency, not a server authorization failure or plugin execution failure. The existing long-response timeout is intentional and must not be removed; an existing regression test protects it.
6. Proposed fix and validation
Use the existing undici EnvHttpProxyAgent for the cached command dispatcher, retaining the same headers timeout. It routes according to HTTP_PROXY / HTTPS_PROXY and NO_PROXY, including their lowercase forms, and uses a direct agent when no proxy applies. No dependency, protocol, schema, or stored-data change is needed. Document the command transport's environment handling in the existing networking documentation.
pnpm exec turbo run test --filter=@bb/cli -- plugin-cli-env-proxy.test.ts # after fix: 5 passed (5) pnpm exec turbo run test typecheck build --filter=@bb/cli # 80 test files passed; 1412 tests passed, 1 skipped; all 8 Turbo tasks succeeded
The existing delayed-response test also passes, protecting commands that wait for human input. HTTPS TLS interception and the original macOS sandbox have not been directly tested. The candidate changes four text files, totaling 121 added and deleted lines, within the existing CLI transport subsystem and its documentation.
7. Related work
No linked open pull request was present in the issue timeline or the repository's open-PR search during investigation. No linked pull request code was checked out or executed. Other issue references were not used as reproduction instructions.
8. Verification
The same agent repeated the reproduction in a second initially clean detached checkout created with git worktree add --detach <fresh-temporary-directory>/source 9f4c15646d3d7d9320191d4a2cd76199471a1ddc. The recorded HEAD matched the base and the checkout was clean before adding only the regression file. A separate frozen install and Turbo CLI build succeeded. The identical test command ran in that checkout, allocating new loopback servers and producing the same two proxy failures and three passing direct/bypass controls (exit 1). This is a repeat check by the same agent, not a separate reviewer. No report corrections were needed; the final test type annotation was corrected before the saved repeat run.
9. Appendix and artifacts
- Regression test
- First trusted-main failure
- Second clean-checkout failure
- Focused post-fix success
- Complete CLI test, typecheck, and build output
This is a nonvisual transport bug, so screenshots are not applicable. Logs have local checkout paths redacted. Issue content was treated only as untrusted claims: no issue-provided script, patch, branch, binary, or external URL was executed or fetched.
> AGENT GENERATED