{"record":{"id":"06f914f61ca1e1af","repo":"hashicorp/nomad","slug":"could-not-find-allocation-task-group-s-06f914","errorCode":null,"errorMessage":"Could not find allocation task group: %s","messagePattern":"Could not find allocation task group: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/alloc_restart.go","lineNumber":168,"sourceCode":"\t} else {\n\t\terr = client.Allocations().Restart(alloc, task, nil)\n\t}\n\tif err != nil {\n\t\ttarget := \"allocation\"\n\t\tif task != \"\" {\n\t\t\ttarget = \"task\"\n\t\t}\n\t\tc.Ui.Error(fmt.Sprintf(\"Failed to restart %s:\\n\\n%s\", target, err.Error()))\n\t\treturn 1\n\t}\n\n\treturn 0\n}\n\nfunc validateTaskExistsInAllocation(taskName string, alloc *api.Allocation) error {\n\ttg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\n\tif tg == nil {\n\t\treturn fmt.Errorf(\"Could not find allocation task group: %s\", alloc.TaskGroup)\n\t}\n\n\tfoundTaskNames := make([]string, len(tg.Tasks))\n\tfor i, task := range tg.Tasks {\n\t\tfoundTaskNames[i] = task.Name\n\t\tif task.Name == taskName {\n\t\t\treturn nil\n\t\t}\n\t}\n\n\treturn fmt.Errorf(\"Could not find task named: %s, found:\\n%s\", taskName, formatList(foundTaskNames))\n}\n\nfunc (c *AllocRestartCommand) Synopsis() string {\n\treturn \"Restart a running allocation\"\n}\n\nfunc (c *AllocRestartCommand) AutocompleteFlags() complete.Flags {","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/alloc_restart.go#L150-L186","documentation":"`nomad alloc restart` validates the target task via validateTaskExistsInAllocation, which resolves alloc.Job.LookupTaskGroup(alloc.TaskGroup). If that lookup returns nil, the task group cannot be found in the allocation's embedded job and this error is thrown before any task-name check. Like the alloc_logs variant, it indicates stale/incomplete allocation data or a task group that no longer exists in the current job version.","triggerScenarios":"Running `nomad alloc restart <alloc-id>` (or with -task) where alloc.Job is nil or has no task group named alloc.TaskGroup: allocation stub from a job version whose group was renamed/removed, garbage-collected job, manual api.Allocation construction without Job populated, or API version skew producing partial Job data.","commonSituations":"Restarting an allocation after a deployment changed the task group name; scripting against allocations of jobs that were purged or rescheduled to new versions; older CLI against newer server returning reduced Job stubs; CI jobs holding onto a previously fetched alloc object.","solutions":["Re-fetch fresh allocation info (`nomad alloc status <alloc-id>`) and retry with the current allocation ID and task group names.","Verify the task group name in the live job spec: `nomad job inspect <job>` and use a group/task that exists.","Pass an explicit valid task with `-task <name>` from the group listed by `nomad alloc status`.","Align CLI and agent versions, or in code, ensure alloc.Job is fully populated before calling validateTaskExistsInAllocation."],"exampleFix":"// before: restarting with a stale alloc handle from before a deploy\nerr := validateTaskExistsInAllocation(\"app\", staleAlloc)\n\n// after: re-fetch the allocation before validating\nalloc, _, err := client.Allocations().Info(allocID, nil)\nif err != nil { return err }\nif err := validateTaskExistsInAllocation(\"app\", alloc); err != nil { return err }","handlingStrategy":"validation","validationCode":"alloc, _, err := client.Allocations().Info(allocID, nil)\nif err != nil { return err }\nif alloc.Job == nil || alloc.Job.LookupTaskGroup(alloc.TaskGroup) == nil {\n    return fmt.Errorf(\"cannot restart: task group %q missing from allocation %s (stale job version? re-fetch)\", alloc.TaskGroup, allocID)\n}\nfor _, t := range alloc.Job.LookupTaskGroup(alloc.TaskGroup).Tasks {\n    if t.Name == taskName { return nil }\n}\nreturn fmt.Errorf(\"task %q not in group %q\", taskName, alloc.TaskGroup)","typeGuard":"func canRestartTask(alloc *api.Allocation, taskName string) bool {\n    tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\n    if tg == nil { return false }\n    for _, t := range tg.Tasks {\n        if t.Name == taskName { return true }\n    }\n    return false\n}","tryCatchPattern":"if err := validateTaskExistsInAllocation(taskName, alloc); err != nil {\n    if strings.Contains(err.Error(), \"Could not find allocation task group\") {\n        fresh, _, ferr := client.Allocations().Info(alloc.ID, nil)\n        if ferr == nil {\n            return validateTaskExistsInAllocation(taskName, fresh)\n        }\n    }\n    return err\n}","preventionTips":["Re-fetch allocation info immediately before restarting; never restart against long-cached alloc objects.","Derive task names from `nomad alloc status` / job inspect output rather than hardcoding them in scripts.","After deploys that rename groups or tasks, update automation before restarting allocations.","Ensure alloc.Job is fully populated when constructing api.Allocation in code."],"tags":["nomad","cli","task-group","stale-state"],"backgroundTag":"resource-not-found","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"}