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

Đang mở Phù hợp với người mới
#2,869 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@linye157 đang làm issue này rồi.

Từ ngày 30/10/2026.

  • #2875 của @linye157 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
authentication

Hướng nghiên cứu

Bắt đầu với internal/auth/uat_client.go và đọc refreshOnce() để xem trạng thái phản hồi và lỗi làm mới quyết định việc giữ lại hay xóa token đã lưu như thế nào. Sau đó, kiểm tra TestRefreshFailureDeterminesStoredTokenDisposition và client làm mới được lập kịch bản để biết trạng thái phản hồi được biểu diễn ra sao. Công việc hoàn tất khi các phản hồi HTTP 429 được thử lại trong khi token đã lưu vẫn được giữ nguyên, kèm theo một kiểm thử hồi quy bao quát hành vi này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)
Ngôn ngữ chính
Go
Star
18.2k
Fork
1.4k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của larksuite/cli

Tất cả issue của larksuite/cli

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.