{"record":{"id":"5f4dac907a25cc3c","repo":"apache/hadoop","slug":"task-not-found-with-id-tid","errorCode":null,"errorMessage":"task not found with id {tid}","messagePattern":"task not found with id (.+?)","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"warning","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsWebServices.java","lineNumber":393,"sourceCode":"\n  @GET\n  @Path(\"/mapreduce/jobs/{jobid}/tasks/{taskid}/counters\")\n  @Produces({ MediaType.APPLICATION_JSON + \"; \" + JettyUtils.UTF_8,\n      MediaType.APPLICATION_XML + \"; \" + JettyUtils.UTF_8 })\n  public JobTaskCounterInfo getSingleTaskCounters(\n      @Context HttpServletRequest hsr, @PathParam(\"jobid\") String jid,\n      @PathParam(\"taskid\") String tid) {\n\n    init();\n    Job job = AMWebServices.getJobFromJobIdString(jid, ctx);\n    checkAccess(job, hsr);\n    TaskId taskID = MRApps.toTaskID(tid);\n    if (taskID == null) {\n      throw new NotFoundException(\"taskid \" + tid + \" not found or invalid\");\n    }\n    Task task = job.getTask(taskID);\n    if (task == null) {\n      throw new NotFoundException(\"task not found with id \" + tid);\n    }\n    return new JobTaskCounterInfo(task);\n  }\n\n  @GET\n  @Path(\"/mapreduce/jobs/{jobid}/tasks/{taskid}/attempts\")\n  @Produces({ MediaType.APPLICATION_JSON + \"; \" + JettyUtils.UTF_8,\n      MediaType.APPLICATION_XML + \"; \" + JettyUtils.UTF_8 })\n  public TaskAttemptsInfo getJobTaskAttempts(@Context HttpServletRequest hsr,\n      @PathParam(\"jobid\") String jid, @PathParam(\"taskid\") String tid) {\n\n    init();\n    TaskAttemptsInfo attempts = new TaskAttemptsInfo();\n    Job job = AMWebServices.getJobFromJobIdString(jid, ctx);\n    checkAccess(job, hsr);\n    Task task = AMWebServices.getTaskFromTaskIdString(tid, job);\n    for (TaskAttempt ta : task.getAttempts().values()) {\n      if (ta != null) {","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsWebServices.java#L375-L411","documentation":"Returned as HTTP 404 by the JobHistoryServer REST task endpoints (e.g. getSingleTaskCounters) when the task id parsed successfully but job.getTask(taskID) returns null — the task does not exist within that job. The identifier is structurally valid but was never created by the job (wrong task number or wrong job embedded in the id).","triggerScenarios":"GET /ws/v1/history/mapreduce/jobs/job_1400000000000_0001/tasks/task_1400000000000_0001_m_999/counters where the job launched fewer than 1000 map tasks; also when the id's job portion refers to another job.","commonSituations":"Off-by-one when iterating task numbers discovered from a different source; Using an id from a retry/rerun of the job (new job id, different task numbering); Stale cached ids in a dashboard after the job was rerun","solutions":["Fetch the task list (GET .../tasks) and verify the exact id exists before requesting counters/attempts","Ensure the jobid path segment and the job portion of the taskid string match","Refresh any cached task ids after job reruns"],"exampleFix":"# before\ncurl \"http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks/task_1400000000000_0001_m_999/counters\" # 404\n\n# after\nids=$(curl -s \"http://jhs:19888/ws/v1/history/mapreduce/jobs/$JID/tasks\" | jq -r '.tasks.task[].id')\necho \"$ids\" | grep task_1400000000000_0001_m_ # pick a real id, then fetch counters","handlingStrategy":"validation","validationCode":"Set<String> known = jhsClient.listTaskIds(jid); // GET .../tasks\nif (!known.contains(tid)) {\n  // id is valid-shaped but absent: refresh listing or fail with context\n}","typeGuard":null,"tryCatchPattern":"try { info = jhsClient.getTaskCounters(jid, tid); }\ncatch (NotFoundException e) {\n  if (e.getMessage().contains(\"task not found with id\"))\n    tid = resolveFreshTaskId(jid); // re-list and remap\n}","preventionTips":["Treat task ids as ephemeral per job run — refresh after reruns","Bound task numbers to the job's reported map/reduce counts before probing","Cache the task listing per job version instead of hard-coded task numbers"],"tags":["hadoop","mapreduce","jobhistory","rest","http-404","task-id","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}