{"record":{"id":"976c568ce0b6b408","repo":"hashicorp/nomad","slug":"scaling-policy-invalid-s","errorCode":null,"errorMessage":"Scaling policy invalid: %s","messagePattern":"Scaling policy invalid: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7619,"sourceCode":"\t}\n\treturn mErr.ErrorOrNil()\n}\n\n// validateScalingPolicy ensures that the scaling policy has consistent\n// min and max, not in conflict with the task group count\nfunc (tg *TaskGroup) validateScalingPolicy(j *Job) error {\n\tif tg.Scaling == nil {\n\t\treturn nil\n\t}\n\n\tvar mErr multierror.Error\n\n\terr := tg.Scaling.Validate()\n\tif err != nil {\n\t\t// prefix scaling policy errors\n\t\tif me, ok := err.(*multierror.Error); ok {\n\t\t\tfor _, e := range me.Errors {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Scaling policy invalid: %s\", e))\n\t\t\t}\n\t\t}\n\t}\n\n\tif tg.Scaling.Max < int64(tg.Count) {\n\t\tmErr.Errors = append(mErr.Errors,\n\t\t\tfmt.Errorf(\"Scaling policy invalid: task group count must not be greater than maximum count in scaling policy\"))\n\t}\n\n\tif int64(tg.Count) < tg.Scaling.Min && !(j.IsMultiregion() && tg.Count == 0 && j.Region == \"global\") {\n\t\tmErr.Errors = append(mErr.Errors,\n\t\t\tfmt.Errorf(\"Scaling policy invalid: task group count must not be less than minimum count in scaling policy\"))\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\n// Warnings returns a list of warnings that may be from dubious settings or","sourceCodeStart":7601,"sourceCodeEnd":7637,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7601-L7637","documentation":"The task group's scaling policy block failed its own Validate() checks; this error prefixes each individual policy error with 'Scaling policy invalid: ' when the group is validated. The actual cause is described after the prefix (e.g. missing min/max, invalid policy config).","triggerScenarios":"Submitting a job whose task group has a `scaling` block with invalid content — e.g. min > max, missing max, invalid policy stanza — detected inside tg.Scaling.Validate().","commonSituations":"Hand-writing scaling blocks without min/max bounds; copy-pasted scaling policies from jobs with different types; enabling APM/target policies with wrong keys.","solutions":["Read the text after the prefix — it names the exact policy problem","Ensure the scaling block defines valid min and max (max > 0, min <= max)","Validate the job locally with `nomad job validate` before submitting"],"exampleFix":"// before\nscaling {\n  enabled = true\n  min     = 10\n  max     = 5\n}\n// after\nscaling {\n  enabled = true\n  min     = 1\n  max     = 5\n}","handlingStrategy":"validation","validationCode":"if pol := group.Scaling; pol != nil {\n  if pol.Max <= 0 { return errors.New(\"scaling.max must be > 0\") }\n  if pol.Min > pol.Max { return errors.New(\"scaling.min must be <= scaling.max\") }\n}","typeGuard":"func validScaling(p *api.ScalingPolicy) bool {\n  return p == nil || (p.Max > 0 && p.Min >= 0 && p.Min <= p.Max)\n}","tryCatchPattern":null,"preventionTips":["Run `nomad job validate` in CI before submission","Use a shared template for scaling blocks with sane min/max defaults","Read the suffixed detail after 'Scaling policy invalid:' to pinpoint the field"],"tags":["nomad","scaling-policy","job-validation"],"backgroundTag":"schema-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"}