Skip to content

GLM Coding Plan login broken: POST /api/v1/oauth/token returns HTTP 500 {"code":2007,"msg":"http error"} for ALL code exchanges (incl. invalid codes) — ZCode Desktop 3.11.2, Linux #575

Open

Description

@jadmadi

Summary

Sign-in to the GLM Coding Plan from ZCode Desktop fails on every attempt. Browser authentication completes ("Sign-In Complete"), the zcode://oauth/callback deep link is routed correctly and the OAuth state matches, but the app's exchange request POST https://zcode.z.ai/api/v1/oauth/token receives HTTP 500 with empty body, and the UI shows "Login failed, please try again".

The endpoint appears broken server-side for all code-exchange attempts, not account-specific: a minimal curl reproduction with an obviously invalid code returns the same 500, while parameter validation still works (empty body → clean 400).

Environment

  • ZCode Desktop 3.11.2, official .deb (zcode 3.11.2-6792), single installation, Linux
  • Debian 13 (kernel 6.12.0-1-amd64, x64), no proxy, zcode.z.ai reachable, normal TLS
  • z.ai API-key mode works fine on the same machine/network — only coding-plan OAuth fails
  • Account has an active paid subscription (details shared privately via [email protected])

Reproduction A — in-app

  1. Settings → connect GLM Coding Plan (z.ai global) → Login
  2. Complete browser sign-in ("Sign-In Complete")
  3. Redirect to zcode://oauth/callback arrives, state matches (app log: OAuth 回调路由成功 ... completed: true)
  4. App sends POST https://zcode.z.ai/api/v1/oauth/token → HTTP 500 → "Login failed, please try again"

Happens on 100% of attempts today (2026-09-08, ~15+ attempts between 13:27 and 14:45 UTC+3).

Reproduction B — minimal curl, no account, no client

curl -sS -X POST -H "Content-Type: application/json" \
  -d '{"provider":"zai","code":"AAAAAAAAAAAAAAAAA","codeLength":17,"redirect_uri":"https://zcode.z.ai/app/oauth/login?redirect=zcode%3A%2F%2Foauth%2Fcallback&app_version=3.11.2","state":"00000000000000000000000000000000"}' \
  https://zcode.z.ai/api/v1/oauth/token

Actual result:

HTTP 500
{"code":2007,"msg":"http error"}

Expected: a clean 4xx (e.g. invalid_code / invalid_grant) for a garbage code.

Control case showing the endpoint itself is alive and validates parameters:

curl -sS -X POST -H "Content-Type: application/json" -d '{}' https://zcode.z.ai/api/v1/oauth/token
# HTTP 400 {"code":3001,"msg":"parameter error"}

So the failure (error code 2007, "http error") sits in the exchange handling — likely an upstream call from the API failing — before any account or code validation.

Server request IDs from real login attempts

  • 2026090811450158b0f7ab82adc6c4d9ba — 2026-09-08 11:45:02 UTC
  • 20260908113701813e652be62b2ecacc9d — 2026-09-08 11:37:01 UTC

Client log evidence (2026-09-08 14:45 UTC+3)

[oauthService][trace:OAuth polling flow started] {"expiresInMs":299516,"pollIntervalMs":2000,"provider":"zai"}
[deep-link] OAuth 回调路由成功 { state: '5aa97af1…', windowId: 1, provider: 'zai', completed: true }
[zaiOAuth] token request {"method":"POST","url":"https://zcode.z.ai/api/v1/oauth/token","headers":{"Content-Type":"application/json"},"body":{"provider":"zai","code":"code…2ebd","codeLength":17,"redirect_uri":"https://zcode.z.ai/app/oauth/login?redirect=zcode%3A%2F%2Foauth%2Fcallback&app_version":"3.11.2","state":"5aa97af1…"}}
[zaiOAuth] token response error {"method":"POST","url":"https://zcode.z.ai/api/v1/oauth/token","status":500,"responseHeaders":{"x-request-id":"2026090811450158b0f7ab82adc6c4d9ba"}}
[rpc:call] oauth.handleCallback FAIL (667.4ms) {"name":"ApiError","message":"http error", …}

Notes

  • Possibly related: [Bug] Z.ai OAuth succeeds but ZCode fails with zai_oauth_required on Ubuntu #116 — but that report's token response succeeded (code 0) and the failure was in ZaiBusinessTokenResolver.exchangeBusinessToken; here the token endpoint itself 500s for everyone, which may be the upstream cause of that symptom.
  • Earlier "OAuth state mismatch" failures were caused by a coexisting AppImage + .deb fighting over the zcode:// handler; resolved by removing the AppImage. The HTTP 500 is independent of that and remains.

Happily provide full logs or run any server-side-adjacent diagnostics you need.

Activity

  1. github-actions commented on Sep 8, 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. AI-Chef commented on Sep 9, 2026

    @AI-Chef

    me too

  3. jadmadi commented on Sep 16, 2026

    @jadmadi
    Author

    Currently I'm using the API and losing access to this generous offer.

    Image Image

    I'm trying to document the case and share what is happening. I signed up for an annual subscription because it was appealing, but due to issue #575, I lost the leverage I should be enjoying.

    Taking into consideration that the root cause of #575 is not my machine, network, or personal setup, and is not something I have the leverage to fix, else I would.

  4. matiasgel commented on Sep 21, 2026

    @matiasgel

    ZCode 3.14.1 on Ubuntu/Linux.

    Browser OAuth authentication succeeds and the zcode:// callback
    is routed correctly:

    OAuth 回调路由成功
    completed: true

    ZCode then requests:

    POST https://zcode.z.ai/api/v1/oauth/token

    and receives:

    HTTP 500
    x-request-id: 20260921231516fc9596714a422a354e5f

    The client subsequently reports:

    zai_oauth_required
    oauth.handleCallback FAIL
    ApiError: http error

    This appears to be the same server-side issue reported in #575,
    but it is still reproducible on ZCode 3.14.1.

  5. jadmadi commented on Sep 22, 2026

    @jadmadi
    Author

    Update: Still failing on ZCode 3.14.3 (2026-09-22)

    The bug is not fixed in the latest release. Same exact failure, same endpoint, same 500.

    Environment: ZCode 3.14.3 (deb, Linux x64, Ubuntu/Debian), provider: zai, coding-plan connection.

    Client-side evidence (today's attempts)

    [13:39:15] [deep-link] OAuth 回调路由成功 {state, windowId:1, provider:"zai", completed:true}
    [13:39:15] [zaiOAuth] token request POST 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.3",
                       state}
    [13:39:17] [zaiOAuth] token response error status:500
                x-request-id: 2026092210391620c18422c333a7e7f5f9
    [13:39:17] oauth.handleCallback FAIL ApiError: http error
    

    Second attempt the same minute → x-request-id: 20260922103746af3ef5380e10fb8c05, also 500.

    The deep-link callback routing, state validation, and browser handshake all succeed. The only failing step is the token exchange on your side.

    Root cause isolated — minimal server-side reproduction

    I probed POST https://zcode.z.ai/api/v1/oauth/token directly with synthetic data (no account involved). The endpoint returns a clean 400 {"code":3001,"msg":"parameter error"} for most payloads, but reliably returns 500 {"code":2007,"msg":"http error"} whenever the request body contains both a state field and a redirect_uri field.

    Body fields sent Response
    provider + code 400 parameter error
    provider + code + codeLength 400 parameter error
    provider + code + state 400 parameter error
    provider + code + redirect_uri 400 parameter error
    provider + code + codeLength + state 400 parameter error
    provider + code + codeLength + redirect_uri 400 parameter error
    provider + code + state + redirect_uri 500 http error ✅

    The 500 is value-independent — it triggers with a dummy hex state and redirect_uri: "https://example.com/cb", and reproduces consistently on repeat. The crash is caused by the presence of both fields, not their contents.

    This matters because the ZCode desktop client always sends both state and redirect_uri (see the logged request body above). So the official OAuth flow can never complete — the client is sending a perfectly valid request that your token endpoint crashes on.

    Conclusion

    This is a server-side bug in POST /api/v1/oauth/token, triggered by the combination of state + redirect_uri in the request body. It is not account-specific, not client-version-specific (fails identically on 3.11.2, 3.14.1 per @matiasgel, and 3.14.3), and not Linux-specific.

    Suggested server-side fix: the handler for state + redirect_uri throws or errors out before returning a response. Likely an unhandled null/exception in the branch that consumes those two fields together.

    I have a paid Coding Plan I cannot activate. Any status update or ETA would be greatly appreciated — happy to test a fix as soon as one is available.

  6. wesleymatosdev commented on Sep 24, 2026

    @wesleymatosdev

    Adding data from macOS — I hit the identical failure on Sep 4–5, i.e. before this issue was filed, which pushes the server-side window back and adds a cross-platform data point (all other reports so far are Linux/.deb).

    Environment

    • ZCode Desktop 3.10.2 → 3.11.2 (macOS app), macOS 26.4.1, arm64 (Apple Silicon)
    • Same signature: browser sign-in completes, zcode://oauth/callback routes correctly with matching state, then POST https://zcode.z.ai/api/v1/oauth/token → HTTP 500 → "Login failed, please try again"
    • So this isn't anything Linux/deb-packaging-specific — it looks purely server-side

    Client log evidence

    Sep 4, 01:31 UTC-3 (v3.10.2):

    [zaiOAuth] token request  POST https://zcode.z.ai/api/v1/oauth/token  (provider:"zai", codeLength:17, app_version=3.10.2)
    [zaiOAuth] token response error  status:500
      x-request-id: 20260904043122c05215c6248b7cbe4e81
    [rpc:call] oauth.handleCallback FAIL (719.4ms) ApiError: http error
      at readApiJson (out/host/index.js:1247)
      at async ZaiProviderAdapter.exchangeToken (out/host/index.js:1247)
    

    Sep 5, 15:40 and 15:42 UTC-3 (v3.11.2) — two more attempts, same 500:

    x-request-id: 202609051840031d5f51b6827e3801b910
    x-request-id: 2026090518421565954c6036ebf53ba41d
    

    Three observations that may help triage

    1. [oauthService][trace:OAuth polling flow completed] is misleading. At 15:40:07 on Sep 5 this "completed" trace was logged ~2.5s after the 500 and oauth.handleCallback FAIL. Anyone grepping logs for "completed" will misread a failed flow as success (I did, initially). Suggest renaming it to something like polling flow ended or including the outcome.
    2. Retry pattern: 4 attempts across 2 days and 2 client versions, every attempt used a fresh authorization code (never a retry of the same code), zero successes. So this isn't code-reuse or code-expiry — each fresh code still got 500, consistent with the OP's finding that the exchange handler itself is broken.
    3. It eventually resolved for me without any client change: after the failed attempts, a later app restart restored the cached session (restoreCachedSession restored: zai) and OAuth coding-plan mode has worked since (~Sep 8 onward). I never determined whether the server was fixed or a retry finally landed — but it suggests the breakage is intermittent/partial rather than a hard outage, and bounds the bad window to roughly Sep 4 – early Sep 8 for at least one account. The reports here of it still failing on 3.14.3 (Sep 21–22) suggest it regressed or is flapping since.

    Happy to pull the full log lines or request IDs if useful.

  7. romangalaxys10-spec commented on Sep 25, 2026

    @romangalaxys10-spec

    Additional Field Telemetry: Windows 11 Reproduction & Cross-Platform Confirmation

    Discord Incident Reference:

    Reproduction Characteristics:

    1. Platform Independence:
    2. Failure Pattern:
      • User notes intermittent recovery followed by persistent failure ("worked for 1 day & now again", "worked for one evening & again", "same thing now").
      • Reinstallation of client binaries does not resolve the state once the OAuth token exchange gateway rejects requests.
    3. Upstream Root Cause:
      • Points directly to server-side instability / transient rate-limits or state desync on POST /api/v1/oauth/token returning HTTP 500 {"code":2007,"msg":"http error"} regardless of OS host platform.

    Cross-linking to correlate with #523 and consolidate triage for engineering teams.

  8. AUTENTK-EU commented on Oct 23, 2026

    @AUTENTK-EU

    Related case here (different endpoint, same signature): POST https://api.z.ai/api/auth/z/login with the accessToken saved by a successful zcode login zai returns 200 {"code":500,"msg":"Z.ai user information is invalid"} — same result with the zcode JWT and with every API key of the account. Consequence: promo plan «ZCode 1024 Dev Day» active at billing but 0 model requests served (Desktop + CLI 0.16.9, macOS arm64, Oct 23). Full details: #1180

  9. hamidi2 commented on Oct 25, 2026

    @hamidi2

    Still reproducing on 2026-10-25, ZCode Desktop 3.16.3 (Linux x86_64).

    Symptoms are identical: browser sign-in completes, the zcode:// callback
    routes successfully, then POST https://zcode.z.ai/api/v1/oauth/token
    returns HTTP 500 {"code":2007,"msg":"http error"} on every attempt.

    Ruled out on my side:

    • Same failure from two different networks (home and office)
    • Same failure with and without a SOCKS5 proxy
    • Persistent across the 3.16.2 → 3.16.3 upgrade
    • Account itself is fine: API key works, Coding Plan is active and charged

    Server request IDs from my failed exchanges (today):

    • 20261025032421108ce0f94e73cd15f6f7
    • 2026102503402973c2ec619bbbeaec9c95

    I also can't access my 5-hour/weekly reset quotas or the 500M promo
    tokens because they're tied to the logged-in session, so this bug is
    effectively blocking part of a paid plan. Almost 2 months open with P2
    label and no fix — could this please get some attention?

  10. balupton commented on Oct 25, 2026

    @balupton

    I also can't access my 5-hour/weekly reset quotas or the 500M promo
    tokens because they're tied to the logged-in session, so this bug is
    effectively blocking part of a paid plan. Almost 2 months open with P2
    label and no fix — could this please get some attention?

    This also prevented my partner and I from accessing our plans on all our work machines and the promos, we've let the plans expire. Didn't get a refund either.

  11. Black-Japan-Tea commented on Nov 4, 2026

    @Black-Japan-Tea

    +1 — fresh confirmation, and still broken after updating to 3.17.2 (latest).

    Environment: Windows 10 x64 (10.0.19045), ZCode Desktop 3.16.2 → updated to 3.17.2 on 2026-11-04 (auto-updater confirms the app is now on 3.17.2, latest version: 3.17.2), re-attempted sign-in after the update — the flow fails identically.

    Local causes ruled out (evidence from desktop logs, 3.16.2, 2026-11-04):

    • zcode:// protocol handler is registered correctly (HKCU\Software\Classes\zcode + HKCR\zcode) — the zcode://oauth/callback deep link does fire;
    • connectivity to Z.ai infra is fine (CDN update checks succeed every 2 minutes);
    • every app start logs [oauthService] restoreCachedSession skipped: no active provider;
    • all 10 account providers report "availability":"unavailable","entitled":false,"unavailableReason":"not-connected" — the desktop app never receives the exchanged token, while the browser session is fully logged in (chats visible).

    Fresh anonymous probing of POST https://zcode.z.ai/api/v1/oauth/token (2026-11-05, application/json, no account involved, three requests from the same IP seconds apart):

    request body response
    {} HTTP 400 — {"code":3001,"msg":"parameter error"}
    {"state":"probe"} HTTP 400 — {"code":3001,"msg":"parameter error"}
    {"state":"probe","redirect_uri":"zcode://oauth/callback"} ← the combination the client always sends HTTP 429 — empty body

    The 500 {"code":2007,"msg":"http error"} signature reported earlier has apparently changed to a bare HTTP 429 with no JSON body. The empty body (no code/msg) suggests an edge/WAF or rate-limiter rule intercepting the state + redirect_uri combination rather than the API handler itself — but the effect is unchanged: control payloads pass while the exact payload the client must send is still rejected, so the official OAuth flow still cannot complete server-side.

    Additional impact: this blocks more than Coding Plan login. With no OAuth session the app never issues remote-control credentials (web-remote-control:external-relay stays empty), so account-gated features like connecting a phone / remote control are locked as well.

    — @Black-Japan-Tea, 2026-11-05

  12. ctangarife commented on Nov 22, 2026

    @ctangarife

    Fresh reproduction on 2026-11-22, ZCode Desktop 3.19.1, Linux x64 (Bazzite / Fedora 45) — same endpoint, slightly different server response than the HTTP 500/{"code":2007} above: HTTP 400 with oauth authorization code is invalid or expired, returned for every attempt with fresh, immediately-exchanged codes.

    Local chain fully verified working, so this is not client-side:

    • Browser authorization completes; the zcode://oauth/callback deep link routes correctly — desktop log shows OAuth 回调路由成功 {completed:true} with the matching state.
    • The token exchange fires within ~1s of the callback: POST https://zcode.z.ai/api/v1/oauth/token → rejected 400.
    • Reproduced 5× today across two app versions (3.18.2 → 3.19.1), fresh state/code each time, immediate and delayed exchanges alike — identical result. Manual delivery of the callback URL to the app (bypassing the browser entirely) behaves the same, ruling out any deep-link/protocol-handler involvement.
    • Account is healthy on other paths: Coding Plan / CLI auth keeps serving model requests throughout; only the account OAuth cannot complete.
    • Consequence: UI shows logged out ("Connect"), and the mobile / web-remote relay stays down (stopped reason=auth-required after the previous session's tokens expired).

    Request IDs from today's failed exchanges (2026-11-22 ~18:06–18:16 UTC):

    • 20261122180644958655a65bfd3e59bc99
    • 202611221807095c1063895f2a2de7cf30
    • 202611221807429c8e800023c73a91fd7b
    • 2026112218092935f3ef6062f194417911
    • 20261122181639b079534c1891b51a5fab

    Happy to provide full desktop logs for any of these request IDs. Related client-side analysis in #1545 (different root cause — local Secret Service — but same "login cannot complete" impact).

  13. ctangarife commented on Nov 22, 2026

    @ctangarife

    Definitive proof this is server-side, captured just now (2026-11-22 18:25:49 UTC):

    A raw curl raced the desktop app and was first to exchange a brand-new authorization code — captured from the process arguments <1 second after the browser issued the redirect, so expiry is physically impossible:

    POST https://zcode.z.ai/api/v1/oauth/token
    {provider:zai,code:code-9ad07050e077,codeLength:17,
     redirect_uri:https://zcode.z.ai/app/oauth/login?redirect=zcode%3A%2F%2Foauth%2Fcallback
    
  14. ctangarife commented on Nov 22, 2026

    @ctangarife

    Definitive proof this is server-side, captured just now (2026-11-22 18:25:49 UTC):

    A raw curl raced the desktop app and was first to exchange a brand-new authorization code — captured from the process arguments <1 second after the browser issued the redirect, so expiry is physically impossible:

    POST https://zcode.z.ai/api/v1/oauth/token
    {"provider":"zai","code":"code-9ad07050e077","codeLength":17,
     "redirect_uri":"https://zcode.z.ai/app/oauth/login?redirect=zcode%3A%2F%2Foauth%2Fcallback&app_version=3.19.1",
     "state":"dfa84a980a20a7eef52eaaaae0d8e5f2"}
    
    → HTTP 400 {"code":3016,"msg":"oauth authorization code is invalid or expired","logid":"2026112218254907b861c5d1a19a428110"}
    

    The desktop app's own exchange 1s later got the same 400 (x-request-id 202611221825500426289f1...). This eliminates every client-side factor: no app, no browser, no deep link, no timing, no TLS/proxy. The authorization service is issuing codes it cannot validate at exchange time — consistent with the 500/2007 reports above (the token service appears unable to reach its backing store).

    This is now blocking: account login (UI stuck at "Connect"), and consequently the mobile / web-remote-control feature, for paying Coding Plan users. Two months at P2 with multi-platform confirmations — please escalate. Full logs available on request.

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