auth: a 429 from the Token Endpoint during refresh deletes a still-valid login

オープン 初心者向け
#2,869 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@linye157 がすでに取り組んでいます。

2026年10月30日 から。

  • #2875 @linye157 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go

調査の方向性

internal/auth/uat_client.goから始めてrefreshOnce()を読み、レスポンスのステータスとリフレッシュエラーによって、保存されたトークンを保持するか消去するかがどのように決まるかを確認してください。次に、TestRefreshFailureDeterminesStoredTokenDispositionとスクリプト化されたリフレッシュクライアントを調べ、レスポンスのステータスがどのように表現されているかを確認してください。HTTP 429レスポンスが保存されたトークンを保持したまま再試行され、その動作を網羅する回帰テストがある状態を完了とします。

索引モデルが issue の本文から書いたものです。

説明

bug domain/auth domain/im

Summary

When the Token Endpoint answers a user-token refresh with HTTP 429, lark-cli deletes the stored login, even though a rate-limited request was never processed and the refresh token is still valid. The user then has to run auth login again.

We hit this twice in a week on a long-running integration that makes about 10 refreshes a day (one refresh every 2 hours of use). Single, non-concurrent refreshes got two 429 responses in a row, and the token was cleared each time.

Evidence (from ~/.lark-cli/logs/auth-*.log)

time=2026-10-28T10:22:16+01:00 path=/oauth/v3/token status=429 cmdline=lark-cli im +chat-list ...
time=2026-10-28T10:22:17+01:00 path=/oauth/v3/token status=429 cmdline=lark-cli im +chat-list ...

After these two lines, lark-cli auth status reports User identity: missing (no token in keychain ...) and every user call returns token_missing / need_user_authorization. The same happened on 2026-10-22 (two 429s, token cleared). On other days a single 429 was followed by a 200 on the retry, and the login survived.

Cause

internal/auth/uat_client.go, refreshOnce() (v1.0.98) never checks resp.StatusCode:

  1. A 429 with a non-JSON body (for example plain-text rate-limit text) fails json.Unmarshal, which returns refreshRetryAndClear.
  2. A 429 with a JSON body and an unregistered code goes through refreshActionForCode(), which returns refreshStopAndClear for unknown codes.

With refreshMaxAttempts = 2, two 429s in a row end in compareAndDeleteStoredToken().

Suggested fix

Treat HTTP 429 as "not processed": retry and preserve the stored token.

// after reading the body, before json.Unmarshal
if resp.StatusCode == http.StatusTooManyRequests {
    return refreshResult{
        action: refreshRetryAndPreserve,
        err: errs.NewNetworkError(errs.SubtypeNetworkTransport,
            "token refresh rate limited (HTTP 429); the stored token was preserved").
            WithRetryable(),
    }
}

And a case for TestRefreshFailureDeterminesStoredTokenDisposition (plus an optional status int field on refreshHTTPTestStep, applied in scriptedRefreshClient):

{
    name: "rate limited (HTTP 429) responses preserve after retry",
    steps: []refreshHTTPTestStep{
        {status: http.StatusTooManyRequests, body: `rate limit exceeded`},
        {status: http.StatusTooManyRequests, body: `{"code":99991400,"msg":"request trigger frequency limit"}`},
    },
    wantCalls:     2,
    wantPreserved: true,
    wantCategory:  errs.CategoryNetwork,
    wantSubtype:   errs.SubtypeNetworkTransport,
    wantRetryable: true,
},

With the current code this case fails (the token is cleared). With the fix it passes, and go test ./internal/auth/... stays green. A backoff before the second attempt would also help, since our two 429s arrived one second apart.

Environment

  • lark-cli 1.0.98 (npm), macOS, brand lark
  • User identity (UAT), default DPoP mode (preferred)
主要言語
Go
スター
18.2k
フォーク
1.4k
平均マージ
1日 3時間
マージ済み PR(30日)
18

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

larksuite/cli のほかの issue

larksuite/cli の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。