#normalizeRetries silently coerces invalid maxRetries to 2 (e.g. -1 / 1.5 / 0)

Abierto Apto para principiantes
#3,124 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
79/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript

Línea de trabajo

Empieza en src/client.ts, en #normalizeRetries, e inspecciona cómo lo utilizan los valores predeterminados del cliente y el recuento de reintentos por solicitud. Lee las pruebas existentes de validación de reintentos, si las hay, y ejecuta las pruebas pertinentes del cliente. Se considera terminado cuando se rechazan valores no válidos como -1, 1.5 y "0", mientras que undefined sigue usando 2 como valor predeterminado y 0 continúa siendo válido.

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

Descripción

Summary

OpenAI silently coerces invalid maxRetries values to the default 2 instead of rejecting them. Callers that pass a typo / wrong type / non-integer (e.g. -1, 1.5, "0") get retries they did not ask for, with no throw and no warning.

Measured behavior

#normalizeRetries in src/client.ts:

#normalizeRetries(value: unknown): number {
  return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : 2;
}

That path is used both for the client default (this.maxRetries = this.#normalizeRetries(options.maxRetries)) and per-request retry accounting.

input result today what callers likely meant
0 0 (correct) disable retries
2 2 (correct) default
-1 2 invalid / “no retries” in some APIs
1.5 2 typo / bad config parse
"0" 2 stringified config that looks like “off”
undefined 2 default — fine

So "0" and -1 both quietly enable two retries.

Comparison

Sibling SDKs fail closed on the same class of input:

  • @ai-sdk/* / Vercel AI: prepareRetries validates the parameter and throws on invalid values
  • @anthropic-ai/sdk: validatePositiveInteger('maxRetries', …) rejects non-integers

Expected

Invalid maxRetries should throw (or at least warn) at client construction / request time, matching the documented contract that maxRetries is a non-negative integer configuration knob — not a soft hint that falls back to 2.

Suggested fix

Reject anything that is not a safe non-negative integer (same shape as Anthropic’s validatePositiveInteger), and keep undefined → default 2.

Happy to open a PR with a small unit test matrix for the cases above if maintainers want that direction.

Lenguaje dominante
TypeScript
Estrellas
11.3k
Forks
1.6k
Merge medio
12 h 58 min
PR fusionados (30 d)
196

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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 openai/openai-node

Todos los issues de openai/openai-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.