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

Abierto Apto para principiantes
#2,869 5 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@linye157 ya está trabajando en esto.

Desde el 30/10/2026.

  • #2875 de @linye157 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

Empieza por internal/auth/uat_client.go y lee refreshOnce() para ver cómo el estado de la respuesta y los errores de actualización determinan si se conserva o se borra el token almacenado. Después, inspecciona TestRefreshFailureDeterminesStoredTokenDisposition y el cliente de actualización con respuestas programadas para ver cómo se representan los estados de respuesta. El objetivo se cumple cuando se reintentan las respuestas HTTP 429 y se conserva el token almacenado, con una prueba de regresión que cubra este comportamiento.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
Lenguaje dominante
Go
Estrellas
18.2k
Forks
1.4k
Merge medio
1 d 3 h
PR fusionados (30 d)
18

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de larksuite/cli

Todos los issues de larksuite/cli

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.