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

Đang mở
#67,074 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
performance, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
230k
Fork
31.3k
Merge trung bình
5 giờ 32 phút
Pull request đã merge (30 ngày)
453

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của anomalyco/opencode

Tất cả issue của anomalyco/opencode

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.