{"record":{"id":"2a6f0ef2ee02c32a","repo":"hashicorp/nomad","slug":"group-name-in-allocation-is-not-present-in-job","errorCode":null,"errorMessage":"group name in allocation is not present in job","messagePattern":"group name in allocation is not present in job","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/client.go","lineNumber":3069,"sourceCode":"\t\t),\n\t}\n\tc.nomadService = nsd.NewServiceRegistrationHandler(c.logger, &cfg)\n}\n\n// verifiedTasks asserts each task in taskNames actually exists in the given alloc,\n// otherwise an error is returned.\nfunc verifiedTasks(logger hclog.Logger, alloc *structs.Allocation, taskNames []string) ([]string, error) {\n\tif alloc == nil {\n\t\treturn nil, fmt.Errorf(\"nil allocation\")\n\t}\n\n\tif len(taskNames) == 0 {\n\t\treturn nil, fmt.Errorf(\"missing task names\")\n\t}\n\n\tgroup := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\n\tif group == nil {\n\t\treturn nil, fmt.Errorf(\"group name in allocation is not present in job\")\n\t}\n\n\tverifiedTasks := make([]string, 0, len(taskNames))\n\n\t// confirm the requested task names actually exist in the allocation\n\tfor _, taskName := range taskNames {\n\t\tif !taskIsPresent(taskName, group.Tasks) {\n\t\t\tlogger.Error(\"task not found in the allocation\", \"task_name\", taskName)\n\t\t\treturn nil, fmt.Errorf(\"task %q not found in allocation\", taskName)\n\t\t}\n\t\tverifiedTasks = append(verifiedTasks, taskName)\n\t}\n\n\treturn verifiedTasks, nil\n}\n\nfunc taskIsPresent(taskName string, tasks []*structs.Task) bool {\n\tfor _, task := range tasks {","sourceCodeStart":3051,"sourceCodeEnd":3087,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/client.go#L3051-L3087","documentation":"After checking task names, `verifiedTasks` calls alloc.Job.LookupTaskGroup(alloc.TaskGroup) and throws \"group name in allocation is not present in job\" if the job spec embedded in the allocation has no task group matching the allocation's TaskGroup. This indicates the allocation's job data is inconsistent — the task group referenced does not exist in the job definition stored with the allocation.","triggerScenarios":"Passing an allocation whose embedded Job is nil-truncated, pruned, or from a different/older job version so LookupTaskGroup returns nil; constructing an Allocation struct manually with a mismatched TaskGroup and Job.","commonSituations":"Client-side APIs given an allocation fetched with field filtering that dropped the Job; custom tooling that hand-builds structs.Allocation; job spec changes where an old allocation references a since-renamed task group.","solutions":["Ensure the allocation passed to the API includes a complete, matching Job specification","Re-fetch the allocation from the Nomad server so alloc.Job and alloc.TaskGroup are consistent","If building allocations in code, set TaskGroup to a group name that exists in the Job you attach"],"exampleFix":"// before\nalloc.TaskGroup = \"web-v2\"\nalloc.Job = oldJobSnapshot // no \"web-v2\" group\nverified, err := verifiedTasks(logger, alloc, tasks)\n// after\nalloc.TaskGroup = \"web\"\nalloc.Job = currentJob // contains the referenced group\nverified, err := verifiedTasks(logger, alloc, tasks)","handlingStrategy":"validation","validationCode":"group := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\nif group == nil {\n    return fmt.Errorf(\"task group %q missing from job %q\", alloc.TaskGroup, alloc.Job.ID)\n}","typeGuard":"func jobHasAllocGroup(alloc *structs.Allocation) bool {\n    return alloc != nil && alloc.Job != nil &&\n        alloc.Job.LookupTaskGroup(alloc.TaskGroup) != nil\n}","tryCatchPattern":"if err := op(alloc); err != nil {\n    if strings.Contains(err.Error(), \"not present in job\") {\n        alloc, err = reFetchAllocation(alloc.ID) // refresh job data\n    }\n}","preventionTips":["Pass fully-populated allocations (avoid field-filtered fetches that drop Job)","Keep TaskGroup and Job in sync when constructing allocations in code","Re-fetch allocations from the server instead of caching old job versions"],"tags":["nomad","client","allocation","job-spec"],"backgroundTag":"allocation-job-mismatch","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"}