Repository navigation
fix: prevent plugin metadata rescans from stalling Gateway - #125596
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 12:43 PM ET / 16:43 UTC. ClawSweeper reviewWhat this changesThe PR carries the Gateway’s startup-selected plugin metadata generation through agent, model, tool, and skill preparation so admitted turns do not synchronously rediscover plugins. Regression provenancePossible regression — probable (reproduction; failure trace). No predecessor PR is attributed. Merge readinessNo blocking patch defect found. This remains a P1 maintainer PR because it replaces Gateway hot-path metadata discovery with a lifecycle-owned generation; wait for exact-head CI before merging. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 4 Assertions:
How this fits togetherGateway startup and reload publish plugin metadata alongside prepared model runtimes. Admitted agent turns consume that generation while preparing commands, skills, tools, and embedded execution, then return results through the Gateway. flowchart LR
A[Gateway startup or reload] --> B[Plugin metadata generation]
B --> C[Prepared model runtime]
C --> D[Admitted agent turn]
D --> E[Commands tools and skills]
E --> F[Gateway response]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +66, Tests +166, Other -1. Total +231 across 74 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep one Gateway-owned metadata generation, use it through every admitted path, and merge only after exact-head checks confirm reload and dispatch never reopen cold discovery. Do we have a high-confidence way to reproduce the issue? Yes—current main shows operation-local metadata publishing into the process-current slot, and the PR supplies a concrete built-Gateway concurrency benchmark; this review did not re-execute it. Is this the best way to solve the issue? Yes—the patch repairs the lifecycle owner and carries its prepared fact through consumers, rather than adding hot-path compatibility checks or a cold fallback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d8c1d90edb49. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
af737ff to
756c15f
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready verification for
Known local proof gap: The operator Gateway has not been changed yet. The authorized production deployment and soak follow merge; this comment does not claim live production proof. |
|
Merged via squash.
|
…125596) * fix(plugins): preserve gateway metadata ownership Generic runtime contexts no longer displace the Gateway lifecycle snapshot, preventing repeated synchronous plugin inventory validation on session hot paths. * fix(gateway): reuse lifecycle plugin generation for turns * test(agents): align static runtime lifecycle expectations * test(gateway): refresh minimal runtime fixtures * test(runtime): pass lifecycle metadata explicitly * fix(skills): reuse gateway metadata for commands * test(gateway): prepare reply runtime for agent RPCs * style(agents): format rebased runtime preparation * test(gateway): prepare runtime for direct agent RPCs * test(gateway): provide direct agent runtime fixture * test(gateway): prepare chat send reply runtime * test(qa): await descendant process exit
…untime registry (#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 #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.
…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.
Related: #125595
What Problem This Solves
Fixes chronic Gateway event-loop stalls caused by synchronous plugin metadata discovery on admitted agent turns. Under realistic plugin inventories, nested command, auth, model, skill, and tool preparation could reject the Gateway-owned metadata snapshot because the agent workspace or a derived runtime config differed, then rebuild and revalidate the full plugin graph on the Node main thread.
The production profile showed the consequence directly: repeated filesystem
lstat/existsSync/manifest work, event-loop delays up to roughly 70 seconds, and downstream control RPC and native-hook timeouts.Why This Change Was Made
Plugin execution is Gateway-lifecycle-owned, not agent-workspace-owned. This change makes that ownership explicit:
PluginMetadataSnapshotgeneration.No public Plugin SDK, protocol, config, environment-variable, or storage contract changes.
User Impact
Gateway turns no longer synchronously rescan the plugin inventory after startup. Control traffic stays responsive during concurrent tool-enabled runs, and downstream hook relays are no longer starved behind tens of seconds of plugin filesystem work.
Evidence
Reproduction before the complete repair
Isolated built Gateway, eight concurrent tool-enabled turns, 100 config-path plugins, and eight distinct session workspaces:
An intermediate explicit-carrier build proved the remaining ownership gap rather than masking it: 96 scans / 41.6 seconds, with repeated multi-second
readyzandsessions.listdelays.Final strict Gateway benchmark
Command:
Result:
pluginMetadataScanCount: 0pluginMetadataScanTotalDurationMs: 0readyzmax: 438.4 ms; no failed samplessessions.listmax: 438.2 ms; no failed samplesSource and test validation
node scripts/check-changed.mjspassed, including core/test typechecks, lint, import cycles, plugin boundaries, and ratchets.pnpm buildpassed with no ineffective dynamic-import failure.pnpm test:changedtarget discovery was stopped after remaining idle for more than 40 minutes without starting Vitest; exact-head CI remains required before merge.Production LOC across the PR: +393/-336 (net +57). The retained growth is the private lifecycle-generation carrier, explicit skill-command propagation, and authority boundary; obsolete compatibility/revalidation paths were deleted. Tests: +476/-313.
The operator Gateway has not yet been changed. After merge, the exact landed build will be deployed to the authorized team Gateway and soaked against the production liveness, control-RPC, session-history, and native-hook measurements tracked in #125595.