hashicorp/nomad · error
Could not find allocation task group: %s
Error message
Could not find allocation task group: %s
What it means
`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.
Source
Thrown at command/alloc_restart.go:168
} else {
err = client.Allocations().Restart(alloc, task, nil)
}
if err != nil {
target := "allocation"
if task != "" {
target = "task"
}
c.Ui.Error(fmt.Sprintf("Failed to restart %s:\n\n%s", target, err.Error()))
return 1
}
return 0
}
func validateTaskExistsInAllocation(taskName string, alloc *api.Allocation) error {
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg == nil {
return fmt.Errorf("Could not find allocation task group: %s", alloc.TaskGroup)
}
foundTaskNames := make([]string, len(tg.Tasks))
for i, task := range tg.Tasks {
foundTaskNames[i] = task.Name
if task.Name == taskName {
return nil
}
}
return fmt.Errorf("Could not find task named: %s, found:\n%s", taskName, formatList(foundTaskNames))
}
func (c *AllocRestartCommand) Synopsis() string {
return "Restart a running allocation"
}
func (c *AllocRestartCommand) AutocompleteFlags() complete.Flags {View on GitHub (pinned to 482b49bf1a)
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.
Example fix
// before: restarting with a stale alloc handle from before a deploy
err := validateTaskExistsInAllocation("app", staleAlloc)
// after: re-fetch the allocation before validating
alloc, _, err := client.Allocations().Info(allocID, nil)
if err != nil { return err }
if err := validateTaskExistsInAllocation("app", alloc); err != nil { return err } Defensive patterns
Strategy: validation
Validate before calling
alloc, _, err := client.Allocations().Info(allocID, nil)
if err != nil { return err }
if alloc.Job == nil || alloc.Job.LookupTaskGroup(alloc.TaskGroup) == nil {
return fmt.Errorf("cannot restart: task group %q missing from allocation %s (stale job version? re-fetch)", alloc.TaskGroup, allocID)
}
for _, t := range alloc.Job.LookupTaskGroup(alloc.TaskGroup).Tasks {
if t.Name == taskName { return nil }
}
return fmt.Errorf("task %q not in group %q", taskName, alloc.TaskGroup) Type guard
func canRestartTask(alloc *api.Allocation, taskName string) bool {
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg == nil { return false }
for _, t := range tg.Tasks {
if t.Name == taskName { return true }
}
return false
} Try / catch
if err := validateTaskExistsInAllocation(taskName, alloc); err != nil {
if strings.Contains(err.Error(), "Could not find allocation task group") {
fresh, _, ferr := client.Allocations().Info(alloc.ID, nil)
if ferr == nil {
return validateTaskExistsInAllocation(taskName, fresh)
}
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Could not find allocation task group: %s
- A template must be supplied using '-template' when using go-
- Invalid value for "-out"; valid values are [go-template, hcl
- Error listing host volumes
- -node or -node-pool options can only be used when no ID is p
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/06f914f61ca1e1af.
Report an issue: GitHub.