{"record":{"id":"9b491c9f7388b276","repo":"hashicorp/nomad","slug":"task-q-not-found-in-allocation","errorCode":null,"errorMessage":"task %q not found in allocation","messagePattern":"task %q not found in allocation","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/client.go","lineNumber":3078,"sourceCode":"\t\treturn nil, fmt.Errorf(\"nil allocation\")\n\t}\n\n\tif len(taskNames) == 0 {\n\t\treturn nil, fmt.Errorf(\"missing task names\")\n\t}\n\n\tgroup := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\n\tif group == nil {\n\t\treturn nil, fmt.Errorf(\"group name in allocation is not present in job\")\n\t}\n\n\tverifiedTasks := make([]string, 0, len(taskNames))\n\n\t// confirm the requested task names actually exist in the allocation\n\tfor _, taskName := range taskNames {\n\t\tif !taskIsPresent(taskName, group.Tasks) {\n\t\t\tlogger.Error(\"task not found in the allocation\", \"task_name\", taskName)\n\t\t\treturn nil, fmt.Errorf(\"task %q not found in allocation\", taskName)\n\t\t}\n\t\tverifiedTasks = append(verifiedTasks, taskName)\n\t}\n\n\treturn verifiedTasks, nil\n}\n\nfunc taskIsPresent(taskName string, tasks []*structs.Task) bool {\n\tfor _, task := range tasks {\n\t\tif task.Name == taskName {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// triggerDiscovery causes a Consul discovery to begin (if one hasn't already)\nfunc (c *Client) triggerDiscovery() {","sourceCodeStart":3060,"sourceCodeEnd":3096,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/client.go#L3060-L3096","documentation":"`verifiedTasks` iterates the requested task names and throws \"task %q not found in allocation\" when a name is not present in the task group's Tasks list. This prevents operations (log streaming, exec, signals) against tasks that don't exist in the allocation, and logs the offending task name via the client logger before failing.","triggerScenarios":"Requesting logs/exec/signals for a task name that is not defined in the allocation's task group — e.g. a typo, a task removed in a newer job version, or a sidecar task name guessed incorrectly.","commonSituations":"CLI/API calls like `nomad alloc logs <alloc> <task>` with a misspelled task; scripts hardcoding task names from an older job version; querying an allocation from a deployment where the task was renamed or deleted.","solutions":["Check the exact task name with `nomad alloc status <alloc>` (or the Job spec) and correct the typo","Re-read the current job version's task list — the task may have been renamed or removed","Use the API's allocation list endpoint to enumerate valid task names before requesting the operation"],"exampleFix":"// before\n// nomad alloc logs 1a2b3c workr   // typo\nverified, err := verifiedTasks(logger, alloc, []string{\"workr\"})\n// after\nverified, err := verifiedTasks(logger, alloc, []string{\"worker\"})","handlingStrategy":"validation","validationCode":"tasks := taskNamesInAllocation(alloc) // from alloc status / job spec\nfor _, t := range requested {\n    if !slices.Contains(tasks, t) {\n        return fmt.Errorf(\"task %q not in allocation; valid: %v\", t, tasks)\n    }\n}","typeGuard":"func taskIsPresent(name string, tasks []*structs.Task) bool {\n    return slices.ContainsFunc(tasks, func(t *structs.Task) bool { return t.Name == name })\n}","tryCatchPattern":"if err := streamLogs(alloc, task); err != nil {\n    if strings.Contains(err.Error(), \"not found in allocation\") {\n        return listValidTasks(alloc) // surface valid names to user\n    }\n}","preventionTips":["Enumerate task names via `nomad alloc status` before task-specific calls","Avoid hardcoding task names; read them from the job spec or allocation","Update scripts when tasks are renamed or removed across job versions"],"tags":["nomad","client","tasks","not-found"],"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"}