{"record":{"id":"510cd2ab06c8f793","repo":"Significant-Gravitas/AutoGPT","slug":"user-not-found","errorCode":null,"errorMessage":"User not found.","messagePattern":"User not found\\.","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"autogpt_platform/backend/backend/api/external/v1/routes.py","lineNumber":110,"sourceCode":"        require_permission(APIKeyPermission.EXECUTE_BLOCK)\n    ),\n) -> CompletedBlockOutput:\n    # Sync block exec doesn't pass through ``add_graph_execution`` (no\n    # central enqueue), and external API routes use API-key auth instead\n    # of JWT so the JWT-based dep doesn't apply either. Inline strict\n    # gate with the same fail-closed (503-on-blip) posture as the dep —\n    # consistent with chat / internal block / internal graph routes.\n    await enforce_payment_paywall(auth.user_id)\n\n    obj = backend.blocks.get_block(block_id)\n    if not obj:\n        raise HTTPException(status_code=404, detail=f\"Block #{block_id} not found.\")\n    if obj.disabled:\n        raise HTTPException(status_code=403, detail=f\"Block #{block_id} is disabled.\")\n\n    user = await user_db.get_user_by_id(auth.user_id)\n    if not user:\n        raise HTTPException(status_code=404, detail=\"User not found.\")\n\n    try:\n        await charge_for_direct_block_execution(\n            user_id=auth.user_id, block=obj, input_data=data, source=\"external\"\n        )\n    except InsufficientBalanceError as e:\n        raise HTTPException(\n            status_code=status.HTTP_402_PAYMENT_REQUIRED, detail=str(e)\n        ) from e\n\n    # Direct block execution has no graph; build a minimal ExecutionContext\n    # carrying the caller's identity + timezone so blocks that depend on\n    # those (e.g. time blocks) get correct data.\n    execution_context = ExecutionContext(\n        user_id=auth.user_id,\n        user_timezone=get_user_timezone_or_utc(user.timezone),\n    )\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/external/v1/routes.py#L92-L128","documentation":"Raised (HTTP 404) by the external execute-block endpoint when the API key's `auth.user_id` does not resolve to a user via `user_db.get_user_by_id`. Authentication succeeded (a valid API key), but the backing user record is gone or unreachable, so execution cannot proceed (user record is needed for timezone and billing identity).","triggerScenarios":"POST `/blocks/{block_id}/execute` with an API key whose owner account was deleted, anonymized, or whose user row is missing due to a DB issue.","commonSituations":"API key survives user deletion (orphaned key); Supabase user removed without cleaning up API keys; test environments with keys pointing at seeded users that were wiped.","solutions":["Issue a new API key from an active user account and use that.","If you operate the platform, clean up API keys when users are deleted so keys can't outlive their owners.","Check the auth user id tied to the key (backend logs) and restore/recreate the user if the key must keep working."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    client.post(f\"/blocks/{block_id}/execute\", json=data)\nexcept HTTPError as e:\n    if e.response.status_code == 404 and \"User not found\" in e.response.text:\n        raise OrphanedApiKey(\"re-issue the API key from an active account\") from e\n    raise","preventionTips":["Rotate to a fresh API key if the owning account was deleted or recreated.","Operators: delete API keys alongside user deletion to avoid orphaned keys."],"tags":["blocks","user","not-found","api-key"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}