Skip to content

fix(cron): preserve Gateway plugin registry for scheduled runs - #166991

Merged
steipete merged 4 commits into
openclaw:mainfrom
67-luck:67-luck/cron-registry-scope-166756
Oct 8, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
67-luck:67-luck/cron-registry-scope-166756

Conversation

@67-luck

@67-luck 67-luck commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #166756

What Problem This Solves

The first scheduled condition check after Gateway restart can synchronously reload plugins already loaded at startup, exhaust its 30-second budget, and stall Gateway liveness and channel sockets.

User Impact

Scheduled condition checks reuse their Gateway's current compatible plugins after restart and cron hot reload. The existing trigger deadline, tool policy, request isolation, and plugin-generation checks are preserved. No configuration, protocol, SDK, schema, or migration changes are required.

Why This Change Was Made

Detached scheduling deliberately drops request-local state. The cron owner now supplies a live registry resolver through startup, lazy construction, and hot reload, allowing preparation to use the existing Gateway-owned borrowing path. Resolving it per run follows registry replacement without borrowing another Gateway's resources.

Maintainer cleanup removes the ambient request-registry fallback, shares the cron constructor's parameter contract with its lazy adapter, and replaces helper-identity/constructor-argument assertions with real preparation, tool execution, registration-count, and generation coverage.

Original fix by @67-luck; maintainer cleanup and proof by @steipete. Contributor commits and human co-author credit are preserved.

Evidence

Verified candidate c36968226bded0675e8ef07b5adaae9dc4781b31 against captured main 57dd17b4ea39b5f5d87db9faabaa2f0b10fa83f4. Exact-head CI passed. Independent Codex autoreview was scoped-clean through P2. This PR is intentionally left unmerged.

Real Gateway proof ran on secretless AWS lease cbx_211600b2dc4e (r7i.xlarge, 30.81 GiB RAM), with the QA mock OpenAI provider, isolated state, and ephemeral ports. The fixture loaded 31 local plugins with calibrated synchronous PBKDF2 work in register, making duplicate registration measurable without patching production code. These are synthetic registration costs, not a benchmark of the reporter's plugin fleet. Evaluations were naturally scheduled; forced runs, which bypass the condition, were not used. The first evaluation followed a full process restart and the 60-second liveness startup grace.

Revision / first evaluation Completion after due Additional plugin registrations Observed result
Main, after process restart 35,585 ms 31 (35,195 ms registration CPU) Trigger timeout; liveness 20,235 ms overdue; 20 health timeouts
Main, after cron hot reload 30,354 ms after advertised due 0 Quiet check persisted generation 1 from warm cache; no new liveness warning or health timeout
Fix, after process restart 306 ms 0 Condition state persisted; no liveness warning or health timeout
Fix, after cron hot reload 201 ms 0 Same Gateway PID; condition state persisted; no liveness warning or health timeout
Fix, after plugin generation replacement and cron hot reload 167 ms 0 Returned generation 2; no liveness warning or health timeout
Fix, condition-fired agent turn 4,307 ms (4,170 ms payload run) 0 One mock-provider request; one successful persisted run; REGISTRY_OK

After main's initial timeout, the warm-cache reload observation completed without another registry load. Its 30,354 ms figure is completion after the advertised due time, not a measured CPU stall. Quiet conditions preserve prior payload-run status, so the retained error was not counted as a second timeout.

Cron replacement was exercised through supported config.patch updates of cron.enabled false then true. The Gateway PID remained unchanged. plugins.reload deliberately re-registered only the selected probe plugin once; the subsequent condition borrowed that new generation without registering it again.

Main evidence:

cron trigger evaluation failed (timeout): cron trigger evaluation timed out
liveness heartbeat delayed: overdue=20235ms elapsed=50235ms; deferring recovery decisions

All 283 tests across the 19 trigger/cron/Gateway module files passed (156.92 s wall). The changed preparation file passed 5 tests with pnpm test src/cron/trigger-script.preparation.test.ts --maxWorkers=1 (58.93 s cold wall, mostly worker compilation); the new regression took 879 ms within the module run. CI's 17 Node validation jobs totaled 3,856 runner-seconds, including setup and existing selected coverage, not just the added regression.

The production-only negative control kept the test unchanged and reverted only scheduled-run-gateway-context.ts to the main merge-base version. It failed on the intended assertion: startup's single full registration was followed by unwanted discovery and tool-discovery registrations. The fixed production file was restored byte-for-byte before subsequent checks.

Production typecheck passed (63.06 s), as did the three applicable test-type graphs (166.44 s combined). Full build with QA artifacts passed (382.88 s). Local oxfmt, scoped oxlint, and git diff --check passed; no contributor runtime executed locally. The full build reported an unrelated UI startup-bundle-size warning; UI source is unchanged.

Commands and source isolation

The installed Crabbox CLI was launched from a clean trusted main worktree. Every run used the trusted bootstrap, the full pushed PR SHA, --fresh-pr, --no-hydrate, and CRABBOX_ENV_ALLOW=CI. The bootstrap verified the SHA and IMDS no-role boundary and installed dependencies in a fresh temporary HOME. Public networking and no Tailscale were verified before use.

env -u CRABBOX_AWS_INSTANCE_PROFILE CRABBOX_ENV_ALLOW=CI \
  crabbox run --provider aws --id cbx_211600b2dc4e \
  --fresh-pr openclaw/openclaw#166991 --no-hydrate --timing-json \
  --script scripts/crabbox-untrusted-bootstrap.sh -- \
  c36968226bded0675e8ef07b5adaae9dc4781b31 bash -c '<scoped check commands>'

pnpm test src/cron/trigger-script.preparation.test.ts --maxWorkers=1
pnpm test src/cron/trigger-script*.test.ts src/gateway/server-cron*.test.ts \
  src/gateway/scheduled-run-gateway-context.test.ts \
  src/gateway/server-reload-hot.cron-lazy.test.ts --maxWorkers=1
pnpm tsgo:core
pnpm tsgo:core:test --ci-graphs-json \
  '["core-test-services-cron","core-test-gateway-server","core-test-gateway-root"]'
OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build

# Temporary real-Gateway harness; same input fixture on each revision.
pnpm exec tsx /tmp/166991-live-proof.mts --repo-root "$PWD" \
  --head c36968226bded0675e8ef07b5adaae9dc4781b31 --expect fixed \
  --output-dir /tmp/oc-r6-166991-proof/fixed-live-corrected
pnpm exec tsx /tmp/166991-live-proof.mts --repo-root "$PWD" \
  --head c36968226bded0675e8ef07b5adaae9dc4781b31 --expect fixed --turn-only \
  --output-dir /tmp/oc-r6-166991-proof/fixed-live-turn

# Separate remote main worktree; native runtime build for the baseline.
git fetch --no-tags https://github.com/openclaw/openclaw.git \
  57dd17b4ea39b5f5d87db9faabaa2f0b10fa83f4 --depth=1
git worktree add --detach /tmp/oc-r6-166991-main \
  57dd17b4ea39b5f5d87db9faabaa2f0b10fa83f4
cd /tmp/oc-r6-166991-main
pnpm install --frozen-lockfile
OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build qaRuntime
pnpm exec tsx /tmp/166991-live-proof.mts --repo-root "$PWD" \
  --head 57dd17b4ea39b5f5d87db9faabaa2f0b10fa83f4 --expect baseline \
  --output-dir /tmp/oc-r6-166991-proof/main-live

The original-head baseline also passed 32 tests on lease cbx_b35b1f297781. An allocation that fell back to t3.small (cbx_a77651d52052) was stopped without executing candidate code; the memory-capable replacement supplied the final proof.

Two temporary-harness issues were corrected without changing product code: a retired cron.maxConcurrentRuns option, and a counter comparison made before replacing the trigger definition (the owner correctly resets that counter). The three passing registry phases were retained; the fired-turn observation was rerun and passed. After the full build gate passed, pnpm build qaRuntime supplied runtime artifacts for the remaining harness-only work. No failing product check was hidden by a retry.

Review findings and exact change size

The latest ClawSweeper review had no production-code finding. Its missing real restart/hot-reload evidence is supplied above. Both low-value plumbing assertions were removed and replaced with the preparation regression and production-only negative control. No human review findings were outstanding.

Against main's PR merge base: production +25 / -26 (net -1); tests +86 / -4 (net +82); docs +0 / -0. Existing schedule documentation already specifies the behavior restored by this fix. No changelog edits.

86   4  src/cron/trigger-script.preparation.test.ts
 9   3  src/gateway/scheduled-run-gateway-context.ts
 8  20  src/gateway/server-cron-lazy.ts
 6   3  src/gateway/server-cron.ts
 1   0  src/gateway/server-lifecycle.ts
 1   0  src/gateway/server-reload-hot.ts

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 11:12 AM ET / 15:12 UTC (Revision 5).

ClawSweeper review

What this changes

The branch lets scheduled condition checks reuse their owning Gateway’s current plugin registry through startup, lazy construction, and cron hot reload.

Example: A scheduled condition first runs after a Gateway restart with 31 plugins.

  • Before: The recorded baseline registers all 31 plugins again, times out after 35,585 ms, and delays Gateway liveness.
  • After: The recorded fixed run completes in 306 ms with no additional plugin registrations or health timeouts.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-level repair with relevant before/after Gateway proof, a meaningful negative-control regression, successful exact-head CI, and no open findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Exact-head copied runtime observations exercise naturally scheduled conditions through a real isolated Gateway after restart, cron hot reload, and plugin generation replacement, showing no duplicate registrations or health timeouts and a successful condition-fired turn. This resolves the previous proof blocker; the mock provider does not bypass the changed scheduling or plugin-preparation path. No persisted data contract changes require migration.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The first scheduled condition after restart can time out and stall the Gateway while plugins already loaded at startup are registered again.
Reason: This restores existing scheduled-condition behavior with a narrow owner handoff. Recorded area-owner cleanup and real Gateway proof support the direction without introducing a new product contract.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary and is ready from this review: current main lacks the registry handoff, the earlier ownership findings are resolved, and the new real Gateway evidence satisfies the outstanding proof requirement.

Priority: P1
Reviewed head: c36968226bded0675e8ef07b5adaae9dc4781b31

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway runs scheduled jobs and evaluates their conditions before starting a payload. Plugin preparation supplies the tools these conditions can use; this change carries the Gateway’s existing plugin resources into detached scheduling work.

flowchart TD
  A[Gateway startup or cron reload] --> B[Live plugin registry owner]
  A --> C[Scheduled condition becomes due]
  C --> D[Detached scheduled execution]
  B --> D
  D --> E[Check registry compatibility]
  E --> F[Prepare condition tools]
  F --> G[Persist condition result]
  G --> H[Run payload when condition fires]
Loading

Technical review

Best possible solution:

Keep plugin reuse in the existing scheduled-execution owner and retain the established compatibility, generation, and tool-policy checks.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main source exposes the missing registry scope, and the supplied real Gateway baseline reproduces duplicate registration, condition timeout, and liveness delay after restart. This read-only review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: supplying the live registry at the scheduled owner repairs the missing handoff through the existing borrowing path without increasing deadlines, adding a cache, or changing operator settings.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ea7cc1066568.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 1.

Security

None.

Evidence

What I checked:

  • Verified introduced patch: The pinned introduced diff supplies a per-run registry resolver, threads it through both Gateway startup and cron replacement, and reuses the cron constructor contract in the lazy adapter. (src/gateway/scheduled-run-gateway-context.ts:53, c36968226bde)
  • Still necessary on current main: Fetched main still constructs scheduled execution without a plugin-registry resolver. The related merged context, preparation, and spawn-broker fixes establish supporting contracts but do not supply this missing handoff. (src/gateway/scheduled-run-gateway-context.ts:51, ea7cc1066568)
  • Existing borrowing and isolation contract: Preparation resolves the lending registry through its Gateway owner and checks workspace, activation inputs, metadata, and runtime plugin membership before reuse. The patch uses this existing path and retains request isolation, caller clearing, and context lifecycle fencing. (src/agents/prepared-model-runtime.inbound-registry.ts:61, c36968226bde)
  • Real Gateway proof resolves prior blocker: The complete supplied PR body, captured with sourceRevision dcb45f9db5d151277cf3918ab32e272bf0c53b570074906a16e14cc2c53a05b1, records exact-head runs in secretless isolation using a real Gateway and naturally scheduled conditions. Restart completed in 306 ms, cron hot reload in 201 ms, and generation replacement in 167 ms, each with zero duplicate registrations and no health timeout. A condition-fired turn persisted one successful run with REGISTRY_OK. Synthetic registration CPU costs expose duplicate loading; they are not presented as a benchmark of the reporter’s fleet. (c36968226bde)
  • Meaningful regression and negative control: The changed test loads real plugin registrations, executes the probe through the tool dispatcher, and checks generation replacement for existing and rebuilt preparation runtimes. The body records a production-only reversal failing because discovery and tool-discovery registrations recur; the fixed regression took 879 ms. No stored format, schema, configuration default, or migration changes are introduced. (src/cron/trigger-script.preparation.test.ts:145, c36968226bde)
  • Exact-head CI: GitHub confirms https://github.com/openclaw/openclaw/actions/runs/37790171051 completed successfully for the exact reviewed head. The body also records the required full build and focused production/test type checks. (c36968226bde)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Marvinthebored: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source -1, Tests +82. Total +81 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 25 26 -1
Tests 1 86 4 +82
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 111 30 +81

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166756
Summary: This PR is the candidate repair for the linked first-condition registry-loading defect; the older merged context and preparation fixes are supporting history.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported and baseline-observed first scheduled evaluation can exhaust its budget and stall Gateway liveness and channel workflows after restart.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-08T05:52:09.843Z sha bfcc1ef :: needs real behavior proof before merge. :: [P2] Resolve the registry from the scheduler's owning Gateway
  • reviewed 2026-10-08T06:23:31.570Z sha 3c7e7ed :: needs real behavior proof before merge. :: [P2] Preserve the registry resolver when hot reload rebuilds cron
  • reviewed 2026-10-08T08:04:37.838Z sha b4b095b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T14:17:48.052Z sha c369682 :: needs real behavior proof before merge. :: none

@67-luck

67-luck commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Oct 8, 2026
@67-luck

67-luck commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Keep the live registry handoff at the scheduled owner, without recovering
ambient request scope. Reuse the cron constructor contract in the lazy adapter
and replace plumbing assertions with a preparation and generation regression.

Original fix by @67-luck for openclaw#166756; maintainer cleanup and proof coverage.
Co-authored-by: wanghao <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
@steipete
steipete merged commit 3e16525 into openclaw:main Oct 8, 2026
143 checks passed
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…law#166991)

* fix(cron): preserve Gateway plugin registry for scheduled runs

* fix(cron): bind registry from Gateway scheduler owner

* fix(cron): retain Gateway registry binding across hot reload

* fix(cron): prepare scheduled conditions with their Gateway plugins

Keep the live registry handoff at the scheduled owner, without recovering
ambient request scope. Reuse the cron constructor contract in the lazy adapter
and replace plumbing assertions with a preparation and generation regression.

Original fix by @67-luck for openclaw#166756; maintainer cleanup and proof coverage.

---------

Co-authored-by: Peter Steinberger <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 11, 2026
* fix(cron): preserve Gateway plugin registry for scheduled runs

* fix(cron): bind registry from Gateway scheduler owner

* fix(cron): retain Gateway registry binding across hot reload

* fix(cron): prepare scheduled conditions with their Gateway plugins

Keep the live registry handoff at the scheduled owner, without recovering
ambient request scope. Reuse the cron constructor contract in the lazy adapter
and replace plumbing assertions with a preparation and generation regression.

Original fix by @67-luck for #166756; maintainer cleanup and proof coverage.

---------

Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit 3e16525)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
…law#166991)

* fix(cron): preserve Gateway plugin registry for scheduled runs

* fix(cron): bind registry from Gateway scheduler owner

* fix(cron): retain Gateway registry binding across hot reload

* fix(cron): prepare scheduled conditions with their Gateway plugins

Keep the live registry handoff at the scheduled owner, without recovering
ambient request scope. Reuse the cron constructor contract in the lazy adapter
and replace plumbing assertions with a preparation and generation regression.

Original fix by @67-luck for openclaw#166756; maintainer cleanup and proof coverage.

---------

Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit 3e16525)
(cherry picked from commit 360e399)
Co-authored-by: RomneyDa <[email protected]>
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants