hashicorp/nomad · error
Task %d redefines '%s' from task %d
Error message
Task %d redefines '%s' from task %d
What it means
TaskGroup.Validate builds a map of task names and rejects duplicates: when a task reuses a name already defined earlier in the same group, this error is appended, referencing the 1-indexed positions of both the duplicate and the original task. Task names must be unique within a task group because they key allocation state, service checks, and log streams.
Source
Thrown at nomad/structs/structs.go:7256
if err := tg.Migrate.Validate(); err != nil {
mErr = multierror.Append(mErr, err)
}
}
default:
if tg.Migrate != nil {
mErr = multierror.Append(mErr, fmt.Errorf("Job type %q does not allow migrate block", j.Type))
}
}
// Check that there is only one leader task if any
tasks := make(map[string]int)
leaderTasks := 0
mainTasks := 0
for idx, task := range tg.Tasks {
if task.Name == "" {
mErr = multierror.Append(mErr, fmt.Errorf("Task %d missing name", idx+1))
} else if existing, ok := tasks[task.Name]; ok {
mErr = multierror.Append(mErr, fmt.Errorf("Task %d redefines '%s' from task %d", idx+1, task.Name, existing+1))
} else {
tasks[task.Name] = idx
}
if task.Leader {
leaderTasks++
}
if task.IsMain() {
mainTasks++
}
}
if leaderTasks > 1 {
mErr = multierror.Append(mErr, fmt.Errorf("Only one task may be marked as leader"))
}
// A task group made up entirely of lifecycle tasks (prestart, poststart, orView on GitHub (pinned to 482b49bf1a)
Solutions
- Rename one of the duplicate task blocks to a unique name within the group.
- If the tasks are meant to be independent instances, place them in separate groups instead.
Example fix
// before
task "app" { driver = "docker" }
task "app" { driver = "exec" }
// after
task "app" { driver = "docker" }
task "app-sidecar" { driver = "exec" } Defensive patterns
Strategy: validation
Validate before calling
// Go: enforce unique task names per group
for _, tg := range job.TaskGroups {
seen := map[string]bool{}
for _, t := range tg.Tasks {
if seen[t.Name] {
return fmt.Errorf("group %q: duplicate task name %q", tg.Name, t.Name)
}
seen[t.Name] = true
}
} Prevention
- Name tasks after copying a block and immediately rename it.
- In generators, derive task names from unique loop keys.
- Add a unit test that validates all canonical job specs with Nomad's structs API.
When it happens
Trigger: Submitting a job with two `task` blocks sharing the same `name` inside one `group` block.
Common situations: Copy-pasting a task block and forgetting to rename it; merging job fragments; templated loops generating tasks with identical names.
Related errors
- Job task group %d redefines '%s' from group %d
- ErrConnectRequireOneNetwork
- ErrConnectInvalidNetworkMode
- service.port must be set for mesh gateway service
- non-default Consul cluster requires Nomad Enterprise
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/74f6a1585fe40749.
Report an issue: GitHub.