Thread messages disappearing after run completion
I'm building a chatbot using the Assistants API and some messages are disappearing from the thread after a run completes. The user message is there, but the assistant's response sometimes doesn't appear in the messages list.
run = client.beta.threads.runs.create_and_poll(
thread_id=thread.id,
assistant_id=assistant.id,
)if run.status == "completed":
messages = client.beta.threads.messages.list(thread_id=thread.id)
# Sometimes only shows the user message, no assistant response
The run status shows "completed" but the assistant message is missing. This happens about 10% of the time. Am I doing something wrong, or is this a known issue?
This is a known timing issue. After a run completes, there's a brief delay before the message appears in the messages list. Try adding a small delay or polling:
import timeif run.status == 'completed':
time.sleep(1) # Small delay
messages = client.beta.threads.messages.list(thread_id=thread.id)
We're working on a fix to ensure consistency.
Adding the 1-second delay fixed it! Haven't seen a missing message since. Thanks Jessica!
Log in to reply to this topic.