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

Offen
#67,074 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
performance, testing

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
230k
Forks
31.3k
Ø Merge
5 Std. 32 Min.
Gemergte PRs (30 T.)
453

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus anomalyco/opencode

Alle Issues in anomalyco/opencode

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.