{"record":{"id":"47e1e83a7fd4fc38","repo":"hashicorp/nomad","slug":"task-group-scaling-policy-validation-failed-v","errorCode":null,"errorMessage":"Task group scaling policy validation failed: %v","messagePattern":"Task group scaling policy validation failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7312,"sourceCode":"\t\touter := fmt.Errorf(\"Task group network validation failed: %v\", err)\n\t\tmErr = multierror.Append(mErr, outer)\n\t}\n\n\t// Validate task group and task services\n\tif err := tg.validateServices(); err != nil {\n\t\touter := fmt.Errorf(\"Task group service validation failed: %v\", err)\n\t\tmErr = multierror.Append(mErr, outer)\n\t}\n\n\t// Validate group service script-checks\n\tif err := tg.validateScriptChecksInGroupServices(); err != nil {\n\t\touter := fmt.Errorf(\"Task group service check validation failed: %v\", err)\n\t\tmErr = multierror.Append(mErr, outer)\n\t}\n\n\t// Validate the scaling policy\n\tif err := tg.validateScalingPolicy(j); err != nil {\n\t\touter := fmt.Errorf(\"Task group scaling policy validation failed: %v\", err)\n\t\tmErr = multierror.Append(mErr, outer)\n\t}\n\n\t// Validate the tasks\n\tfor _, task := range tg.Tasks {\n\t\tif err := task.Validate(j.Type, tg); err != nil {\n\t\t\touter := fmt.Errorf(\"Task %s validation failed: %v\", task.Name, err)\n\t\t\tmErr = multierror.Append(mErr, outer)\n\t\t}\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\nfunc (tg *TaskGroup) validateNetworks() error {\n\tvar mErr multierror.Error\n\tportLabels := make(map[string]string)\n\t// host_network -> static port tracking","sourceCodeStart":7294,"sourceCodeEnd":7330,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7294-L7330","documentation":"This error is produced during Job validation in nomad/structs/structs.go when a task group's scaling policy (`tg.validateScalingPolicy`) fails validation. Nomad wraps the underlying policy error with 'Task group scaling policy validation failed: %v' and appends it to the job-level multierror. It indicates the scaling block (horizontal scaling for the group) is malformed or inconsistent with the job.","triggerScenarios":"Submitting (job register/plan) a job whose task group has a `scaling` block that: has a negative or non-integer min/max, has max < min, missing required fields, invalid policy `policy` map (e.g. unsupported keys or bad target), or scaling policy on a system/batch job type where scaling is not allowed.","commonSituations":"Hand-writing HCL with a scaling block and typos in min/max; automating scaling config generation (Terraform nomad_job, CI pipelines) that emits invalid bounds; applying job specs written for newer Nomad versions with fields the current server doesn't accept; adding scaling to a system job.","solutions":["Read the wrapped '%v' detail in the error to identify the exact policy field that failed","Fix the scaling block so min <= count <= max and all values are non-negative integers","Remove the scaling block from job types that do not support scaling (e.g. system scheduler jobs)","Validate the job spec with `nomad job validate <file>` before submitting","Upgrade/downgrade Nomad client/agent versions so server and spec fields match"],"exampleFix":"// before\ntask \"web\" {}\nscaling {\n  min = -1\n  max = 0\n}\n// after\nscaling {\n  min = 1\n  max = 10\n  policy {\n    cooldown            = \"1m\"\n    check_idle_delay    = \"30s\"\n  }\n}","handlingStrategy":"validation","validationCode":"func validateScalingBlock(j *api.Job) error {\n  var errs error\n  for _, tg := range j.TaskGroups {\n    if tg.Scaling == nil { continue }\n    s := tg.Scaling\n    if s.Min == nil || s.Max == nil { errs = multierror.Append(errs, fmt.Errorf(\"group %s: scaling min/max required\", *tg.Name)); continue }\n    if *s.Min < 0 { errs = multierror.Append(errs, fmt.Errorf(\"group %s: scaling min negative\", *tg.Name)) }\n    if *s.Max < *s.Min { errs = multierror.Append(errs, fmt.Errorf(\"group %s: scaling max < min\", *tg.Name)) }\n  }\n  return errs\n}\n// run before submitting: nomad job validate <file>","typeGuard":"func hasValidScaling(tg *api.TaskGroup) bool {\n  return tg.Scaling != nil && tg.Scaling.Min != nil && tg.Scaling.Max != nil &&\n    *tg.Scaling.Min >= 0 && *tg.Scaling.Max >= *tg.Scaling.Min\n}","tryCatchPattern":null,"preventionTips":["Always run `nomad job validate` in CI before job register","Keep min <= count <= max in generated scaling blocks","Only add scaling blocks to service jobs (not system/batch)","Pin the Nomad API/CLI version to the cluster version to avoid unsupported policy fields"],"tags":["nomad","job-validation","scaling-policy","hcl"],"backgroundTag":"job-spec-validation-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}