zeroclaw/src/cron
Giulio V c47bbcc972
fix(cron): add startup catch-up and drop login shell flag (#3948)
* fix(cron): add startup catch-up and drop login shell flag

Problems:
1. When ZeroClaw started after downtime (late boot, daemon restart),
   overdue jobs were picked up via `due_jobs()` but limited by
   `max_tasks` per poll cycle — with many overdue jobs, catch-up
   could take many cycles.
2. Cron shell jobs used `sh -lc` (login shell), which loads the
   full user profile on every execution — slow and may cause
   unexpected side effects.

Fixes:
- Add `all_overdue_jobs()` store query without `max_tasks` limit
- Add `catch_up_overdue_jobs()` startup phase that runs ALL overdue
  jobs once before entering the normal polling loop
- Extract `build_cron_shell_command()` helper using `sh -c` (non-login)
- Add structured tracing for catch-up progress
- Add tests for all new functions

* feat(cron): make catch-up configurable via API and control panel

Add `catch_up_on_startup` boolean to `[cron]` config (default: true).
When enabled, the scheduler runs all overdue jobs at startup before
entering the normal polling loop. Users can toggle this from:

- The Cron page toggle switch in the control panel
- PATCH /api/cron/settings { "catch_up_on_startup": false }
- The `[cron]` section of the TOML config editor

Also adds GET /api/cron/settings endpoint to read cron subsystem
settings without parsing the full config.

* fix(config): add catch_up_on_startup to CronConfig test constructors

The CI Lint job failed because the `cron_config_serde_roundtrip` test
constructs CronConfig directly and was missing the new field.
2026-03-19 14:10:37 -04:00
..
mod.rs fix(cron): add startup catch-up and drop login shell flag (#3948) 2026-03-19 14:10:37 -04:00
schedule.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
scheduler.rs fix(cron): add startup catch-up and drop login shell flag (#3948) 2026-03-19 14:10:37 -04:00
store.rs fix(cron): add startup catch-up and drop login shell flag (#3948) 2026-03-19 14:10:37 -04:00
types.rs fix: handle double-serialized schedule in cron_add and cron_update (#3860) (#3905) 2026-03-18 15:15:22 -04:00