Skip to content

fix(ai-chat): reset Copilot conversation when starting a new chat#1245

Merged
datlechin merged 1 commit into
mainfrom
fix/aichat-new-conversation-resets-copilot
May 13, 2026
Merged

fix(ai-chat): reset Copilot conversation when starting a new chat#1245
datlechin merged 1 commit into
mainfrom
fix/aichat-new-conversation-resets-copilot

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

AIChatViewModel.startNewConversation() cleared the local UI state (messages, active id, error) but never told CopilotChatProvider to drop its server-side conversationId. The next message sent after "new conversation" was attached to the prior server-side conversation, so the AI's response was contaminated by the previous chat's context.

switchConversation(to:) already calls AIProviderFactory.resetCopilotConversation(). startNewConversation() was missing the same call.

Fix

One line:

func startNewConversation() {
    AIProviderFactory.resetCopilotConversation()   // added
    cancelStream()
    persistCurrentConversation()
    messages.removeAll()
    activeConversationID = nil
    clearError()
}

This covers all four entry points that reach startNewConversation():

  • /clear slash command
  • /new slash command
  • handleFixError (when an SQL error is forwarded to AI)
  • The "+" button on the right-side chat header (UnifiedRightPanelView)

Why only Copilot

Most providers (OpenAI, Anthropic direct, Gemini) are stateless from the API's perspective — TablePro sends the entire conversation history each turn, so clearing local messages is sufficient. Copilot is the exception: the claude.ai Code API stores the conversation server-side and we send only the new turn plus the cached conversationId. That ID lives on CopilotChatProvider and survives across our local conversation boundaries unless we reset it.

Test plan

Pre-fix repro:

  1. Open AI Chat with Copilot provider.
  2. Ask: "remember the number 42".
  3. Click "+" to start a new conversation.
  4. Ask: "what number did I say?"
  5. Bug: the model answers "42".

Post-fix:
5. Model answers something like "I don't have any prior context."

@datlechin datlechin merged commit f315fdd into main May 13, 2026
2 checks passed
@datlechin datlechin deleted the fix/aichat-new-conversation-resets-copilot branch May 13, 2026 02:46
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.

1 participant