Skip to content

feat(cron): usercron hot-reload via external cronjob.toml#629

Merged
thepagent merged 10 commits intoopenabdev:mainfrom
chaodu-agent:feat/usercron-hot-reload
Apr 29, 2026
Merged

feat(cron): usercron hot-reload via external cronjob.toml#629
thepagent merged 10 commits intoopenabdev:mainfrom
chaodu-agent:feat/usercron-hot-reload

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

@chaodu-agent chaodu-agent commented Apr 28, 2026

Summary

Add usercron support and consolidate all cron config under [cron].

BREAKING CHANGE: [[cronjobs]][[cron.jobs]]

Closes #628

Flow

                         config.toml                        $HOME/cronjob.toml
                    ┌──────────────────┐                 ┌──────────────────────┐
                    │ [cron]           │                 │ [[jobs]]             │
                    │ usercron_enabled │                 │ schedule = "* * * *" │
                    │   = true         │                 │ channel  = "123..."  │
                    │ usercron_path    │                 │ message  = "ping"    │
                    │   = "cronjob.toml│"                └──────────┬───────────┘
                    │                  │                            │
                    │ [[cron.jobs]]    │                   Agent writes here
                    │ (baseline jobs)  │                   anytime (mobile/CLI)
                    └────────┬─────────┘                           │
                             │                                     │
                    ┌────────▼─────────┐                           │
                    │  OAB Scheduler   │◄──────────────────────────┘
                    │  (ticks every    │   check mtime every tick
                    │   1 minute)      │   reload if changed
                    └────────┬─────────┘
                             │
              ┌──────────────┼──────────────┐
              │              │              │
     baseline jobs    usercron jobs    should_fire()?
     (immutable)      (hot-reload)         │
              │              │         ┌────▼────┐
              └──────────────┘    no── │ match?  │ ──yes──► fire_cronjob()
                                      └─────────┘          → send message
                                                            → create thread
                                                            → agent processes

Config

[cron]
usercron_enabled = true
usercron_path = "cronjob.toml"   # resolves to $HOME/cronjob.toml

[[cron.jobs]]
schedule = "0 9 * * 1-5"
channel = "123456789"
message = "daily summary"

External cronjob.toml uses [[jobs]] (same fields).

Changes

  • config.rs: New CronConfig struct with usercron_enabled, usercron_path, jobs; [[cronjobs]][[cron.jobs]]
  • cron.rs: load_usercron_file(), parse_job_list(), mtime-based hot-reload; external file uses [[jobs]]
  • main.rs: Gate usercron on [cron].usercron_enabled, resolve relative paths from $HOME
  • config.toml.example: All cron config under [cron]
  • docs/cronjob.md: Full rewrite with ASCII flow diagram
  • docs/config-reference.md: Consolidated [cron] section

Testing

  • 5 new unit tests for usercron file loading/validation
  • All 166 existing tests pass

Discord Discussion: https://discord.com/channels/1491295327620169908/1491365150664560881/1498838230018298026

Add usercron_path config option that points to an external cronjob.toml.
The scheduler checks the file mtime every tick and reloads when modified,
enabling agents to manage schedules at runtime without redeployment.

- config.rs: add usercron_path field to Config
- cron.rs: add load_usercron_file(), parse_job_list(), mtime-based reload
- main.rs: pass usercron_path and configured_platforms to scheduler
- 5 new tests for usercron loading/validation
- docs: add Usercron section to cronjob.md

Closes openabdev#628
@chaodu-agent chaodu-agent requested a review from thepagent as a code owner April 28, 2026 23:12
@github-actions github-actions Bot added pending-screening PR awaiting automated screening closing-soon PR missing Discord Discussion URL — will auto-close in 3 days labels Apr 28, 2026
- Add design decision comment for same-tick reload collision in cron.rs
- Fix docs K8s section: usercron_path is a config.toml field, not env var
@chaodu-agent
Copy link
Copy Markdown
Collaborator Author

Relative paths like 'cronjob.toml' now resolve to $HOME/cronjob.toml.
Absolute paths are used as-is. Updated docs accordingly.
Add usercron_enabled flag (default: false). Usercron hot-reload only
activates when explicitly enabled in config.toml.
@github-actions github-actions Bot removed the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Apr 28, 2026
…]] top-level

[cron] section holds usercron_enabled and usercron_path.
[[cronjobs]] stays as a top-level array for baseline jobs (no breaking change).

Config layout:
  [cron]
  usercron_enabled = true
  usercron_path = "cronjob.toml"

  [[cronjobs]]
  schedule = "0 9 * * 1-5"
  ...
BREAKING CHANGE: [[cronjobs]] is now [[cron.jobs]] under the [cron] section.
usercron settings also live under [cron].

Config layout:
  [cron]
  usercron_enabled = true
  usercron_path = "cronjob.toml"

  [[cron.jobs]]
  schedule = "0 9 * * 1-5"
  channel = "123"
  message = "hello"

External cronjob.toml uses [[jobs]] (same fields).
…empty file

- validate_cronjobs: valid/invalid cron/tz/unknown platform/unconfigured
- file_mtime: detects change after write
- CronConfig: [cron] + [[cron.jobs]] TOML parses correctly, defaults when omitted
- load_usercron: empty file returns empty vec
@thepagent thepagent merged commit 838ef1e into openabdev:main Apr 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-maintainer pending-screening PR awaiting automated screening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: usercron — hot-reload cronjob.toml for agent-managed schedules

2 participants