You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to take this on and prepare a fix with regression tests. Thanks for the detailed analysis above; I'll use it as a starting point and preserve the behavior of existing Cron jobs.
@Soulter Could the maintainers pick one of the options below for this issue? I'll follow whichever you choose:
A. Full fix (#10373, already submitted)
Following LIghtJUNction's analysis above, intervals become a separate schedule type, run by APScheduler's IntervalTrigger with a persisted UTC anchor. Every 40 minutes, 60 minutes, or 24 hours becomes a true fixed interval and keeps its phase across restarts; existing jobs keep their original Cron expressions, and regression tests are included. The cost is two nullable columns on the cron_jobs table (with a migration), plus API and WebUI changes. The PR is up to date with the latest master and has no conflicts; as a first-time contribution, its CI needs maintainer approval before it can run.
B. Small frontend-only fix
The WebUI only accepts intervals that divide evenly: minutes must be a factor of 60, hours a factor of 24, and days only 1. 60 minutes becomes hourly, 24 hours becomes daily, and other values show a hint to use a custom Cron expression. The change is small and leaves the database and API untouched, but it cannot provide true fixed intervals such as every 40 minutes.
C. No change for now
Keep the current behavior (already described in the docs).
If you choose B, I'll close #10373 and submit a small PR within a day or two; if you choose C, I'll close #10373 as well. Thanks!
Activity
LIghtJUNction commentedon Oct 4, 2026
我按当前
master@42972e9复核了 WebUI、API service、持久化模型和调度器。issue 的复现成立,而且不能只把59/23改成60/24:当前整条数据模型只表达 Date/Cron,没有表达“固定持续时间间隔”。判断与代码依据
dashboard/src/views/CronJobPage.vue::buildCronExpression()将 interval 强制编码为 crontab 字段步长;validateScheduleFields()却允许任意正整数,所以 40 分钟、60 分钟、24 小时都会通过校验。readScheduleFromJob()和scheduleProductLabel()又把*/N反向解释/展示成“每隔 N”。这不只是调度错误,也会在编辑页和任务卡片上继续向用户承诺错误语义。buildPayload()只提交run_once / cron_expression。后端astrbot/dashboard/services/cron_service.py::create_job()、_merge_active_agent_updates()对非一次性任务强制要求cron_expression。astrbot/core/db/po.py::CronJob没有 interval 类型或锚点字段;astrbot/core/cron/manager.py::_build_trigger()也只构造DateTrigger或CronTrigger。因此仅改前端表达式无法获得固定间隔,也无法在重启后恢复其相位。已确认的原因链是:
interval_value/unit→ 前端转换为五段 Cron → interval 原始语义被丢弃 → DB 只保存 Cron 字符串 →CronTrigger.from_crontab()按日历字段边界触发 → 出现 40/20、59/1、23/1 的交替间隔。修改建议
建议把 interval 作为真正的第三种调度类型,而不是特殊 Cron。最小可执行的数据契约可以是:
同时持久化一个 UTC 的
interval_anchor_at。具体改动边界:CronJob、数据库创建/更新方法以及旧 SQLite 前向迁移中增加 nullableinterval_seconds、interval_anchor_at;二者与cron_expression做互斥校验。API/OpenAPI 类型也同步更新。CronService.create_job()和_merge_active_agent_updates()对 interval 做服务端整数、正数和合理上限校验,不能只信任前端。创建 interval 时固定一次 anchor;仅修改名称、备注、会话或启用状态不应重置 anchor,修改间隔时才按明确规则重置。CronJobManager._build_trigger()引入 APScheduler 的IntervalTrigger,从已持久化的 seconds + anchor 重建。建议定义:anchor + interval,而不是创建后立刻执行;buildCronExpression();readScheduleFromJob()只在后端明确返回 interval 字段时恢复为 interval。*/N自动迁移为 interval。 旧记录只保留转换后的 Cron,无法知道用户原本选的是 interval 还是手写 Cron;应继续按 Cron 执行并在 UI 按自定义 Cron 展示。否则升级会静默改变既有任务的触发时刻。scheduleProductLabel()对旧*/N不再显示“每隔 N”,或至少标明它是“Cron 字段步长”;只有真正的 IntervalTrigger 才使用“每隔 N”文案。修改后的效果
新建的 40 分钟、60 分钟、24 小时间隔任务会保持固定时间差,并能在重启后保持相位;每天/每周/每月和自定义 Cron 的日历语义不变。旧任务不会被错误猜测、自动改义。编辑任务的备注等非时间字段也不会意外推迟下一次执行。
建议验证
*/40 * * * *仍按 Cron 运行且编辑页不冒充固定间隔;tests/unit/test_cron_manager.py、test_cron_service.py增加后端用例,并为CronJobPage.vue的构建、回读和标签增加前端单测。ArcueidMP commentedon Oct 4, 2026
I'd like to take this on and prepare a fix with regression tests. Thanks for the detailed analysis above; I'll use it as a starting point and preserve the behavior of existing Cron jobs.
Please assign this issue to me if possible.
ArcueidMP commentedon Nov 10, 2026
@Soulter Could the maintainers pick one of the options below for this issue? I'll follow whichever you choose:
A. Full fix (#10373, already submitted)
Following LIghtJUNction's analysis above, intervals become a separate schedule type, run by APScheduler's
IntervalTriggerwith a persisted UTC anchor. Every 40 minutes, 60 minutes, or 24 hours becomes a true fixed interval and keeps its phase across restarts; existing jobs keep their original Cron expressions, and regression tests are included. The cost is two nullable columns on thecron_jobstable (with a migration), plus API and WebUI changes. The PR is up to date with the latest master and has no conflicts; as a first-time contribution, its CI needs maintainer approval before it can run.B. Small frontend-only fix
The WebUI only accepts intervals that divide evenly: minutes must be a factor of 60, hours a factor of 24, and days only 1. 60 minutes becomes hourly, 24 hours becomes daily, and other values show a hint to use a custom Cron expression. The change is small and leaves the database and API untouched, but it cannot provide true fixed intervals such as every 40 minutes.
C. No change for now
Keep the current behavior (already described in the docs).
If you choose B, I'll close #10373 and submit a small PR within a day or two; if you choose C, I'll close #10373 as well. Thanks!