Scheduler: one invalid persisted cron entry kills the whole UI state snapshot and aborts every tick
Summary
An invalid cron field persisted in usr/scheduler/tasks.json (e.g. day: "100") causes two independent failures, and neither path has any error isolation.
- The UI state snapshot dies - the sidebar chat list never arrives, so every chat appears to have vanished even though all
chat.jsonfiles are intact.api/poll.py->build_snapshot_from_request()->scheduler.serialize_task()->task.get_next_run()->CronTab(...)raisesValueError, and nothing on that path catches it. One bad task destroys the entire snapshot payload. - Every scheduler tick aborts -
TaskScheduler.tick()->get_due_tasks(), wheretask.check_schedule()is evaluated inside a list comprehension. The first invalid task raises, so no other due tasks start for that minute.
Observed in a live Docker deployment: ~144 tracebacks/hour, empty sidebar, and all scheduled tasks silently not running.
Reproduction (verified on main)
from helpers.task_scheduler import TaskSchedule, ScheduledTask, serialize_task
s = TaskSchedule(minute='*', hour='*', day='100', month='*', weekday='*', timezone='America/Chicago')
t = ScheduledTask.create(name='broken', system_prompt='x', prompt='x', schedule=s)
serialize_task(t)
task created OK -> * * 100 * *
serialize_task RAISES -> ValueError : item value 100 out of range [1, 31]
check_schedule RAISES -> ValueError : item value 100 out of range [1, 31]
Note that day: "" is not a valid remedy - it yields * * * * and raises ValueError: improper number of cron entries specified; got 4 need 5 to 7. The neutral value is "*".
Root cause
TaskSchedule (helpers/task_scheduler.py:91) is six plain str fields with no cron validation, and parse_task_schedule() only wraps Pydantic construction. Any string is therefore accepted and persisted. Validation is deferred to CronTab(...) inside ScheduledTask.check_schedule() and ScheduledTask.get_next_run(), both of which run on read paths that have no error isolation.
Relationship to existing work
- PR #1990 (
fix/scheduler-cron-validation-20261030) addsCronTab(...)validation toScheduledTask.create()andScheduledTask.update(schedule=...). That correctly blocks newly saved invalid schedules, but it does nothing for installations that already contain one. - #1264 reported this same crash class. It was closed by the 90-day inactivity bot, not by a fix, and both code paths are still unguarded on
maintoday.
Requested follow-up
- Isolate the read path.
serialize_task()insidebuild_snapshot_from_request()must not be able to kill the whole snapshot. Emitnext_run=Noneplus an error marker for the offending task instead of propagating. - Isolate the tick.
get_due_tasks()should evaluate each task individually:
out = []
for task in self.tasks:
if task.state != TaskState.IDLE:
continue
try:
if task.check_schedule():
out.append(task)
except Exception as e:
PrintStyle.error(f"Task '{task.name}' has an invalid schedule: {e}")
return out
- Surface the failure. Park the offending task in
TaskState.ERROR(or quarantine it) so it becomes visible in the scheduler UI instead of silently blanking the sidebar.
With (1) and (2), an already-corrupt tasks.json degrades to one broken task rather than a broken UI, and PR #1990 prevents new corruption going forward.
Environment
Agent Zero v2.13 (e3051fb5), Docker, Python 3.12, crontab package. 15 tasks total, 2 invalid.