mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
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:
@@ -141,6 +141,12 @@ func (t *CronTool) addJob(ctx context.Context, args map[string]any) *ToolResult
|
||||
everySeconds, hasEvery := args["every_seconds"].(float64)
|
||||
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
|
||||
if hasAt {
|
||||
atMS := time.Now().UnixMilli() + int64(atSeconds)*1000
|
||||
|
||||
Reference in New Issue
Block a user