{"record":{"id":"6cf3ec06d9721354","repo":"hashicorp/nomad","slug":"interval-must-be-a-non-zero-value-if-attempts-0","errorCode":null,"errorMessage":"Interval must be a non zero value if Attempts > 0","messagePattern":"Interval must be a non zero value if Attempts > 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":6655,"sourceCode":"\nfunc (r *ReschedulePolicy) Enabled() bool {\n\tenabled := r != nil && (r.Attempts > 0 || r.Unlimited)\n\treturn enabled\n}\n\n// Validate uses different criteria to validate the reschedule policy\n// Delay must be a minimum of 1 second\n// Delay Ceiling is ignored if Delay Function is \"constant\"\n// Number of possible attempts is validated, given the interval, delay and delay function\nfunc (r *ReschedulePolicy) Validate() error {\n\tif !r.Enabled() {\n\t\treturn nil\n\t}\n\tvar mErr multierror.Error\n\t// Check for ambiguous/confusing settings\n\tif r.Attempts > 0 {\n\t\tif r.Interval <= 0 {\n\t\t\t_ = multierror.Append(&mErr, fmt.Errorf(\"Interval must be a non zero value if Attempts > 0\"))\n\t\t}\n\t\tif r.Unlimited {\n\t\t\t_ = multierror.Append(&mErr, fmt.Errorf(\"Reschedule Policy with Attempts = %v, Interval = %v, \"+\n\t\t\t\t\"and Unlimited = %v is ambiguous\", r.Attempts, r.Interval, r.Unlimited))\n\t\t\t_ = multierror.Append(&mErr, errors.New(\"If Attempts >0, Unlimited cannot also be set to true\"))\n\t\t}\n\t}\n\n\tdelayPreCheck := true\n\t// Delay should be bigger than the default\n\tif r.Delay.Nanoseconds() < ReschedulePolicyMinDelay.Nanoseconds() {\n\t\t_ = multierror.Append(&mErr, fmt.Errorf(\"Delay cannot be less than %v (got %v)\", ReschedulePolicyMinDelay, r.Delay))\n\t\tdelayPreCheck = false\n\t}\n\n\t// Must use a valid delay function\n\tif !isValidDelayFunction(r.DelayFunction) {\n\t\t_ = multierror.Append(&mErr, fmt.Errorf(\"Invalid delay function %q, must be one of %q\", r.DelayFunction, RescheduleDelayFunctions))","sourceCodeStart":6637,"sourceCodeEnd":6673,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L6637-L6673","documentation":"ReschedulePolicy.Validate() in structs.go requires a non-zero Interval whenever Attempts > 0. A reschedule policy that limits attempts must define the window over which they are counted; Attempts > 0 with Interval <= 0 is ambiguous and rejected.","triggerScenarios":"A reschedule block (or ReschedulePolicy struct built in code) with attempts set to a positive number but interval left at 0 or negative — often because interval was omitted from the job file or defaulted from the zero-value struct.","commonSituations":"Hand-written reschedule stanzas missing the interval line, JSON job payloads that omit the field, or constructors that set attempts without interval.","solutions":["Set reschedule.interval to a positive duration (e.g. interval = \"30m\").","If unlimited rescheduling is desired, set unlimited = true and attempts = 0 instead.","Run `nomad job validate` before submission to catch the missing field."],"exampleFix":"// before\nreschedule {\n  attempts = 5\n  delay    = \"30s\"\n}\n// after\nreschedule {\n  attempts = 5\n  interval = \"1h\"\n  delay    = \"30s\"\n}","handlingStrategy":"validation","validationCode":"if rsl := tg.Reschedule; rsl != nil && rsl.Attempts > 0 && rsl.Interval <= 0 {\n    return fmt.Errorf(\"reschedule attempts=%d requires a positive interval\", rsl.Attempts)\n}","typeGuard":"func rescheduleSane(r *structs.ReschedulePolicy) bool {\n    return r.Attempts == 0 || r.Interval > 0\n}","tryCatchPattern":null,"preventionTips":["Never set attempts without also setting interval.","Use NewReschedulePolicy(jobType) defaults for limited policies.","Template generators should emit interval whenever attempts is emitted."],"tags":["nomad","validation","job-spec","reschedule-policy"],"backgroundTag":"missing-required-argument","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"}