Repository navigation
perf(cron): carry the published plugin generation into hook/cron isolated runs - #130581
Conversation
…ated runs 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.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 9:52 PM ET / August 27, 2026, 01:52 UTC. ClawSweeper reviewWhat this changesThe PR reuses the Gateway-published plugin metadata generation for isolated cron and hook agent runs, avoiding per-run plugin metadata rescans. Merge readinessKeep open. Current main still lacks the cron generation handoff, while the patch follows the established prepared-runtime lease pattern and no concrete correctness defect was found. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — execution before step 1 Assertions:
How this fits togetherHook and cron jobs prepare an isolated agent runtime before invoking the embedded agent runner. Gateway-hosted runs can reuse lifecycle-owned plugin metadata, while standalone runs retain local admission behavior. flowchart LR
A[Hook or cron job] --> B[Isolated run preparation]
B --> C[Published Gateway runtime]
C --> D[Generation lease]
D --> E[Embedded agent runner]
E --> F[Provider attempt]
D --> G[Reused metadata snapshot]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +81, Tests +128. Total +209 across 4 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the explicit cron publication lookup and reuse the existing static lease/scope contract; a net-neutral refactor is not apparent because cron must obtain the published runtime independently of reply dispatch context. Do we have a high-confidence way to reproduce the issue? Yes (source-reproducible): current main's isolated-run path has no generation scope, while the embedded runner reloads metadata whenever no generation is supplied. This review did not execute the submitted live Gateway scenario. Is this the best way to solve the issue? Yes: the change reuses the established reply-path lease and scope contract, while retaining generation-free behavior when no Gateway publication is available. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3cb0dd4851e8. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Addressing the ClawSweeper before-merge items ahead of landing:
|
|
Merged via squash.
|
…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.
What Problem This Solves
#130167 fixed the catastrophic cold full-registry load on hook/cron isolated runs (42.6s event-loop block), but a CPU profile of a 13-run gmail hook burst still showed ~5-6s aggregate of per-run synchronous work:
prepareCronRunContextrebuilt a plugin metadata snapshot per run throughloadAgentRuntimePluginRegistryHandle(installed-plugin-indexsafeHashFile~2.2s,resolvePluginDoctorContractArtifactPath~1.8s,realpathSyncwalks), and the embedded orchestrator rebuilt-and-froze another snapshot plus a fresh prepared-runtime owner per run.The channel path already avoids this: #125596 carries
dispatchRuntime.pluginGenerationfrom the published Gateway generation into every reply turn, and the gatewayagentRPC path carriescommandRuntimeContext.pluginGenerationthe same way. Hook dispatch and the cron scheduler passed no generation, so isolated runs violated "Gateway/plugin metadata is process-stable; runtime hot paths never freshness-poll."Why This Change Was Made
Root cause: the isolated-run owner (
runCronIsolatedAgentTurn) never consumed the published prepared-runtime generation, even thoughprepareCronRunContextalready resolves the published model-catalog owner for model selection. Two carries complete the invariant at the owner:prepareCronRunContextnow passes the published owner'smetadataSnapshotintoloadAgentRuntimePluginRegistryHandle, so the per-run registry handle (still built per run because cron runtime selections differ per job) reuses the prepared metadata instead of re-hashing every installed plugin.runCronIsolatedAgentTurnloads the published Gateway dispatch runtime for the resolved agent, acquires a static prepared-runtime lease pinned to itspluginGeneration(mirroringrunPreparedReply), and wraps execution inwithPreparedModelRuntimePluginGenerationScopewith a borrow accessor. The embedded orchestrator picks the generation up from the ambient scope, skips its ownloadPluginMetadataSnapshot, and its prepared-runtime acquisition reuses the published generation; a config/plugin reload mid-run lets nested admissions borrow the leased snapshot instead of failing on the superseded configured owner.Standalone hosts (no Gateway lifecycle) and startup/replacement races return
undefinedfrom the loader and keep today's behavior: the orchestrator admits on whatever generation is current at execution time. No hook/cron call-site signatures changed.User Impact
Hook bursts (e.g. gmail fan-out) and cron isolated runs no longer spend seconds of synchronous event-loop time per run rebuilding process-stable plugin metadata; gateway responsiveness under bursts improves accordingly. No behavior or config surface changes.
Evidence
src/cron/isolated-agent/run.plugin-generation.test.tsproves the published generation is admitted (acquireAgentRunPreparedModelRuntimecalled with{catalogMode: "static", pluginGeneration}), stays ambient through embedded execution, releases its lease, and that missing/unpublished publications fall back to generation-free execution;run.runtime-plugins.test.tsproves the exact ownermetadataSnapshotobject reaches the registry load.prepared-model-runtime.test.ts,get-reply-run.prepared-metadata.test.ts, embedded-runner prepared-harness integration) green.OPENCLAW_STATE_DIR, port 19850,OPENCLAW_DIAGNOSTICStimeline): twocron runexecutions of an isolated agentTurn job traversed prepare → embedded runner → live Anthropic API (expected 401 with a dummy key — both hotspots run before the provider call).plugins.metadata.scantimeline spans: 22 at startup, still 22 after both runs — zero per-run metadata rebuilds; no generation-supersession errors. Pre-fix,loadAgentRuntimePluginRegistryHandleunconditionally calledloadPluginMetadataSnapshot, which always emits this span.pnpm buildclean (no[INEFFECTIVE_DYNAMIC_IMPORT]);check:changedgates green.Production LOC: +81 (run.ts +78, run-prepare.ts +3), all in the new generation-admission helper and scope wiring that mirrors
runPreparedReply; no net-neutral absorbing refactor exists because the cron path previously had no generation consumption to reshape.Follow-ups from the same investigation (out of scope here, evidence in #130167): (1)
prepareCronRunContextruns before the HookDispatch lane bounds anything, so N concurrent preps still run on burst admission — much cheaper now, but still unbounded; (2) first dispatch cold-evaluates the embedded-runner dist chunk graph (~4-6s once per process) — a post-ready background warmup would hide it.