datawhalechina/hello-agents · error · HTTPException
Task '{task_id}' not found
Error message
Task '{task_id}' not found What it means
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.
Source
Thrown at Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py:93
@app.post("/tasks", response_model=TaskRecord)
def create_task(request: TaskCreateRequest) -> TaskRecord:
if request.agent_id not in set(registry.ids()):
raise HTTPException(status_code=404, detail=f"Agent '{request.agent_id}' not found")
return task_manager.create(request)
@app.get("/tasks")
def list_tasks() -> dict:
tasks = task_manager.list()
return {"tasks": tasks, "total": len(tasks)}
@app.get("/tasks/{task_id}", response_model=TaskRecord)
def get_task(task_id: str) -> TaskRecord:
try:
return task_manager.get(task_id)
except KeyError:
raise HTTPException(status_code=404, detail=f"Task '{task_id}' not found")
@app.post("/tasks/{task_id}/run", response_model=TaskRecord)
def run_task(task_id: str, background: bool = True) -> TaskRecord:
try:
task_manager.get(task_id)
except KeyError:
raise HTTPException(status_code=404, detail=f"Task '{task_id}' not found")
if background:
return task_runner.start_background(task_id)
return task_runner.run(task_id)
@app.post("/batch/run")
def run_batch(request: BatchRunRequest) -> dict:
try:
return {"responses": batch_runner.run(request.requests)}
except KeyError as exc:View on GitHub (pinned to 606a07d341)
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.
Example fix
# before
resp = requests.get(f"{BASE}/tasks/{task_id}") # 404 after restart
# after
if resp.status_code == 404:
existing = {t["id"] for t in requests.get(f"{BASE}/tasks").json()["tasks"]}
if task_id not in existing:
task_id = requests.post(f"{BASE}/tasks", json=original_payload).json()["id"]
resp = requests.get(f"{BASE}/tasks/{task_id}") Defensive patterns
Strategy: try-catch
Validate before calling
existing = {t["id"] for t in requests.get(f"{BASE}/tasks").json()["tasks"]}
if task_id not in existing:
raise LookupError(f"task {task_id} not found; recreate via POST /tasks") Type guard
def task_exists(task_id: str, existing_ids: set[str]) -> bool:
return task_id in existing_ids Try / catch
try:
resp = requests.get(f"{BASE}/tasks/{task_id}")
resp.raise_for_status()
except HTTPError as e:
if e.response.status_code == 404:
task = requests.post(f"{BASE}/tasks", json=original_create_payload).json() # recreate after restart
task_id = task["id"]
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Backend restarts wiping in-memory task state; multiple environments (dev/prod) confusing saved task ids; typos in ids saved in scripts or notebooks.
Related errors
- Agent '{request.agent_id}' not found
- Session not found
- No report found for '{incident_id}'. Call POST /incidents/in
- 任务不存在
- 用户不存在
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/385bdf21afed109d.
Report an issue: GitHub.