Description
What happened?
When using CosmosChatMessageStore, calls to GetMessageCountAsync() and ClearMessagesAsync() always return 0, even when there are messages present in the container that can be retrieved via other methods.
What did you expect to happen?
GetMessageCountAsync() should return the actual number of messages for the given conversation, and ClearMessagesAsync() should delete the messages and return the count of removed items.
Steps to reproduce the issue:
- Initialize CosmosChatMessageStore with a valid connection string and container.
- Add messages to the store (or verify they exist).
- Call GetMessageCountAsync().
- Observe that it returns 0 regardless of the actual data.
Code Sample
var cosmosProvider = new CosmosChatMessageStore(
"AccountEndpoint=xxxx;AccountKey=xxxx",
"my-databaseid",
"my-container",
"my-conversationId");
// Retrieval works fine
var messages = await cosmosProvider.InvokingAsync(new ChatMessageStore.InvokingContext([]));
// Bug: Always returns 0
var count = await cosmosProvider.GetMessageCountAsync();
// Bug: No messages are deleted and returns 0
var removedMessagesCount1 = await cosmosProvider.ClearMessagesAsync();
Error Messages / Stack Traces
No exception is thrown; the methods silently fail to match any documents due to an incorrect property name in the underlying Cosmos DB SQL query.
Package Versions
Microsoft.Agents.AI.CosmosNoSql: 1.0.0-preview.260121.1
.NET Version
NET 10
Additional Context
The issue appears to be caused by a case-sensitivity mismatch in the query string.
In CosmosChatMessageStore.cs, the query uses c.Type = @type instead of c.type = @type (lowercase 't').
Description
What happened?
When using CosmosChatMessageStore, calls to GetMessageCountAsync() and ClearMessagesAsync() always return 0, even when there are messages present in the container that can be retrieved via other methods.
What did you expect to happen?
GetMessageCountAsync() should return the actual number of messages for the given conversation, and ClearMessagesAsync() should delete the messages and return the count of removed items.
Steps to reproduce the issue:
Code Sample
var cosmosProvider = new CosmosChatMessageStore( "AccountEndpoint=xxxx;AccountKey=xxxx", "my-databaseid", "my-container", "my-conversationId"); // Retrieval works fine var messages = await cosmosProvider.InvokingAsync(new ChatMessageStore.InvokingContext([])); // Bug: Always returns 0 var count = await cosmosProvider.GetMessageCountAsync(); // Bug: No messages are deleted and returns 0 var removedMessagesCount1 = await cosmosProvider.ClearMessagesAsync();Error Messages / Stack Traces
Package Versions
Microsoft.Agents.AI.CosmosNoSql: 1.0.0-preview.260121.1
.NET Version
NET 10
Additional Context
The issue appears to be caused by a case-sensitivity mismatch in the query string.
In
CosmosChatMessageStore.cs, the query usesc.Type = @typeinstead ofc.type = @type(lowercase 't').CosmosChatHistoryProvider): The bug seems to persist in the new implementation here: Line 555 in CosmosChatHistoryProvider.cs