Repository navigation
Description
提交前确认 · Pre-submission checklist
- 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
- 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category
对话 / Agent 交互 · Agent chat
涉及的 Agent 框架 · Agent framework
ZCode Agent(自研)
严重程度 · Severity
阻塞使用 · Blocking (无法使用核心功能 / core function unusable)
复现频率 · Reproducibility
必现 · Always
问题描述 · Description
Every agent turn dies before the first token: the UI shows the request being retried and the turn fails. The Coding Plan key itself is fine — the same key returns HTTP 200 on GET /api/coding/paas/v4/models, on POST /api/coding/paas/v4/chat/completions and on POST /api/anthropic/v1/messages (curl), and non-Node clients to the same endpoints work.
The failure is in the client's HTTP connect and is reproducible with plain Node (no ZCode). Measured on this host:
api.z.aipublishes 2 A and 2 AAAA records, but this network has no IPv6 route: a TCP connect to the AAAA addresses fails withENETUNREACH.- Node/undici uses happy-eyeballs (
autoSelectFamily) with the defaultautoSelectFamilyAttemptTimeout = 250 ms, while the TCP handshake to api.z.ai takes ~286 ms on this link (stable ping RTT; the host is far away: AR -> US -> CN). - With all four addresses present, every connection attempt is aborted before it completes, so the request fails with
UND_ERR_CONNECT_TIMEOUT; the agent classifies it asreason: "timeout"/statusMessage: "Cannot connect to API:", retriesmaxRetries: 10(maxAttempts: 11) with exponential backoff, and the turn fails.
Evidence with the same runtime and the same credentials: restricting the resolution to the two IPv4 addresses makes the identical request return HTTP 200 (model: glm-5.3-flash).
Contrast that narrows it down: zcode.z.ai and chat.z.ai publish A records only — which is why login/OAuth traffic does reach your servers and only the model endpoint (api.z.ai) breaks.
复现步骤 · Steps to reproduce
- Show that the host publishes unroutable AAAA:
getent ahosts api.z.ai
getent ahostsv6 api.z.ai
node -e 'require("net").connect({host:"api.z.ai",port:443}).on("error",e=>console.log(e.code))'
# the AAAA attempt -> ENETUNREACH- Show that happy-eyeballs then aborts the IPv4 attempt too (250 ms vs ~286 ms RTT):
node -e 'require("net").connect({host:"api.z.ai",port:443,autoSelectFamily:true,autoSelectFamilyAttemptTimeout:250}).on("error",e=>console.log(e.code))'
# ETIMEDOUT
node -e 'require("net").connect({host:"api.z.ai",port:443,autoSelectFamily:false}).on("connect",()=>console.log("ok"))'
# connects in ~290 ms- Full request with undici (exactly what the agent does), with the key in
$K:
node -e 'const {Agent,fetch}=require("undici");fetch("https://api.z.ai/api/anthropic/v1/messages",{method:"POST",dispatcher:new Agent(),headers:{"x-api-key":process.env.K,"anthropic-version":"2023-06-01","content-type":"application/json"},body:JSON.stringify({model:"glm-5.3-flash",max_tokens:2,messages:[{role:"user",content:"hi"}]})}).then(r=>console.log(r.status)).catch(e=>console.log(e.cause&&e.cause.code))'
# -> UND_ERR_CONNECT_TIMEOUT (with only the IPv4 addresses resolved: 200)- In ZCode, send any message and watch the agent log
~/.zcode/cli/log/zcode-<date>.jsonl: repeatedmodel.client_signing.handshake_failed {"errorKind":"handshake-network"}, thenmodel.request.failedwith the fields above, thenturn.failed.
期望表现 · Expected behavior
The agent should reach api.z.ai and run turns. A host that publishes AAAA records that are not routable on the client network should not make every request fail, and not every retry should abort at the connect stage.
The client-side fix looks small: raise autoSelectFamilyAttemptTimeout (e.g. 3000 ms) or disable autoSelectFamily for the model transport, or drop address families that fail with ENETUNREACH before starting the parallel attempts. Note that dns.setDefaultResultOrder("ipv4first") alone is NOT enough — the AAAA entries are still attempted and the connect still aborts.
实际表现 · Actual behavior
Every attempt is aborted at connect, the request is retried 11 times with growing backoff (1.5 s -> 47 s) and the turn fails with "Cannot connect to API". The app is unusable for model work on any network whose RTT to api.z.ai exceeds the 250 ms happy-eyeballs timeout.
Local workaround that works today (no app change): pin the host to its IPv4 addresses in /etc/hosts so Node resolves IPv4 only:
47.251.69.60 api.z.ai
47.251.169.173 api.z.ai
ZCode 版本 · ZCode version
3.14.4 (.AppImage, linux-x64). The app's own update check reports "latest version: 3.14.4".
设备 / 系统 / 浏览器 · Device / OS / Browser
Ubuntu / GNOME on Wayland / kernel 7.0.0-34-generic / Firefox / AppImage launched with --no-sandbox. Network: Argentina; ping 47.251.69.60 -> 286 ms average.
截图 / 录屏 / 日志 · Screenshots / Recordings / Logs
Sanitized agent-log lines (~/.zcode/cli/log/zcode-2026-09-30.jsonl):
{"event":"model.client_signing.handshake_failed","level":"warn",
"context":{"errorKind":"handshake-network","providerId":"zai-api",
"requestId":"895b72b9-f0d7-4102-b985-2ddd1b2e79f7"}}
{"event":"model.request.failed","level":"warn","message":"Model request attempt failed",
"context":{"attempt":1,"baseURL":"https://api.z.ai/api/anthropic","maxAttempts":11,
"maxRetries":10,"modelId":"GLM-5.3-Flash","providerKind":"anthropic",
"transport":"sse","reason":"timeout","retryable":true,
"statusMessage":"Cannot connect to API:"}}
{"event":"turn.failed","level":"error","message":"Turn failed",
"context":{"providerId":"zai-api","turnNumber":39}}Related: #699 ("model requests and OAuth login fail with ETIMEDOUT").
Activity
github-actions commentedon Sep 30, 2026
👋 感谢你的反馈,我们已经收到。
status: 待评估,你可以随时补充信息。needs: 更多信息标签并 @ 你。👋 Thanks — we've received your issue.
status: 待评估(Triage); feel free to add context.needs: 更多信息and ping you.felipeatp commentedon Sep 30, 2026
Update / additional data point: fixing this locally also unblocked the OAuth login, which is worth noting because it shows how much of the app depends on
api.z.ai.The business-token exchange (
ZaiBusinessTokenResolver.exchangeBusinessToken) POSTs tohttps://api.z.ai/api/auth/z/login, i.e. the same host that was failing for the model requests. On this network that call timed out, the app reportedoauth.pollPendingOAuth FAIL {"message":"zai_oauth_required"}and login never completed, even though the browser said "Authorization successful".After pinning
api.z.aito its IPv4 addresses in/etc/hosts(the workaround in the description):The session was created (
credentials.jsoncontainsoauth:zai:access_token,oauth:active_provider), the agent started withproviderId: zai-api, and the coding-plan calls that previously failed with "Coding Plan entitlement refresh failed" now return OK (usage-stats.getCodingPlanResetStatus OK,billing/balance 请求完成).So on a host with RTT > 250 ms to api.z.ai and AAAA records that the client network cannot route, not only model requests fail: login and quota/entitlement refresh fail too. Raising
autoSelectFamilyAttemptTimeout(or dropping families that answer ENETUNREACH) in the model/business HTTP transport would fix all of it at once.panda920 commentedon Oct 11, 2026
感谢反馈!这条与 #699 说的是同一件事,我们合并到 #699 统一跟进,后续进展会在那边同步。
本 issue 先关闭,欢迎到 #699 补充信息或点 👍。
Thanks for the report! This is the same as #699, so we're tracking it there and will post updates in that thread.
Closing this one as a duplicate — feel free to add details or a 👍 on #699.