Skip to content

perf(cron): skip history checks for future jobs - #128048

Merged
steipete merged 1 commit into
mainfrom
codex/perf-scheduler-due-current
Aug 22, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-scheduler-due-current

Conversation

@steipete

@steipete steipete commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves a problem where ordinary Cron scheduler ticks normalized run history for every enabled, inactive job even when its finite nextRunAtMs already proved that the job was strictly in the future. Large resident job stores paid this avoidable work on every no-due or small-due scan.

Why This Change Was Made

The runnable-job owner now checks the already-persisted next wake before run-history normalization, but only for ordinary ticks. Startup missed-run recovery retains the existing history-aware path, and due/error paths reuse the status already resolved by the owner.

This change was AI-assisted. I reviewed the complete owner, caller, recovery, backoff, and one-shot paths and understand the resulting behavior.

User Impact

Operators with large Cron job stores should see lower scheduler CPU and due-selection latency when most jobs are scheduled in the future. Runnable selection, ordering, startup catch-up, retries, persistence, and delivery behavior are unchanged.

Evidence

  • Exact head: dfdbbd3339cb38e7c529cb1a03628cd363d2908c; parent/current-main baseline: b7cafbe7e82686b14c0f7c8e7af83194fd05ad42.
  • Deterministic current-main red/green probe: three ordinary future jobs performed 7 irrelevant history reads before the repair and 0 after it, while selecting no jobs in both cases. The getter-count probe was removed before commit under test-audit because it is implementation-coupled rather than a persisted-data behavior contract.
  • Independent base/head differential: 22,680 combinations covering missing/zero/NaN/past/exact/future/infinite next wakes, every/at/cron schedules, canonical and legacy statuses, enabled/active states, skip IDs, one-shot handling, and startup missed-run options. Results, returned identity, and ordering were exact across 4,932,085 bytes at SHA-256 75defa96e5f60caaebc78515088b78b4c05df29a1856f3afc3269c9d251806be.
  • Current-base owner benchmark: 100,000 future jobs, 10 scans/sample × 9 alternating samples after warmup. Median fell from 203.192 ms to 145.023 ms (28.63% lower) with identical zero-selection checksums; instrumented history reads fell from 2,500 to 0 for 1,000 representative jobs. This is owner-stage evidence, not an end-to-end throughput claim.
  • Focused owner/recovery/backoff proof: 5 files / 97 tests passed after the final rebase.
  • Full Cron suite: 183 files / 2,348 tests passed.
  • node scripts/check-changed.mjs -- src/cron/service/timer-runnable.ts: passed formatting, typechecks, lint, dead exports, guards, and import-cycle checks.
  • pnpm build: passed all core, package, plugin, SDK, postbuild, and Control UI phases.
  • Exact committed-head Codex Sol/high autoreview: clean, no accepted/actionable P0/P1 findings; TruffleHog preflight clean.
  • Exact-head CI run 32602232212: passed at dfdbbd3339cb38e7c529cb1a03628cd363d2908c.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128048: passed in hosted_exact_or_recent_parent mode without changing the PR head.
  • ClawSweeper exact-head review run 32602306206: keep_open, patch correct at 0.93 confidence, no review/security findings, and no rank-up moves. Its terminal proof used the nonexistent path src/cron/service/restart-catchup.test.ts; rerunning the repository-native command against the actual exact-head file, node scripts/run-vitest.mjs src/cron/service.restart-catchup.test.ts, passed 1 file / 26 tests.
  • Live GitHub overlap search found no open PR for collectRunnableJobs, due selection, or this performance cause. Open feat(cron): shell precheck gate to skip LLM when no work #112375 adds a separate pre-execution shell gate and does not touch timer-runnable.ts.

@clawsweeper

clawsweeper Bot commented Aug 22, 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: XS maintainer Maintainer-authored PR labels Aug 22, 2026
@steipete
steipete marked this pull request as ready for review August 22, 2026 22:22
@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 Aug 22, 2026
@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

This PR skips Cron run-history status lookup on ordinary scheduler scans when a job has a finite next wake strictly in the future.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this maintainer-authored PR open for ordinary exact-head CI and merge review. The early return is at the runnable-job owner, preserves startup missed-run recovery, and current main still has the pre-optimization path.

Priority: P3
Reviewed head: dfdbbd3339cb38e7c529cb1a03628cd363d2908c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, owner-level optimization with no concrete correctness or security finding after ordinary, recovery, and revalidation paths were traced.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository context identifies this as a maintainer-authored PR; the supplied benchmark and differential evidence is supplemental to the source review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository context identifies this as a maintainer-authored PR; the supplied benchmark and differential evidence is supplemental to the source review.
Evidence reviewed 7 items Current-main behavior: Current main still resolves run status before checking the next wake, so it retains the work this PR removes.
Owner-level patch: The PR checks a finite future wake only when missed-run recovery is not enabled, then reuses the one resolved status for backoff.
Caller and recovery boundary: Ordinary scheduling calls the filter without recovery options, while startup catch-up explicitly enables missed-run recovery and carries that option into reservation revalidation.
Findings None None.
Security None None.

Live Verification

Command: pnpm exec vitest run src/cron/service/restart-catchup.test.ts

Result: FAIL (failed) — step 1 run pnpm exec vitest run src/cron/service/restart-catchup.test.ts: terminal command did not produce output within 20 seconds: "pnpm exec vitest run src/cron/service/restart-catchup.test.ts"

pnpm exec vitest run src/cron/service/restart-catchup.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128048-NEMXk7/target$ pnpm exec vitest run src/cron/service/restart-catchup.test.ts
pnpm exec vitest run src/cron/service/restart-catchup.test.ts
















































Assertions:

  • FAIL expect_output: Test Files

How this fits together

Cron loads persisted jobs, filters runnable jobs, and dispatches due work. This change short-circuits ordinary no-due scans before status and backoff logic while leaving startup recovery on its history-aware path.

flowchart LR
  A[Persisted Cron jobs] --> B[Timer scan]
  B --> C[Runnable-job filter]
  C --> D{Future finite wake on ordinary tick?}
  D -->|Yes| E[Skip history lookup]
  D -->|No or startup recovery| F[Status and backoff checks]
  F --> G[Due-job selection]
  G --> H[Job execution]
Loading

Before merge

  • Complete next step (P2) - This maintainer-owned PR has no concrete repair finding; await ordinary exact-head CI and merge review.
Agent review details

Security

None.

PR surface

Source +9. Total +9 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 13 4 +9
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 13 4 +9

Review metrics

Metric Value Why it matters
Production versus test LOC production +9/-4, tests +0/-0 The small production increase implements the necessary early no-due exit; no test-only seam or implementation-coupled counter test was added.

Technical review

Best possible solution:

Land the owner-level future-wake short circuit once the remaining exact-head checks and normal merge gates are satisfied.

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

Yes, at source level: ordinary ticks resolve status before discovering a finite future wake, while startup recovery explicitly takes the separate history-aware option. The PR body also supplies a differential benchmark, though this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The guard belongs in the runnable-job owner before the pure status coalescer; moving it into startup recovery would risk suppressing the missed-slot behavior that recovery deliberately enables.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a narrow scheduler-performance improvement with no demonstrated correctness or security regression.
  • 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: Repository context identifies this as a maintainer-authored PR; the supplied benchmark and differential evidence is supplemental to the source review.

Label justifications:

  • P3: This is a narrow scheduler-performance improvement with no demonstrated correctness or security regression.
  • 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: Repository context identifies this as a maintainer-authored PR; the supplied benchmark and differential evidence is supplemental to the source review.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the current Cron lifecycle, missed-slot, and timestamp-repair history around this runnable-job owner. (role: recent Cron lifecycle contributor; confidence: high; commits: 06776e707b44, d4c6ed4bd9f5, 8e1c238c1c25; files: src/cron/service/timer-runnable.ts, src/cron/service/timer-catchup.ts, src/cron/service/timer-scheduler.ts)
  • Riive: Authored the schedule-edit missed-slot repair that touches the same runnable and catch-up boundaries. (role: adjacent Cron scheduling contributor; confidence: medium; commits: 82af1bf7d403; files: src/cron/service/timer-runnable.ts, src/cron/service/timer-catchup.ts, src/cron/service/jobs-scheduling.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.

Copy link
Copy Markdown
Contributor Author

Land-ready verification

  • Exact PR head: dfdbbd3339cb38e7c529cb1a03628cd363d2908c.
  • Exact-head CI: run 32602232212 completed successfully at that SHA.
  • Native review artifacts validate with READY FOR /prepare-pr, zero findings, a passing runtime branch sweep, and no silent-drop risk.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128048 passed in hosted_exact_or_recent_parent mode. It preserved the exact head, found no changelog requirement, and verified the remote PR tree against the local prep tree.

Reproduction and semantic proof

  • Current-main red/green probe: three ordinary future jobs performed 7 irrelevant history reads before the repair and 0 after it; both selected no jobs. The temporary accessor-count test was removed under test-audit because it asserted implementation mechanics on persisted plain CronJob data, not a product contract.
  • Independent differential: 22,680 combinations matched exactly across 4,932,085 semantic bytes (SHA-256 75defa96e5f60caaebc78515088b78b4c05df29a1856f3afc3269c9d251806be). This covered finite and non-finite wakes, past/exact/future times, schedule kinds, statuses, active/disabled/skipped jobs, one-shot behavior, backoff, and startup missed-run options.
  • Owner benchmark: 100,000 future jobs, 10 scans/sample × 9 alternating samples; median fell from 203.192091 ms to 145.023208 ms (28.6275%). Instrumented history reads fell from 2,500 to 0 with identical zero-selection results.

Executed checks

  • Focused owner/recovery/backoff suite: 5 files / 97 tests passed.
  • Full Cron suite: 183 files / 2,348 tests passed.
  • node scripts/check-changed.mjs -- src/cron/service/timer-runnable.ts passed.
  • pnpm build passed.
  • Exact committed-head Codex Sol/high autoreview completed after a clean TruffleHog scan with no accepted/actionable P0/P1 finding.

No live Gateway run was needed: this is a deterministic internal due-selection predicate with exact differential, owner/sibling/full-suite, build, and hosted exact-head proof.

ClawSweeper's exact-head review (run 32602306206) found no review or security findings, rated the patch correct at 0.93 confidence, and listed no rank-up moves. Its one generic pre-merge item was to await exact-head CI and maintainer merge review; both are now satisfied by run 32602232212 and the validated native review/prepare artifacts. Its terminal proof command referenced the nonexistent path src/cron/service/restart-catchup.test.ts and timed out without output; the repository-native command against the actual exact-head file, node scripts/run-vitest.mjs src/cron/service.restart-catchup.test.ts, passed 1 file / 26 tests. No ClawSweeper action remains unresolved.

@steipete
steipete merged commit a3c007f into main Aug 22, 2026
302 of 303 checks passed
@steipete
steipete deleted the codex/perf-scheduler-due-current branch August 22, 2026 22:48

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

2 participants