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

Ouverte
#67,074 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
52/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
typescript
Domaine
performance, testing

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
TypeScript
Étoiles
230k
Forks
31.3k
Merge moyen
5 h 32 min
PR mergées (30 j)
453

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de anomalyco/opencode

Toutes les issues de anomalyco/opencode

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.