← Back to PRs

#8837: fix(cron): guard against undefined job.state in printCronList

by fxd-jason open 2026-02-04 13:37 View on GitHub →
cli stale
Cluster: Cron Job Fixes
Fixes TypeError: Cannot read properties of undefined (reading 'nextRunAtMs') when running 'openclaw cron list' or other cron commands that print job info. The issue occurs when job.state is undefined (shouldn't happen per types, but can occur in edge cases like corrupted state file or incomplete initialization). Changes: - formatStatus: Use optional chaining (?.) when accessing job.state - printCronList: Add guard for job.state?.nextRunAtMs and job.state?.lastRunAtMs - Add explanatory comments for the guards <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Investigated `cron list` crashes caused by unexpected `job.state` being `undefined` (e.g., corrupted state file or partial initialization). The change hardens CLI output helpers by using optional chaining in `formatStatus` and adding guards around `nextRunAtMs` / `lastRunAtMs` in `printCronList`, preventing `TypeError: Cannot read properties of undefined` while still printing usable job information. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk. - Change is narrowly scoped to CLI display logic and only adds defensive optional chaining/guards for unexpected undefined state; it should not affect scheduling or persistence behavior. - No files require special attention <!-- 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