Skip to content

fix(foundation): pre-validate cron expressions to prevent runtime panics (#1476)#1533

Open
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
SH20RAJ:fix/1476-cron-scheduler-panic
Open

fix(foundation): pre-validate cron expressions to prevent runtime panics (#1476)#1533
SH20RAJ wants to merge 1 commit intomofa-org:mainfrom
SH20RAJ:fix/1476-cron-scheduler-panic

Conversation

@SH20RAJ
Copy link
Copy Markdown

@SH20RAJ SH20RAJ commented Mar 28, 2026

This PR addresses a critical stability issue where invalid cron expressions could cause background tasks to panic at runtime.

Changes

  • Refactored CronScheduler::add_task to return Result and pre-validate expressions using the cron crate.
  • Replaced .unwrap() with proper error propagation in the scheduler registration phase.
  • Updated internal task spawning to handle validated expressions safely.
  • Added unit tests to verify that invalid cron expressions are caught early.

Verification

  • cargo test -p mofa-foundation --lib scheduler::cron::tests passed.
  • Verified that registering a task with "* * * * * * *" (invalid) now returns an error instead of panicking.

Motivation

Improves production reliability by ensuring that misconfigured periodic tasks fail fast at registration rather than crashing the runtime later. (GSoC 2026: Idea 16 related).

@SH20RAJ
Copy link
Copy Markdown
Author

SH20RAJ commented Mar 28, 2026

Hi! This PR adds pre-validation for cron expressions in the CronScheduler. By failing fast at task registration, we prevent the background runtime from panicking due to malformed schedule strings. This aligns with the 'Framework Hardening' direction in Idea 16. (Fixes #1476)

@SH20RAJ
Copy link
Copy Markdown
Author

SH20RAJ commented Mar 29, 2026

Addressing Issue #1476. This PR ensures that invalid cron expressions are caught early during task registration in CronScheduler, instead of causing background panics at runtime. It refactors add_task to return Result and adds comprehensive validation tests. This improves the overall stability of periodic agent execution (GSoC Idea #16). ⏰

@SH20RAJ
Copy link
Copy Markdown
Author

SH20RAJ commented Mar 30, 2026

All checks are green here as well. I aimed for a minimal reliability fix: validate cron expressions at registration time so misconfigurations fail fast instead of panicking later in the scheduler. If maintainers would rather place that validation at a different boundary, I can update it quickly.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant