Skip to content

Commit f8fd73c

Browse files
Merge pull request #901 from microsoft/pls-Fix-DeleteAll
fix: Enhance delete_all_conversations to handle transient connection error with a retry mechanism
2 parents 575d615 + 1e75b87 commit f8fd73c

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/api/api/history_routes.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,22 @@ async def delete_all_conversations(request: Request):
387387
user_id = authenticated_user["user_principal_id"]
388388
logger.info("DELETE /history/delete_all called")
389389

390-
# Get all user conversations
390+
# Get all user conversations.
391+
# NOTE: After the web page sits idle for >10 minutes, the first call
392+
# to Cosmos DB from this long-lived process can fail with a transient
393+
# connection-reset / token-expiry error. `history_service.get_conversations`
394+
# swallows that exception and returns []. Without the retry below,
395+
# "Clear all chat history" would then 404 -> get masked to 500 even
396+
# though chats actually exist. Single-conversation delete is unaffected
397+
# because it does not pre-list conversations. Retry once before giving up.
391398
conversations = await history_service.get_conversations(user_id, offset=0, limit=None)
399+
if not conversations:
400+
logger.info(
401+
"delete_all: initial get_conversations returned empty; "
402+
"retrying once to recover from possible idle-connection failure"
403+
)
404+
conversations = await history_service.get_conversations(user_id, offset=0, limit=None)
405+
392406
if not conversations:
393407
track_event_if_configured("DeleteAllConversationsNotFound", {
394408
"user_id": user_id
@@ -413,6 +427,10 @@ async def delete_all_conversations(request: Request):
413427
status_code=200,
414428
)
415429

430+
except HTTPException:
431+
# Let FastAPI translate HTTPException to its proper status code
432+
# instead of masking it as a 500 below.
433+
raise
416434
except Exception as e:
417435
logger.exception("Exception in /history/delete_all: %s", str(e))
418436
track_event_if_configured("AllConversationsDeleteError", {

0 commit comments

Comments
 (0)