Repository navigation
fix(plugins): release preparation workers after plugin startup - #177141
vincentkoc wants to merge 10 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
|
@vincentkoc There’s overlap with #176192 at the plugin capture/loading boundary. Our approach retains preparation-worker ownership while removing synchronous worker round trips from module loading; yours transfers source state to the plugin owner and retires the workers. Our isolated Windows/Node 24.21.0 workload with 1,000 dependencies and 10,000 imported modules completed startup in 74.9 s and changed-plugin reload in 67.8 s, with zero 15-second HTTP/WS deadline misses. Three HTTP connection resets remained, so this was not a zero-failure responsiveness result. The harness and revision-specific evidence are in #176192. A Windows CI package also passed build and fresh-install verification; those checks are separate from the local workload measurements above. Would comparing the same dependency-heavy fixture against your handoff help us coordinate the changes and preserve the ownership, native-custody, and recovery contracts? |
Landing hold: the completed 20-run cold-cache comparison fails the recorded acceptance rule. Do not merge until performance acceptance is resolved. One-plugin median RSS rises 8.0%; five-plugin median RSS falls 3.2% but startup rises 34.0%. Worker retirement alone is not an accepted process-memory win.
What Problem This Solves
External plugins keep their source-preparation workers alive for as long as their loaded artifacts survive, retaining an isolate per plugin after startup work has finished.
User Impact
The fix transfers prepared source facts to the loaded artifact owner, then waits for physical worker exit before publishing loaded plugins. Lazy imports, captured source bytes, native-library custody, and reload recovery remain functional. The paired workload below does not establish an acceptable process-memory improvement; this implementation remains under investigation.
Why This Change Was Made
Preparation workers should own initial capture work. The loaded plugin instance should own the resulting source artifact and its lazy execution state. Moving prepared facts to that existing owner removes the need for a permanent preparation isolate.
Evidence
Source-reviewed regression loads a real external plugin, requires preparation workers to have exited while its registered tool remains live, then edits the original helper before its first lazy import and checks the captured value.
The existing Gateway concurrency workload now samples the physical worker census through
diagnostics.lanesbefore and after the timed load window.Targeted formatting, staged diff checks, and the line-cap ratchet passed. The initial Testbox allocation queued and was stopped without running tests; local proof uses the native PR checkout with its own qualified dependencies. The baseline regression fails on the retained preparation worker; candidate retirement, lazy imports, native custody, recovery, and independent capture disposal tests pass. Node sibling coverage passed: 146 tests, with 7 platform skips. Core and script type checks and targeted lint passed. Independent reviews found no remaining product finding.
The first real baseline smoke completed its four requested agent turns but failed teardown because the generic child stopper forced SIGKILL after two seconds. It is excluded from performance evidence. Both measured variants used the same committed benchmark harness from
7d63c2fd41aaf978ecaff8a02cb347518cd2fb4b, which uses acknowledged Gateway shutdown and rejects every forced child cleanup. Slow-shutdown CPU-profile flushing and forced-descendant failure are covered by CLI tests. Runtime build identities remain separate: baseline097f40bde788c85c4696eaaad78a9a13424cbbd5, candidate7d63c2fd41aaf978ecaff8a02cb347518cd2fb4b. Both receive only the same benchmark-script and shared benchmark-environment overlays from7d63c2fd41aaf978ecaff8a02cb347518cd2fb4b; the final source also removes a type-only import cycle found by hosted CI. The nine affected modules emit byte-identical JavaScript before and after that type repair, and the final candidate was rebuilt from its exact source head.Final candidate build, core/script type checks, and the full import-cycle guard passed (zero cycles). The architecture failure on the previous CI head was introduced by this branch and is repaired here. The subsequent CI failure in the Doctor readiness test is detailed below.
Ownership and scope
The plugin instance owns the prepared source artifact. Preparation borrows host capture/native custody, transfers plain facts, settles admission publication, and physically exits before registration. The existing artifact builder resumes lazy capture and recovery locally. The worker RPC codec and retained artifact proxy are removed. Native admission borrowers survive cache retirement until their owning artifacts are disposed. Failed physical stops remain reachable for terminal cleanup retries.
The first completed pair is diagnostic-only: baseline had already populated its build-qualified worker bytecode cache during the earlier smoke, while the candidate had not. Both formerly used a shared system temp directory. RSS was 2,303 vs 2,070 MiB, startup 6,425 vs 12,955 ms, and load CPU 2,535 vs 4,248 ms; these are not accepted improvement/regression estimates. Provider request counts and bytes matched. The common harness now confines TMPDIR/TMP/TEMP to each fixture, so every process starts with a fresh worker cache without changing main-thread cache policy. All 47 focused benchmark tests passed. The completed paired series used that explicit cold-cache condition; the same acceptance thresholds below remain binding.
Performance acceptance rule, recorded before the first run:
Command shape (repeat with
--plugin-count 5):Completed paired results
Five interleaved baseline/candidate pairs per plugin count; all 20 runs included. Baseline 097f40b; candidate and common harness 7d63c2f. Separate compiled generations, Node 26.7.0, macOS arm64, 18 logical CPUs, 48 GiB physical memory, fixture-owned cold worker caches. With five runs, nearest-rank p95 is the maximum, not a stable population tail.
1 external plugin
5 external plugins
All 20 runs completed one verified warmup plus three verified measured turns, registered every synthetic plugin, and exited cleanly. Preparation census was 1 or 5 on baseline and zero on every candidate before and after load. Both cohorts performed the same benchmark-turn and activity-recap inference work; background embedding timing crossed the warmup/load boundary and adaptive probe counts varied. These remain comparability limits. No high or low sample was discarded.
One-plugin paired RSS changes were +260.00, -213.20, -76.53, +530.73, and -380.05 MiB. Three of five pairs improved, but the cohort median rose. The fourth pair exceeded the 20% RSS/peak regression threshold. Worst per-run p95 probe tails also worsened (readyz +73.6%, sessions.list +74.5%, Control UI +41.3%), although pooled p95 improved. The five-plugin startup median and p95 worsened by 34.0% and 26.4%. These failures prevent landing under the recorded rule.
Host load and free memory varied; one-plugin one-minute host load ranged 11.26–25.63, and one candidate started with 469 MiB free. This is not a causal attribution or a waiver. Much of the first two five-plugin startup gaps precedes preparation; separate startup and load CPU profiles are being collected to locate the cost.
CI test-lifetime repair
The Doctor readiness test granted each of three sequential child phases 30 seconds but granted their parent only 45 seconds. In the failed CI run, Doctor completed after 24.4 seconds and Gateway readiness after 41.3 seconds; the parent aborted the status child at 45.1 seconds, before its own deadline. The existing getCliProcessTestTimeout helper now derives the parent budget from all three unchanged 30-second phase budgets. Assertions, startup coverage, cancellation and cleanup remain intact. The focused process test and targeted test lint passed; independent review found no scoped issue. Test-only head c9f4644 does not alter the measured runtime at 7d63c2f or resolve the performance hold.
Instrumented attribution follow-up
A separate five-plugin profile pair completed the workload and clean shutdown. These instrumented runs are diagnostic only and do not replace the 20 unprofiled samples above. Six transcript threads identified by loaded execution frames retained 378.9 MiB baseline and 372.1 MiB candidate of aggregate used V8 heap at the final sampled instant. This is worker heap, not attributed RSS; two census transcript workers lacked identity mapping, and idle preparation isolates lacked heap samples. Each run also had one worker retire before profiler stop. The next investigation targets read-only transcript paths importing writable database/schema modules, with unchanged read/admission/lifecycle behavior as a required contract. No memory gain from that follow-up is established.
Validation follow-up
A subsequent full-tree and production unused-export scan on this head identified two exports left behind by the preparation-worker handoff:
recordPluginNativeLoadandsubscribePluginNativeLoadsinsrc/plugins/plugin-source-capture-native-loads.ts. The recorder is still used internally, but its export has no consumer; the subscription and observer dispatch have no remaining consumer. This is an unresolved cleanup in this held PR. The independent transcript-reader change does not modify these files and does not resolve the performance hold.