Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss of Chat message response on chat switch mid response #4190

Open
4 tasks done
bekhruz-ti opened this issue May 8, 2024 · 1 comment
Open
4 tasks done

Loss of Chat message response on chat switch mid response #4190

bekhruz-ti opened this issue May 8, 2024 · 1 comment
Labels
🐞 bug Something isn't working

Comments

@bekhruz-ti
Copy link

bekhruz-ti commented May 8, 2024

Self Checks

  • This is only for bug report, if you would like to ask a quesion, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.6

Cloud or Self Hosted

Cloud and Self Hosted (Docker)

Steps to reproduce

  1. Start a conversation with an agent through the chat interface.
  2. While the agent is formulating a response, switch to a different chat with the same agent. (In the screenshot below, I switched from chat Greeting to Greeting myself and back)
  3. Return to the original chat.

image

This issue can be reproduced both in the Cloud and Self Hosted Docker versions of Dify.

✔️ Expected Behavior

When switching chats, the agent's entire response should be saved. This means that not only the part of the response generated before the chat switch, but also the full, completed response should be visible when returning to the original chat.

Ideally, the expected behavior is similar to the current behavior with starting different chats with the same agent on different browser tabs. In such a case, you can see the message being generated in real time as you switch between tabs, and the final version is properly saved.

❌ Actual Behavior

  • In the case when user switches the chat while the agent was responding, the agent's response is not saved and is not visible when returning to the original chat. In fact on return user does not even see the message they initially wrote to trigger the agent, that message only becomes available on page reload (ctrl + R) however the agent message bubble remains empty.

image

As a side note,

  • If the ChatStopAPI functionality is disabled, the cutoff response will appear but only after a page reload. ChatStopAPI is prematurely terminating the message generation process when a chat context switch occurs. Based on the behavior chat messages are being saved only on the agent_though event received from the backend which is cutoff on context switch due to ChatStopAPI call.
  • This limitation where ChatStopAPI cuts off chat completion response before agent_thought event is recieved also means if you hit Stop Responding Icon on the UI, the half-generated message will not be saved in DB and disappear on reload. See image below:

image

Copy link

dosubot bot commented May 8, 2024

To address the issue of losing chat message responses when switching between chats mid-response in Dify, you can implement a mechanism to save and restore the chat response state. This involves capturing the current state of the chat response before switching and restoring it upon returning to the original chat. Here's a concise approach:

  1. Save Current Chat Response: Before switching chats, capture and save the current state of the chat response. This can be achieved by modifying the handleConversationSwitch function to include logic for saving the current response state in a temporary storage solution, like local storage, keyed by the conversation ID.

  2. Restore Chat Response: Upon returning to a chat, check for a saved response state for the current conversation ID. If found, restore this state to the chat input field, allowing the agent to continue their response. After restoring, clear the saved response from storage to prevent it from being restored again unnecessarily.

Example implementation snippet:

// Modify handleConversationSwitch to save current chat response
const handleConversationSwitch = () => {
  const currentResponse = getCurrentChatResponse(); // Implement based on your chat input management
  localStorage.setItem(`chatResponse_${currConversationId}`, currentResponse);
}

// Restore chat response when returning to a chat
useEffect(() => {
  const savedResponse = localStorage.getItem(`chatResponse_${currConversationId}`);
  if (savedResponse) {
    restoreChatResponse(savedResponse); // Implement to restore chat response
    localStorage.removeItem(`chatResponse_${currConversationId}`);
  }
}, [currConversationId]);

Ensure to adapt this example to fit your application's specific data structures and state management approaches. This solution should prevent the loss of chat message responses during chat switches.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@dosubot dosubot bot added the 🐞 bug Something isn't working label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant