hashicorp/nomad · error

task %q not found in allocation

Error message

task %q not found in allocation

What it means

`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.

Source

Thrown at client/client.go:3078

		return nil, fmt.Errorf("nil allocation")
	}

	if len(taskNames) == 0 {
		return nil, fmt.Errorf("missing task names")
	}

	group := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
	if group == nil {
		return nil, fmt.Errorf("group name in allocation is not present in job")
	}

	verifiedTasks := make([]string, 0, len(taskNames))

	// confirm the requested task names actually exist in the allocation
	for _, taskName := range taskNames {
		if !taskIsPresent(taskName, group.Tasks) {
			logger.Error("task not found in the allocation", "task_name", taskName)
			return nil, fmt.Errorf("task %q not found in allocation", taskName)
		}
		verifiedTasks = append(verifiedTasks, taskName)
	}

	return verifiedTasks, nil
}

func taskIsPresent(taskName string, tasks []*structs.Task) bool {
	for _, task := range tasks {
		if task.Name == taskName {
			return true
		}
	}
	return false
}

// triggerDiscovery causes a Consul discovery to begin (if one hasn't already)
func (c *Client) triggerDiscovery() {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check the exact task name with `nomad alloc status <alloc>` (or the Job spec) and correct the typo
  2. Re-read the current job version's task list — the task may have been renamed or removed
  3. Use the API's allocation list endpoint to enumerate valid task names before requesting the operation

Example fix

// before
// nomad alloc logs 1a2b3c workr   // typo
verified, err := verifiedTasks(logger, alloc, []string{"workr"})
// after
verified, err := verifiedTasks(logger, alloc, []string{"worker"})
Defensive patterns

Strategy: validation

Validate before calling

tasks := taskNamesInAllocation(alloc) // from alloc status / job spec
for _, t := range requested {
    if !slices.Contains(tasks, t) {
        return fmt.Errorf("task %q not in allocation; valid: %v", t, tasks)
    }
}

Type guard

func taskIsPresent(name string, tasks []*structs.Task) bool {
    return slices.ContainsFunc(tasks, func(t *structs.Task) bool { return t.Name == name })
}

Try / catch

if err := streamLogs(alloc, task); err != nil {
    if strings.Contains(err.Error(), "not found in allocation") {
        return listValidTasks(alloc) // surface valid names to user
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/9b491c9f7388b276. Report an issue: GitHub.