Repository navigation
fix(agents): scope fall-through plugin registry loads to the active runtime registry - #130167
Conversation
…untime registry First hook/cron isolated-run dispatch in a gateway process cold-loaded every discovered plugin (~70 bundled providers) because the registry loader's startup-scope fallback chain came up empty on that path and dropped onlyPluginIds entirely. In dev checkouts each provider plugin loads from TypeScript source through jiti's synchronous babel transform: a CPU profile of a live 13-message gmail hook burst showed one contiguous 42.6s event-loop block (36.2s extension module loading; amazon-bedrock 16.8s, opencode 13.1s), the gateway HTTP server unresponsive for ~31s, and the fan-out handler's own 8s response deadline unable to fire - the livelock recorded in #130002. The fallback chain now consults the process's active plugin registry before giving up to full discovery: explicit base -> request-scope registry -> metadata snapshot pluginIds -> active runtime plugin ids -> unrestricted. resolveAgentRuntimePluginLoadPlan still adds the run's selected provider, harness, memory, and context-engine owners on top, so any selected provider outside the startup set keeps joining the immutable run generation. Hosts with no active registry (pure library use) keep full discovery. Live re-verification on the same rig: cold burst answered in 8.03s with the designed 503 partial fan-out response, probe max latency 4.56s (was a 31.5s outage), longest event-loop block 5.5s (was 42.6s), and only startup-registry plugins load. Follow-up of the gmail hook fan-out landing (#130002); same defect family as the channel-path fix in #125596.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 1:32 PM ET / 17:32 UTC. ClawSweeper reviewWhat this changesThe PR bounds isolated agent-run plugin loading to the Gateway process’s active runtime plugins while retaining the plugins explicitly selected for that run. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessKeep open for maintainer review. The patch is a focused owner-boundary repair for unscoped isolated-agent registry loads; no discrete correctness defect was found, but its availability-sensitive scope change still needs exact-head validation after the branch is refreshed. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherHook and cron dispatches prepare an isolated agent runtime before executing work. That preparation selects a plugin registry, which determines both startup cost and the provider, harness, and tool capabilities available to the run. flowchart LR
A[Hook or cron request] --> B[Isolated run preparation]
B --> C[Plugin registry scope selection]
C --> D{Existing scope available?}
D -->|Yes| E[Reuse scoped plugin ids]
D -->|No| F[Use active runtime plugin ids]
E --> G[Add selected run owners]
F --> G
G --> H[Prepared agent run and Gateway response]
Decision needed
Why: The protected maintainer label and the change to runtime plugin scope require a maintainer to accept the final operational proof, not merely the mocked load-plan assertion. Before merge
Agent review detailsSecurityNone. PR surfaceSource +8, Tests +48. Total +56 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the scoped fallback only after exact-head focused regression coverage and a Gateway hook/cron smoke trace show that selected owners remain available while the response deadline stays live. Do we have a high-confidence way to reproduce the issue? Yes—current source reproducibly shows that an unscoped load leaves onlyPluginIds unset, while the PR’s focused test establishes the intended active-registry and selected-owner boundary; no local runtime execution was performed in this read-only checkout. Is this the best way to solve the issue? Yes—the fallback is placed in the shared registry-load decision point and reuses the existing active-runtime ID helper, rather than adding hook- or cron-specific loading policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 772f6a3d5ea9. 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 (1 earlier review cycle)
|
|
Merged via squash.
|
…ated runs (#130581) Hook dispatch and the cron scheduler rebuilt process-stable plugin metadata on every isolated run: prepareCronRunContext reloaded a metadata snapshot per run inside loadAgentRuntimePluginRegistryHandle (installed-plugin-index safeHashFile ~2.2s, doctor contract artifact resolution ~1.8s, realpathSync walks), and the embedded orchestrator rebuilt-and-froze another snapshot plus a fresh prepared-runtime owner per run — ~5-6s aggregate synchronous work across a 13-run gmail hook burst even after #130167 removed the cold full-registry load. The channel path already carries dispatchRuntime.pluginGeneration (#125596) and the gateway agent RPC carries commandRuntimeContext.pluginGeneration. This completes the same carry at the isolated-run owner: prepareCronRunContext reuses the published model-catalog owner's metadataSnapshot for the run registry handle, and runCronIsolatedAgentTurn admits the published Gateway generation (static prepared-runtime lease + withPreparedModelRuntimePluginGenerationScope with a borrow accessor, mirroring runPreparedReply) so the embedded orchestrator reuses the generation instead of rebuilding it. Standalone hosts and startup/replacement races keep generation-free execution. Live proof on an isolated dev gateway: plugins.metadata.scan timeline spans stayed at the 22 startup scans across two full isolated cron runs (zero per-run rebuilds); regression tests fail pre-fix.
…untime registry (openclaw#130167) First hook/cron isolated-run dispatch in a gateway process cold-loaded every discovered plugin (~70 bundled providers) because the registry loader's startup-scope fallback chain came up empty on that path and dropped onlyPluginIds entirely. In dev checkouts each provider plugin loads from TypeScript source through jiti's synchronous babel transform: a CPU profile of a live 13-message gmail hook burst showed one contiguous 42.6s event-loop block (36.2s extension module loading; amazon-bedrock 16.8s, opencode 13.1s), the gateway HTTP server unresponsive for ~31s, and the fan-out handler's own 8s response deadline unable to fire - the livelock recorded in openclaw#130002. The fallback chain now consults the process's active plugin registry before giving up to full discovery: explicit base -> request-scope registry -> metadata snapshot pluginIds -> active runtime plugin ids -> unrestricted. resolveAgentRuntimePluginLoadPlan still adds the run's selected provider, harness, memory, and context-engine owners on top, so any selected provider outside the startup set keeps joining the immutable run generation. Hosts with no active registry (pure library use) keep full discovery. Live re-verification on the same rig: cold burst answered in 8.03s with the designed 503 partial fan-out response, probe max latency 4.56s (was a 31.5s outage), longest event-loop block 5.5s (was 42.6s), and only startup-registry plugins load. Follow-up of the gmail hook fan-out landing (openclaw#130002); same defect family as the channel-path fix in openclaw#125596.
…ated runs (openclaw#130581) Hook dispatch and the cron scheduler rebuilt process-stable plugin metadata on every isolated run: prepareCronRunContext reloaded a metadata snapshot per run inside loadAgentRuntimePluginRegistryHandle (installed-plugin-index safeHashFile ~2.2s, doctor contract artifact resolution ~1.8s, realpathSync walks), and the embedded orchestrator rebuilt-and-froze another snapshot plus a fresh prepared-runtime owner per run — ~5-6s aggregate synchronous work across a 13-run gmail hook burst even after openclaw#130167 removed the cold full-registry load. The channel path already carries dispatchRuntime.pluginGeneration (openclaw#125596) and the gateway agent RPC carries commandRuntimeContext.pluginGeneration. This completes the same carry at the isolated-run owner: prepareCronRunContext reuses the published model-catalog owner's metadataSnapshot for the run registry handle, and runCronIsolatedAgentTurn admits the published Gateway generation (static prepared-runtime lease + withPreparedModelRuntimePluginGenerationScope with a borrow accessor, mirroring runPreparedReply) so the embedded orchestrator reuses the generation instead of rebuilding it. Standalone hosts and startup/replacement races keep generation-free execution. Live proof on an isolated dev gateway: plugins.metadata.scan timeline spans stayed at the 22 startup scans across two full isolated cron runs (zero per-run rebuilds); regression tests fail pre-fix.
fix(agents): scope fall-through plugin registry loads to the active runtime registry
What Problem This Solves
First hook/cron isolated-run dispatch in a gateway process blocks the Node event loop for 30-45s, making the gateway HTTP server completely unresponsive (hook POSTs time out past gog's 10s client deadline; the fan-out handler's own 8s response-deadline timer cannot fire). During the gmail hook fan-out live test (PR #130002 follow-up), a 13-message burst pushed every embedded run's
attempt-workspacestage to 14-15.4s with all stages ending at the same wall-clock instant — classic event-loop starvation.Root cause (proven by CPU profile of a live dev-gateway repro):
prepareCronRunContext(src/cron/isolated-agent/run-prepare.ts:641) builds its plugin registry vialoadAgentRuntimePluginRegistryHandlewith only run selections. InresolveAgentRuntimePluginRegistryLoad, the startup-scope fallback chain (explicit base → request-scope registry → snapshot pluginIds) resolves empty on the hook/cron path, and with no base the loader dropsonlyPluginIdsentirely — cold-loading every discovered plugin (~70 bundled providers). In a dev checkout each uninstalled provider plugin loads from TypeScript source through jiti's synchronous babel transform: one contiguous 42.6s block, of which 36.2s is extension module loading (amazon-bedrock 16.8s, opencode 13.1s), plus ~4s GC from AST churn. The gateway process already owns an active startup plugin registry; the fall-through simply never consulted it. PR #125596 fixed this class for the channel path (which carries its admitted plugin generation); hooks/cron never got the same treatment.Why This Change Was Made
Owner-level repair: the "what to load" policy lives in
resolveAgentRuntimePluginRegistryLoad, and every fall-through caller (hook dispatch, cron scheduler, trigger scripts, subagent registry) benefits from fixing it there. The fallback chain gains one step: when no explicit base, request scope, or snapshot scope exists, use the active process registry's runtime plugin ids as the startup base.resolveAgentRuntimePluginLoadPlanthen adds the run's selected provider/harness/memory/context-engine owners on top, preserving the invariant that every selected provider joins the immutable run generation. Hosts with no active registry (pure library use) keep full discovery unchanged.User Impact
Evidence
BEFORE (cold 13-message POST to /hooks/gmail, dev gateway, fresh process):
prepareCronRunContext → loadAgentRuntimePluginRegistryHandle → loadOpenClawPlugins, dominated by jiti/babel TS transpile (18.3s babel.cjs + 5.5s jiti.cjs self time) and jiti cache fs (2.5s readFileUtf8, 2.1s writeFileUtf8).AFTER (same rig, fresh state dir + fresh process, fix applied):
Regression test:
bounds unscoped agent loads to active runtime plugins and selected ownersinsrc/agents/runtime-plugins.test.ts— fails pre-fix (noonlyPluginIds), passes post-fix.Production LOC delta: +8 (helper import, invariant comment, one fallback branch). Tests +49/-1.
Follow-ups (recorded, out of scope here)
safeHashFile, doctor-contract path resolution, realpath walks — measured ~5-6s aggregate across a 13-run warm burst). Canonical fix is carrying the gateway's admitted plugin generation into hook/cron dispatch, completing fix: prevent plugin metadata rescans from stalling Gateway #125596 for this ingress.prepareCronRunContextruns before the HookDispatch lane bounds anything, so N preparations run unbounded on burst admission.