{"record":{"id":"9ce627cde35a2f54","repo":"apache/hadoop","slug":"task-not-found-with-id","errorCode":null,"errorMessage":"task not found with id {}","messagePattern":"task not found with id (.+?)","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebServices.java","lineNumber":186,"sourceCode":"    } catch (YarnRuntimeException e) {\n      // TODO: after MAPREDUCE-2793 YarnRuntimeException is probably not expected here\n      // anymore but keeping it for now just in case other stuff starts failing.\n      // Also, the webservice should ideally return BadRequest (HTTP:400) when\n      // the id is malformed instead of NotFound (HTTP:404). The webserver on\n      // top of which AMWebServices is built seems to automatically do that for\n      // unhandled exceptions\n      throw new NotFoundException(e.getMessage());\n    } catch (NumberFormatException ne) {\n      throw new NotFoundException(ne.getMessage());\n    } catch (IllegalArgumentException e) {\n      throw new NotFoundException(e.getMessage());\n    } \n    if (taskID == null) {\n      throw new NotFoundException(\"taskid \" + tid + \" not found or invalid\");\n    }\n    task = job.getTask(taskID);\n    if (task == null) {\n      throw new NotFoundException(\"task not found with id \" + tid);\n    }\n    return task;\n  }\n\n  /**\n   * convert a task attempt id string to an actual task attempt and handle all\n   * the error checking.\n   */\n  public static TaskAttempt getTaskAttemptFromTaskAttemptString(String attId, Task task)\n      throws NotFoundException {\n    TaskAttemptId attemptId;\n    TaskAttempt ta;\n    try {\n      attemptId = MRApps.toTaskAttemptID(attId);\n    } catch (YarnRuntimeException e) {\n      // TODO: after MAPREDUCE-2793 YarnRuntimeException is probably not expected here\n      // anymore but keeping it for now just in case other stuff starts failing.\n      // Also, the webservice should ideally return BadRequest (HTTP:400) when","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebServices.java#L168-L204","documentation":"The task id string parsed into a valid TaskId, but job.getTask(taskID) returned null: the running ApplicationMaster does not know this task under that job. AMWebServices reports it as HTTP 404 with 'task not found with id <tid>'.","triggerScenarios":"GET /ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid} (and its /counters, /attempts sub-resources) where the task id belongs to a different job, has a wrong sequence number or task-type letter, or the task never existed in this job.","commonSituations":"Task id reused from a previous run of the job (the job part embedded in the task id differs from {jobid}); copy-paste between jobs; querying after the job restarted so ids shifted; scripted iteration over stale ids.","solutions":["List tasks with GET /ws/v1/mapreduce/jobs/{jobid}/tasks and use an id from that response","Verify the job portion of the task id (task_<ts>_<seq>_...) equals the {jobid} in the URL","If the job already finished, query the Job History Server REST API (/ws/v1/history) instead of the AM"],"exampleFix":"// before: task id from job 0001 sent to job 0002\nGET /ws/v1/mapreduce/jobs/job_1401318629735_0002/tasks/task_1401318629735_0001_m_000003\n// 404 { \"task not found with id ...\" }\n\n// after: job part of the task id matches the URL\nGET /ws/v1/mapreduce/jobs/job_1401318629735_0001/tasks/task_1401318629735_0001_m_000003","handlingStrategy":"validation","validationCode":"// The task id embeds its job id: task_<ts>_<seq>_... must extend the URL's jid\nString expectedPrefix = \"task_\" + jid.substring(\"job_\".length());\nif (!tid.startsWith(expectedPrefix)) {\n  // task cannot belong to this job; skip the request or refresh the id\n}","typeGuard":"static boolean taskBelongsToJob(String tid, String jid) {\n  return tid != null && jid != null\n      && tid.startsWith(\"task_\" + jid.substring(4));\n}","tryCatchPattern":"try {\n  return getTask(jid, tid);\n} catch (javax.ws.rs.NotFoundException e) {\n  // id valid but unknown to this job: re-list tasks and retry once with a fresh id\n  tasks = listTasks(jid);\n}","preventionTips":["Store task ids together with the job id they came from","Refresh id lists after a job restarts or an AM failover","Treat 404 as 'unknown (job, task) pair', not only 'unknown task'"],"tags":["mapreduce","rest","http-404","applicationmaster","task-id"],"backgroundTag":"rest-resource-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}