Promise plugin cleanup can rebuild command and integration registries on every transform disposal

Abierto
#67,074 2 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
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Start with packages/plugin/src/promise/adapter.ts, especially setup-runtime capture and cleanup disposal, then trace scope closing in packages/core/src/plugin.ts and registry notifications in packages/core/src/state.ts. Reproduce with command and integration transforms that count schema conversions during plugin removal. Done means explicit disposals trigger zero replays, each affected registry rebuilds once after the active batch, and shutdown does not materialize a registry being closed; add a regression test for those behaviors.

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

Descripción

area/plugins reproduced type/bug version/v2

A Promise plugin can return a cleanup function that calls dispose() on its command or integration transform registrations. During a plugin swap or server shutdown, those explicit disposals can bypass the host's current registry batch and replay the remaining transforms after each removal. If those transforms convert schemas or clone definitions, the registry pays that cost again even when there is no reader.

How to reproduce: Load one Promise plugin that registers four command transforms and four integration transforms. Each transform performs one counted schema conversion. Load a second, later plugin that registers two transforms in each registry and returns cleanup that explicitly awaits the four disposers. Remove that second plugin and count conversions during cleanup and over the whole swap. Explicit disposal should remove each registration immediately, but should not replay surviving transforms in the absence of a read until the host batch ends.

Source: On dev at e1d864a24dec1507160e430597eae53487358c21, the Promise adapter captures the setup runtime and reuses it for dispose() and invokes returned cleanup on scope release. The captured setup batch is no longer active. Plugin.activate closes the old scopes inside a new State.batch; full close uses State.shutdown. Without seeing the current batch, dispose calls changed, which runs notify immediately. notify reads the dirty registry, replaying the remaining transforms.

Measurements on 2.4.2-based builds: The fixture above made 16 schema conversions during the four explicit disposal calls before the fix and zero after. Total conversions for the swap fell from 16 to 8, with one rebuild per affected registry after the batch. In a separate 20-location benchmark, a combined patch (disposal batching plus reduced tool replays) reduced main-thread CPU through reload settle from 5.165 s to 3.045 s (41%) for a plugin-tree swap and from 11.870 s to 3.820 s (68%) for a swap limited to a subset of configured plugin paths. Separate instrumented runs counted 1,500–2,080 retiring tool transform calls per swap before the combined patch and zero after. These are not estimates of the disposal fix alone or benchmarks of current dev.

The broad tool-reload trigger in that older baseline has already been addressed by #66873. dev uses diffed flag changes, one tool-registry subscriber, and config selectors. This report is about the separate disposal path, not restoring that older observer change.

Shutdown observation, not an attribution: Loaded services based on 2.3.2 and 2.4.2, with about 25 plugins across 26 project directories, printed shutdown did not finish within 10s with plugin-supervisor releasing pending on every loaded stop we recorded (five), then exited with status 1 or were killed at 30 s. A 5 ms sample of the main thread's kernel state through one such stop showed it running on CPU for 29.9 of the 30 s (one unbroken 12 s run, which delayed the deadline message by 10.8 s) and in disk wait for 0.03 s, so the stop is synchronous CPU work in teardown, not I/O. Scratch stops did not reproduce the timeout, including a 26-directory run with three active request streams and about 700 tools per directory. No stack profile ties the live stop to registry work, and we have not shown that batching fixes the stop. #55272 tracks a related but different problem: expensive callbacks monopolizing the event loop even when each runs only once.

Proposed fix: Associate the host's current batch with the scope being closed, so explicit disposers use the active close batch rather than the inactive setup batch. Keep registry reads fresh and disposal outside an active close batch unchanged. During shutdown, do not materialize a registry the host is closing. We can share the batching patch and regression test.

Lenguaje dominante
TypeScript
Estrellas
230k
Forks
31.3k
Merge medio
5 h 32 min
PR fusionados (30 d)
453

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 anomalyco/opencode

Todos los issues de anomalyco/opencode

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.