fix: handle zero values in cron schedule type assertions (#1147)
Fixes #1126 Go type assertions return true for zero values, which caused recurring cron jobs (every_seconds/cron_expr) to silently become one-time 'at' tasks when LLMs filled unused optional parameters with default values (0). Changes: - Add validity checks after type assertions: atSeconds > 0, everySeconds > 0, cronExpr != "" - This ensures zero values are treated as 'not set' rather than valid schedule values - Recurring tasks like "remind me every 2 hours" now correctly create recurring jobs
This commit is contained in:
parent
23abbb67ea
commit
7f6d95c026
1 changed files with 6 additions and 0 deletions
|
|
@ -141,6 +141,12 @@ 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
|
||||||
|
// This prevents LLMs that fill unused optional parameters with defaults (0) from triggering wrong type
|
||||||
|
hasAt = hasAt && atSeconds > 0
|
||||||
|
hasEvery = hasEvery && everySeconds > 0
|
||||||
|
hasCron = hasCron && cronExpr != ""
|
||||||
|
|
||||||
// Priority: at_seconds > every_seconds > cron_expr
|
// Priority: at_seconds > every_seconds > cron_expr
|
||||||
if hasAt {
|
if hasAt {
|
||||||
atMS := time.Now().UnixMilli() + int64(atSeconds)*1000
|
atMS := time.Now().UnixMilli() + int64(atSeconds)*1000
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue