fix(cron): validate schedule params to prevent LLM default values from hijacking priority

LLMs often fill unused optional parameters with default values (e.g.,
at_seconds=0). Go's type assertion on float64 returns true for zero
values, causing at_seconds to always win the priority check. This
turns all recurring tasks (every_seconds, cron_expr) into one-time
'at' tasks with deleteAfterRun=true.

Add value validity checks after type assertions:
- hasAt requires atSeconds > 0
- hasEvery requires everySeconds > 0
- hasCron requires cronExpr != ""
This commit is contained in:
王路路 2026-03-04 09:12:32 +08:00
parent b8f8e3f25f
commit c2d814bdc6

View file

@ -141,8 +141,7 @@ func (t *CronTool) addJob(ctx context.Context, args map[string]any) *ToolResult
everySeconds, hasEvery := args["every_seconds"].(float64) everySeconds, hasEvery := args["every_seconds"].(float64)
cronExpr, hasCron := args["cron_expr"].(string) cronExpr, hasCron := args["cron_expr"].(string)
// Fix: type assertions return true for zero values, need additional validity checks // Validate: ignore zero/empty values (LLMs often send default 0 for unused params)
// This prevents LLMs that fill unused optional parameters with defaults (0) from triggering wrong type
hasAt = hasAt && atSeconds > 0 hasAt = hasAt && atSeconds > 0
hasEvery = hasEvery && everySeconds > 0 hasEvery = hasEvery && everySeconds > 0
hasCron = hasCron && cronExpr != "" hasCron = hasCron && cronExpr != ""