refactor(api): move hand-written abort bridges to the shared helper

Abierto
#2,486 9 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
eslint, typescript

Línea de trabajo

Start with src/api/providers/utils/abort-signal.ts and its callers, then review the listed provider locations and tests. The work covers seven providers, timeout helper consolidation, and two lint selectors, so map each special callback and controller use before changing the shared helper. Done means the providers’ tests pass and both selectors have zero violations, while the two fetchers/modelCache.ts listeners remain untouched.

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

Descripción

Seven providers on main bridge the caller's abortSignal with their own AbortController and abort listener. bridgeExternalAbortSignal in src/api/providers/utils/abort-signal.ts does the same work. anthropic.ts, anthropic-vertex.ts, minimax.ts and xai.ts already use it. Each hand-written copy adds one more place for a listener leak or a missed pre-aborted check.

Sites at origin/main 66b07e0e65:

  • bedrock.ts (~593): its 10-minute timer also aborts the request controller.
  • lm-studio.ts (~137) and qwen-code.ts (~293): both need a signal even with no caller signal, and abort the controller in finally.
  • openai-native.ts (~471, attachExternalAbort): the controller is exposed to the stop-button path.
  • openai-codex.ts (~524): both transports abort through the controller.
  • native-ollama.ts (~481 and ~736): the abort callback also calls client.abort().
  • vscode-lm.ts (~1198 and ~1684): the callback cancels a token source and records abortedByCaller.

fetchers/modelCache.ts has two abort listeners. They are not request bridges, so leave them as they are.

The helper returns only a signal, and returns undefined when there is no caller signal. Most sites above need a controller or an extra callback. Extend the helper first, for example with an optional controller and an onAbort hook. Then migrate each site and keep its provider tests green.

Also in scope:

  • main has two createTimeoutError helpers: one in utils/abort-signal.ts and one in utils/request-timeout.ts with a phase argument. Keep one. Move the callers.
  • After the migration, add a lint selector in packages/config-eslint/api-provider-hygiene.js that flags addEventListener("abort", …) outside the helper. Add one that flags a hand-built TimeoutError. Both need zero violations when they land.

Context: review of #1535 and the open abort PRs #1545 and #1311.

Lenguaje dominante
TypeScript
Estrellas
2k
Forks
301
Merge medio
3 d 14 h
PR fusionados (30 d)
103

Preparar el entorno

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 Zoo-Code-Org/Zoo-Code

Todos los issues de Zoo-Code-Org/Zoo-Code

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.