Skip to content

perf(cron): carry the published plugin generation into hook/cron isolated runs - #130581

Merged
steipete merged 1 commit into
mainfrom
claude/wizardly-leakey-5f93ba
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/wizardly-leakey-5f93ba

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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: prepareCronRunContext rebuilt a plugin metadata snapshot per run through loadAgentRuntimePluginRegistryHandle (installed-plugin-index safeHashFile ~2.2s, resolvePluginDoctorContractArtifactPath ~1.8s, realpathSync walks), 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.pluginGeneration from the published Gateway generation into every reply turn, and the gateway agent RPC path carries commandRuntimeContext.pluginGeneration the 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 though prepareCronRunContext already resolves the published model-catalog owner for model selection. Two carries complete the invariant at the owner:

  • prepareCronRunContext now passes the published owner's metadataSnapshot into loadAgentRuntimePluginRegistryHandle, 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.
  • runCronIsolatedAgentTurn loads the published Gateway dispatch runtime for the resolved agent, acquires a static prepared-runtime lease pinned to its pluginGeneration (mirroring runPreparedReply), and wraps execution in withPreparedModelRuntimePluginGenerationScope with a borrow accessor. The embedded orchestrator picks the generation up from the ambient scope, skips its own loadPluginMetadataSnapshot, 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 undefined from 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

  • New regression tests (both fail on pre-fix code, verified): src/cron/isolated-agent/run.plugin-generation.test.ts proves the published generation is admitted (acquireAgentRunPreparedModelRuntime called 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.ts proves the exact owner metadataSnapshot object reaches the registry load.
  • Full cron isolated-agent suite: 42 files, 628 tests green. Sibling generation-semantics suites (prepared-model-runtime.test.ts, get-reply-run.prepared-metadata.test.ts, embedded-runner prepared-harness integration) green.
  • Live proof on an isolated dev gateway (own OPENCLAW_STATE_DIR, port 19850, OPENCLAW_DIAGNOSTICS timeline): two cron run executions 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.scan timeline spans: 22 at startup, still 22 after both runs — zero per-run metadata rebuilds; no generation-supersession errors. Pre-fix, loadAgentRuntimePluginRegistryHandle unconditionally called loadPluginMetadataSnapshot, which always emits this span.
  • pnpm build clean (no [INEFFECTIVE_DYNAMIC_IMPORT]); check:changed gates 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) prepareCronRunContext runs 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.

…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.
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 01:45
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 9:52 PM ET / August 27, 2026, 01:52 UTC.

ClawSweeper review

What this changes

The PR reuses the Gateway-published plugin metadata generation for isolated cron and hook agent runs, avoiding per-run plugin metadata rescans.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep 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
Reviewed head: 0fea4159bca60099f111eb34583ed4754ec683f8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused regression coverage and the existing lifecycle pattern support the patch; normal exact-head validation remains.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes an after-fix isolated Gateway diagnostic trace.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes an after-fix isolated Gateway diagnostic trace.
Evidence reviewed 7 items Current-main gap: Current main executes the isolated cron run under session, lifecycle, and plugin-registry scopes, but has no published plugin-generation lease or ambient generation scope.
Proposed owner-boundary repair: The branch loads the published runtime, acquires a static lease pinned to its generation, scopes execution, and releases the lease in finally.
Embedded consumer and reload contract: The embedded runner consumes the ambient generation, uses it for prepared-runtime acquisition, and rejects a mismatched metadata snapshot; the lease layer permits a scoped borrowed snapshot only while the parent lease remains active.
Findings None None.
Security None None.

Live Verification

Command: pnpm exec openclaw cron --help

Result: FAIL (failed) — execution before step 1 run: terminal command failed with exit status 1: "pnpm exec openclaw cron --help"

terminal command failed with exit status 1: "pnpm exec openclaw cron --help"

Captured output:
undefined
[ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL] Command "openclaw" not found

Did you mean "pnpm exec openclaw.invoke"?















































Assertions:

  • FAIL expect_output: Manage automations (via Gateway)

How this fits together

Hook 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]
Loading

Before merge

  • Resolve merge risk (P1) - The repair adds production +81/-6 at a lifecycle boundary; no net-neutral absorption is apparent because cron lacks the reply path's request-scoped dispatch runtime, so exact-head validation should retain the shared lease semantics.
  • Complete next step (P2) - This active member-authored, maintainer-labeled PR needs normal exact-head review and validation, not repair dispatch.
Agent review details

Security

None.

PR surface

Source +81, Tests +128. Total +209 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 87 6 +81
Tests 2 128 0 +128
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 215 6 +209

Review metrics

Metric Value Why it matters
Production versus tests production +81/-6; tests +128/-0 The added production code is the cron-specific generation admission and scope wiring; tests cover its lease and metadata-identity invariants.

Stored data model

Persistent data-model change detected: vector/embedding metadata: src/cron/isolated-agent/run.runtime-plugins.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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.

Labels

Label changes:

  • add P1: The repair targets Gateway responsiveness during hook and cron bursts, where repeated synchronous metadata work can delay active automation.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes an after-fix isolated Gateway diagnostic trace.

Label justifications:

  • P1: The repair targets Gateway responsiveness during hook and cron bursts, where repeated synchronous metadata work can delay active automation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless describes an after-fix isolated Gateway diagnostic trace.

Evidence

What I checked:

Likely related people:

  • steipete: Authored this change and prior merged work on prepared runtime ownership and plugin-rescan prevention. (role: major lifecycle and cron contributor; confidence: high; commits: 0fea4159bca6, 93d879dcd120, fd216cb5509e; files: src/cron/isolated-agent/run.ts, src/cron/isolated-agent/run-prepare.ts, src/agents/prepared-model-runtime.ts)
  • Josh Lehman: Recent history attributes the cron entry-path and prepared-runtime area to the registry activation rollback work. (role: recent runtime lifecycle contributor; confidence: medium; commits: bcf330c77a82; files: src/cron/isolated-agent/run.ts, src/agents/prepared-model-runtime.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the ClawSweeper before-merge items ahead of landing:

  • P1 merge risk (production +81/-6 at a lifecycle boundary): agreed with the review's own "best possible solution" — the explicit cron publication lookup stays, reusing the exact static lease + generation-scope + borrow + finally-release contract the reply path already owns (get-reply-run.ts). No net-neutral absorbing refactor exists because cron must obtain the published runtime independently of reply dispatch context. Exact-head validation retained the shared lease semantics: full cron isolated-agent suite (42 files / 628 tests), sibling generation suites (prepared-model-runtime, get-reply-run.prepared-metadata, embedded-runner prepared-harness integration), exact-head CI green on 0fea4159bca60099f111eb34583ed4754ec683f8, plus the live zero-rescan gateway proof in the PR body.
  • P2 (normal exact-head review and validation): done via the repo-native scripts/pr review flow — review artifacts completed and validated at this head, Codex autoreview clean (0 accepted findings), exact-head CI green.
  • Live Verification FAIL (pnpm exec openclaw cron --help): reviewer-harness invocation error, not a PR defect — the repo exposes the CLI as the pnpm openclaw script (or node dist/index.js); pnpm exec openclaw has never resolved. The PR body's live proof covers the changed path on a real gateway.
  • Stored data model note (vector/embedding metadata in run.runtime-plugins.test.ts): false positive — that file is a Vitest test; the PR touches no persistent store, schema, or migration surface.

@steipete
steipete merged commit bdc0c92 into main Aug 27, 2026
271 checks passed
@steipete
steipete deleted the claude/wizardly-leakey-5f93ba branch August 27, 2026 02:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant