{"record":{"id":"385bdf21afed109d","repo":"datawhalechina/hello-agents","slug":"task-task-id-not-found","errorCode":null,"errorMessage":"Task '{task_id}' not found","messagePattern":"Task '(.+?)' not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py","lineNumber":93,"sourceCode":"@app.post(\"/tasks\", response_model=TaskRecord)\ndef create_task(request: TaskCreateRequest) -> TaskRecord:\n    if request.agent_id not in set(registry.ids()):\n        raise HTTPException(status_code=404, detail=f\"Agent '{request.agent_id}' not found\")\n    return task_manager.create(request)\n\n\n@app.get(\"/tasks\")\ndef list_tasks() -> dict:\n    tasks = task_manager.list()\n    return {\"tasks\": tasks, \"total\": len(tasks)}\n\n\n@app.get(\"/tasks/{task_id}\", response_model=TaskRecord)\ndef get_task(task_id: str) -> TaskRecord:\n    try:\n        return task_manager.get(task_id)\n    except KeyError:\n        raise HTTPException(status_code=404, detail=f\"Task '{task_id}' not found\")\n\n\n@app.post(\"/tasks/{task_id}/run\", response_model=TaskRecord)\ndef run_task(task_id: str, background: bool = True) -> TaskRecord:\n    try:\n        task_manager.get(task_id)\n    except KeyError:\n        raise HTTPException(status_code=404, detail=f\"Task '{task_id}' not found\")\n    if background:\n        return task_runner.start_background(task_id)\n    return task_runner.run(task_id)\n\n\n@app.post(\"/batch/run\")\ndef run_batch(request: BatchRunRequest) -> dict:\n    try:\n        return {\"responses\": batch_runner.run(request.requests)}\n    except KeyError as exc:","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py#L75-L111","documentation":"GET /tasks/{task_id} returns HTTP 404 when task_manager.get(task_id) raises KeyError — the task id does not exist in the (in-memory or persisted) task store. Task ids are generated by POST /tasks, so any id not issued by that endpoint (or lost after a restart of an in-memory store) triggers this.","triggerScenarios":"GET /tasks/<stale-id> after the backend restarted with an in-memory task manager; a truncated/copy-pasted task id; querying a task created on a different backend instance.","commonSituations":"Backend restarts wiping in-memory task state; multiple environments (dev/prod) confusing saved task ids; typos in ids saved in scripts or notebooks.","solutions":["GET /tasks (list) to confirm which task ids currently exist, then use one of those.","If tasks must survive restarts, back task_manager with persistent storage instead of memory.","Re-create the task via POST /tasks if it was lost to a restart.","Double-check the id for truncation or whitespace when copying."],"exampleFix":"# before\nresp = requests.get(f\"{BASE}/tasks/{task_id}\")  # 404 after restart\n\n# after\nif resp.status_code == 404:\n    existing = {t[\"id\"] for t in requests.get(f\"{BASE}/tasks\").json()[\"tasks\"]}\n    if task_id not in existing:\n        task_id = requests.post(f\"{BASE}/tasks\", json=original_payload).json()[\"id\"]\n        resp = requests.get(f\"{BASE}/tasks/{task_id}\")","handlingStrategy":"try-catch","validationCode":"existing = {t[\"id\"] for t in requests.get(f\"{BASE}/tasks\").json()[\"tasks\"]}\nif task_id not in existing:\n    raise LookupError(f\"task {task_id} not found; recreate via POST /tasks\")","typeGuard":"def task_exists(task_id: str, existing_ids: set[str]) -> bool:\n    return task_id in existing_ids","tryCatchPattern":"try:\n    resp = requests.get(f\"{BASE}/tasks/{task_id}\")\n    resp.raise_for_status()\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        task = requests.post(f\"{BASE}/tasks\", json=original_create_payload).json()  # recreate after restart\n        task_id = task[\"id\"]\n    else:\n        raise","preventionTips":["Persist task ids durably on the client side; treat 404 as 'recreate'.","Back task_manager with persistent storage if ids must survive restarts.","Poll task status via the list endpoint to detect store resets."],"tags":["http-404","task-queue","state-management","fastapi"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}