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
- Have a multi-turn conversation in Agent mode
- The conversation includes tool calls and assistant responses
- Restart the ide and restore the previous conversation
- First request fails with 400, subsequent retry succeeds
Expected behavior
Should have no error
Screenshots
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:
-
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.
-
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.
Environment
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
Expected behavior
Should have no error
Screenshots
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:
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.
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.