{"record":{"id":"878c282abb4d5dd6","repo":"hashicorp/nomad","slug":"could-not-find-task-runner-for-task-s","errorCode":null,"errorMessage":"Could not find task runner for task: %s","messagePattern":"Could not find task runner for task: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/alloc_runner.go","lineNumber":1405,"sourceCode":"\t\t\t\tDetails:       ev.Annotations,\n\t\t\t\tDriverMessage: ev.Message,\n\t\t\t})\n\t\t}\n\t}\n\treturn nil\n}\n\n// Restart satisfies the WorkloadRestarter interface and restarts all tasks\n// that are currently running.\nfunc (ar *allocRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error {\n\treturn ar.restartTasks(ctx, event, failure, false)\n}\n\n// RestartTask restarts the provided task.\nfunc (ar *allocRunner) RestartTask(taskName string, event *structs.TaskEvent) error {\n\ttr, ok := ar.tasks[taskName]\n\tif !ok {\n\t\treturn fmt.Errorf(\"Could not find task runner for task: %s\", taskName)\n\t}\n\n\treturn tr.Restart(context.TODO(), event, false)\n}\n\n// RestartRunning restarts all tasks that are currently running.\nfunc (ar *allocRunner) RestartRunning(event *structs.TaskEvent) error {\n\treturn ar.restartTasks(context.TODO(), event, false, false)\n}\n\n// RestartAll restarts all tasks in the allocation, including dead ones. They\n// will restart following their lifecycle order.\nfunc (ar *allocRunner) RestartAll(event *structs.TaskEvent) error {\n\t// Restart the taskCoordinator to allow dead tasks to run again.\n\tar.taskCoordinator.Restart()\n\treturn ar.restartTasks(context.TODO(), event, false, true)\n}\n","sourceCodeStart":1387,"sourceCodeEnd":1423,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/alloc_runner.go#L1387-L1423","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nclient.Allocations().Restart(allocID, \"ap\", nil) // typo\n// after\nalloc, _ := client.Allocations().Info(allocID)\nfor _, tg := range alloc.Job.TaskGroups {\n  for _, t := range tg.Tasks { /* match exact t.Name before restarting */ }\n}","handlingStrategy":"validation","validationCode":"// Derive task names from the alloc's job instead of hardcoding\nalloc, _, err := client.Allocations().Info(allocID, nil)\nif err != nil { return err }\nvalid := map[string]bool{}\nfor _, tg := range alloc.Job.TaskGroups {\n  for _, t := range tg.Tasks { valid[t.Name] = true }\n}\nif !valid[taskName] { return fmt.Errorf(\"task %q not in alloc %s\", taskName, allocID) }","typeGuard":null,"tryCatchPattern":"err := client.Allocations().Restart(allocID, taskName, nil)\nif err != nil && strings.Contains(err.Error(), \"Could not find task runner\") {\n  // list tasks via nomad alloc status and retry with a valid name\n}","preventionTips":["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"],"tags":["api","task-runner","name-mismatch","alloc-runner"],"backgroundTag":"task-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"}