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
账号 / 登录 · Account / Login
涉及的 Agent 框架 · Agent framework
不涉及框架 · Not framework-specific
严重程度 · Severity
阻塞使用 · Blocking (无法使用核心功能 / core function unusable)
复现频率 · Reproducibility
必现 · Always
问题描述 · Description
I purchased an active ZCode subscription and attempted to sign in to the ZCode desktop application on Ubuntu using “Connect to Z.ai — Global.”
The browser authentication completes successfully and displays “Authorization successful,” but ZCode does not complete the login. The application displays “登录失败,请重试” (“Login failed, please retry”).
The terminal log shows that the initial authentication/token response succeeds with code 0, but the subsequent business-token exchange fails with:
Error: zai_oauth_required
The failure occurs inside ZaiBusinessTokenResolver.exchangeBusinessToken and OAuthService.handleCallback. Because of this, I cannot sign in to ZCode or use my paid subscription.
复现步骤 · Steps to reproduce
- Install and open the ZCode desktop application on Ubuntu Linux.
- Click “Connect to Z.ai.”
- Select/use the Global Z.ai authentication option.
- Sign in through the browser using the account that owns the active paid ZCode subscription.
- Complete the authorization process.
- Observe that the browser displays “Authorization successful” and redirects back to the application.
- Observe that ZCode displays “登录失败,请重试” (“Login failed, please retry”).
- Check the terminal output.
- Observe that oauth.handleCallback fails with Error: zai_oauth_required.
期望表现 · Expected behavior
After successful browser authorization, ZCode should accept the OAuth callback, connect my Z.ai subscription to the desktop application, and sign me in successfully.
实际表现 · Actual behavior
The browser reports that authorization was successful, and the initial token response returns code 0. However, ZCode fails during the business-token exchange with Error: zai_oauth_required.
The application remains logged out and displays “登录失败,请重试” (“Login failed, please retry”).
ZCode 版本 · ZCode version
v3.3.4 [.deb]
设备 / 系统 / 浏览器 · Device / OS / Browser
Ubuntu 24.04 LTS
截图 / 录屏 / 日志 · Screenshots / Recordings / Logs
Browser result:
“Authorization successful — Redirecting to the application...”
ZCode result:
“登录失败,请重试” (“Login failed, please retry”)
Relevant sanitized terminal log:
[zaiOAuth] token final response body:
{
"code": 0,
"msg": "",
"data": {
"token": "[REDACTED]",
"user": {
"user_id": "[REDACTED]",
"email": "[REDACTED]",
"name": "[REDACTED]"
},
"zai": {
"access_token": "[REDACTED]"
}
}
}
[zcode-host] [rpc:call] oauth.handleCallback FAIL
Error: zai_oauth_required
at ZaiBusinessTokenResolver.exchangeBusinessToken
at ZaiProviderAdapter.exchangeToken
at OAuthService.runWithAdapterError
at OAuthService.handleCallback
The initial OAuth/token response succeeds, but the subsequent business-token exchange fails.

Activity
github-actions commentedon Jul 12, 2026
👋 感谢你的反馈,我们已经收到。
status: 待评估,你可以随时补充信息。needs: 更多信息标签并 @ 你。👋 Thanks — we've received your issue.
status: 待评估(Triage); feel free to add context.needs: 更多信息and ping you.dancenowjid commentedon Jul 15, 2026
Please very urgent, i am also having this same issue.
antonzvonovge commentedon Aug 23, 2026
I hit the same bug on Ubuntu. Browser login completes (“登录已完成” / returning to ZCode desktop), but the app still shows Login failed, please try again.
This is not a
zcode://handler problem on my machine: the desktop app does receive the callback (OAuth 回调路由成功). The first token exchange succeeds (POST https://zcode.z.ai/api/v1/oauth/token→code: 0with user data). Login then fails on the business-token step.Environment
6.8.0-138-generic, x86_64ZCode.AppImage)provider: "zai")Sanitized log (same stack as this issue)
Happy to provide more logs (redacted) if useful.
kadiratesdev commentedon Aug 30, 2026
Same bug here on CachyOS (Arch-based) Linux, ZCode 3.10.1. Browser login completes (“Authorization successful” / returning to the desktop app), but ZCode still shows Login failed, please try again.
This is not a
zcode://handler problem on this machine: the desktop app does receive the callback (OAuth 回调路由成功). The first token exchange succeeds (POST https://zcode.z.ai/api/v1/oauth/token→code: 0with user +data.zai.access_token). Login then fails on the business-token step.Environment
ID_LIKE=arch), kernel7.2.2-1-cachyos, x86_64XDG_SESSION_TYPE=wayland,WAYLAND_DISPLAY=wayland-0,DISPLAY=:0)zcode 3.10.1-2→/opt/ZCode/zcode(Electron 41.0.3)provider: "zai")152.0.7977.64(xdg default forhttpsand the login redirect)1000(not root / not sudo)xdg-mime query default x-scheme-handler/zcode→zcode.desktopExec="/opt/ZCode/zcode" %USanitized log (same stack as this issue)
Reproduced 5 times in a row on 2026-08-30. Latency of
handleCallbackis consistently ~1250–1500ms, matching a completed HTTP round-trip rather than a timeout (timeoutMsfor this step is 10s).Extra probe (this machine)
https://api.z.ai/api/auth/z/loginis reachable from the same host (HTTP 200, ~1.0–1.5s, TLS OK, no proxy env). A dummy POST returns:{"code":500,"msg":"User login failed","data":500,"success":false}ZCode maps
success === false(and missingdata.access_token) to a genericError: zai_oauth_required, so the real upstream body never appears in the app log.API Key mode against
https://api.z.ai/api/paas/v4/modelsworks on this machine (HTTP 200), so general Z.ai API access is fine — only the OAuth business-token exchange fails.Happy to provide more redacted logs if useful.
TON14 commentedon Aug 31, 2026
Fourth independent report, and I think I have the first concrete lead plus a
working workaround.
TL;DR
.rpm. Togetherwith the reports above this now spans four distros, four install methods and
versions 3.3.4 → 3.10.2, so it is neither distro-, version- nor
packaging-specific.
the code and replayed both calls by hand from the same machine:
POST api.z.ai/api/auth/z/loginreturned{"code":200,"success":true}with avalid business token. All three checks in
exchangeBusinessTokenwould havepassed — the request simply never reached the server from inside the app.
fetchtoapi.z.aifails after ~550 ms withAggregateError: ETIMEDOUTwhile
curlto the identical URL succeeds. It correlated withapi.z.airesolving to both A and AAAA on a machine with no working IPv6.
api.z.aito its IPv4 addresses in/etc/hosts, restart the app.exchangeBusinessTokencollapses four different failure modes into one
zai_oauth_required, and thebare
catchdiscards the original error. Four users in this thread, fourenvironments — and none of us can tell which branch is firing. That is the
core problem.
Why nobody in this thread can pin it down
exchangeBusinessTokeninapp.asar(out/host/index.js):Four distinct causes, one identical message, and the transport branch throws the
original exception away. The name also actively misleads:
zai_oauth_requiredreads as "not authenticated", which is why this thread is full of people with
active paid subscriptions auditing their accounts. I lost hours to exactly
that before instrumenting the call.
A note on timing
Total
handleCallbacklatency cannot separate the branches: it also containsthe first exchange against
zcode.z.ai/api/v1/oauth/token, which alonetakes ~1 s. My totals were 1570 / 1706 / 2170 / 2580 ms, yet isolating the
second call showed ~600 ms and a provable transport failure.
Worth timing the two calls separately before concluding the server answered.
Evidence for the transport branch
Same Node
fetch, three hosts used by the login flow, from the machine whereZCode was failing:
Identical with system Node v22.22.2 and with the Node bundled in ZCode
(
ELECTRON_RUN_AS_NODE=1 /opt/ZCode/zcode probe.js, v24.14.0).curlto thesame URL succeeded every time — which is exactly why a manual sanity check
suggests everything is healthy while the app keeps failing.
RTT is high from here: the TCP handshake alone is ~600 ms
(
connect=0.586…0.624s, DNS excluded). That may be a precondition.Workaround
Then fully restart the app (
pkill -f '/opt/ZCode/[z]code'). Login completes andcredentials.jsongetsoauth:zai:access_token,zcodejwttoken,oauth:zai:user_info,oauth:active_provider— previously it held onlyoauth:login_attribution.NODE_OPTIONS=--network-family-autoselection-attempt-timeout=…does nothelp — Electron strips
NODE_OPTIONSwhen spawning the host process in apackaged app:
What I could NOT verify
The tempting explanation is Node's Happy Eyeballs per-attempt budget
(
autoSelectFamilyAttemptTimeout, default 250 ms) being blown by the ~600 mshandshake. I could not confirm that. A control test with raw
net.connect,both families and a 250 ms limit connected fine — Node waits for already-started
attempts instead of abandoning them:
The real failure happened inside undici, not raw TCP, and I could not finish
that experiment: the AAAA records for
api.z.aidisappeared from DNS duringthe investigation (present 19:30–19:44 UTC+3 on 2026-08-31, gone by 19:55;
dignow returnshas no AAAA record). Nothing left to reproduce against.So: "dual-family resolution → failure, IPv4-only → works" is reproducible and
solid. The mechanism inside undici is not established. It is also possible that
others here are hitting branch (2) or (3) instead — which brings me back to the
main point.
Suggested fixes, in descending order of confidence
throwing a bare
zai_oauth_required. This is the one change I am certainabout, and it does not depend on my network theory being right. Right now
four reporters across four distros cannot distinguish a DNS/transport failure
from a genuine authorization rejection.
code/missing
access_token), and log the two token calls with separate timings.autoSelectFamilyAttemptTimeout, or setautoSelectFamily: false, for these endpoints. Flagged as a guess — seeabove.
For others hitting this
An AAAA record present,
connectwell above 0.25 s, andFAIL ETIMEDOUTwhilecurlsucceeds is the pattern I saw. If yourdigshows no AAAA and the Nodecheck returns
OK, your cause is probably branch (2) or (3) and the log willstay useless until fix #1 lands.
kadiratesdev commentedon Aug 31, 2026
Thanks @TON14 — confirmed that your diagnosis and workaround solve the issue on my machine.
Environment: CachyOS Linux, ZCode 3.10.1 (Electron 41.0.3 / bundled Node v24.14.0).
Before the workaround:
api.z.airesolved to both A and AAAA records.fetchfailed 3/3 times withAggregateError: ETIMEDOUT; the IPv6 attempts also reportedENETUNREACH.curl -4to the same host succeeded.After pinning the two IPv4 addresses from your comment in
/etc/hosts:zai_oauth_requiredlogin failure is gone.So this is a second confirmed case where the IPv4 pinning workaround fixes the actual ZCode OAuth flow. Thank you for the detailed investigation and for sharing a working workaround — it saved me a lot of time.
p99will commentedon Sep 1, 2026
Big thanks to @TON14 for your work investigating this and coming up with a resolve!.
Fifth independent report — and the first on Windows, so the bug is not Linux-specific either.
TL;DR
%LOCALAPPDATA%\Programs\ZCode). Same signature as everyone above: browser OAuth completes, first token exchange succeeds, login dies at the business-token step withzai_oauth_required./etc/hostsIPv4 pinning workaround fixed login on Windows immediately, no restart of the machine needed.api.z.airesolves A + AAAA, my IPv6 path to it is dead (connection failure, not just DNS), and my TCP handshake to the IPv4 edge is ~285 ms — above the ~250 msautoSelectFamilyAttemptTimeoutdefault TON14 flagged.exchangeBusinessTokenfired without instrumenting the app. The barecatchthat discards the original error is what turned a 30-second network problem into an evening of account auditing.Environment
%LOCALAPPDATA%\Programs\ZCodeprovider: "zai")api.z.ai(Aliyun) edge; IPv6 present in DNS but not usable on this machine (see below)Sanitized log (trimmed to the relevant lines; same stack as the issue)
The deep-link handler received the callback fine, the first exchange against
zcode.z.aireturnedcode: 0with full user data, and then the second call (api.z.ai/api/auth/z/login) produced the genericzai_oauth_required~800 ms later — same four-branches-one-message dead end everyone else hit.Diagnostics from my machine (pre-fix, captured after removing the hosts pin)
I captured the failing state directly on Windows by removing the pin, flushing DNS, and re-running the probes — so this is a live pre-fix reproduction, not just a post-hoc guess:
DNS is dual-stack:
nslookup -type=AAAA api.z.aireturns two240b:4001:...addresses,-type=Areturns the two Aliyun IPv4 edges.Node
fetchto the login endpoint fails reproducibly, curl succeeds. With Node v24.19.0 (same major as the Electron-bundled runtime), 3/3 attempts toPOST https://api.z.ai/api/auth/z/loginfail in 564–872 ms withfetch failed → AggregateError: ETIMEDOUT. In the same state,curlover IPv4 returns HTTP 200 withtcp_connect = 0.443 s.Full per-attempt breakdown (
e.cause.errors) — this is the interesting part:Both IPv6 attempts fail immediately with
ENETUNREACH(no usable v6 route — confirmed separately: forcedcurl -6 --resolveover a real AAAA address cannot connect at all). But note the IPv4 attempts also fail withETIMEDOUTeven though curl connects fine to the same IPs in ~440 ms — i.e. the v4 attempts are being abandoned before they can complete. That is consistent with undici's ~250 msautoSelectFamilyAttemptTimeoutbudget being blown by a >250 ms handshake, and unlike TON14's rawnet.connectcontrol test, this failure is inside undici's connection logic — so my data strengthens the hypothesis they couldn't confirm. My handshake times to this edge ranged 0.28–0.44 s across the evening, straddling that threshold.With the hosts pin in place, everything flips: the same Node probe returns
OK 200 {"code":1002,"msg":"token is empty"}(code:1002is expected for an empty body — the point is the request reaches the server), and login completes.Login state after the fix:
credentials.json(in my case%USERPROFILE%\.zcode\v2\credentials.json) went fromoauth:login_attributiononly to containingoauth:zai:access_token,oauth:zai:user_info,zcodejwttoken,oauth:active_provider— the same post-success key set TON14 described.Windows version of the workaround
Open Notepad as Administrator, open
C:\Windows\System32\drivers\etc\hosts, and add (use fresh IPs — see caveat):Flush the resolver cache:
ipconfig /flushdnsFully quit ZCode from the system tray (right-click tray icon → quit; closing the window is not enough) and relaunch.
Connect to Z.ai — Global → completes normally.
Caveat
These are Aliyun CDN addresses and the AAAA records were already appearing/disappearing around TON14's investigation, so they may rotate. If login breaks again weeks from now, check
nslookup api.z.aiand update the two hosts lines to whatever the current A records are.+1 on the suggested fixes
Especially #1 and #2. Four or five of us across five OSes produced four identical, undebuggable logs.
zai_oauth_requiredreads as "you're not authenticated" when the actual causes span DNS/transport failure, a non-success business code, and a missingaccess_token. Distinct error messages plus the original exception would have saved every one of us the account/subscription audit — and would tell you whether the remaining reports are the IPv6 issue or something else entirely.KNawm commentedon Sep 4, 2026
guys if you hit this,
ping api.z.ainear or >250ms and this right here is your bugproblem is syns to the correct ip are abandoned at ~250ms. temporary workaround if ur network sucks:
as the saying goes: it works where the wires are short...
deegool commentedon Sep 7, 2026
Thanks @TON14 it solved mine aswell
faik-sevim commentedon Sep 8, 2026
Can confirm this bug affects macOS as well. Huge thanks to @KNawm and @TON14 for the diagnosis and the relay concept. If you are physically far from the servers, the hardcoded ~250ms timeout in Node.js/undici will instantly kill your login attempt.
Here is the step-by-step local relay workaround perfectly adapted for macOS users.
How to fix on macOS
1. Check your ping (Diagnosis)
Open Terminal and run:
If your
time=is consistently around or above 250ms, you are definitely hitting this exact timeout bug.2. The Workaround (Local Relay Bridge)
Since we can't lower the physical ping, we can trick the app by creating a local bridge (0ms ping) that forwards the request to the real server.
Step A: Redirect the domain to localhost
Open Terminal and edit your hosts file:
Add this line to the very bottom:
127.0.0.2 api.z.ai(Save and exit:
Ctrl+O,Enter,Ctrl+X)Step B: Flush macOS DNS Cache
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderStep C: Run the Node.js Relay Bridge
Paste this script into the Terminal and hit Enter. Leave this window open. It creates a local macOS network alias and forwards the traffic, bypassing the app's internal timeout:
sudo node -e 'const{execSync}=require("child_process"),net=require("net");try{execSync("ifconfig lo0 alias 127.0.0.2 up")}catch{}net.createServer({pauseOnConnect:true},c=>{const s=net.connect({host:"8.217.100.151",port:443});s.on("connect",()=>{c.pipe(s);s.pipe(c);c.resume()});const k=()=>{c.destroy();s.destroy()};s.on("error",k);c.on("error",k);s.on("close",()=>c.end());c.on("close",()=>s.end())}).listen(443,"127.0.0.2",()=>console.log("Relay active: 127.0.0.2 -> 8.217.100.151"))'Step D: Log in
Completely Quit ZCode from the macOS Dock (Right Click -> Quit, don't just close the window), open it again, and complete the "Connect to Z.ai" login. It should work instantly. Once logged in, you can remove the line from your
/etc/hostsand close the Terminal.Shadid516 commentedon Sep 8, 2026
Sixth independent confirmation + a cleaner workaround (no /etc/hosts IP pinning).
Environment: Debian 13 (trixie), ZCode 3.11.2 AppImage (bundled Electron 41 / Node 24, undici v6.24.1). Login path: Connect to Z.ai -> Global.
Same signature as everyone above:
POST /api/v1/oauth/token->code:0withdata.zai.access_token, thenZaiBusinessTokenResolver.exchangeBusinessToken->zai_oauth_required, underlying errorfetch failed.Metrics match @TON14 / @KNawm exactly:
curl -6 https://api.z.ai/...-> fails instantly (broken IPv6)curl -4 https://api.z.ai/...-> OK, butconnect = 0.319s(i.e. >250ms)undicidefault ->fetch failedundiciwithAgent({ connect: { family: 4 } })-> HTTP 200So it's the same
autoSelectFamilyAttemptTimeout ~= 250msabandonment, on a machine that is both IPv6-dead and ~320ms from the IPv4 edge.Cleaner workaround (no hardcoded IPs): patch the host bundle's network transport to force IPv4. Two spots in
resources/app.asar/out/host/index.js:createDispatcher(lHe) - build the undiciAgentwithconnect: { family: 4 }.if (W.kind==="direct" && !$.caCertPath) return globalThis.fetch(k,I)- bypasses that dispatcher; reroute it through the dispatcher sofamily:4actually applies.This makes
api.z.aireachable over IPv4, and login plus the paid Coding Plan complete, with no dependence on the current GA/CDN IPs.Even simpler OS-level alternative (system-wide, affects all apps): just disable IPv6 so undici only ever sees an IPv4 route.
Persist across reboot:
Suggested root fix for the team: in the host undici dispatcher, disable
autoSelectFamily(or raiseautoSelectFamilyAttemptTimeout) instead of the 250ms default - e.g.new Agent({ connect: { autoSelectFamily: false } }). And please stop swallowing the real error inexchangeBusinessToken(logerror.cause).capgelka commentedon Nov 10, 2026
I've got the same problem, so vibecoded a solution https://github.com/capgelka/zcode-bridge based on a @faik-sevim comment. Works fine on my Mac and should support Linux as well, though I haven't checked it myself on it yet.