{"record":{"id":"6aa94770faaac077","repo":"datawhalechina/hello-agents","slug":"run","errorCode":null,"errorMessage":"未找到该饮食推荐 run","messagePattern":"未找到该饮食推荐 run","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/api/routes/diet.py","lineNumber":135,"sourceCode":"    uid = user_id.strip()\n    if not uid:\n        raise HTTPException(status_code=400, detail=\"user_id 无效\")\n    return {\"user_id\": uid, \"items\": list_diet_runs_for_user(uid, limit=limit)}\n\n\n@router.get(\"/diet/users/{user_id}/reflect_history\")\nasync def diet_reflect_history(user_id: str, limit: int = 20):\n    uid = user_id.strip()\n    if not uid:\n        raise HTTPException(status_code=400, detail=\"user_id 无效\")\n    return {\"user_id\": uid, \"items\": list_recent_diet_reflect(uid, limit=limit)}\n\n\n@router.get(\"/diet/runs/{run_id}\")\nasync def diet_run_detail(run_id: str):\n    row = get_diet_run(run_id.strip())\n    if not row:\n        raise HTTPException(status_code=404, detail=\"未找到该饮食推荐 run\")\n    return row\n\n\n@router.get(\"/diet/runs/{run_id}/observability\")\nasync def diet_run_observability(run_id: str):\n    \"\"\"\n    阶段 3：可观测性视图 — timeline / errors / replay 说明（trace 已持久化在 diet_runs）。\n    \"\"\"\n    row = get_diet_run(run_id.strip())\n    if not row:\n        raise HTTPException(status_code=404, detail=\"未找到该饮食推荐 run\")\n    return build_diet_observability(row)\n\n\n@router.post(\"/diet/runs/{run_id}/replay\")\nasync def diet_run_replay(\n    run_id: str,\n    body: DietReplayRequest | None = Body(default=None),","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/api/routes/diet.py#L117-L153","documentation":"HTTP 404 raised by GET /diet/runs/{run_id} when get_diet_run(run_id.strip()) returns nothing — the diet recommendation run does not exist (or the id is whitespace/typo'd after stripping).","triggerScenarios":"GET /diet/runs/<unknown-id> with a run id never returned by /diet/recommend, a truncated id, or after the storage was reset/restarted (in-memory store).","commonSituations":"Bookmarking or logging a run URL and revisiting it after a DB reset; client storing the wrong field from the recommend response.","solutions":["Re-run /diet/recommend to get a fresh diet_run_id and use that.","Confirm the id matches exactly what the recommend response returned (no truncation, correct field).","List the user's runs via GET /diet/users/{user_id}/runs to discover valid ids."],"exampleFix":"# before\nrequests.get(f'{base}/diet/runs/00000000-0000-0000-0000-000000000000')  # 404\n\n# after\nruns = requests.get(f'{base}/diet/users/{uid}/runs').json()['items']\nrid = runs[0]['diet_run_id']\nrequests.get(f'{base}/diet/runs/{rid}')","handlingStrategy":"validation","validationCode":"run = requests.get(f\"{base}/diet/runs/{quote(run_id.strip())}\")\nif run.status_code == 404:\n    runs = requests.get(f\"{base}/diet/users/{uid}/runs\").json()[\"items\"]\n    run_id = runs[0][\"diet_run_id\"]  # recover a valid id","typeGuard":null,"tryCatchPattern":"try:\n    r = requests.get(f\"{base}/diet/runs/{rid}\")\n    r.raise_for_status()\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        log.warning(\"run %s not found; listing fresh runs\", rid)\n    raise","preventionTips":["Store the full diet_run_id unchanged right after /diet/recommend returns.","Never truncate or hand-type run ids; copy them programmatically.","Use the user's runs listing to reconcile stale ids."],"tags":["fastapi","http-404","diet-api","lookup"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}