Skip to content

[Bug] Repo Wiki generation fails with "fetch failed" — httpProxy setting not applied to wiki generator (host process / undici) #199

Description

@NonEstSpes

提交前确认 · Pre-submission checklist

  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.

问题类别 · Category

模型设置 / 切换 · Model config

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

阻塞使用 · Blocking (无法使用核心功能 / core function unusable)

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

Repo Wiki generation always fails with fetch failed in an environment that requires an HTTP proxy to reach api.z.ai. Meanwhile, the agent chat (same provider builtin:zai, same model GLM-5.2, same endpoint https://api.z.ai/api/anthropic) works fine in the same session.

This indicates the httpProxy setting from Settings is applied to the agent runtime but not to the wiki generator, which runs in the host process and uses Node's undici/fetch.

Related: #187 — same root cause (httpProxy only applied to a subset of network clients), different affected component. #187 covers Token Plan + feedback upload; this issue covers repo-wiki generation.

Steps to reproduce

  1. Configure ZCode with a corporate HTTP proxy in Settings:
    • httpProxy: http://user:pass@proxy.corp.example:8080
    • httpProxyNoProxy: *.corp.example
  2. Open a repository in an air-gapped / proxy-only network where direct egress to api.z.ai:443 is blocked.
  3. Trigger Repo Wiki generation (e.g. via the "Generate Wiki" / Knowledge Base action).
  4. Observe failure within ~10s.

Expected behavior

Wiki generation should use the configured httpProxy (same as agent chat does) and succeed.

Actual behavior

Every wiki task fails on the first (catalog) request with a TCP connect timeout to api.z.ai:443:

TypeError: fetch failed
  cause: ConnectTimeoutError: Connect Timeout Error
    (attempted address: api.z.ai:443, timeout: 10000ms)
    at onConnectTimeout (node:internal/deps/undici/undici:1936:23)
    at Immediate._onImmediate (node:internal/deps/undici/undici:1902:35)

The host-process log shows:

[repoWiki] Wiki 模型请求开始 {"kind":"catalog","providerId":"builtin:zai","model":"GLM-5.2","endpoint":"https://api.z.ai/api/anthropic","promptChars":20125}
[repoWiki] Wiki 模型请求失败 {"error":"fetch failed"}
[repoWiki] Wiki 生成失败 {"error":"fetch failed"}

At the same timestamp, the agent runtime successfully reaches the identical endpoint:

[zcode-agent-service] 开始请求 ZCode Protocol session/resume
  runtimeModel.baseURL: "https://api.z.ai/api/anthropic"  ← works

Root cause analysis

Two different HTTP stacks, two different proxy behaviors:

Component Process HTTP client Reads httpProxy setting? Result
Agent chat ZCode Protocol (child) Electron/net ✅ yes works
Repo Wiki generator Host process (main) Node undici/fetch ❌ no ConnectTimeoutError

Node undici ignores the application-level httpProxy setting — by default it only honors HTTP_PROXY/HTTPS_PROXY env variables, which are not set (and even if set at OS level, ZCode does not propagate them to the host process, per #187). As a result the wiki generator attempts a direct connection to api.z.ai:443, which the corporate firewall drops → 10s ConnectTimeoutError.

Note the failure is at the TCP handshake (before any HTTP body is sent), so request size is not a factor — even the smallest catalog request (~20K chars / ~5KB) fails identically.

Suggested fix

Propagate the httpProxy setting into an undici ProxyAgent / EnvHttpProxyAgent used by the wiki generator (and other host-process callers), the same way the agent runtime honors it. Alternatively, set process.env.HTTPS_PROXY from the setting on host-process boot so undici's default env-based proxy resolution picks it up.

Workaround (for affected users)

Set HTTPS_PROXY / HTTP_PROXY as a system/user environment variable (not just in ZCode Settings) and restart ZCode — undici will then read it. (Unverified in this specific setup due to air-gapped constraints; reported to help in similar cases.)

Environment

  • ZCode version: 3.4.2 (Windows Desktop)
  • OS: Windows 10 19045 x64
  • Provider: builtin:zai (Z.ai API Key), model GLM-5.2, format anthropic-messages
  • Proxy: corporate forward proxy (HTTP), air-gapped network — direct egress to api.z.ai blocked
  • Node (bundled): v24.12.0

Logs

Full stack trace and timeline available from ~/.zcode/v2/logs/ (host-process log, [repoWiki] entries). Can attach sanitized excerpts on request.

复现步骤 · Steps to reproduce

  1. In ZCode Settings, configure a corporate HTTP proxy:

  2. Open any repository and confirm the agent chat works (it reaches
    api.z.ai/api/anthropic through the configured proxy).

  3. Trigger Repo Wiki generation (e.g. open the repository's Wiki /
    Knowledge Base panel and click "Generate").

  4. Wait ~10 seconds. Generation fails with "fetch failed".

期望表现 · Expected behavior

Repo Wiki generation should use the configured httpProxy (the same way
the agent chat already does) and complete successfully. All HTTP requests
made by the wiki generator — starting with the catalog request — should
go through the proxy, not attempt a direct connection to api.z.ai:443.

实际表现 · Actual behavior

Every wiki task fails on the first (catalog) request with a TCP connect timeout to api.z.ai:443:

TypeError: fetch failed
  cause: ConnectTimeoutError: Connect Timeout Error
    (attempted address: api.z.ai:443, timeout: 10000ms)
    at onConnectTimeout (node:internal/deps/undici/undici:1936:23)
    at Immediate._onImmediate (node:internal/deps/undici/undici:1902:35)

The host-process log shows:

[repoWiki] Wiki 模型请求开始 {"kind":"catalog","providerId":"builtin:zai","model":"GLM-5.2","endpoint":"https://api.z.ai/api/anthropic","promptChars":20125}
[repoWiki] Wiki 模型请求失败 {"error":"fetch failed"}
[repoWiki] Wiki 生成失败 {"error":"fetch failed"}

At the same timestamp, the agent runtime successfully reaches the identical endpoint:

[zcode-agent-service] 开始请求 ZCode Protocol session/resume
  runtimeModel.baseURL: "https://api.z.ai/api/anthropic"  ← works

ZCode 版本 · ZCode version

ZCode 3.4.2

设备 / 系统 / 浏览器 · Device / OS / Browser

Win10, Node 24.12, provider/proxy

截图 / 录屏 / 日志 · Screenshots / Recordings / Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions