Repository navigation
perf(agents): reuse gateway plugin generation for prepared model runtime - #126630
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 1:50 PM ET / 17:50 UTC. ClawSweeper reviewWhat this changesThe PR reuses the Gateway’s active plugin generation for prepared model runtimes and loads only selected runtime additions, reducing duplicate plugin loading during startup. Merge readinessNo blocking correctness defect was found in the generation-bound reuse path. This protected maintainer PR remains necessary because current main still performs the cold registry load, while a second open PR covers the same optimization and maintainers must select one canonical landing path. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherPrepared model runtimes are assembled during Gateway startup from plugin metadata and registries. The change reuses the active Gateway generation only for an exact matching lifecycle snapshot, then loads any model-selected plugin delta. flowchart LR
A[Gateway startup] --> B[Published plugin generation]
C[Prepared model runtime] --> D[Metadata snapshot]
B --> E{Exact generation and binding match?}
D --> E
E -->|yes| F[Reuse Gateway registry]
E -->|no| G[Load isolated registry]
F --> H[Load selected plugin delta]
G --> H
H --> I[Prepared model runtime]
Decision needed
Why: Both open PRs target the same lifecycle boundary but their final heads were not available for a direct source comparison; the protected maintainer label requires explicit owner handling. Before merge
Agent review detailsSecurityNone. PR surfaceSource +55, Tests +128. Total +183 across 5 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain one generation-bound reuse implementation that preserves isolated, custom-environment, mismatched-workspace, and stale-generation loads; select one PR, complete exact-head validation, and close the other only after that selection. Do we have a high-confidence way to reproduce the issue? Not applicable as an issue reproduction; the PR supplies a concrete isolated Gateway startup measurement and source-visible current-main cold-load path. Is this the best way to solve the issue? Unclear which open PR is the best final vehicle, but the branch’s exact-snapshot identity guard and isolated fallback are the correct owner-boundary shape. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 81ace374f99f. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
The model-runtime sidecar rebuilt two broad plugin registries on gateway startup: 167 imports across 84 plugins (83 loaded twice) with 82 forced TypeScript transformations, ~39.6s of a ~50s source-checkout startup. - Reuse the active gateway registry for inbound dispatch when the gateway-bindable subagent mode, workspace, and manifest identity of the requesting snapshot generation all match; fall back to isolated loading otherwise. - Seed the runtime registry from the inbound registry's plugin ids instead of a second unscoped broad load. - Prefer built plugin artifacts on the agents lane, matching the gateway loader; externally-packaged plugins no longer force source transforms. Measured (M3 Ultra, dist build, median of 3): sidecars.model-runtime 33.93s -> 0.379s; gateway readiness 41.69s -> 7.58s; plugin imports 167 -> 18; TypeScript transformations 82 -> 0.
The full agents lane caught ~20 Code Mode regressions from preferring built artifacts on the agents loader lane: in a source checkout a stale dist silently replaces edited plugin source. The gateway-generation reuse already removes the broad re-imports that made source transforms expensive, so the artifact preference is unnecessary for the startup win and unsafe for dev checkouts.
…ration Reuse authority is identity-based: the requesting snapshot must be the process-current published generation. Bundled manifest records compare by id+origin only, so an equivalence check alone could let an older or leaked active registry serve a different generation's plugins.
…eneration The sidecar acquired its snapshot with loadPluginMetadataSnapshot, which always constructs a fresh object, so the generation-identity reuse guard could never hold in the gateway and inbound loads stayed isolated. Resolve through the slot-probing entry instead; the published current generation satisfies the read and registry reuse engages. Test updates: model the current-generation identity in the reuse fixture, drop stale preferBuiltPluginArtifacts expectations from the isolated-load fixtures, and add a negative case proving a non-current generation refuses reuse.
…generation The runtime-registry delta load re-imported teams-meetings and zoom-meetings channel graphs through forced source transforms (~9.2s) even though the reused gateway generation had already realized them from built artifacts. When the inbound registry is the active gateway registry, the delta load now inherits the generation owner's built-artifact preference; isolated loads keep source truth, so source-executed tests and dev flows are unaffected. Measured (M3 Ultra, dist build, 3 runs): sidecars.model-runtime 289-331ms (baseline 33,930ms); gateway ready 3.7-4.0s (baseline 41.7s); forced source transforms 0 (baseline 82).
…startup The prepared cold plugin context now resolves through the canonical slot-probing entry, joining the model-id normalization lane's existing resolution. Both share the published generation; the eager-work protections remain the catalog laziness assertions.
…lection Rebase over #125957, which preserves built-artifact mode for lifecycle-selected prepared registries. Reuse of the active gateway generation and the generation-inherited delta preference compose with that owner's parameter instead of duplicating the forwarding.
55f1056 to
860c7ee
Compare
|
Merged via squash.
|
|
The canonical corrective follow-up has landed in #127278.
#126630 had already merged while the replacement was under review, so it cannot be closed as superseded. #127278 supersedes its implementation on |
…ime (openclaw#126630) * perf(agents): reuse gateway plugin generation for prepared model runtime The model-runtime sidecar rebuilt two broad plugin registries on gateway startup: 167 imports across 84 plugins (83 loaded twice) with 82 forced TypeScript transformations, ~39.6s of a ~50s source-checkout startup. - Reuse the active gateway registry for inbound dispatch when the gateway-bindable subagent mode, workspace, and manifest identity of the requesting snapshot generation all match; fall back to isolated loading otherwise. - Seed the runtime registry from the inbound registry's plugin ids instead of a second unscoped broad load. - Prefer built plugin artifacts on the agents lane, matching the gateway loader; externally-packaged plugins no longer force source transforms. Measured (M3 Ultra, dist build, median of 3): sidecars.model-runtime 33.93s -> 0.379s; gateway readiness 41.69s -> 7.58s; plugin imports 167 -> 18; TypeScript transformations 82 -> 0. * fix(agents): keep source artifacts on isolated agent registry loads The full agents lane caught ~20 Code Mode regressions from preferring built artifacts on the agents loader lane: in a source checkout a stale dist silently replaces edited plugin source. The gateway-generation reuse already removes the broad re-imports that made source transforms expensive, so the artifact preference is unnecessary for the startup win and unsafe for dev checkouts. * fix(agents): bind gateway registry reuse to the current metadata generation Reuse authority is identity-based: the requesting snapshot must be the process-current published generation. Bundled manifest records compare by id+origin only, so an equivalence check alone could let an older or leaked active registry serve a different generation's plugins. * perf(agents): resolve prepared-runtime metadata through the current generation The sidecar acquired its snapshot with loadPluginMetadataSnapshot, which always constructs a fresh object, so the generation-identity reuse guard could never hold in the gateway and inbound loads stayed isolated. Resolve through the slot-probing entry instead; the published current generation satisfies the read and registry reuse engages. Test updates: model the current-generation identity in the reuse fixture, drop stale preferBuiltPluginArtifacts expectations from the isolated-load fixtures, and add a negative case proving a non-current generation refuses reuse. * perf(agents): inherit gateway artifact preference when extending its generation The runtime-registry delta load re-imported teams-meetings and zoom-meetings channel graphs through forced source transforms (~9.2s) even though the reused gateway generation had already realized them from built artifacts. When the inbound registry is the active gateway registry, the delta load now inherits the generation owner's built-artifact preference; isolated loads keep source truth, so source-executed tests and dev flows are unaffected. Measured (M3 Ultra, dist build, 3 runs): sidecars.model-runtime 289-331ms (baseline 33,930ms); gateway ready 3.7-4.0s (baseline 41.7s); forced source transforms 0 (baseline 82). * test(agents): count both slot-probing metadata resolutions in static startup The prepared cold plugin context now resolves through the canonical slot-probing entry, joining the model-id normalization lane's existing resolution. Both share the published generation; the eager-work protections remain the catalog laziness assertions. * refactor(agents): compose generation reuse with lifecycle artifact selection Rebase over openclaw#125957, which preserves built-artifact mode for lifecycle-selected prepared registries. Reuse of the active gateway generation and the generation-inherited delta preference compose with that owner's parameter instead of duplicating the forwarding.
What Problem This Solves
Gateway startup in a source checkout took ~50s, and 79% of it was the model-runtime sidecar rebuilding two broad plugin registries the gateway had already loaded: 167 plugin imports across 84 plugins (83 imported twice), 82 forced TypeScript source transformations across 41 source-backed plugins — 36.7s of which came from 39 plugins outside the gateway's own 16-plugin startup plan (
amazon-bedrock17.4s,opencode14.2s).Why This Change Was Made
src/agents/runtime-plugins.tsdroppedonlyPluginIdswhenever no request scope or explicit base ids existed, so the prepared model runtime re-loaded the full enabled set — twice — instead of reusing the gateway's activated generation. Four changes fix the ownership boundary:resolvePluginMetadataSnapshot, so the published generation satisfies the read and identity holds.preferBuiltPluginArtifacts; isolated loads keep source truth, so source-executed tests and dev flows are unchanged. A global flag was tried and reverted — it silently substituted stale dist for edited plugin source in checkouts.User Impact
Gateway readiness on a source checkout: 41.7s → 3.7–4.0s.
sidecars.model-runtime: 33,930ms → 289–331ms. Plugin loader calls at startup: 169 → 19; forced source transformations: 82 → 0. Packaged installs improve proportionally (the double broad load existed in every environment). No config changes; isolated/CLI registry loads behave exactly as before.Evidence
OPENCLAW_STATE_DIR, own port,/readyz-gated) per build, before/after,OPENCLAW_GATEWAY_STARTUP_TRACEspans quoted aboveonlyPluginIds, isolated loads keep prior args (src/agents/runtime-plugins.test.ts,prepared-model-runtime.plugin-context.test.ts)src/agentslane failures were attributed with a pristine-baseline control: the same Code Mode files fail on cleanorigin/mainunder 16-worker load on this host and pass serially — machine contention, not this change; two genuinely pre-existing failures on clean main (sandbox/fs-bridge.boundaryFIFO case,skill-workshop-tool.collection-restore) are noted for follow-upcheck:changedgreen; autoreview (Codex/gpt-5.6-sol, high): "No P0 defects"