datawhalechina/hello-agents · error · HTTPException

未找到该饮食推荐 run

Error message

未找到该饮食推荐 run

What it means

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).

Source

Thrown at Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/api/routes/diet.py:135

    uid = user_id.strip()
    if not uid:
        raise HTTPException(status_code=400, detail="user_id 无效")
    return {"user_id": uid, "items": list_diet_runs_for_user(uid, limit=limit)}


@router.get("/diet/users/{user_id}/reflect_history")
async def diet_reflect_history(user_id: str, limit: int = 20):
    uid = user_id.strip()
    if not uid:
        raise HTTPException(status_code=400, detail="user_id 无效")
    return {"user_id": uid, "items": list_recent_diet_reflect(uid, limit=limit)}


@router.get("/diet/runs/{run_id}")
async def diet_run_detail(run_id: str):
    row = get_diet_run(run_id.strip())
    if not row:
        raise HTTPException(status_code=404, detail="未找到该饮食推荐 run")
    return row


@router.get("/diet/runs/{run_id}/observability")
async def diet_run_observability(run_id: str):
    """
    阶段 3:可观测性视图 — timeline / errors / replay 说明(trace 已持久化在 diet_runs)。
    """
    row = get_diet_run(run_id.strip())
    if not row:
        raise HTTPException(status_code=404, detail="未找到该饮食推荐 run")
    return build_diet_observability(row)


@router.post("/diet/runs/{run_id}/replay")
async def diet_run_replay(
    run_id: str,
    body: DietReplayRequest | None = Body(default=None),

View on GitHub (pinned to 606a07d341)

Solutions

  1. Re-run /diet/recommend to get a fresh diet_run_id and use that.
  2. Confirm the id matches exactly what the recommend response returned (no truncation, correct field).
  3. List the user's runs via GET /diet/users/{user_id}/runs to discover valid ids.

Example fix

# before
requests.get(f'{base}/diet/runs/00000000-0000-0000-0000-000000000000')  # 404

# after
runs = requests.get(f'{base}/diet/users/{uid}/runs').json()['items']
rid = runs[0]['diet_run_id']
requests.get(f'{base}/diet/runs/{rid}')
Defensive patterns

Strategy: validation

Validate before calling

run = requests.get(f"{base}/diet/runs/{quote(run_id.strip())}")
if run.status_code == 404:
    runs = requests.get(f"{base}/diet/users/{uid}/runs").json()["items"]
    run_id = runs[0]["diet_run_id"]  # recover a valid id

Try / catch

try:
    r = requests.get(f"{base}/diet/runs/{rid}")
    r.raise_for_status()
except HTTPError as e:
    if e.response.status_code == 404:
        log.warning("run %s not found; listing fresh runs", rid)
    raise

Prevention

When it happens

Trigger: 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).

Common situations: Bookmarking or logging a run URL and revisiting it after a DB reset; client storing the wrong field from the recommend response.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/6aa94770faaac077. Report an issue: GitHub.