Skip to content

[Bug] 400 Bad Request when restoring conversation from persistence #131

@xinyi-gong

Description

@xinyi-gong

Environment

  • OS:
  • Eclipse Version:
  • Plugin Version:

Describe the bug
When restoring a conversation from persistent storage (history-based conversation), the first request to the LLM intermittently fails with a 400 Bad Request error:

To Reproduce

  1. Have a multi-turn conversation in Agent mode
  2. The conversation includes tool calls and assistant responses
  3. Restart the ide and restore the previous conversation
  4. First request fails with 400, subsequent retry succeeds

Expected behavior
Should have no error

Screenshots

Image

Root Cause
After debugging the CLS and inspecting the constructed messages array sent to the model API, two issues were found in how Eclipse reconstructs conversation turns from persistence:

  1. New user message not appended at the end
    When creating a history-based conversation, the current user message is placed as the first turn, and historical turns are appended after it. This results in the messages array ending with an assistant role message. Claude API requires the last message to be role: "user", so the request returns 400.

  2. Assistant response duplicated as user message
    When converting persisted CopilotTurnData back to Turn objects, the assistant's response text is incorrectly assigned to both the request field (user message) and response field (assistant message). This causes the LLM's previous reply to appear as a role: "user" message in the history, resulting in duplicated content and wasted tokens.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions