#7984: fix undefined variable in cron
stale
Cluster:
Cron Job Fixes
Fixes #7935
When createJob() receives input without an explicit enabled value,
it was stored as undefined. The list() function filters by j.enabled,
which excluded these jobs since undefined is falsy.
Default enabled to true using nullish coalescing.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates cron job creation to default `enabled` to `true` when callers omit it (`enabled: input.enabled ?? true`). This aligns job creation with downstream behavior in `ops.list()`/scheduling, which filters on `j.enabled` and previously excluded jobs that had `enabled` stored as `undefined`.
One thing to double-check is migration/normalization of persisted jobs: `ensureLoaded()` currently normalizes name/description/payload but not `enabled`, so previously-saved jobs with missing `enabled` will remain hidden/treated as disabled until explicitly updated.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge and fixes the immediate undefined-enabled creation path.
- Change is a small, well-scoped defaulting behavior (`?? true`) that preserves explicit `false`. Main residual risk is incomplete remediation for already-persisted jobs with missing `enabled`, which may still not appear/run without an additional migration step.
- src/cron/service/jobs.ts (change) and src/cron/service/store.ts (potential normalization/migration gap)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#8701: fix: default enabled to true for cron jobs created via tool API
by maximus-claw · 2026-02-04
84.0%
#8698: fix(cron): default enabled to true for new jobs
by emmick4 · 2026-02-04
83.8%
#9088: fix(cron): ensure nextRunAtMs is computed when enabled is undefined...
by divol89 · 2026-02-04
82.9%
#8837: fix(cron): guard against undefined job.state in printCronList
by fxd-jason · 2026-02-04
78.7%
#18960: fix: don't disable one-shot cron jobs on skipped status
by jwchmodx · 2026-02-17
77.5%
#5428: fix(Cron): prevent one-shot loop on skip
by imshrishk · 2026-01-31
77.5%
#15446: feat(cron): support prefix matching for job IDs
by andrewdamelio · 2026-02-13
77.0%
#12443: fix(cron): don't advance past-due jobs that haven't been executed
by rummangeminicode · 2026-02-09
76.8%
#9393: fix(cron): avoid recomputeNextRuns on forceReload
by matthewpapa07 · 2026-02-05
76.7%
#19372: fix(cron): normalize jobId → id for file-backed jobs
by namabile · 2026-02-17
76.2%