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

オープン
#67,074 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
230k
フォーク
31.3k
平均マージ
5時間 32分
マージ済み PR(30日)
453

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anomalyco/opencode のほかの issue

anomalyco/opencode の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。