{"record":{"id":"ad782456efed95b7","repo":"Significant-Gravitas/AutoGPT","slug":"user-request-user-id-not-found","errorCode":null,"errorMessage":"User {request.user_id} not found","messagePattern":"User (.+?) not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"autogpt_platform/backend/backend/api/features/admin/rate_limit_admin_routes.py","lineNumber":224,"sourceCode":"    request: SetUserTierRequest,\n    admin_user_id: str = Security(get_user_id),\n) -> UserTierResponse:\n    \"\"\"Set a user's rate-limit tier. Admin-only.\n\n    Returns 404 if the user does not exist in the database.\n    \"\"\"\n    try:\n        resolved_email = await get_user_email_by_id(request.user_id)\n    except Exception:\n        logger.warning(\n            \"Failed to resolve email for user %s\",\n            request.user_id,\n            exc_info=True,\n        )\n        resolved_email = None\n\n    if resolved_email is None:\n        raise HTTPException(status_code=404, detail=f\"User {request.user_id} not found\")\n\n    old_tier = await get_user_tier(request.user_id)\n    logger.info(\n        \"Admin %s changing tier for user %s (%s): %s -> %s\",\n        admin_user_id,\n        request.user_id,\n        resolved_email,\n        old_tier.value,\n        request.tier.value,\n    )\n    try:\n        await set_user_tier(request.user_id, request.tier)\n    except Exception as e:\n        logger.exception(\"Failed to set user tier\")\n        raise HTTPException(status_code=500, detail=\"Failed to set tier\") from e\n\n    return UserTierResponse(user_id=request.user_id, tier=request.tier)\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/admin/rate_limit_admin_routes.py#L206-L242","documentation":"HTTP 404 from the admin set-tier endpoint: resolving request.user_id's email returned None (email lookup wrapped in try/except that swallows to None on exception, so both 'no such user' and 'lookup infrastructure error' surface as this 404). The tier change is refused before old_tier is read.","triggerScenarios":"POST the tier-set route with a request body user_id that has no User row — invalid/foreign UUID, deleted user — or when the email lookup throws (DB connectivity) and is swallowed to None, misreporting a live user as missing.","commonSituations":"Admin panel caches stale user ids after account deletion; environment mismatch (staging id against prod API); transient DB errors during the email lookup silently converted to 404; race where the user row is created after the tier call.","solutions":["Confirm the user_id exists in the same database the API targets","If the user should exist, check DB connectivity/logs — the 404 may mask a lookup exception","Retry once after confirming health, since transient lookup failures present identically","Cache-bust admin UI user lists so deleted users can't be selected for tier changes"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from uuid import UUID\nuid = UUID(request_user_id)\nassert await user_exists(uid), \"user must exist before setting tier\"","typeGuard":null,"tryCatchPattern":"if resp.status_code == 404:\n    # could be no-such-user OR a swallowed email-lookup exception — check DB health/logs\n","preventionTips":["Verify user existence before tier mutation in admin flows","Remember a transient DB error in email lookup presents as this same 404","Refresh admin user lists to avoid deleted accounts"],"tags":["http-404","user-lookup","user-id","rate-limit","tier"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}