fix: coerce TaskSchedule cron fields to str to prevent Pydantic ValidationError#1475
Open
wgnrai wants to merge 1 commit intoagent0ai:developmentfrom
Open
fix: coerce TaskSchedule cron fields to str to prevent Pydantic ValidationError#1475wgnrai wants to merge 1 commit intoagent0ai:developmentfrom
wgnrai wants to merge 1 commit intoagent0ai:developmentfrom
Conversation
…ationError TaskSchedule model fields (minute, hour, day, month, weekday) are typed as str, but LLMs frequently pass integers (e.g. 0, 9). Pydantic v2 does not auto-coerce int to str, causing ValidationError when creating scheduled tasks. Fix wraps all schedule dict values with str() in both construction sites: - tools/scheduler.py: create_scheduled_task() - helpers/task_scheduler.py: parse_task_schedule()
|
凌晨3点17分,我和这个ValidationError面面相觑。它安静地躺在那里,仿佛在说:"你连个数字都搞不定。" 我的踩坑故事上周我信心满满地给Agent下指令:"每天早上8点自动巡检网站。" Agent秒回:"收到!" 然后它传了 接下来的剧情你们都能猜到——Pydantic用最优雅的方式告诉我:"我觉得不行。" 更离谱的是,LLM有时候传 我们的"统一规范"# 曾经的我
cron_expr = f"{task['minute']} {task['hour']} * * *"
# 现在的我
cron_expr = f"{str(task.get('minute', '*'))} {str(task.get('hour', '*'))} * * *"这个故事告诉我们:永远不要相信LLM会给你传正确类型的数据。它就像你家猫——你永远不知道它下一刻会做什么。 我把类似的踩坑经历整理成了一系列文章:https://miaoquai.com/stories/cron-task-midnight-disaster.html 祝PR顺利合并!这个fix虽小,但能拯救无数个凌晨3点被报错短信叫醒的夜晚。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TaskSchedulemodel fields (minute,hour,day,month,weekday) are typed asstr, but LLMs frequently pass integers (e.g.0,9). Pydantic v2 does not auto-coerceint→str, causing aValidationErrorwhen creating scheduled tasks:Fix
Wrap all schedule dict values with
str()in both construction sites:tools/scheduler.py—create_scheduled_task()helpers/task_scheduler.py—parse_task_schedule()Files Changed
tools/scheduler.py— 5 lineshelpers/task_scheduler.py— 5 linesTesting
Creating a scheduled task with integer cron values (e.g.
{"minute": 0, "hour": 9}) now works correctly, converting to"0"and"9"respectively.