Skip to content

fix: fail over when DeepSeek reports an expired login with HTTP 200 - #43

Open
sorolt wants to merge 1 commit into
ForgetMeAI:mainfrom
sorolt:fix/invalid-token-failover
Open

sorolt wants to merge 1 commit into
ForgetMeAI:mainfrom
sorolt:fix/invalid-token-failover

Conversation

@sorolt

@sorolt sorolt commented Nov 12, 2026

Copy link
Copy Markdown

Summary

When a DeepSeek Web login expires or is revoked, chat_session/create and create_pow_challenge still answer HTTP 200, with the error in the body:

{"code":40003,"msg":"INVALID_TOKEN","data":null}

The account pool only reacts to HTTP 401/403/429, so such an account is never put into cooldown. It stays in rotation, /health keeps reporting it as ready, and every request routed to it fails with Could not create DeepSeek chat session (HTTP 200) ... INVALID_TOKEN. This is the error reported in #42.

This PR:

  • treats an invalid-token body (HTTP 200) from chat_session/create, file upload/status and create_pow_challenge as HTTP 401;
  • the account goes into the normal DEEPSEEK_ACCOUNT_COOLDOWN_MS cooldown and the request is replayed on another ready account through the existing failover path;
  • with no other account left, the client gets a 401 authentication_error instead of a generic 500;
  • matches the message text (INVALID_TOKEN / invalid token / Authorization Failed), not the code: 40003 is also used for "Too many messages", which must keep its short rate-limit cooldown.

Refs #42

Verification

  • npm test: 104/104 passing, including 2 new integration tests:
    • an account whose login returns HTTP 200 INVALID_TOKEN fails over to the next account and is put into cooldown;
    • with a single expired account the client gets HTTP 401.
  • Both new tests fail on current main and pass with this change.
  • git diff --check passes.
  • Running against live DeepSeek with 5 accounts: one account started returning {"code":40003,"msg":"INVALID_TOKEN"} (confirmed by npm run doctor: Authorization Failed (invalid token)) while /health still listed it as ready. The live failover itself was only covered by the mock tests, because the expired account had already been re-logged in by then.

🤖 Generated with Claude Code

DeepSeek answers chat_session/create and create_pow_challenge for an
expired or revoked login with HTTP 200 and {"code":40003,"msg":"INVALID_TOKEN"}.
The account pool only reacted to HTTP 401/403/429, so such an account stayed
in rotation and every request routed to it failed with "Could not create
DeepSeek chat session (HTTP 200)".

Treat an invalid-token body as HTTP 401: the account goes into cooldown
and the request is replayed on another ready account; with no other
account the client gets a 401 authentication_error. The message text is
matched, not the code, because 40003 is also used for "Too many messages".

Refs ForgetMeAI#42

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant