Skip to content

Commit 19fd555

Browse files
committed
address review comments and resolve test failures
Signed-off-by: Stephanie <yangcao@redhat.com>
1 parent dec7a5e commit 19fd555

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/app/endpoints/conversations.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ async def get_conversation_endpoint_handler(
254254
status_code=status.HTTP_404_NOT_FOUND,
255255
detail={
256256
"response": "Conversation not found",
257-
"cause": f"Conversation {conversation_id} could not be deleted: no sessions found",
257+
"cause": f"Conversation {conversation_id} could not be retrieved.",
258258
},
259259
)
260260
session_id = str(agent_sessions[0].get("session_id"))
@@ -354,13 +354,12 @@ async def delete_conversation_endpoint_handler(
354354
agent_sessions = (await client.agents.session.list(agent_id=agent_id)).data
355355

356356
if not agent_sessions:
357-
logger.error("No sessions found for conversation %s", conversation_id)
358-
raise HTTPException(
359-
status_code=status.HTTP_404_NOT_FOUND,
360-
detail={
361-
"response": "Conversation not found",
362-
"cause": f"Conversation {conversation_id} could not be deleted: no sessions found",
363-
},
357+
# If no sessions are found, do not raise an error, just return a success response
358+
logger.info("No sessions found for conversation %s", conversation_id)
359+
return ConversationDeleteResponse(
360+
conversation_id=conversation_id,
361+
success=True,
362+
response="Conversation deleted successfully",
364363
)
365364

366365
session_id = str(agent_sessions[0].get("session_id"))

src/utils/endpoints.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ async def get_agent(
109109
await client.agents.delete(agent_id=orphan_agent_id)
110110
sessions_response = await client.agents.session.list(agent_id=conversation_id)
111111
logger.info("session response: %s", sessions_response)
112-
if not sessions_response or not sessions_response.data:
112+
try:
113+
session_id = str(sessions_response.data[0]["session_id"])
114+
except IndexError as e:
113115
logger.error("No sessions found for conversation %s", conversation_id)
114116
raise HTTPException(
115117
status_code=status.HTTP_404_NOT_FOUND,
116118
detail={
117119
"response": "Conversation not found",
118120
"cause": f"Conversation {conversation_id} could not be retrieved.",
119121
},
120-
)
121-
session_id = str(sessions_response.data[0]["session_id"])
122+
) from e
122123
else:
123124
conversation_id = agent.agent_id
124125
session_id = await agent.create_session(get_suid())

tests/unit/app/endpoints/test_conversations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,10 @@ async def test_successful_conversation_deletion(self, mocker, setup_configuratio
490490

491491
# Mock AsyncLlamaStackClientHolder
492492
mock_client = mocker.AsyncMock()
493+
# Ensure the endpoint sees an existing session so it proceeds to delete
494+
mock_client.agents.session.list.return_value = mocker.Mock(
495+
data=[{"session_id": VALID_CONVERSATION_ID}]
496+
)
493497
mock_client.agents.session.delete.return_value = None # Successful deletion
494498
mock_client_holder = mocker.patch(
495499
"app.endpoints.conversations.AsyncLlamaStackClientHolder"

0 commit comments

Comments
 (0)