Fix: Recurring cron jobs silently become one-time tasks

Fixes #1043

Added value validity checks after type assertions to prevent
LLMs from inadvertently triggering wrong schedule types.
This commit is contained in:
hobostay 2026-03-05 13:00:05 +08:00
parent bb8b9243b7
commit 0583374864
No known key found for this signature in database

View file

@ -150,6 +150,13 @@ func (t *CronTool) addJob(args map[string]any) *ToolResult {
everySeconds, hasEvery := args["every_seconds"].(float64)
cronExpr, hasCron := args["cron_expr"].(string)
// Validate that values are meaningful (not zero/empty)
// This prevents LLMs from setting unused optional params to default values (e.g., at_seconds: 0)
// which would otherwise cause hasAt/hasEvery to be true via Go type assertion
hasAt = hasAt && atSeconds > 0
hasEvery = hasEvery && everySeconds > 0
hasCron = hasCron && cronExpr != ""
// Priority: at_seconds > every_seconds > cron_expr
if hasAt {
atMS := time.Now().UnixMilli() + int64(atSeconds)*1000