Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app-prefixable/src/context/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ interface ProviderContextValue {
}
refetch: () => void
connectProvider: (providerID: string, apiKey: string) => Promise<boolean>
disconnectProvider: (providerID: string) => Promise<boolean>
startOAuth: (providerID: string, methodIndex: number) => Promise<OAuthAuthorization | undefined>
completeOAuth: (providerID: string, methodIndex: number, code?: string) => Promise<boolean>
}
Expand Down Expand Up @@ -447,6 +448,30 @@ export function ProviderProvider(props: ParentProps) {
}
}

async function disconnectProvider(providerID: string): Promise<boolean> {
try {
await client.auth.remove({ providerID })
setStore("modelsByAgent", produce((state) => {
for (const [agent, model] of Object.entries(state)) {
if (model.providerID !== providerID) continue
delete state[agent]
}
}))
setStore("sessionModels", produce((state) => {
for (const [sessionID, model] of Object.entries(state)) {
if (model.providerID !== providerID) continue
delete state[sessionID]
}
}))
await client.instance.dispose()
await refetchProviders()
return true
Comment on lines +451 to +472
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disconnectProvider returns false for any failure in the post-remove cleanup (client.instance.dispose() / refetchProviders()), even though the provider credentials may already have been removed successfully. That can leave the UI showing a disconnect failure (and possibly still showing the provider as connected) while the backend state has already changed, leading to confusing retries/404s and inconsistent in-memory state. Consider treating client.auth.remove success as the primary success criterion (return true once it succeeds), and run dispose/refetch in a best-effort try/catch (or surface a separate "refresh failed" warning) so the disconnect outcome isn’t misreported.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d91ccb7. client.auth.remove is now treated as the primary success condition, while the dispose/refetch refresh step is best-effort and only logs if it fails, so the UI no longer misreports a successful disconnect as a failure.

} catch (e) {
console.error("Failed to disconnect provider:", e)
return false
}
}

async function startOAuth(providerID: string, methodIndex: number): Promise<OAuthAuthorization | undefined> {
try {
const res = await client.provider.oauth.authorize({
Expand Down Expand Up @@ -526,6 +551,7 @@ export function ProviderProvider(props: ParentProps) {
},
refetch,
connectProvider,
disconnectProvider,
startOAuth,
completeOAuth,
}
Expand Down
Loading