Issue with Assistant API - “Cannot Add Message to Thread Due to Active Run”

Hello OpenAI Team,

I am experiencing an issue while using the Assistant API. Often, when trying to add a message to a thread, I receive an error stating:

Error: 400 Can't add messages to thread_Q0xWQ629YGYYCK0IjwZSFcXY while a run run_x56KLMwFzb3tCAIQkcRz11Et is active.

However, when I call the API to check for active runs (active_runs), it consistently returns that no active runs exist. This creates a loop where the user is stuck in a bug, and we are unsure how to resolve it.

Could you please provide guidance on how to address this issue or clarify if it’s a known bug?

Thank you for your support!

Active runs? Do you mean https://api.openai.com/v1/threads/{thread_id}/runs

I’m not aware of a function that would show ‘active runs’ - just ‘runs’ on a thread?
You screen shots shows ‘pending’ as an empty array which might be for ‘queed’ runs?
Runs can have these statuses:
queued , in_progress , requires_action , cancelling , cancelled , failed , completed , incomplete , or expired
https://platform.openai.com/docs/api-reference/runs/object

So I would expect the message to be correct (ie there is an active run). You could also try/confirm this by cancelling the run specifcally and then retrying. Or waiting - since the run will time out as well automatically :slight_smile:

did you try canceling the run?

you should have a reference of run id when running,
sometimes api not returning the runs.

API Reference - OpenAI API

this happens to me when error is not handle correctly and the thread run (tool call) left in limbo.

Thank you @jlvanhulst and @jabolaso1 for your explanations.

Here is my code which I run before submitting a message to a thread Just for checking the errors and what’s going on.

As you can see, I fetch the list of in_progress, 'requires_action, queuedandincomplete` runs and then cancel them one by one.

P.S: the first “logger” is the first printed log in my previous screen shot (the empty runs’ array).

Also, it seems happen after running an AI Function.
Meanwhile, I am checking my implementations and the docs.
But it seems it happens lately and before (1 week ago) we didn’t have this issue.

Not sure why you want to cancel in progress runs but if you do - you should proably Await the cancel before trying to do something with the thread? The cancel(s) might not be ‘instant’?

1 Like

Some “runs” will not complete even I submit the output. That’s why I do this trick before sending a message to make sure all “runs” are cancelled.

for example: this run is still in “cancelling” process even after I’d killed my IOS app and opened the app again then tried to send a new message to a thread (assume 10-15 seconds):

That’s the thing that I need to solve, why running/cancelling a “run” takes a lot of time.