{"record":{"id":"4f3dc37eaa459058","repo":"hashicorp/nomad","slug":"task-q-not-started-yet-no-logs-available","errorCode":null,"errorMessage":"task %q not started yet. No logs available","messagePattern":"task %q not started yet\\. No logs available","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"client/fs_endpoint.go","lineNumber":445,"sourceCode":"\t\t}\n\n\t\thandleStreamResultError(err, code, encoder)\n\t\treturn\n\t}\n\n\t// Check that the task is there\n\ttaskState := allocState.TaskStates[req.Task]\n\tif taskState == nil {\n\t\thandleStreamResultError(\n\t\t\tfmt.Errorf(\"unknown task name %q\", req.Task),\n\t\t\tnew(int64(http.StatusBadRequest)),\n\t\t\tencoder)\n\t\treturn\n\t}\n\n\tif taskState.StartedAt.IsZero() {\n\t\thandleStreamResultError(\n\t\t\tfmt.Errorf(\"task %q not started yet. No logs available\", req.Task),\n\t\t\tnew(int64(http.StatusNotFound)),\n\t\t\tencoder)\n\t\treturn\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tframes := make(chan *sframer.StreamFrame, streamFramesBuffer)\n\terrCh := make(chan error)\n\n\t// Start streaming\n\tgo func() {\n\t\tif err := f.logsImpl(ctx, req.Follow, req.PlainText,\n\t\t\treq.Offset, req.Origin, req.Task, req.LogType, fs, frames); err != nil {\n\t\t\tselect {\n\t\t\tcase errCh <- err:\n\t\t\tcase <-ctx.Done():","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/fs_endpoint.go#L427-L463","documentation":"The logs endpoint found the requested task in the allocation's TaskStates, but StartedAt is zero, meaning the task has never actually started. Since no logs can exist before a task starts, the endpoint returns HTTP 404 with this message.","triggerScenarios":"Requesting logs for a task in pending state, a task waiting on image pull or driver startup, or a task whose start attempt failed — the alloc and task state exist, but the task process has never run.","commonSituations":"Immediately tailing logs after submitting a job while containers are still starting; tasks stuck pending due to missing artifacts, failed image pull, or placement constraints; dry-run/monitoring scripts hitting logs too early; prestart sidecar tasks that haven't fired yet.","solutions":["Wait until the task's ClientStatus is running (poll allocation info / TaskStates) before fetching logs.","Check the task's events and RecentEvent list to see why it hasn't started (image pull failure, artifact error).","Retry with backoff if the task is legitimately starting; treat as terminal if the task is stuck pending.","Inspect task startup failures via the alloc's task state events instead of the logs endpoint."],"exampleFix":"// before\nlogs, err := client.Allocs().Logs(alloc, true, \"web\", \"stdout\", nil, nil)\n// after\nfor {\n    a, _, _ := client.Allocations().Info(alloc.ID, nil)\n    ts := a.TaskStates[\"web\"]\n    if ts != nil && !ts.StartedAt.IsZero() {\n        break\n    }\n    time.Sleep(2 * time.Second)\n}\nlogs, err = client.Allocs().Logs(alloc, true, \"web\", \"stdout\", nil, nil)","handlingStrategy":"retry","validationCode":"a, _, err := client.Allocations().Info(allocID, nil)\nts := a.TaskStates[task]\nif ts == nil || ts.StartedAt.IsZero() {\n    return fmt.Errorf(\"task %q not started yet\", task)\n}","typeGuard":"func taskStarted(a *api.Allocation, task string) bool {\n    ts := a.TaskStates[task]\n    return ts != nil && !ts.StartedAt.IsZero()\n}","tryCatchPattern":"err := retry(10, 2*time.Second, func() error {\n    a, _, e := client.Allocations().Info(allocID, nil)\n    if e != nil {\n        return e\n    }\n    if !taskStarted(a, task) {\n        return errNotStarted\n    }\n    return fetchLogs(a, task)\n})","preventionTips":["Wait for StartedAt to be set before requesting logs.","Inspect task events for pending/failed starts before retrying indefinitely.","Bound retry attempts and surface why the task hasn't started."],"tags":["nomad","client","logs","task-not-started","http-404"],"backgroundTag":"task-not-started","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"}