Repository navigation
fix(plugins): share native module resolution hooks - #185033
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Dispatch captured module resolution by boundary and instance instead of walking every live plugin's hook. Preserve retained ESM authority and remove the shared hook after the last owner retires. Index prepared SDK roots within their existing cache generation. With 40 plugins, owner proof reduces resolve hooks from 41 to 2, process CPU by 23.8%, and sampled allocation by 61.6% over five paired runs of 5,000 imports. Native module and SDK regressions fail on the base and pass with the fix. Focused Node tests preserve reload and custody.
7dea6ad to
f7004d9
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR shares native plugin resolution hooks and indexes prepared SDK roots within their existing cache generation. Example: A Gateway retains 40 external plugin instances.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR removes measured resolver overhead while preserving capture ownership, with no definite introduced correctness defect found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe plugin loader connects native Node imports to captured plugin sources, live instance ownership, and host SDK aliases, producing prepared module URLs for execution. flowchart LR
A[Native import] --> B[Shared resolve hook]
B --> C[Live owner check]
C --> D[Capture boundary lookup]
D --> E[Instance source resolver]
E --> F[Native resolution and SDK aliases]
F --> G[Prepared module URL]
Technical reviewBest possible solution: Use one capture dispatcher and the existing generation-owned SDK cache while preserving instance admission, module identity, and disposal. Do we have a high-confidence way to reproduce the issue? Current-main source establishes per-instance hook traversal and repeated SDK-context scans; the PR reports base-failing regressions and paired owner measurements, which were inspected without executing target code. Is this the best way to solve the issue? The patch addresses repeated dispatch at its owner, removes the replaced registration path, and carries prepared SDK membership through the existing cache lifecycle. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9137d88c70f5. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +89, Tests +41, Other +282. Total +412 across 10 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 26, 2026, 5:41 PM ET / 21:41 UTC. |
|
Maintainer landing note: merging at exact head
Review: the shared dispatcher keeps per-instance authority. Each registration's resolve body still runs the unchanged |
* fix(plugins): share native module resolution hooks Dispatch captured module resolution by boundary and instance instead of walking every live plugin's hook. Preserve retained ESM authority and remove the shared hook after the last owner retires. Index prepared SDK roots within their existing cache generation. With 40 plugins, owner proof reduces resolve hooks from 41 to 2, process CPU by 23.8%, and sampled allocation by 61.6% over five paired runs of 5,000 imports. Native module and SDK regressions fail on the base and pass with the fix. Focused Node tests preserve reload and custody. * test(plugins): iterate known resolver fixture entries
What Problem This Solves
Native module resolution becomes more expensive as a Gateway retains more plugin instances: every import walks a process-wide hook for each live source capture, and the SDK hook scans all prepared alias contexts.
User Impact
Reduces import CPU and allocation without changing plugin module identity, reload behavior, SDK aliases, or capture custody. No configuration or migration is required.
Why This Change Was Made
Use one process-level resolve hook to select the capture boundary and its registration. Entry loads still resolve natively before the selected owner admits and prepares their target. Instance disposal removes the registration, and the hook deregisters when the last boundary retires. Retained native ESM keeps its current-instance selection and rejects failed/retired acquisition owners before resolution, including imports outside the capture.
SDK alias preparation now records root membership in its existing cache generation. The global resolver consumes that index instead of allocating an array and repeatedly deriving the same parent directory. Per-context roots remain intact for native-loader ownership checks.
This fixes residual active-instance cost: the base already deregisters hooks on disposal, so this is not a claim of an unbounded retirement leak. The production delta is +89 LOC (source only, excluding tests and benchmarks). That increase is required for shared dispatch, lifecycle cleanup, and the existing retained-owner authority contract; the per-instance Node hook registration path is removed.
Evidence
Acceptance: preserve resolution/identity/custody and reload tests, keep resolve-hook count independent of live plugin count, reduce warmed import CPU/allocation, and check real Gateway reload behavior. Timing and allocation passes are separate; no traced timing is used as a latency gate.
Dispatcher numbers: five counterbalanced pairs, 5,000 imports per arm per timing/allocation pass. The original dispatcher source uses the same SDK implementation as the candidate to isolate dispatch cost. All five pairs improved CPU and allocation. Host 1-minute load was 25.9–37.8; timing mean was 83.71→61.31 ms. SDK numbers: two counterbalanced pairs (BAAB), 5,000 imports per arm/pass, host load 18.09. Reported numbers are owner measurements, not whole-Gateway performance claims. Reproduction commands are in each benchmark script's header; the shared perf README is untouched.
Regressions fail on unchanged main: four plugin instances install five resolve hooks (expected at most two); the native eager/lazy SDK fixture performs seven context scans (expected zero). The candidate passed 229 tests across six focused Node files, including module generations, interop, demanded work, failed acquisitions, SDK aliases, and native SDK resolution. Node was selected explicitly because the local runner defaults to Bun, which does not exercise Node hooks.
Independent subagent review (autoreview route unavailable): no actionable P0/P1/P2 findings. The configured autoreview provider failed its route-match preflight before inference; no operator configuration was changed.
Built-Gateway proof: the supported
qaRuntimebuild passed in 114.9 seconds. An isolateddist/entry.jsGateway loaded 40 synthetic external plugins against 10,800 sessions and served 65 WebSocket clients. Seven source-edit/reload operations each passed a revision RPC assertion. Boot and all completed reloads retained exactly two active resolve hooks and 40 capture owners; all 76 periodic samples with 40 live owners had two hooks. A transient native loader hook reached peak/depth three. Shutdown released all capture owners and left only the SDK hook. The build preceded the mechanical SDK publication helper extraction; the resolver behavior is identical. No production Gateway was accessed.After the resolver-module extraction, another 73 plugin tests passed, including retained native ESM inspection/recovery authority. Both closure guard files passed after adding the new internal module to the tooling source inventory (23 + 3 tests). The initial missing-inventory failure was repaired, not waived. Targeted lint and oxfmt passed, the core tsrs typecheck passed, and the export-name collision guard passed. The line-cap guard passed without a baseline exception. Broad proof is PR CI. The scoped fast-path instruction uses owner measurements and focused proof rather than a multi-pair ten-minute stress campaign; no whole-Gateway CPU/GC/tail improvement is claimed.
The first CI head caught unchecked indexed reads in the two benchmark scripts and the new regression. Their loops now iterate typed entries; production behavior is unchanged. The script and plugin-test typecheck leaves and bounded-hook regression were rerun locally before the repair push. SDK figures above use the final workload.
Exact-head CI and inherited UI failures
Head
f7004d97323812a00e2418d59af1e12150bbe766completed CI run 40404251337. Plugin/Node tests, production and test types, lint, build artifacts, security checks, and the other UI shards passed. Four UI E2E shards and the aggregate gate remain red; this PR is not CI-green. GitHub Codex and ClawSweeper also reviewed this exact head with no findings.All failing files were then run with the supported headless synthetic UI wrapper and one worker on the unchanged exact base
5df1d936646f8a34d20c46602bae37d4c5002581. Every candidate failure reproduced:new-session-page.prompt-attachments.e2e.test.tsthin, receivedauto; height 222 and line height 21 match CIchat-composer-pointer-activation.e2e.test.tschat-attachment-menu.e2e.test.tsCamera,Media,File; missingTake photolocatorschat-media-picker.e2e.test.tsPhotos & videosmenu item at line 49The first file took 55.70 seconds. The other three files ran together in 230.41 seconds (16 failed, 4 passed); the two filechooser unhandled errors also match CI. Local UI timeout policy uses 10-second locator waits where CI uses 30 seconds; failure names, assertion values, and locator sites match. No CI reruns were requested.
Source attribution: #184759 (
b22e014dfa7da4ce3476672afe955cad806c98e9) introduced Chromiumscrollbar-width: autoand reduced the mobile composer bottom gap from 10 to 6 pixels. #184780 (9d44439eecaa) renamed the attachment controls. This PR changes no UI files. These inherited failures need separate UI reconciliation; the resolver PR remains open and unmerged for the lead's review.