Skip to content

Commit 46b98ea

Browse files
committed
fix: show anonymous conversations in chat history
When user_id is 'anonymous', query also matches conversations where user_id is empty string, null, or undefined. This handles legacy data created before 'anonymous' was used as the default user_id.
1 parent 6dbbe7d commit 46b98ea

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

content-gen/src/backend/services/cosmos_service.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,34 @@ async def get_user_conversations(
439439
"""
440440
await self.initialize()
441441

442-
query = """
443-
SELECT TOP @limit c.id, c.user_id, c.updated_at, c.messages, c.brief
444-
FROM c
445-
WHERE c.user_id = @user_id
446-
ORDER BY c.updated_at DESC
447-
"""
448-
params = [
449-
{"name": "@user_id", "value": user_id},
450-
{"name": "@limit", "value": limit}
451-
]
442+
# For anonymous users, also include conversations with empty/null/undefined user_id
443+
# This handles legacy data before "anonymous" was used as the default
444+
if user_id == "anonymous":
445+
query = """
446+
SELECT TOP @limit c.id, c.user_id, c.updated_at, c.messages, c.brief
447+
FROM c
448+
WHERE c.user_id = @user_id
449+
OR c.user_id = ""
450+
OR c.user_id = null
451+
OR NOT IS_DEFINED(c.user_id)
452+
ORDER BY c.updated_at DESC
453+
"""
454+
params = [
455+
{"name": "@user_id", "value": user_id},
456+
{"name": "@limit", "value": limit}
457+
]
458+
else:
459+
# For authenticated users, only show their conversations
460+
query = """
461+
SELECT TOP @limit c.id, c.user_id, c.updated_at, c.messages, c.brief
462+
FROM c
463+
WHERE c.user_id = @user_id
464+
ORDER BY c.updated_at DESC
465+
"""
466+
params = [
467+
{"name": "@user_id", "value": user_id},
468+
{"name": "@limit", "value": limit}
469+
]
452470

453471
conversations = []
454472
async for item in self._conversations_container.query_items(

0 commit comments

Comments
 (0)