Skip to content

[Bug] ZCode 3.14.4 (Linux): OAuth token exchange returns HTTP 500 after a successful browser authorization (login fails, agent blocked) #877

Open

Description

@felipeatp

提交前确认 · 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

ZCode Agent(自研)

严重程度 · Severity

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

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

"Connect to Z.ai" never completes on the desktop app: the browser reports "Authorization successful", but the app shows "登录失败,请重试" / "Login failed, please retry".

The deep link does reach the app, so the callback routing is fine:

[deep-link] OAuth 回调路由成功 {"state":"...","windowId":1,"provider":"zai","completed":true}

The app then exchanges the code and the endpoint answers HTTP 500 every time:

[zaiOAuth] token request  {"method":"POST","url":"https://zcode.z.ai/api/v1/oauth/token",
  "body":{"provider":"zai","code":"...","codeLength":17,
          "redirect_uri":"https://zcode.z.ai/app/oauth/login?redirect=zcode%3A%2F%2Foauth%2Fcallback&app_version=3.14.4",
          "state":"..."}}
[zaiOAuth] token response error {"method":"POST","url":"https://zcode.z.ai/api/v1/oauth/token",
  "status":500,"responseHeaders":{"x-request-id":"20260930025531952fc805c88dfa9ca0c1"}}

3 out of 3 attempts today returned HTTP 500, with request-ids 2026093002182481f1d08f9be0e3dad4bb, 2026093002200033d365133046746c96ca, 20260930025531952fc805c88dfa9ca0c1.

Downstream symptoms: oauth.pollPendingOAuth FAIL {"message":"zai_oauth_required"} raised from ZaiBusinessTokenResolver.exchangeBusinessToken, and the agent stays blocked with 当前没有可用的模型供应商和模型,请先登录或配置 API Key.

复现步骤 · Steps to reproduce

  1. Open ZCode on Linux and click "Connect to Z.ai".
  2. Complete the authorization in the browser ("Authorization successful").
  3. The app shows "登录失败,请重试"; the agent log shows zai_oauth_required.
  4. Independently of any account, the failure is reproducible with an invalid code (the request shape is accepted; an incomplete body returns 400):
curl -s -w '\n%{http_code}\n' -X POST https://zcode.z.ai/api/v1/oauth/token \
  -H 'Content-Type: application/json' \
  -d '{"provider":"zai","code":"code0000000000dummy","redirect_uri":"https://zcode.z.ai/app/oauth/login?redirect=zcode%3A%2F%2Foauth%2Fcallback&app_version=3.14.4","state":"0123456789abcdef0123456789abcdef"}'
# -> 500 {"code":2007,"msg":"http error"}
# same body without redirect_uri -> 400 {"code":3001,"msg":"parameter error"}
# repeated calls return 429, so avoid hammering the endpoint

期望表现 · Expected behavior

After a successful browser authorization the token exchange should return a token and the app should be signed in. An invalid or expired code should produce a 4xx with a meaningful message, not a 500.

实际表现 · Actual behavior

HTTP 500 on every exchange, so the login never completes and the agent cannot run.

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 / Firefox / AppImage launched with --no-sandbox.

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

Log lines quoted above, from ~/.zcode/v2/logs/2026-09-30.log.

Existing related reports: #116, #699.

Activity

  1. github-actions commented on Sep 30, 2026

    @github-actions

    👋 感谢你的反馈,我们已经收到。

    • 维护者看到后会尽快回复你。
    • 状态保持为 status: 待评估,你可以随时补充信息。
    • 信息不全时我们会打上 needs: 更多信息 标签并 @ 你。

    👋 Thanks — we've received your issue.

    • A maintainer will get back to you as soon as we can.
    • Status stays at status: 待评估 (Triage); feel free to add context.
    • If we need more details, we'll add needs: 更多信息 and ping you.
  2. felipeatp commented on Sep 30, 2026

    @felipeatp
    Author

    Update (2026-09-30 00:51 local) — this 500 is real but it is not always what blocks the login, and in my case it was not the blocker.

    The same flow completed successfully while this endpoint was still failing:

    00:50:53  oauth.startOAuthWithPolling OK
    00:51:01  [zaiOAuth] token request  -> https://zcode.z.ai/api/v1/oauth/token
    00:51:02  [zaiOAuth] token response error {"status":500}          <-- still 500
    00:51:03  [oauthService][trace:OAuth polling flow completed] {"provider":"zai"}
    00:51:03  oauth.pollPendingOAuth OK
    00:51:03  oauth.handleCallback OK
    00:51:10  oauth.handleCallback OK
    

    After that run the session exists (credentials.json now contains oauth:zai:access_token, oauth:zai:user_info, oauth:active_provider, plus an account-provider:...:zai-individual-coding-plan:... credential), so the app is signed in.

    What actually blocked login here was a second, independent failure: the business-token exchange goes to https://api.z.ai/api/auth/z/login (ZaiBusinessTokenResolver.exchangeBusinessToken, wired to businessLoginUrl), and on this network every request to api.z.ai was timing out — api.z.ai publishes AAAA records that are unroutable here, and Node/undici's happy-eyeballs aborts every connect attempt (250 ms attempt timeout vs ~286 ms RTT). That produced oauth.pollPendingOAuth FAIL {"message":"zai_oauth_required"} and the login never completed. See #876 for the full diagnosis and the reproduction.

    Once api.z.ai was pinned to its IPv4 addresses in /etc/hosts, the business-token exchange succeeded, the polling flow completed and the login went through — with this 500 still being returned on the code exchange.

    So there are two separate issues in this path:

    1. POST https://zcode.z.ai/api/v1/oauth/token returns HTTP 500 for every code exchange (reproducible with an invalid code too — reported here).
    2. The business-token exchange to api.z.ai fails on networks where api.z.ai's AAAA records are unroutable, which is what makes the login fail end to end ([Bug] ZCode 3.14.4 (Linux): every agent model request fails with "Cannot connect to API" / ETIMEDOUT — api.z.ai publishes AAAA records this network cannot route (Node happy-eyeballs 250 ms) #876).

    Point 1 is worth fixing on its own (a 500 for an invalid code should be a 4xx), but it does not appear to block login by itself.

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

    priority: P2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions