chenhg5/cc-connect · error

timeout_mins must be >= 0

Error message

timeout_mins must be >= 0

What it means

validateCronJob rejects a CronJob whose TimeoutMins pointer is set to a negative value. Cron job timeouts must be zero or positive minutes; a negative value cannot be honored by the scheduler and is caught before the job is persisted or scheduled. AddJob runs this validation first, so nothing is stored when it fires.

Source

Thrown at core/cron.go:111

	// `platform "" not found for session ""`. Reject it up front so the
	// caller (management API, /cron/add, /cron edit) sees an immediate
	// 400 instead of a job that silently never runs.
	if strings.TrimSpace(j.SessionKey) == "" {
		return fmt.Errorf("session_key is required")
	}
	mode := NormalizeCronSessionMode(j.SessionMode)
	if mode != "" && mode != "new_per_run" {
		return fmt.Errorf("invalid session_mode %q (want reuse, new_per_run, or new-per-run)", j.SessionMode)
	}
	if j.Mode != "" {
		switch j.Mode {
		case "default", "bypassPermissions", "acceptEdits", "plan", "auto", "dontAsk":
		default:
			return fmt.Errorf("invalid mode %q (want default, bypassPermissions, acceptEdits, plan, auto, or dontAsk)", j.Mode)
		}
	}
	if j.TimeoutMins != nil && *j.TimeoutMins < 0 {
		return fmt.Errorf("timeout_mins must be >= 0")
	}
	return nil
}

// CronStore persists cron jobs to a JSON file.
type CronStore struct {
	path string
	mu   sync.Mutex
	jobs []*CronJob
}

func NewCronStore(dataDir string) (*CronStore, error) {
	dir := filepath.Join(dataDir, "crons")
	if err := os.MkdirAll(dir, 0o755); err != nil {
		return nil, err
	}
	path := filepath.Join(dir, "jobs.json")
	s := &CronStore{path: path}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Set TimeoutMins to a non-negative value (or leave it nil for no timeout).
  2. Clamp or reject negative input at the command/config layer before constructing the CronJob.
  3. If timeout is computed, take max(0, computed).

Example fix

// before
job.TimeoutMins = &(-5)
sched.AddJob(job)
// after
t := 30
job.TimeoutMins = &t
if err := sched.AddJob(job); err != nil { return err }
Defensive patterns

Strategy: validation

Validate before calling

func validTimeout(m *int) bool { return m == nil || *m >= 0 }

Prevention

When it happens

Trigger: Calling CronScheduler.AddJob (directly or via handleCronAdd) with a job whose TimeoutMins is a pointer to a negative int, e.g. parsed from `timeout_mins = -5` in a cron add command.

Common situations: Users typing negative timeout values in a chat /cron add command; config generators computing timeout as a difference of timestamps that went negative; defaulting logic subtracting elapsed time.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/7bf6a15fe0ff56ff. Report an issue: GitHub.