Skip to content

improve(gateway): load cron only when reload requests it - #143500

Merged
vincentkoc merged 2 commits into
mainfrom
perf/gateway-cron-reload-lazy-20260909
Sep 15, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/gateway-cron-reload-lazy-20260909

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Gateway reload-handler initialization loads cron execution even when no cron restart is requested. Deferring that load also needs to keep canceled or superseded reloads from publishing stale cron state.

User Impact

Reload handlers can initialize without loading cron execution. Cron reloads retain their watcher handoff, candidate environment, and recovery behavior. No configuration, schema, protocol, dependency, migration, or operator action changes. No measured latency or memory improvement is claimed.

Why This Change Was Made

Load the builder inside the existing cron-restart branch. Recheck the live publication and reload generation after loading, after watcher preparation, and immediately before synchronous publication. Keep the existing invoker check before plugin publication and state selection.

An already-committed replacement still drains its predecessor even when newer work supersedes it. Replacement watcher adoption and startup remain current-owner-only.

Evidence

Current qualification date: September 15, 2026. Main integration base: 76aa544c38c4746936c1aafa5a79e8cb9ea6bc8d. Signed candidate head: 7d6aad10267b7ce451e35cd72b8fb2a3902aff20; integrated main without rewriting the existing PR history.

  • Both P7 suites used identical final test bytes: 13 intended failures against unchanged main production, then 13 passes against the candidate, no skips.
  • The complete reload-handler, hot-reload status, managed-secrets, lazy-cron, and reconciliation suites passed: 308 cases, no skips. These include real supervised watcher continuity and committed-predecessor cleanup.
  • Formatting, production typechecking, and remaining canonical changed-file guards passed. A test mock's inferred Set<unknown> was corrected with its existing typed callback contract; the Gateway test graph then passed.
  • The subsequent full local test-type run is unqualified: its logger failed with ENOSPC and no terminal compiler result was retained. Its processes are closed. Exact-head hosted type gates passed.
  • Exact-head CI completed successfully: 121 successful jobs, 17 skipped, no failures. https://github.com/openclaw/openclaw/actions/runs/34940657636
  • Full normal pnpm build passed on Linux x64, Node v24.19.0, using configured blacksmith-testbox. The complete source tree was verified as d872b48c96c3587b984751218c406942eb648293, matching the signed candidate.
  • The real isolated Gateway/cron flow passed: accepted config reload without process restart; same owned SQLite store; an on-exit watcher started exactly once and completed across reload; cron disabled/re-enabled; shutdown exited 0 with all owned processes closed.
  • Two independent full-source reviews found no actionable issues, including the unchanged managed-secrets publication owner. The only subsequent fixture edit is a type annotation.

Latest ClawSweeper revision 3 reviewed this exact head on September 15, 2026 at 07:38:54.348 UTC; the durable comment was updated at 07:39:48 UTC: #143500 (comment). No source/security findings. Its two remaining proof items and sole Rank-up move are fulfilled by the complete build and isolated operator results above.

Remote proof: provider blacksmith-testbox, lease tbx_01m2hz2130qf74wz0m19kw02ez, provisioned by https://github.com/openclaw/openclaw/actions/runs/34941277179. Full build finished at 07:45:27 UTC; operator proof finished at 07:48:51 UTC; the normal wrapper closed with exit 0. The workflow provisions the lease; the delegated command result is the proof, not the workflow's eventual cleanup status.

The build stamp is builtAt=1789458250292, carrier 5d9d8b0a769af46893cd4d0872527ad80a76763d. Operator-only retry used normal full-source synchronization, verified the same candidate tree and original successful build record, and required the stamp to remain identical. Its source carrier was 4b81aefd857017d1d7ee4e4197c9073501ff6ee5; no build was fabricated or repeated.

{"build":"PASS","operator":"PASS","sameGatewayProcess":true,"sameCronStore":true,"storeOwned":true,"storage":"sqlite","watcherStarts":1,"completionObserved":true,"disabledAndReenabled":true,"shutdownExitCode":0,"ownedProcessesClosed":true}

Protected autoreview remains BLOCKED/UNRUN: its filename admission guard rejects required src/gateway/server-reload-managed-secrets.ts context before engine execution. No automated clean-review verdict exists, and no scanner, filename, isolation, or helper guard was changed. The maintainer explicitly approved independent complete-source review, fresh ClawSweeper review, and full proportional validation as the substitute for this PR.

Production delta is +16/-1 (net +15), needed for the deferred import's new awaited owner boundary and current-owner checks. Tests add 278 lines. All three changed files remain within the original cron reload owner.

Historical proof, not current-head qualification

The September 9 candidate was ac9dbb0887859e9ee05850dff66e41c2a24b40e3, based on 8642c68b6b9f6ee42fa91641dd8656fcf0a617a9. Earlier scoped results and the original autoreview admission failure remain historical evidence; they are not being counted as current-head build, CI, or operator proof.

The September 15 local source transfer initially failed with ENOSPC before testing. Only its own incomplete pack was removed; a bounded transfer then succeeded. The failure is retained separately from test results.

Two initial Testbox attempts failed local staging/lease-claim writes before remote payload execution. Task-owned RAM staging and narrowly verified task-owned cache recovery allowed the unchanged supported route to proceed. Provider, source verification, ownership guards, and the staging-space minimum were not bypassed.

The first private operator probe reintroduced retired config fields after startup normalization, so the Gateway correctly rejected its invalid reload. All owned processes closed. Only the private probe was corrected to the current schema, rereading canonical startup config/meta and using supported cron.skipMissedJobs as the same-store reload trigger. The second probe passed against the verified unchanged build. Product source and regression tests stayed at the signed candidate throughout.

Defer the cron builder import to the existing restartCron branch and revalidate reload ownership after loading, watcher preparation, and at publication. Preserve candidate inputs and committed predecessor draining.

Validation: 95 unique passes across scoped runs, not a full final-head rerun: 11 before the mechanical fixture correction, one corrected retry, 57 siblings, and 26 selected cases with 252 skipped. Scoped lint and formatting passed.

Protected autoreview remains blocked before capture by its required-context dataset policy. No review verdict or merge qualification; complete-source build and broader checks remain pending.
@clawsweeper

clawsweeper Bot commented Sep 9, 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.

@vincentkoc vincentkoc added the r: too-many-prs-override Maintainer override for the active-PR limit auto-close. label Sep 9, 2026
@vincentkoc vincentkoc self-assigned this Sep 9, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 9, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 3:38 AM ET / 07:38 UTC (Revision 3).

ClawSweeper review

What this changes

Defers loading the Gateway’s cron scheduler until a reload requests a rebuild and rejects canceled or superseded replacements before publication.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful, focused improvement absent from current main. Source review found no actionable defect; the maintainer-authored PR remains open with its acknowledged qualification gaps.

Priority: P3
Reviewed head: 7d6aad10267b7ce451e35cd72b8fb2a3902aff20

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and supported by meaningful cancellation coverage, with no source findings; final qualification remains incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Reported owner/sibling tests support reload behavior, but the separate, acknowledged compiled-build and operator-flow qualification remains pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Reported owner/sibling tests support reload behavior, but the separate, acknowledged compiled-build and operator-flow qualification remains pending.
Evidence reviewed 10 items Verified introduced production change: The pinned base-to-head diff replaces the static cron import with a dynamic import inside restartCron and adds checks after loading, after handoff preparation, and before publication. No configuration, storage format, dependency, or public API changes are introduced.
Current main still needs the change: Fetched main retains the eager buildGatewayCronService import. Its reload-handler file matches the pinned base, so the existing startup lazy proxy has not eliminated this separate eager reload-handler dependency.
Latest release comparison: The release-tag source also retains the static cron builder import. This was read through GitHub after the local release blob could not be retrieved.
Findings None None.
Security None None.

How this fits together

Gateway reload handlers translate configuration changes into runtime updates. Cron rebuilds prepare a replacement scheduler, publish it, transfer eligible watchers, and drain the previous scheduler.

flowchart TD
  A[Configuration change] --> B[Reload plan]
  B --> C{Cron rebuild requested?}
  C -->|No| D[Apply other runtime changes]
  C -->|Yes| E[Load scheduler and prepare replacement]
  E --> F{Reload still current?}
  F -->|No| G[Reject replacement]
  F -->|Yes| H[Publish scheduler and drain predecessor]
Loading

Before merge

  • Resolve merge risk (P1) - Compiled lazy-loading behavior and the integrated Gateway operator flow remain unverified in the captured candidate evidence.
  • Complete next step (P2) - Supply the required successful complete-source pnpm build and finish the isolated Gateway operator qualification already marked pending in the PR body.
Agent review details

Security

None.

PR surface

Source +15, Tests +278. Total +293 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 16 1 +15
Tests 2 278 0 +278
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 294 1 +293

Review metrics

Metric Value Why it matters
Production versus test growth Production net +15 lines; tests +278 lines Production growth supplies ownership checks around the newly awaited import; tests cover the resulting cancellation boundaries.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep cron construction within the existing reload owner, with deferred loading and current-generation checks preserving scheduler and watcher continuity.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep cron construction within the existing reload owner, with deferred loading and current-generation checks preserving scheduler and watcher continuity.

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

Not applicable as a user-facing bug reproduction: current source directly shows the eager import being removed. No runtime execution was performed in this read-only review.

Is this the best way to solve the issue?

Yes. Moving the import into the existing rebuild branch avoids a competing scheduler owner, and the added checks cover the new asynchronous boundary without changing settings or persisted data.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a bounded internal loading improvement without a claimed measured performance gain or demonstrated urgent user failure.
  • 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: The MEMBER-authored PR is exempt from the external-contributor proof gate. Reported owner/sibling tests support reload behavior, but the separate, acknowledged compiled-build and operator-flow qualification remains pending.

Evidence

What I checked:

  • Verified introduced production change: The pinned base-to-head diff replaces the static cron import with a dynamic import inside restartCron and adds checks after loading, after handoff preparation, and before publication. No configuration, storage format, dependency, or public API changes are introduced. (src/gateway/server-reload-hot.ts:134, 7d6aad10267b)
  • Current main still needs the change: Fetched main retains the eager buildGatewayCronService import. Its reload-handler file matches the pinned base, so the existing startup lazy proxy has not eliminated this separate eager reload-handler dependency. (src/gateway/server-reload-hot.ts:25, 7dcdb14e8435)
  • Latest release comparison: The release-tag source also retains the static cron builder import. This was read through GitHub after the local release blob could not be retrieved. (src/gateway/server-reload-hot.ts:19, 3a9d69db306c)
  • Publication and cleanup ordering: The complete reload handler preserves the invoker assertion before plugin publication and state selection. Committed replacements still drain their predecessors even after losing ownership; adoption and startup remain ownership-guarded. The managed publication owner retains its existing secrets activation and rollback contract. (src/gateway/server-reload-hot.ts:273, 7d6aad10267b)
  • Managed publication owner inspected: The unchanged managed-secrets owner forwards current transaction and invoker checks into the hot reload handler, validates before activation, and restores uncommitted publication state on rejection. (src/gateway/server-reload-managed-secrets.ts:397, 7d6aad10267b)
  • Regression coverage: The added tests exercise cold import, requested rebuild, loader failure, and ten cancellation interleavings across loading, handoff, and publication, including mixed plugin/cron supersession. They assert that rejection leaves the previous scheduler running and prevents replacement publication or startup. (src/gateway/server-reload-hot.cron-lazy.test.ts:138, 7d6aad10267b)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record a successful complete-source pnpm build and the already-pending isolated Gateway operator qualification for the reviewed candidate.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-09T23:46:31.411Z sha ac9dbb0 :: blocked before merge. :: none
  • reviewed 2026-09-15T07:18:53.343Z sha 7d6aad1 :: blocked before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review September 15, 2026 07:13
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

The cron reload repair is now integrated with current main at signed head 7d6aad10267b7ce451e35cd72b8fb2a3902aff20. Please review the deferred import and current-owner publication checks, including the mixed plugin/cron supersession regression. The PR body separates current proof from historical evidence and explicitly records the approved substitute for blocked, unrun autoreview. Complete build/operator qualification and exact-head CI are still in progress.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc merged commit f9ccd87 into main Sep 15, 2026
269 of 271 checks passed
@vincentkoc
vincentkoc deleted the perf/gateway-cron-reload-lazy-20260909 branch September 15, 2026 07:53
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

@vincentkoc

Copy link
Copy Markdown
Member Author

Final qualification clarification for f9ccd87:

The squash description retained historical partial-validation notes. Those are not the final qualification for reviewed head 7d6aad10267b7ce451e35cd72b8fb2a3902aff20.

  • Final identical-test-byte reproduction: 13 intentional RED failures, then 13 focused passes; all 308 sibling cases passed, no skips.
  • Exact-head CI completed successfully: https://github.com/openclaw/openclaw/actions/runs/34940657636
  • Complete-source pnpm build passed on Linux Node 24 at September 15, 2026, 07:45:27 UTC.
  • Real isolated Gateway/cron proof passed at 07:48:51 UTC: same process and owned SQLite store, one watcher start/completion, cron disable/re-enable, clean shutdown.
  • Protected autoreview remains BLOCKED/UNRUN. The explicitly approved substitute was independent complete-source review, fresh ClawSweeper, and full proportional validation; no automated clean-review claim is made.

The PR body records the final source/tree/build identities and proof. No source, commit, signature, or native completion receipt was rewritten.

vincentkoc added a commit that referenced this pull request Sep 15, 2026
* commit '0945dabbe487213e95e84a72ad1aae3659e0e000': (115 commits)
  fix: omit automation service aliases from squash coauthors (#148883)
  test: restore services typecheck shard headroom (#148885)
  perf(trajectory): avoid native probes for truncation records (#148870)
  improve(gateway): load cron only when reload requests it (#143500)
  fix: resolve issue #146088 — [Bug]: The most recent Linux AppImage does not ship with the correct versions of libs needed to run (#148174)
  refactor(theme): share nonvirtual ANSI color lookup (#148717)
  perf(gateway): scope exact session row topology reads (#148836)
  improve(memory): reduce vector replacement overhead (#148201)
  fix(i18n): keep HTTP headers out of native translations (#147119)
  refactor(plugins): share source-root display formatting (#148646)
  fix(cron): reject blank script paths before mutations (#148787)
  refactor(config): share audit positional scanning (#148643)
  fix(test): restore infrastructure typecheck shard headroom (#148861)
  fix(release): harden package validation fallbacks (#148729)
  refactor(config): share leaf and descendant unset pruning (#148216)
  test: reuse prepared runtime for pristine preflight (#148858)
  fix(ui): settle global model drafts across agent switches (#148843)
  fix(queue): avoid repeated scans when cancelling backlogs (#148754)
  fix(logging): orphaned \\\\?\\ path markers corrupt redacted Windows diagnostics (#147542)
  refactor(hooks): share optional reply metadata projection (#148641)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…3500)

Defer the cron builder import to the existing restartCron branch and revalidate reload ownership after loading, watcher preparation, and at publication. Preserve candidate inputs and committed predecessor draining.

Validation: 95 unique passes across scoped runs, not a full final-head rerun: 11 before the mechanical fixture correction, one corrected retry, 57 siblings, and 26 selected cases with 252 skipped. Scoped lint and formatting passed.

Protected autoreview remains blocked before capture by its required-context dataset policy. No review verdict or merge qualification; complete-source build and broader checks remain pending.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. r: too-many-prs-override Maintainer override for the active-PR limit auto-close. 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