From 79d6e8e2d7c121cac9e90776b6b355578d162e6a Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Tue, 10 Feb 2026 16:54:17 +0400 Subject: [PATCH] fix(frontend/credentials): Handle stale credential IDs in CredentialsSelect When a credential is deleted but the node still references its ID, CredentialsSelect now treats the stale ID as unselected and falls back to the first available credential instead of showing the raw ID. --- .../CredentialsSelect/CredentialsSelect.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsSelect/CredentialsSelect.tsx b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsSelect/CredentialsSelect.tsx index 9e1d312008..8f1b06f120 100644 --- a/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsSelect/CredentialsSelect.tsx +++ b/autogpt_platform/frontend/src/components/contextual/CredentialsInput/components/CredentialsSelect/CredentialsSelect.tsx @@ -42,11 +42,12 @@ export function CredentialsSelect({ } } + // Resolve the selected credential — treat stale/deleted IDs as unselected const selectedCredential = selectedCredentials ? credentials.find((c) => c.id === selectedCredentials.id) : null; - // When credentials exist and nothing is explicitly selected, + // When credentials exist and nothing is matched, // default to the first credential instead of "None" const effectiveCredential = selectedCredential ?? (credentials.length > 0 ? credentials[0] : null); @@ -73,21 +74,21 @@ export function CredentialsSelect({ provider: provider, }; - // Default to the first credential when any are available + // Use matched credential ID (not the raw selectedCredentials.id which may be stale) const defaultValue = - selectedCredentials?.id ?? + effectiveCredential?.id ?? (credentials.length > 0 ? credentials[0].id : "__none__"); // Notify parent when defaulting to a credential so the value is captured on submit const hasNotifiedDefault = useRef(false); useEffect(() => { if (hasNotifiedDefault.current) return; - if (selectedCredentials?.id) return; + if (selectedCredential) return; // Already matched — no need to override if (credentials.length > 0) { hasNotifiedDefault.current = true; onSelectCredential(credentials[0].id); } - }, [credentials, selectedCredentials?.id, onSelectCredential]); + }, [credentials, selectedCredential, onSelectCredential]); return (