{"record":{"id":"c55825fa6325cdf1","repo":"hashicorp/nomad","slug":"scaling-policy-invalid-task-group-count-must-not","errorCode":null,"errorMessage":"Scaling policy invalid: task group count must not be greater than maximum count in scaling policy","messagePattern":"Scaling policy invalid: task group count must not be greater than maximum count in scaling policy","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7626,"sourceCode":"\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\n// deprecation warnings.\nfunc (tg *TaskGroup) Warnings(j *Job) error {\n\tvar mErr multierror.Error\n\n\t// Validate the update strategy\n\tif u := tg.Update; u != nil {\n\t\t// Check the counts are appropriate","sourceCodeStart":7608,"sourceCodeEnd":7644,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7608-L7644","documentation":"TaskGroup validation rejects a job where the group's static `count` exceeds the `max` declared in its scaling policy, since the scheduler would then run allocations outside the policy's allowed range.","triggerScenarios":"Submitting a job with `count = N` in the task group while the `scaling` block has `max < N` (e.g. count=5, scaling max=3).","commonSituations":"Manually raising `count` (or via `nomad job scale` interplay) after adding a scaling policy; copy-pasting a scaling block from another group with a lower max.","solutions":["Lower the group `count` to be <= scaling max","Raise `max` in the scaling block to at least the desired count","Remove the static count and let the scaling policy govern instances"],"exampleFix":"// before\ncount = 5\nscaling { min = 1 max = 3 }\n// after\ncount = 3\nscaling { min = 1 max = 3 }","handlingStrategy":"validation","validationCode":"if g.Scaling != nil && int64(g.Count) > g.Scaling.Max {\n  return fmt.Errorf(\"count %d exceeds scaling.max %d\", g.Count, g.Scaling.Max)\n}","typeGuard":"func countWithinMax(g *api.TaskGroup) bool {\n  return g.Scaling == nil || int64(g.Count) <= g.Scaling.Max\n}","tryCatchPattern":null,"preventionTips":["Keep one source of truth for count: prefer the scaling policy","Audit scaling max when changing count manually","Remember `nomad job scale` interactions with static count"],"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"}