chenhg5/cc-connect · error

session_key is required

Error message

session_key is required

What it means

validateCronJob requires a non-empty SessionKey on every cron job. SessionKey encodes the platform and chat the job runs against; without it the job would be persisted but fail at fire time with an unhelpful 'platform "" not found'. The validation makes the failure an immediate, actionable 400 at job creation.

Source

Thrown at core/cron.go:97

	switch low {
	case "", "reuse":
		return ""
	case "new_per_run", "new-per-run":
		return "new_per_run"
	default:
		return s
	}
}

func validateCronJob(j *CronJob) error {
	// SessionKey anchors the cron execution to a platform (ExecuteCronJob
	// derives platformName from the prefix before ":"). Without it the job
	// is persisted but fails at fire-time with the unhelpful
	// `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
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Set session_key to the target conversation's key (format platform:chatID, e.g. "feishu:oc_abc123").
  2. If creating via API, include session_key in the JSON body; check the response status is not 400.
  3. When constructing CronJob in Go, populate SessionKey from the active session's key rather than leaving it zero-valued.
  4. Update old automation/clients to send the field; it is now mandatory, not defaulted.

Example fix

// before
core.AddJob(core.CronJob{Name: "nightly", Schedule: "0 2 * * *", Prompt: "run report"})
// after
core.AddJob(core.CronJob{Name: "nightly", Schedule: "0 2 * * *", Prompt: "run report",
    SessionKey: "feishu:oc_abc123"})
Defensive patterns

Strategy: validation

Validate before calling

func validateJobInput(j core.CronJob) error {
    if strings.TrimSpace(j.SessionKey) == "" {
        return fmt.Errorf("session_key is required (platform:chatID)")
    }
    return nil
}

Try / catch

if err := core.AddJob(job); err != nil {
    if strings.Contains(err.Error(), "session_key is required") {
        http.Error(w, "session_key is required", http.StatusBadRequest)
        return
    }
    http.Error(w, err.Error(), http.StatusInternalServerError)
}

Prevention

When it happens

Trigger: Calling Engine.AddJob (or the /cron/add or /cron edit management API) with a CronJob whose SessionKey field is empty or whitespace-only.

Common situations: A client building the job payload omits session_key because it only set the schedule and prompt; an older management-API client predating the field; programmatic job creation that copies a config struct with unset SessionKey; editing a job and accidentally clearing the field.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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