Skip to content

session.create fails with "fetch failed" in SDK headless mode behind corporate proxy (v1.0.36) #2978

Open

Description

@mohan3006

Describe the bug

When using @github/copilot-sdk v0.3.0 (CLI v1.0.36) in headless mode behind a corporate HTTP proxy, session.create fails with "fetch failed". The CLI subprocess receives all proxy env vars correctly, and standalone undici 7.22 can reach api.github.com through the same proxy from the same container — but the CLI's internal fetch ignores the proxy.

This is a regression from CLI v0.0.394 where the same setup worked.

Key evidence

  1. Standalone undici works — from inside the Docker container:

    undici version: 7.22.0
    Status: 200
    Body: {"login":"...", "copilot_plan":"copilot_for_business"...}
    
  2. curl works — through the same proxy:

    curl -x http://proxy:443 https://api.github.com/copilot_internal/user → 200
    
  3. CLI subprocess gets proxy env — confirmed by intercepting child_process.spawn:

    SPAWN command: node /app/node_modules/@github/copilot/index.js --headless --no-auto-update
    SPAWN HTTPS_PROXY: http://proxy:443
    SPAWN HTTP_PROXY: http://proxy:443
    SPAWN NODE_TLS_REJECT_UNAUTHORIZED: 0
    SPAWN env: COPILOT_SDK_AUTH_TOKEN = gho_xxx...
    
  4. CLI fails anyway:

    FAILED: Request session.create failed with message: fetch failed
    
  5. No TLS MITM — the proxy does transparent CONNECT (real *.github.com cert from Sectigo, not a proxy-injected cert):

    subject=CN = *.github.com
    issuer=C = GB, O = Sectigo Limited, CN = Sectigo Public Server Authentication CA DV E36
    
  6. NODE_EXTRA_CA_CERTS doesn't help — tested with the full cert chain, same result

Version comparison

Component Working Broken
@github/copilot-sdk 0.1.19 0.3.0
@github/copilot CLI 0.0.394 1.0.36
Node.js v22.22.0 v22.22.0
Result Sessions work "fetch failed"

Affected version

GitHub Copilot CLI 1.0.36

Steps to reproduce the behavior

  1. Run in a Docker container with HTTPS_PROXY set to a corporate HTTP CONNECT proxy
  2. Install @github/[email protected] + @github/[email protected]
  3. Create a CopilotClient with gitHubToken and start it:
    const { CopilotClient } = require("@github/copilot-sdk");
    const client = new CopilotClient({ gitHubToken: token, useLoggedInUser: false });
    await client.start();
  4. Call createSession with gitHubToken:
    const session = await client.createSession({
      model: "gpt-4o",
      gitHubToken: token,
      streaming: false,
      systemMessage: { content: "Be brief." },
      onPermissionRequest: () => ({ result: "allow" }),
    });
  5. Observe: Request session.create failed with message: fetch failed

Expected behavior

session.create should respect HTTPS_PROXY / HTTP_PROXY environment variables for its internal auth fetch to api.github.com, the same way standalone undici 7.22 does from the same container.

Additional context

Activity

  1. added theissue type on Apr 26, 2026
  2. added
    area:networking
    area:enterprise
    and removed on Apr 26, 2026
  3. pWoLiAn commented on Jun 24, 2026

    @pWoLiAn

    Root cause identified

    I hit this same issue in a corporate environment and traced it to the Rust native fetch layer introduced in ~v1.0.36.

    Code path

    web_fetch (and all internal API calls that go through ADe) funnel through xC, which calls I.networkFetchStreamStart — a Rust native binding — instead of Node's fetch or undici.

    The request is prepared in v$n:

    async function v$n(t, e) {
      let o = e?.rustPinnedAddresses ?? [];
      let s = o.length === 0 ? void 0 : {};  // <-- always empty object when addresses are pinned
      return {
        ...s === void 0 ? {} : { proxyEnv: s },  // proxyEnv: {} passed to Rust
        pinnedAddresses: o,
        ...
      }
    }

    For web_fetch, EDe always DNS-resolves the hostname (SSRF protection), producing pinned addresses — so rustPinnedAddresses is always non-empty, and proxyEnv is always passed as an empty object {} to the Rust layer.

    The Rust layer interprets proxyEnv: {} as "no proxy" rather than falling back to reading HTTP_PROXY/HTTPS_PROXY from the process environment.

    Why internal CLI API calls work but web_fetch doesn't

    The CLI's own GitHub API calls go through bf → plain fetch(url, opts) without rustPinnedAddresses, so proxyEnv is never set → Rust reads proxy from env vars → works correctly.

    Fix

    In v$n, populate proxyEnv from the environment instead of passing an empty object:

    let s = o.length === 0 ? void 0 : {
      http: process.env.HTTP_PROXY || process.env.http_proxy,
      https: process.env.HTTPS_PROXY || process.env.https_proxy,
      no: process.env.NO_PROXY || process.env.no_proxy,
    };

    Environment

    • CLI v1.0.64 (Linux x64)
    • Corporate proxy configured via HTTPS_PROXY env var (set and verified)
    • curl through the same proxy works fine; web_fetch tool fails with TypeError: fetch failed
    • Confirmed: NODE_EXTRA_CA_CERTS does not help since the issue is proxy bypass, not TLS cert validation
  4. arielgee commented on Jun 28, 2026

    @arielgee

    Got this same issue in GitHub Desktop 3.6.1 on Windows 10 behind a corporate proxy. Error surfaces when trying to generate a Copilot commit message:

    Request session.create failed with message: Authentication
    failed: Failed to validate SDK token: network fetch failed: request failed:
    error sending request for url (https://api.github.com/copilot_internal/user)
    
  5. arvindkannan commented on Oct 4, 2026

    @arvindkannan

    got this same issue for chat :

    error when trying to initiate new chat, where existing chat works

    Error: (sendFailed) Request session.create failed with message: Standalone managed telemetry preparation failed: network fetch failed: request failed: error sending request for url (https://api.github.com/copilot_internal/user)

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

    area:enterprisearea:networking

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions