Fix 400 Bad Request when restoring conversation from persistence#152
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes intermittent 400 Bad Request when restoring a history-based chat conversation by correcting how persisted turns are reconstructed and ordered before sending the first request to the language server/LLM.
Changes:
- Fix persisted assistant turns so the assistant response is no longer duplicated into the
Turn.request(user) field. - Insert historical turns before the current user message when creating a history-based conversation, ensuring the last message is the new user request.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java | Adjusts persisted turn conversion so assistant turns don’t populate the user request content. |
| com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java | Reorders turn insertion so historical turns precede the current user message to satisfy model API constraints. |
jdneo
approved these changes
May 8, 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.
fix #131
When restoring a history-based conversation, the first request to the LLM intermittently fails with a 400 Bad Request error. Two issues were found:
1. Assistant response duplicated as user message
In
ConversationDataFactory.convertToTurns(), the assistant's response text was incorrectly assigned to therequestfield of theTurnobject, causing the LLM's previous reply to appear as arole: "user"message in the history.Fix: Use an empty string for the
requestfield on assistant turns, keeping the response text only in theresponsefield.2. New user message not appended at the end
In
CopilotLanguageServerConnection.createConversation(), historical turns were appended after the current user message (addAll(turns)). SinceConversationCreateParamsplaces the current user message as the first turn, this resulted in the messages array ending with an assistant role message. Claude API requires the last message to berole: "user", causing a 400 error.Fix: Insert historical turns before the current user message using
addAll(0, turns).