Skip to content

Commit 8315905

Browse files
committed
resolve comments
1 parent 1c9acf7 commit 8315905

3 files changed

Lines changed: 31 additions & 24 deletions

File tree

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/ConversationCreateParams.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public int hashCode() {
225225
result = prime * result
226226
+ Objects.hash(capabilities, chatMode, computeSuggestions, customChatModeId, model, needToolCallConfirmation,
227227
references, source, textDocument, userLanguage, workDoneToken, workspaceFolder, workspaceFolders,
228-
modelProviderName, todoList);
228+
modelProviderName, todoList, conversationId, restoreToTurnId);
229229
return result;
230230
}
231231

@@ -251,7 +251,9 @@ public boolean equals(Object obj) {
251251
&& Objects.equals(workDoneToken, other.workDoneToken) && Objects.equals(workspaceFolder, other.workspaceFolder)
252252
&& Objects.equals(workspaceFolders, other.workspaceFolders)
253253
&& Objects.equals(modelProviderName, other.modelProviderName)
254-
&& Objects.equals(todoList, other.todoList);
254+
&& Objects.equals(todoList, other.todoList)
255+
&& Objects.equals(conversationId, other.conversationId)
256+
&& Objects.equals(restoreToTurnId, other.restoreToTurnId);
255257
}
256258

257259
@Override
@@ -274,6 +276,8 @@ public String toString() {
274276
builder.append("customChatModeId", customChatModeId);
275277
builder.append("needToolCallConfirmation", needToolCallConfirmation);
276278
builder.append("todoList", todoList);
279+
builder.append("conversationId", conversationId);
280+
builder.append("restoreToTurnId", restoreToTurnId);
277281
return builder.toString();
278282
}
279283
}

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/persistence/ConversationDataFactory.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,37 +207,37 @@ public List<Turn> convertToTurns(List<AbstractTurnData> turnDataList) {
207207
// Defensive copy to avoid ConcurrentModificationException if another thread mutates the list while iterating.
208208
List<AbstractTurnData> snapshot = new ArrayList<>(turnDataList);
209209
List<Turn> result = new ArrayList<>(snapshot.size());
210-
Turn pendingTurn = null;
210+
Turn unpairedUserTurn = null;
211211

212212
for (AbstractTurnData turnData : snapshot) {
213213
if (turnData == null) {
214214
continue;
215215
}
216216
if (turnData instanceof UserTurnData userTurnData) {
217-
// Flush any pending turn without a response
218-
if (pendingTurn != null) {
219-
result.add(pendingTurn);
217+
// Flush any unpaired user turn without a response
218+
if (unpairedUserTurn != null) {
219+
result.add(unpairedUserTurn);
220220
}
221221
String requestText = userTurnData.getMessage() != null ? userTurnData.getMessage().getText() : "";
222222
Either<String, List<ChatCompletionContentPart>> request = Either
223223
.forLeft(requestText == null ? "" : requestText);
224-
pendingTurn = new Turn(request, null, null, turnData.getTurnId());
224+
unpairedUserTurn = new Turn(request, null, null, turnData.getTurnId());
225225
} else if (turnData instanceof CopilotTurnData copilotTurnData) {
226226
String responseText = extractResponseFromCopilotTurnData(copilotTurnData);
227-
if (pendingTurn != null) {
228-
// Pair the response with the pending user turn
229-
pendingTurn.setResponse(responseText);
230-
result.add(pendingTurn);
231-
pendingTurn = null;
227+
if (unpairedUserTurn != null) {
228+
// Pair the response with the unpaired user turn
229+
unpairedUserTurn.setResponse(responseText);
230+
result.add(unpairedUserTurn);
231+
unpairedUserTurn = null;
232232
} else {
233233
// Orphaned copilot turn (no preceding user turn), create a standalone turn
234234
result.add(new Turn(Either.forLeft(""), responseText, null, turnData.getTurnId()));
235235
}
236236
}
237237
}
238-
// Flush any remaining pending turn (user message without a response)
239-
if (pendingTurn != null) {
240-
result.add(pendingTurn);
238+
// Flush any remaining unpaired user turn (user message without a response)
239+
if (unpairedUserTurn != null) {
240+
result.add(unpairedUserTurn);
241241
}
242242
return result;
243243
}

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ChatView.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public class ChatView extends ViewPart implements ChatProgressListener, MessageL
111111
private String conversationId = "";
112112
private String subagentConversationId = null;
113113
private ConversationState conversationState = ConversationState.NEW_CONVERSATION;
114+
private CompletableFuture<?> persistUserTurnFuture = CompletableFuture.completedFuture(null);
114115
private Set<CompletableFuture<?>> conversationFutures = new HashSet<>();
115116
private IEventBroker eventBroker = PlatformUI.getWorkbench().getService(IEventBroker.class);
116117
private DragReferenceManager dragReferenceManager;
@@ -796,9 +797,12 @@ public void onChatProgress(ChatProgressValue value) {
796797
// Cache conversation progress on begin
797798
persistenceManager.cacheConversationProgress(this.conversationId, value);
798799

799-
// Set the CLS-assigned turnId on the last user turn that doesn't have one yet
800+
// Set the CLS-assigned turnId on the last user turn that doesn't have one yet.
801+
// Chain off persistUserTurnFuture to ensure the UserTurnData has been created first.
800802
if (StringUtils.isNotBlank(value.getTurnId())) {
801-
persistenceManager.setUserTurnId(this.conversationId, value.getTurnId());
803+
final String convId = this.conversationId;
804+
final String turnId = value.getTurnId();
805+
persistUserTurnFuture.thenRun(() -> persistenceManager.setUserTurnId(convId, turnId));
802806
}
803807

804808
// Hide handoff container when new turn starts
@@ -948,8 +952,8 @@ private void onSendInternal(String workDoneToken, String message, String agentSl
948952
if (conversationState == ConversationState.CONTINUED_CONVERSATION) {
949953
// Continue existing conversation - persist user message and send to existing conversation
950954
if (persistenceManager != null) {
951-
persistenceManager.persistUserTurnInfo(conversationId, null, processedMessage, activeModel,
952-
chatModeName, customChatModeId, currentFile, references);
955+
this.persistUserTurnFuture = persistenceManager.persistUserTurnInfo(conversationId, null, processedMessage,
956+
activeModel, chatModeName, customChatModeId, currentFile, references);
953957
}
954958

955959
// Get current todo list to sync with the server
@@ -994,11 +998,10 @@ private void onSendInternal(String workDoneToken, String message, String agentSl
994998
if (conversationState == ConversationState.NEW_HISTORY_BASED_CONVERSATION) {
995999
// Load turns from the history conversation and persist user turn with current conversation ID
9961000
turns = persistenceManager.loadConversationTurns(this.conversationId);
997-
persistenceManager.persistUserTurnInfo(this.conversationId, null, processedMessage, activeModel,
998-
chatModeName, customChatModeId, currentFile, references);
1001+
this.persistUserTurnFuture = persistenceManager.persistUserTurnInfo(this.conversationId, null,
1002+
processedMessage, activeModel, chatModeName, customChatModeId, currentFile, references);
9991003

10001004
// Set conversationId and last completed turnId for CLS server-side session restoration.
1001-
// Only use turnId from turns that have a response (completed turns), not cancelled ones.
10021005
restoredConversationId = this.conversationId;
10031006
if (turns != null && !turns.isEmpty()) {
10041007
for (int i = turns.size() - 1; i >= 0; i--) {
@@ -1018,8 +1021,8 @@ private void onSendInternal(String workDoneToken, String message, String agentSl
10181021
} else if (conversationState == ConversationState.NEW_CONVERSATION) {
10191022
// Generate a temporary ID for brand new conversation and persist user turn
10201023
this.conversationId = UUID.randomUUID().toString();
1021-
persistenceManager.persistUserTurnInfo(this.conversationId, null, processedMessage, activeModel,
1022-
chatModeName, customChatModeId, currentFile, references);
1024+
this.persistUserTurnFuture = persistenceManager.persistUserTurnInfo(this.conversationId, null,
1025+
processedMessage, activeModel, chatModeName, customChatModeId, currentFile, references);
10231026
}
10241027

10251028
CompletableFuture<ChatCreateResult> createConversationFuture = null;

0 commit comments

Comments
 (0)