fix: return undefined when session provider is missing#302860
Merged
bryanchen-d merged 4 commits intomainfrom Mar 18, 2026
Merged
fix: return undefined when session provider is missing#302860bryanchen-d merged 4 commits intomainfrom
bryanchen-d merged 4 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an unhandled error when attempting to load a contributed/remote chat session whose provider is no longer registered (e.g. extension uninstalled/disabled), by short-circuiting loadRemoteSession when the session scheme can’t be resolved.
Changes:
- Check the boolean result of
chatSessionService.canResolveChatSession(...)inloadRemoteSession(). - Return
undefinedearly when the provider cannot be resolved (instead of proceeding intogetOrCreateChatSessionand throwing).
Comments suppressed due to low confidence (1)
src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts:592
- This early return happens before checking
_sessionModelsfor an already-loaded model. Previously, even ifcanResolveChatSessionreturnedfalse(provider removed after load), the method could still return an existing in-memory session ref. With this change,loadRemoteSessionwill returnundefinedand callers may show the fallback UI despite having a usable cached model. Consider checkingacquireExistingSession(sessionResource)before thecanResolveChatSessionguard (or returning the existing ref even when the provider can’t be resolved).
private async loadRemoteSession(sessionResource: URI, location: ChatAgentLocation, token: CancellationToken): Promise<IChatModelReference | undefined> {
if (!await this.chatSessionService.canResolveChatSession(sessionResource.scheme)) {
return undefined;
}
// Check if session already exists
src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts
Outdated
Show resolved
Hide resolved
bhavyaus
approved these changes
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an unhandled error
Can not find provider for openai-codex:/...that occurs when a chat session's provider is no longer registered (e.g., extension uninstalled/disabled).Fixes #301203
Triggering Scenarios
openai-codex)Code Flow
AgentSessionHoverWidget.loadModel()callschatService.acquireOrLoadSession(resource)ChatServiceImpl.loadRemoteSession()callschatSessionService.canResolveChatSession(scheme)but discards the return valuechatSessionService.getOrCreateChatSession(resource)getOrCreateChatSession()callscanResolveChatSession()again internally and throws when it returnsfalseFix
In
loadRemoteSession():acquireExistingSession()— this ensures that if the session was already loaded into memory, it's returned even when the provider is no longer registered.canResolveChatSession()and returnundefinedwhen no provider exists, instead of proceeding to throw.This is consistent with the method's return type
Promise<IChatModelReference | undefined>and all callers already handleundefinedgracefully (e.g., the hover widget shows a fallback tooltip).Manual Validation
Changed Files
acquireExistingSession()check beforecanResolveChatSession()guard, and checkcanResolveChatSession()return value to returnundefinedinstead of proceeding to throw.acquireOrLoadSessionreturnsundefinedwhen no provider is registered.