Skip to content

fix: return undefined when session provider is missing#302860

Merged
bryanchen-d merged 4 commits intomainfrom
bryanchen-d/fix-missing-session-provider
Mar 18, 2026
Merged

fix: return undefined when session provider is missing#302860
bryanchen-d merged 4 commits intomainfrom
bryanchen-d/fix-missing-session-provider

Conversation

@bryanchen-d
Copy link
Contributor

@bryanchen-d bryanchen-d commented Mar 18, 2026

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

  • An extension registers a chat session provider with a custom scheme (e.g. openai-codex)
  • Sessions with that scheme are persisted in the sessions list
  • The extension is later uninstalled, disabled, or not yet activated
  • Hovering over such a session in the agent sessions view triggers the hover widget, which tries to load the session model

Code Flow

  1. AgentSessionHoverWidget.loadModel() calls chatService.acquireOrLoadSession(resource)
  2. ChatServiceImpl.loadRemoteSession() calls chatSessionService.canResolveChatSession(scheme) but discards the return value
  3. It unconditionally calls chatSessionService.getOrCreateChatSession(resource)
  4. getOrCreateChatSession() calls canResolveChatSession() again internally and throws when it returns false
  5. The error propagates as an unhandled promise rejection

Fix

In loadRemoteSession():

  1. First check for an already-cached session model via acquireExistingSession() — this ensures that if the session was already loaded into memory, it's returned even when the provider is no longer registered.
  2. Then check the return value of canResolveChatSession() and return undefined when no provider exists, instead of proceeding to throw.
    This is consistent with the method's return type Promise<IChatModelReference | undefined> and all callers already handle undefined gracefully (e.g., the hover widget shows a fallback tooltip).

Manual Validation

  1. Install an extension that registers a custom chat session provider
  2. Create sessions using that provider
  3. Disable/uninstall the extension
  4. Hover over one of the persisted sessions in the agent sessions view
  5. Verify: no unhandled error, fallback tooltip is displayed

Changed Files

  • src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts: Move acquireExistingSession() check before canResolveChatSession() guard, and check canResolveChatSession() return value to return undefined instead of proceeding to throw.
  • src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts: Add regression test verifying acquireOrLoadSession returns undefined when no provider is registered.

Copilot AI review requested due to automatic review settings March 18, 2026 15:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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(...) in loadRemoteSession().
  • Return undefined early when the provider cannot be resolved (instead of proceeding into getOrCreateChatSession and throwing).
Comments suppressed due to low confidence (1)

src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts:592

  • This early return happens before checking _sessionModels for an already-loaded model. Previously, even if canResolveChatSession returned false (provider removed after load), the method could still return an existing in-memory session ref. With this change, loadRemoteSession will return undefined and callers may show the fallback UI despite having a usable cached model. Consider checking acquireExistingSession(sessionResource) before the canResolveChatSession guard (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

@bryanchen-d bryanchen-d marked this pull request as ready for review March 18, 2026 21:00
@vs-code-engineering vs-code-engineering bot added this to the 1.113.0 milestone Mar 18, 2026
@bryanchen-d bryanchen-d merged commit ca52dc8 into main Mar 18, 2026
19 of 20 checks passed
@bryanchen-d bryanchen-d deleted the bryanchen-d/fix-missing-session-provider branch March 18, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Unhandled Error] Can not find provider for openai-codex:/...

3 participants