diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java index e2251bd90d..de0d06b2bd 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java @@ -98,7 +98,6 @@ protected void doExecute(Task task, CreateInteractionRequest request, ActionList ActionListener internalListener = ActionListener.runBefore(actionListener, () -> context.restore()); ActionListener al = ActionListener.wrap(iid -> { cmHandler.updateConversation(cid, new HashMap<>(), getUpdateResponseListener(cid, iid, internalListener)); - // internalListener.onResponse(new CreateInteractionResponse(iid)); }, e -> { internalListener.onFailure(e); }); if (parintIid == null || traceNumber == null) { cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, additionalInfo, al); @@ -119,14 +118,14 @@ private ActionListener getUpdateResponseListener( return ActionListener.wrap(updateResponse -> { if (updateResponse != null && updateResponse.getResult() == DocWriteResponse.Result.UPDATED) { log - .info( + .debug( "Successfully updated the Conversation with ID: {} after interaction {} is created", conversationId, interactionId ); actionListener.onResponse(new CreateInteractionResponse(interactionId)); } else { - log.info("Failed to update the Conversation with ID: {} after interaction {} is created", conversationId, interactionId); + log.error("Failed to update the Conversation with ID: {} after interaction {} is created", conversationId, interactionId); actionListener.onResponse(new CreateInteractionResponse(interactionId)); } }, exception -> { diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java index 2db08f357b..fd62ad87c1 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java @@ -23,6 +23,8 @@ import org.opensearch.client.Requests; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.commons.ConfigConstants; +import org.opensearch.commons.authuser.User; import org.opensearch.core.action.ActionListener; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.ExistsQueryBuilder; @@ -144,11 +146,17 @@ public void getFinalInteractions(String conversationId, int lastNInteraction, Ac if (access) { innerGetFinalInteractions(conversationId, lastNInteraction, actionListener); } else { - throw new OpenSearchSecurityException("User does not have access to conversation " + conversationId); + String userstr = client + .threadPool() + .getThreadContext() + .getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT); + String user = User.parse(userstr) == null ? "" : User.parse(userstr).getName(); + throw new OpenSearchSecurityException("User [" + user + "] does not have access to conversation " + conversationId); } }, e -> { actionListener.onFailure(e); }); conversationMetaIndex.checkAccess(conversationId, accessListener); } catch (Exception e) { + log.error("Failed to get final interactions for conversation " + conversationId, e); actionListener.onFailure(e); } } diff --git a/ml-algorithms/src/test/java/org/opensearch/ml/engine/memory/MLMemoryManagerTests.java b/ml-algorithms/src/test/java/org/opensearch/ml/engine/memory/MLMemoryManagerTests.java index 1c2c25186e..aa9a2ba75d 100644 --- a/ml-algorithms/src/test/java/org/opensearch/ml/engine/memory/MLMemoryManagerTests.java +++ b/ml-algorithms/src/test/java/org/opensearch/ml/engine/memory/MLMemoryManagerTests.java @@ -253,7 +253,8 @@ public void testGetInteractions_NoAccessNoUser_ThenFail() { mlMemoryManager.getFinalInteractions("cid", 10, interactionListActionListener); ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); verify(interactionListActionListener, times(1)).onFailure(argCaptor.capture()); - assert (argCaptor.getValue().getMessage().equals("User does not have access to conversation cid")); + System.out.println(argCaptor.getValue().getMessage()); + assert (argCaptor.getValue().getMessage().equals("User [] does not have access to conversation cid")); } @Test