aft icon indicating copy to clipboard operation
aft copied to clipboard

Binary and ONNX downloads fail behind HTTP(S)_PROXY on Node.js with opaque "fetch failed" (err.cause dropped)

Open lmonkt opened this issue 1 week ago • 0 comments

Problem

When running npx @cortexkit/aft@latest setup or npx @cortexkit/aft doctor --fix behind an HTTP/HTTPS proxy (http_proxy / https_proxy / HTTP_PROXY / HTTPS_PROXY), binary and ONNX Runtime downloads fail on Node.js with an opaque fetch failed message:

AFT binary download failed: could not reach GitHub to download the v0.68.0 binary (Failed to download AFT binary: fetch failed). Check your network connection or proxy.

Two things make this difficult to diagnose:

  1. Bun vs. Node.js runtime difference for fetch(): OpenCode runs on Bun, where fetch() honours HTTP(S)_PROXY / NO_PROXY by default. However, npx @cortexkit/aft (and @cortexkit/aft-pi) runs on Node.js, where built-in fetch (undici) ignores HTTP(S)_PROXY unless NODE_USE_ENV_PROXY=1 or --use-env-proxy is set (Node >= 22.21 / 24).
  2. err.cause is dropped in downloader.ts and onnx-runtime.ts: Both downloadBinary() (packages/aft-bridge/src/downloader.ts:350) and downloadOnnxRuntime() (packages/aft-bridge/src/onnx-runtime.ts:800) log only err.message ("fetch failed"), discarding err.cause (UND_ERR_CONNECT_TIMEOUT, ENOTFOUND, ECONNREFUSED, or AggregateError.errors).

Reproduction

On Node v24.21.0 behind a proxy (https_proxy=http://127.0.0.1:7890) where direct connections to release-assets.githubusercontent.com time out:

# Bypasses proxy -> fails after 10s (undici connectTimeout) with bare TypeError: fetch failed
env -u NODE_USE_ENV_PROXY https_proxy=http://127.0.0.1:7890 \
  node -e 'fetch("https://github.com/cortexkit/aft/releases/download/v0.68.0/checksums.sha256").then(r => console.log(r.status))'

# Succeeds via proxy
NODE_USE_ENV_PROXY=1 https_proxy=http://127.0.0.1:7890 \
  node -e 'fetch("https://github.com/cortexkit/aft/releases/download/v0.68.0/checksums.sha256").then(r => console.log(r.status))'

Proposed Fix

Keep aft-bridge free of global side effects (do not mutate Node's process-wide HTTP dispatcher from a library that also runs inside host processes) and fix the diagnostic gap:

  1. Walk error.cause (and AggregateError.errors) when formatting fetch failures in downloadBinary() and downloadOnnxRuntime(), and distinguish the 300s download timeout from external aborts.
  2. When a download fails on Node.js with HTTP(S)_PROXY set in the environment while neither NODE_USE_ENV_PROXY=1 nor --use-env-proxy is active, append an explicit hint: (HTTP(S)_PROXY is set, but Node.js fetch ignores it unless NODE_USE_ENV_PROXY=1 is set)

(Open question for maintainers: if you would also like aft-cli or aft-bridge to opt into http.setGlobalProxyFromEnv() on Node >= 24.14 when proxy env vars are present, happy to add that if desired.)

lmonkt avatar Nov 26 '26 16:11 lmonkt