Hey, everyone!
I am getting a very strange bug with session states in my chat bot app. I store all messages as st.session_state.messages
and when I refresh the page, chat history persists. Even more strangely, it become visible to the other user - so sometimes I see other people unfinished conversation.
This is very untypical to my previous experience with Streamlit and everything written on the Forum where people usually complain that it does not keep session states on browser refresh (as it should not).
There is no cached functions and the app is pretty simple, and I would say that the code is pretty simple and straightforward, so I am deeply confused.
Browser cookies clearing does not have any impact, as well as changing streamlit version to 1.31 which I have used for much longer and never experienced anything similar. I debug this bt refreshing the browser and by opening a new browser session in incognito window where I see the previous chat history right upon opening. Different browsers are checked as well.
The worst thing is that this lead to cross-users chat history leaking. So sometimes I can see other people dialogues which is unacceptable. However, no external database communication is used so I do not even understand where do this information is stored.
I also have a feeling that this behaviour appered just recently, but do not have any proof here.
code used to init session state:
if "messages" not in st.session_state:
st.session_state.messages = initial_messages
code to show messages:
with st.container():
for message in st.session_state.messages:
if message["role"] != "system":
avatar = avatars.get(message["role"], "👤")
#time.sleep(1)
with st.chat_message(avatar):
st.markdown(message["content"])
and functions to append new messages:
def add_assistant_message(self, message: str):
if message and message != "":
st.session_state.messages.append({"role": "assistant", "content": message})
def add_user_message(self, message: str):
if message and message != "":
st.session_state.messages.append({"role": "user", "content": message})
Strewmlit version = 1.33
Python = 3.11
App url in streamlit cloud: https://betterway.streamlit.app/
Any help is deeply appreciated, plese share if you have met anything similar and what helped you to solve it.