hashicorp/nomad · error
Could not find allocation task group: %s
Error message
Could not find allocation task group: %s
What it means
`nomad alloc logs` (without -task when the allocation has multiple tasks) resolves the task via lookupAllocTask, which calls alloc.Job.LookupTaskGroup(alloc.TaskGroup). If the job stored in the allocation has no task group matching alloc.TaskGroup, the lookup returns nil and this error is thrown. It signals corrupted/stale allocation data or a version mismatch between the allocation's Job stub and its TaskGroup field.
Source
Thrown at command/alloc_logs.go:427
return fmt.Errorf("received an error from stdout log stream: %v", stdoutErr)
case stdoutFrame := <-stdoutFrames:
if stdoutFrame != nil {
logUI.Output(string(stdoutFrame.Data))
}
case stderrErr := <-stderrErrCh:
return fmt.Errorf("received an error from stderr log stream: %v", stderrErr)
case stderrFrame := <-stderrFrames:
if stderrFrame != nil {
logUI.Warn(string(stderrFrame.Data))
}
}
}
}
func lookupAllocTask(alloc *api.Allocation) (string, error) {
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
if tg == nil {
return "", fmt.Errorf("Could not find allocation task group: %s", alloc.TaskGroup)
}
if len(tg.Tasks) == 1 {
return tg.Tasks[0].Name, nil
}
var errStr strings.Builder
fmt.Fprintf(&errStr, "Allocation %q is running the following tasks:\n", limit(alloc.ID, shortId))
for _, t := range tg.Tasks {
fmt.Fprintf(&errStr, " * %s\n", t.Name)
}
fmt.Fprintf(&errStr, "\nPlease specify the task.")
return "", errors.New(errStr.String())
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Pass the task explicitly: `nomad alloc logs -task <task-name> <alloc-id>` so lookupAllocTask isn't needed.
- Refresh the allocation data: re-fetch with `nomad alloc status <alloc-id>` and confirm the task group name matches a group in the current job spec (`nomad job inspect <job>`).
- Update the Nomad CLI and server to matching versions to avoid truncated allocation stubs over the API.
- If building api.Allocation in code, ensure alloc.Job is populated (fetch via Alloc().Info with the full job) before calling lookupAllocTask.
Example fix
// before: relying on auto-detection with a stale/renamed task group
alloc, _, _ := client.Allocations().Info(allocID, nil)
task, err := lookupAllocTask(alloc) // "Could not find allocation task group: web"
// after: fetch full allocation info and pass the task explicitly
alloc, _, err := client.Allocations().Info(allocID, nil)
if err != nil { return err }
task := "web" // name from the current job spec
cmdFlags.StringVar(&task, "task", "", ...) Defensive patterns
Strategy: validation
Validate before calling
alloc, _, err := client.Allocations().Info(allocID, nil)
if err != nil { return err }
if alloc.Job == nil {
return fmt.Errorf("allocation %s has no embedded job; re-fetch full alloc info", allocID)
}
if alloc.Job.LookupTaskGroup(alloc.TaskGroup) == nil {
return fmt.Errorf("task group %q not found in job %q; check current job spec", alloc.TaskGroup, alloc.Job.ID)
}
return nil Type guard
func taskGroupExists(alloc *api.Allocation) bool {
return alloc != nil && alloc.Job != nil &&
alloc.Job.LookupTaskGroup(alloc.TaskGroup) != nil
} Try / catch
task, err := lookupAllocTask(alloc)
if err != nil && strings.Contains(err.Error(), "Could not find allocation task group") {
// stale/partial alloc data: re-fetch, then pass -task explicitly
alloc, _, ferr := client.Allocations().Info(alloc.ID, nil)
if ferr != nil { return ferr }
task, err = lookupAllocTask(alloc)
} Prevention
- Always fetch the full allocation via Allocations().Info before inspecting Job/TaskGroup fields.
- Pass -task explicitly when a job has multiple tasks instead of relying on auto-detection.
- After job deploys that rename task groups, resolve the current group/task names with `nomad job inspect`.
- Keep CLI and server versions aligned so allocation stubs include the full Job document.
When it happens
Trigger: Running `nomad alloc logs <alloc-id>` where alloc.Job is nil or alloc.Job.LookupTaskGroup(alloc.TaskGroup) returns nil — e.g. the API returned an allocation stub whose embedded Job is truncated/partial, the allocation references a job version whose task group was removed, or TaskGroup was renamed between job versions.
Common situations: Querying an allocation from an old/failed job version after a deployment renamed the task group; CLI/API version skew where the allocation stub lacks the full Job document; garbage-collected jobs whose allocations still reference them; automation that constructs api.Allocation structs manually without populating Job.
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/c5805acab0932614.
Report an issue: GitHub.