Repository navigation
cron: unify stale-run recovery and preserve manual-run every anchors - #35363
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🔵 Cron jobs can be permanently blocked via non-finite/invalid
|
| Property | Value |
|---|---|
| Severity | Low |
| CWE | CWE-400 |
| Location | src/cron/service/jobs.ts:465-469 |
Description
The scheduler treats any numeric job.state.runningAtMs value as an active run marker. With JSON5-backed persistence (which can represent NaN/Infinity) or a manipulated stored state, an attacker can set runningAtMs to a non-finite or far-future number that is never cleared, causing the job to never become runnable.
In the new maintenance recovery path (recomputeExpired), the job is also considered “running” whenever typeof runningAtMs === "number", so the scheduler will not repair expired nextRunAtMs entries for such jobs.
Impact (availability):
- A job with
runningAtMs: NaN/Infinity(or an extremely large timestamp) is never runnable becauseisRunnableJob/isJobDueshort-circuit ontypeof runningAtMs === "number". - The stuck-marker cleanup (
nowMs - runningAtMs > STUCK_RUN_MS) does not clearNaN/Infinitybecause the subtraction yieldsNaN/-Infinity, making the comparison false. - With a past-due
nextRunAtMs,armTimer()may wake frequently (floored toMIN_REFIRE_GAP_MS), resulting in a persistent scheduler spin and missed executions.
Vulnerable code (new logic relying on typeof):
} else if (
recomputeExpired &&
now >= job.state.nextRunAtMs &&
typeof job.state.runningAtMs !== "number"
) {
// ...
}Recommendation
Treat runningAtMs as a finite timestamp, and proactively clear/ignore invalid values.
- Replace
typeof job.state.runningAtMs !== "number"with a finiteness check:
const runningAt = job.state.runningAtMs;
const isRunning = isFiniteTimestamp(runningAt);
// optionally: treat future timestamps as invalid
const validRunningAt = isRunning && runningAt <= nowMs + 5 * 60_000;
if (recomputeExpired && now >= job.state.nextRunAtMs && !validRunningAt) {
// recovery recompute
}- In
normalizeJobTickState, clear invalidrunningAtMsvalues:
const runningAt = job.state.runningAtMs;
if (!isFiniteTimestamp(runningAt) && runningAt !== undefined) {
job.state.runningAtMs = undefined;
changed = true;
}This prevents crafted state (including JSON5 NaN/Infinity) from permanently blocking execution.
Analyzed PR: #35363 at commit 831feeb
Last updated on: 2026-03-05T04:43:13Z
left a comment
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2144da3a6a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Greptile SummaryThis PR unifies the stale-run recovery contract across maintenance, timer, and manual-run paths in the cron service, and adds string-coercion safety for legacy-persisted Key changes:
Confidence Score: 4/5
Last reviewed commit: 2144da3
|
commented
Mar 5, 2026
|
Addressed follow-up review items and pushed update What was fixed:
Verification rerun:
All unresolved review threads are now resolved. |
7e41584 to
831feeb
Compare
Summary
Describe the problem and fix in 2–5 bullets:
nextRunAtMsand manualeveryrun anchor drift.recomputeExpiredsemantics, preservedeveryschedule anchor on manual force runs (including error-backoff path), and added shared coercion for legacy string-typedeveryMs/anchorMs.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
nextRunAtMsnever execute after gateway restart #34432User-visible / Behavior Changes
openclaw cron run <id> --forceno longer shiftseveryschedule anchor to the manual run time.everyMs/anchorMsstring values are coerced safely, preventing cron schedules from becoming non-runnable due toNaNschedule math.Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
Steps
nextRunAtMsadvancement behavior and anchor preservation via cron suites.Expected
everyanchor cadence.Actual
Evidence
Attach at least one:
Verification commands run locally:
pnpm checkpnpm test -- src/cron/pnpm test:macminiHuman Verification (required)
What you personally verified (not just CI), and how:
everyforce-run anchor preservation, legacy string schedule coercion.runningAtMsclearing, already-executed vs never-executed stale slots, error-backoff path withpreserveSchedule, non-numeric string schedule values.Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
src/cron/service/jobs.ts,src/cron/service/timer.ts,src/cron/service/ops.ts,src/cron/schedule.ts,src/cron/service/store.ts.everyjobs stuck due to invalid coerced schedule values.Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.undefinedand are covered by schedule tests.