Skip to content

fix(cron): keep read RPCs from blocking the gateway - #133552

Merged
vincentkoc merged 2 commits into
mainfrom
fix/cron-read-maintenance
Aug 30, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/cron-read-maintenance

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #133442

What Problem This Solves

Fixes an issue where cron read RPCs and no-runnable-job timer ticks could enter full synchronous SQLite write maintenance after the scheduler had started. On nontrivial stores, nominal reads and no-op timer wakes could block the gateway event loop.

Why This Change Was Made

Started read operations now load current state without performing durable schedule repair; unstarted reads retain the existing missing-schedule repair. Empty timer ticks enter maintenance only for exact expired repair candidates or enabled timed jobs with no valid next run and no active marker.

Real maintenance sweeps now load cron rows once, decode once, and fetch active receipt job IDs with one indexed query inside the existing transaction. Receipt-owned jobs remain untouched. This does not change schema versions, migrations, retention, configuration, protocol, locking, queues, workers, or timeouts.

The regression was introduced by d3308e2cfd9d8818c5663811e7ea9fd5b66be82f in #122948. That commit is present in beta tags beginning with v2026.8.1-beta.2; stable v2026.7.1-2 predates it.

User Impact

Cron status, list, paginated list, and job-read calls remain observational after scheduler startup. Stable and receipt-owned timer states no longer trigger no-op write sweeps, while missing schedules, stale backoff slots, overdue execution, retries, and auto-disable behavior continue to work.

Accepted Residuals

  • A started read can briefly observe a missing nextRunAtMs; the scheduler-owned timer repairs it within the existing 60-second watchdog cadence. This bounded deferral is intentional so read RPCs remain write-free.
  • Production is net +15 lines. The growth is accepted because it centralizes exact timer admission and batches receipt ownership lookup without weakening stale-future cron repair.

Evidence

Pre-fix regression run:

  • 5 failures, 39 passes.
  • Four started read surfaces over 100 stable jobs performed 4 cron.schedule-unowned transactions; post-fix: 0.
  • Stable-future, event-driven no-next, and active-due timer cases each performed 1 maintenance transaction; post-fix: 0.
  • A 100-job repair performed 100 active-receipt queries; post-fix: 1.

Post-fix:

  • node scripts/run-vitest.mjs src/cron/service.read-ops-nonblocking.test.ts src/cron/service.timer-maintenance.test.ts src/cron/service.overdue-scheduling.test.ts src/cron/service/run-recovery.test.ts src/cron/store/run-receipt-store.test.ts src/cron/service.every-jobs-fire.test.ts src/cron/service/store.test.ts src/cron/service.prevents-duplicate-timers.test.ts src/cron/service.list-past-due.test.ts
    • 9 files, 122 tests passed.
  • Started reads: 0 durable schedule-repair transactions; unstarted missing-next read: exactly 1.
  • Stable future, stream/on-exit, active queued/running, startup catch-up, force-preserved, and receipt-owned due cases: 0 timer maintenance.
  • Valid future cron slots: 0 timer maintenance.
  • ClawSweeper P1 red proof against prior head 41f8e3cc5bba: stale invalid future cron slot performed 0 sweeps and failed the new timer-boundary regression.
  • Amended head: the same stale future slot performs exactly 1 sweep and repairs to the natural next run; future repair remains disabled when no exact stale-future candidate exists.
  • Stale-backoff and already-executed candidate predicates: admitted; ordinary due slots: excluded.
  • Malformed timed missing-next jobs retain bounded retry and auto-disable on the third error.
  • 100-job repair: 1 active-receipt query, 99 unowned jobs repaired, owned row/receipt unchanged, original sort order preserved.
  • Lazy receipt-table creation is covered for single and batched lookups.
  • Pause/resume, reload, overdue execution, and duplicate-service behavior remain green.
  • node scripts/check-changed.mjs: passed.
  • pnpm tsgo:core:test: passed.
  • Dead-export, max-lines, database-first, native schema, import-cycle, auth, webhook, formatting, and lint guards: passed.
  • pnpm check: all preflights plus core/UI production typecheck passed; extension typecheck was not usable in this linked worktree because its mandated shared install provides @grammyjs/[email protected] while this commit's lockfile requires 5.0.0. Exact-head CI will run with a clean dependency install.
  • Final mandatory Sol/high autoreview after the ClawSweeper repair: scoped clean, no actionable findings; correctness 0.97.
  • Separate read-only independent review: clean; no correctness or scope regressions.
  • Codebase-memory graph: blocked by an active/unverified generation and left untouched; exact source and raw-parent history were inspected instead.

LOC:

  • Production: +89 / -74, net +15.
  • Tests: +409 / -20, net +389.

The production growth is the shared timer-admission predicates and batched active-receipt lookup needed to eliminate repeated write sweeps and per-row receipt queries without losing stale-future cron repair.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@vincentkoc vincentkoc self-assigned this Aug 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Aug 30, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 30, 2026 21:17
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 6:29 PM ET / 22:29 UTC.

ClawSweeper review

What this changes

The PR makes started cron reads observational, runs timer maintenance only for actual repair candidates, and batches active receipt lookup during real cron maintenance.

Regression provenance

Possible regression — probable (reviewed change; failure trace; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: current main still routes started cron reads through synchronous maintenance, and this protected maintainer PR supplies a focused, source-backed repair with no discrete blocking defect found.

Priority: P1
Reviewed head: 7dd1929258edb61f8b3e02e44d5bcc3da412d725

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with substantial targeted coverage and no identified source-level regression.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored internal scheduler repair is outside the external-contributor proof gate; the supplied targeted terminal test evidence remains useful supplemental validation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored internal scheduler repair is outside the external-contributor proof gate; the supplied targeted terminal test evidence remains useful supplemental validation.
Evidence reviewed 6 items Current-main read path: At the verified PR base/current main, every read load continues into recomputeUnownedCronSchedules, which opens the cron.schedule-unowned write transaction.
Introduced owner-boundary repair: The branch returns after loading when the scheduler has started, preserving the existing unstarted-service repair path.
Timer preserves necessary repair: The timer now opens maintenance only when a job needs it and explicitly retains stale-future cron repair.
Findings None None.
Security None None.

How this fits together

Gateway cron RPCs read scheduled-job state while the scheduler timer owns time-based repair and execution. SQLite run receipts identify active jobs so recovery and maintenance do not alter work owned by another scheduler.

flowchart LR
  RPC[Gateway cron reads] --> Read[Load cron state]
  Timer[Scheduler timer] --> Gate[Maintenance admission]
  Read --> Reply[Status and job results]
  Gate -->|repair candidate| SQLite[SQLite cron and receipt rows]
  Gate -->|no candidate| Recheck[Next scheduler wake]
  SQLite --> Runs[Scheduled agent execution]
Loading

Before merge

  • Complete next step (P2) - This protected maintainer PR has no actionable repair finding; normal exact-head CI and maintainer merge handling remain.
Agent review details

Security

None.

PR surface

Source +15, Tests +389. Total +404 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 89 74 +15
Tests 5 409 20 +389
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 498 94 +404

Review metrics

Metric Value Why it matters
Production versus tests production +89/-74 (net +15); tests +409/-20 (net +389) The small production increase centralizes maintenance admission and receipt batching, while the tests cover the preserved scheduling boundary.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #133442
Summary: This PR is the concrete candidate fix for the linked cron read-RPC and empty-timer maintenance regression.

Members:

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

Technical review

Best possible solution:

Land the single scheduler-owned maintenance flow while retaining the unstarted repair and the exact overdue, retry, active-receipt, stale-future, and invalid-schedule cases.

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

Yes—current main’s read operations call ensureLoadedForRead(), which invokes the synchronous maintenance transaction; the added tests instrument that same transaction label across the public read surface.

Is this the best way to solve the issue?

Yes. Moving repair responsibility to the scheduler after startup removes write work from observational RPCs without dropping the timer’s required recovery cases.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7504a3b3c453.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: The PR addresses normal cron reads and idle timer wakes that can synchronously delay gateway traffic.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored internal scheduler repair is outside the external-contributor proof gate; the supplied targeted terminal test evidence remains useful supplemental validation.

Evidence

What I checked:

Likely related people:

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

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 (3 earlier review cycles)
  • reviewed 2026-08-30T21:21:54.374Z sha 41f8e3cc5bba9d8ea63edfab3aae4416d9c83f04 :: found issues before merge. :: [P1] Preserve stale future-slot repair on empty timer ticks
  • reviewed 2026-08-30T21:52:06.082Z sha 5c22988 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T22:06:24.174Z sha 5c22988 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the fix/cron-read-maintenance branch from 41f8e3c to 5c22988 Compare August 30, 2026 21:45
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
* origin/main: (55 commits)
  test: include v2026.8.1 release navigation (#133581)
  fix: stop cloud work before unrelated provider inspection finishes (#133476)
  fix(e2e): keep delete fixture target-compatible (#133526)
  fix(release): detect optional target E2E capability (#133525)
  fix(package): publish readable dist inventory (#133549)
  docs: add complete v2026.8.1 maintainer change index (#133585)
  fix(browser): preserve contextless worker and iframe sessions (#133571)
  fix(voice): discover configured provider candidates (#133507)
  refactor(ui): simplify chat rendering and lifecycle state (#133567)
  test: reduce maturity fixture cleanup time (#133566)
  improve: speed up legacy imports and transcript replacement (#133546)
  docs: add draft v2026.8.1 release notes (#133557)
  test: guard multi-project Vitest cache ownership (#133554)
  fix(memory): clarify default agent scope in command help (#133560)
  fix(clawdock): keep credentials out of diagnostic output (#133547)
  refactor(ui): avoid redundant presence work in avatar lists (#133548)
  fix(agents): recognize internal requester completion replies (#133543)
  fix: prevent duplicate queued user messages in chat clients (#133542)
  chore(ui): refresh control ui locales (#133544)
  fix(beam): restart delivery when the receiver changes (#133533)
  ...
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 30, 2026
@vincentkoc
vincentkoc merged commit ca90c24 into main Aug 30, 2026
241 checks passed
@vincentkoc
vincentkoc deleted the fix/cron-read-maintenance branch August 30, 2026 22:38
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit to shojikumaru/openclaw that referenced this pull request Aug 30, 2026
…cked-delivery

* origin/main:
  fix(ui): wait for restored draft before clearing (openclaw#133575)
  fix(deps): update fast-uri security patches (openclaw#133572)
  test: reduce workflow sanity fixture cleanup time (openclaw#133588)
  fix(media): normalize detected Matroska MIME (openclaw#133383)
  refactor(docker): retire ClawDock shell helpers (openclaw#133594)
  perf(browser): reuse snapshot refs and screenshot metadata (openclaw#133598)
  perf: load web chat history in larger, faster batches (openclaw#133565)
  fix(plugins): keep bundled plugins bundled when selected by plugins.load.paths (openclaw#133584)
  test: isolate shared /tmp session-store paths in runner and health suites (openclaw#133568)
  fix(cron): avoid no-op schedule repair writes (openclaw#133552)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L 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.

[Bug]: cron read RPCs perform full synchronous write maintenance and starve the gateway event loop

1 participant