{"record":{"id":"cee05f8c8418db66","repo":"Significant-Gravitas/AutoGPT","slug":"credential-to-upgrade-not-found","errorCode":null,"errorMessage":"Credential to upgrade not found","messagePattern":"Credential to upgrade not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"autogpt_platform/backend/backend/api/features/integrations/router.py","lineNumber":975,"sourceCode":"\n    For providers without native incremental auth (e.g. GitHub), returns the\n    union of existing + requested scopes.  For providers that handle merging\n    server-side (e.g. Google with ``include_granted_scopes``), returns the\n    requested scopes unchanged.\n\n    Raises HTTPException on validation failure.\n    \"\"\"\n    # Platform-owned system credentials must never be upgraded — scope\n    # changes here would leak across every user that shares them.\n    if is_system_credential(credential_id):\n        raise HTTPException(\n            status_code=status.HTTP_400_BAD_REQUEST,\n            detail=\"System credentials cannot be upgraded\",\n        )\n\n    existing = await creds_manager.store.get_creds_by_id(user_id, credential_id)\n    if not existing:\n        raise HTTPException(\n            status_code=status.HTTP_404_NOT_FOUND,\n            detail=\"Credential to upgrade not found\",\n        )\n    if not isinstance(existing, OAuth2Credentials):\n        raise HTTPException(\n            status_code=status.HTTP_400_BAD_REQUEST,\n            detail=\"Only OAuth2 credentials can be upgraded\",\n        )\n    if not provider_matches(existing.provider, provider.value):\n        raise HTTPException(\n            status_code=status.HTTP_400_BAD_REQUEST,\n            detail=\"Credential provider does not match the requested provider\",\n        )\n    if existing.is_managed:\n        raise HTTPException(\n            status_code=status.HTTP_400_BAD_REQUEST,\n            detail=\"Managed credentials cannot be upgraded\",\n        )","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/integrations/router.py#L957-L993","documentation":"In _prepare_scope_upgrade, after passing the system-credential check, the existing credential is fetched with creds_manager.store.get_creds_by_id(user_id, credential_id). If the lookup returns nothing (wrong ID, deleted credential, or credential owned by a different user), HTTP 404 'Credential to upgrade not found' is raised.","triggerScenarios":"Initiating a scope upgrade for a credential_id that was deleted (revoked/expired cleanup) between listing and clicking upgrade; passing an ID from another user or another environment; typo/mangled ID in the request.","commonSituations":"Stale frontend state after the user deleted the connection in another tab; environment mismatch (dev frontend talking to prod backend); credential ID truncated when passed through a URL or log.","solutions":["Re-fetch the user's credential list (GET /integrations/{provider}/credentials) and confirm the ID is present before retrying.","If the credential was deleted, re-authenticate the provider to create a fresh credential, then request the desired scopes during that flow.","Ensure the authenticated user matches the credential owner — the lookup is scoped by user_id.","Confirm frontend and backend point at the same environment so IDs resolve."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Confirm the credential exists before starting the upgrade flow\ncreds = (await client.get(f\"/integrations/{provider}/credentials\")).json()\nif credential_id not in {c[\"id\"] for c in creds}:\n    refresh_credential_list()  # stale state — don't call the upgrade/login API","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-validate IDs from server state right before use instead of trusting long-lived frontend state.","Handle the deletion-in-another-tab race by refreshing on focus.","Keep frontend/backend environment pairs consistent so IDs always resolve."],"tags":["oauth","credentials","http-404","stale-state"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}