Skip to content

Fix 400 Bad Request when restoring conversation from persistence#152

Merged
jdneo merged 2 commits into
mainfrom
tori/fix400
May 8, 2026
Merged

Fix 400 Bad Request when restoring conversation from persistence#152
jdneo merged 2 commits into
mainfrom
tori/fix400

Conversation

@xinyi-gong
Copy link
Copy Markdown
Member

@xinyi-gong xinyi-gong commented May 8, 2026

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 the request field of the Turn object, causing the LLM's previous reply to appear as a role: "user" message in the history.

Fix: Use an empty string for the request field on assistant turns, keeping the response text only in the response field.

2. New user message not appended at the end

In CopilotLanguageServerConnection.createConversation(), historical turns were appended after the current user message (addAll(turns)). Since ConversationCreateParams places 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 be role: "user", causing a 400 error.

Fix: Insert historical turns before the current user message using addAll(0, turns).

Copilot AI review requested due to automatic review settings May 8, 2026 06:33
Copy link
Copy Markdown
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 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 jdneo merged commit 86d147a into main May 8, 2026
4 checks passed
@jdneo jdneo deleted the tori/fix400 branch May 8, 2026 08:07
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.

[Bug] 400 Bad Request when restoring conversation from persistence

3 participants