Azure / Azure/azure-sdk-for-java

[BUG] chatClient.createChatThread reuses a old thread ID and sets thread to deleted.

Open
#47,688 14 comments 0 reactions 1 assignee Assigned to @AliRafiee View on GitHub
bug Communication - Chat customer-reported needs-team-attention
Dominant language
Java
Stars
2.6k
Forks
2.2k
Avg merge
2d 8h
Merged PRs (30d)
178

Description

**Describe the bug**
When creating a new chat thread using the SDK, sometimes the returned CreateChatThreadResult has the same threadID as an existing chat thread. Instead of creating a new chatThread it will add a message to an existing thread as a topic change. Also, sometimes it will set the thread to deleted.

***Exception or Stack Trace***
No failure message is sent from ACS because the create chatClient.createChatThread(createChatThreadOptions); returns information.

**To Reproduce**
Setup: Using Android, and using the ACS dependencies listed herein.
1) Obtain ACS token.
2) Use token to create ChatClient.
3) Use chatclient to createChatThread.
4) Observe and record threadId, message history and thread title for newly created chatThread,
5) Repeat steps 2 thru 4, in less than 10 tries, a returned threadID will be a reused threadId.
6) GET from /chat/threads?api-version=2025-03-15 for list of chat threads will show the reused threadId with the new topic name.
7) If the thread has not been set to "deletedOn", getting the message will show a topic name change in the history.

Note: Using a HTTP helper tool like Postman to create new Threads via the API does not cause this issue. Only when using the SDK does this issue happen.

***Code Snippet***

` public final class ChatClientSingleton {

// Volatile ensures visibility across threads
private static volatile ChatClient instance;

// Private constructor to prevent instantiation
private ChatClientSingleton() { }

/**
* Returns the singleton ChatClient instance.
*
* @param endpoint The ACS endpoint (e.g., "https://.communication.azure.com")
* @param accessToken The user access token for authentication
* @return ChatClient instance
*/
public static ChatClient getInstance(String endpoint, String accessToken) {
// First check without locking (fast path)
if (instance == null) {
synchronized (ChatClientSingleton.class) {
// Double-check inside synchronized block
if (instance == null) {
CommunicationTokenCredential credential = new CommunicationTokenCredential(accessToken);

instance = new ChatClientBuilder()
.endpoint(endpoint)
.credential(credential)
.buildClient();
}
}
}
return instance;
}
public String createChat(String title, List participantsList){
ChatClient chatClient = ChatClientSingleton.getInstance(acsBaseUrl, acsToken);;
CreateChatThreadOptions createChatThreadOptions = new CreateChatThreadOptions(title);
for(Participant participant : participantsList){
ChatParticipant threadParticipant = new ChatParticipant()
.setCommunicationIdentifier(new CommunicationUserIdentifier(participant.getAcsId()))
.setDisplayName(participant.getDisplayName());
createChatThreadOptions.addParticipant(threadParticipant);
}
CreateChatThreadResult result = chatClient.createChatThread(createChatThreadOptions);
return result.getChatThread().getId();
}
}
`

**Expected behavior**
The CreateChatThreadResult returned from ACS should always be a new threadId and never reuse an existing threadId. When creating a new chat, it should not set an existing thread to be deleted. When creating a new chat, it should not add a message as a topic changed to an existing thread.

**Screenshots**
Here is some returned JSON when calling the API directly via external HTTP tool like postman. Topic was created with DEC 29 name, and when making a new chat thread today, it treated like a chat thread update and added a message event for topicUpdated.
` {
"id": "1768249434087",
"type": "topicUpdated",
"sequenceId": "7",
"version": "1768249434087",
"content": {
"topic": "JAN 12 AF 22",
"initiatorCommunicationIdentifier": {
"rawId": "",
"communicationUser": {
"id": ""
}
}
},
"createdOn": "2026-01-12T20:23:54Z"
},
...,
{
"id": "1767024814780",
"type": "topicUpdated",
"sequenceId": "2",
"version": "1767024814780",
"content": {
"topic": "DEC 29",
"initiatorCommunicationIdentifier": {
"rawId": "",
"communicationUser": {
"id": ""
}
}
},
"createdOn": "2025-12-29T16:13:34Z"
},
{
"id": "1767024814752",
"type": "participantAdded",
"sequenceId": "1",
"version": "1767024814752",
"content": {
"participants": [
{... },
"createdOn": "2025-12-29T16:13:34Z"
}

,`

**Setup (please complete the following information):**
- OS: Android
- Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)]

implementation group: 'com.azure', name: 'azure-communication-chat', version: '1.6.1'
// https://mvnrepository.com/artifact/com.azure/azure-communication-common
implementation("com.azure:azure-communication-common:1.4.1")

// https://mvnrepository.com/artifact/com.azure/azure-messaging-eventhubs
implementation("com.azure:azure-messaging-eventhubs:5.21.1")
- Java version: 17
- App Server/Environment: n/a
- Frameworks: n/a

**Additional context**
Using Azure Gov.

**Information Checklist**
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x ] Bug Description Added
- [x ] Repro Steps Added
- [x ] Setup information Added

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.