hashicorp/nomad · error
Could not find task runner for task: %s
Error message
Could not find task runner for task: %s
What it means
RestartTask (used by the Restart API and task lifecycle endpoints) looks up the named task runner in the alloc runner's task map. This error means no task runner exists under that name in this allocation — the request named a task that is not part of the alloc's task group.
Source
Thrown at client/allocrunner/alloc_runner.go:1405
Details: ev.Annotations,
DriverMessage: ev.Message,
})
}
}
return nil
}
// Restart satisfies the WorkloadRestarter interface and restarts all tasks
// that are currently running.
func (ar *allocRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error {
return ar.restartTasks(ctx, event, failure, false)
}
// RestartTask restarts the provided task.
func (ar *allocRunner) RestartTask(taskName string, event *structs.TaskEvent) error {
tr, ok := ar.tasks[taskName]
if !ok {
return fmt.Errorf("Could not find task runner for task: %s", taskName)
}
return tr.Restart(context.TODO(), event, false)
}
// RestartRunning restarts all tasks that are currently running.
func (ar *allocRunner) RestartRunning(event *structs.TaskEvent) error {
return ar.restartTasks(context.TODO(), event, false, false)
}
// RestartAll restarts all tasks in the allocation, including dead ones. They
// will restart following their lifecycle order.
func (ar *allocRunner) RestartAll(event *structs.TaskEvent) error {
// Restart the taskCoordinator to allow dead tasks to run again.
ar.taskCoordinator.Restart()
return ar.restartTasks(context.TODO(), event, false, true)
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- List valid task names with `nomad alloc status <alloc-id>` and retry with an exact task name
- Confirm you are targeting the right allocation ID (task names are per task-group/job version)
- If using the API, read the alloc's Job to derive task names instead of hardcoding them
- If the task genuinely should exist but doesn't, check client logs for initTaskRunners failures on this alloc
Example fix
// before
client.Allocations().Restart(allocID, "ap", nil) // typo
// after
alloc, _ := client.Allocations().Info(allocID)
for _, tg := range alloc.Job.TaskGroups {
for _, t := range tg.Tasks { /* match exact t.Name before restarting */ }
} Defensive patterns
Strategy: validation
Validate before calling
// Derive task names from the alloc's job instead of hardcoding
alloc, _, err := client.Allocations().Info(allocID, nil)
if err != nil { return err }
valid := map[string]bool{}
for _, tg := range alloc.Job.TaskGroups {
for _, t := range tg.Tasks { valid[t.Name] = true }
}
if !valid[taskName] { return fmt.Errorf("task %q not in alloc %s", taskName, allocID) } Try / catch
err := client.Allocations().Restart(allocID, taskName, nil)
if err != nil && strings.Contains(err.Error(), "Could not find task runner") {
// list tasks via nomad alloc status and retry with a valid name
} Prevention
- Always look up task names from `nomad alloc status` or the Job API, never hardcode
- Target the current deployment's allocs, not old job versions
- Double-check spelling of task names in automation scripts
- If the task should exist, check client logs for earlier initTaskRunners failures
When it happens
Trigger: RestartTask(taskName, event) called via API/endpoint with a taskName not present in ar.tasks: typo in the task name, task from a different alloc, or a task group that never initialized (initTaskRunners failed earlier).
Common situations: Operators calling `nomad alloc restart <alloc> <task>` with the wrong task name; automation targeting stale allocs from a previous job version whose task names changed; API scripts hardcoding task names across jobs.
Related errors
- failed creating runner for task %q: %v
- restart of an alloc that should not run
- Nomad Enterprise only endpoint
- missing policy name
- Unknown log level
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/878c282abb4d5dd6.
Report an issue: GitHub.