{"record":{"id":"322fff13196164ea","repo":"hashicorp/nomad","slug":"job-type-q-does-not-allow-max-run-duration","errorCode":null,"errorMessage":"Job type %q does not allow max_run_duration","messagePattern":"Job type %q does not allow max_run_duration","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7156,"sourceCode":"\t\t// could be a lone consul gateway inserted by the connect mutator\n\t\tmErr = multierror.Append(mErr, errors.New(\"Missing tasks for task group\"))\n\t}\n\n\tif tg.Disconnect != nil {\n\t\tif err := tg.Disconnect.Validate(j); err != nil {\n\t\t\tmErr = multierror.Append(mErr, err)\n\t\t}\n\t}\n\n\tif tg.MaxRunDuration != nil {\n\t\tif *tg.MaxRunDuration <= 0 {\n\t\t\tmErr = multierror.Append(mErr, errors.New(\"MaxRunDuration must be greater than zero\"))\n\t\t}\n\n\t\tswitch j.Type {\n\t\tcase JobTypeBatch, JobTypeSysBatch:\n\t\tdefault:\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"Job type %q does not allow max_run_duration\", j.Type))\n\t\t}\n\t}\n\n\tfor idx, constr := range tg.Constraints {\n\t\tif err := constr.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Constraint %d validation failed: %s\", idx+1, err)\n\t\t\tmErr = multierror.Append(mErr, outer)\n\t\t}\n\t}\n\tif j.Type == JobTypeSystem {\n\t\tif tg.Affinities != nil {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"System jobs may not have an affinity block\"))\n\t\t}\n\t} else {\n\t\tfor idx, affinity := range tg.Affinities {\n\t\t\tif err := affinity.Validate(); err != nil {\n\t\t\t\touter := fmt.Errorf(\"Affinity %d validation failed: %s\", idx+1, err)\n\t\t\t\tmErr = multierror.Append(mErr, outer)","sourceCodeStart":7138,"sourceCodeEnd":7174,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7138-L7174","documentation":"During Job validation in nomad/structs/structs.go, if a task group sets max_run_duration, only batch and sysbatch job types are permitted to use it. Any other job type (service, system, etc.) with max_run_duration set causes this error to be appended to the multierror returned by Job.Validate. It exists because max_run_duration semantics (killing/rescheduling the allocation after a fixed duration) only make sense for batch-style workloads.","triggerScenarios":"Submitting (job register/plan) a job spec where any task group defines max_run_duration (directly or via `max_run_duration` in the group block) while the job `type` is not \"batch\" or \"sysbatch\" — e.g. type = \"service\" or \"system\".","commonSituations":"Copy-pasting a batch job HCL/JSON that includes max_run_duration into a service job; converting a scheduled batch task into a long-running service without removing the duration cap; tooling that templates max_run_duration into every group.","solutions":["Remove the max_run_duration field from the task group if the job is not batch/sysbatch.","Change the job type to \"batch\" or \"sysbatch\" if the workload really is finite/periodic.","If you need periodic behavior for a service job, use a separate batch job with cron/periodic config instead."],"exampleFix":"// before\njob \"svc\" {\n  type = \"service\"\n  group \"web\" {\n    max_run_duration = \"1h\"\n  }\n}\n// after\njob \"svc\" {\n  type = \"service\"\n  group \"web\" {\n    # max_run_duration removed: not allowed for service jobs\n  }\n}","handlingStrategy":"validation","validationCode":"func validateMaxRunDuration(jobType string, groups []map[string]interface{}) error {\n  for _, tg := range groups {\n    if _, ok := tg[\"max_run_duration\"]; ok && jobType != \"batch\" && jobType != \"sysbatch\" {\n      return fmt.Errorf(\"group %v: max_run_duration not allowed for job type %q\", tg[\"name\"], jobType)\n    }\n  }\n  return nil\n}","typeGuard":"func allowsMaxRunDuration(jobType string) bool {\n  return jobType == \"batch\" || jobType == \"sysbatch\"\n}","tryCatchPattern":null,"preventionTips":["Only emit max_run_duration from templates when job type is batch/sysbatch.","Run `nomad job validate` in CI before every submit.","Keep service job HCL free of batch-only fields."],"tags":["nomad","job-validation","max-run-duration","job-type"],"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"}