Skip to content

A message sent while the conversation is still busy waits and goes by itself - #3037

Merged
davidmckayv merged 3 commits into
mainfrom
fix/queued-send-waits
Dec 5, 2026
Merged

davidmckayv merged 3 commits into
mainfrom
fix/queued-send-waits

Conversation

@davidmckayv

@davidmckayv davidmckayv commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

A message sent into a conversation that is still busy now waits and goes by itself. It never shows an error, and it is never drawn as sent before it runs.

The report (OpenBot Cloud, 2026-12-05). A person queued a message while their Bot worked and pressed Send now. Under the message they read Thread <the conversation's id> is locked, word for word. The message stayed on screen as if sent, and a second copy waited as queued ("Up next", Remove). They pressed Remove. The first copy still looked sent, nothing ran, and they had to type it again.

What actually happened (from the server's logs and the stored run events).

  • Send now stopped the turn over the conversation's socket. That Stop never reached the server's stop route, so the server gave the turn back to its queue, and 29 ms later another server carried the stopped turn on in a run of its own.
  • That run held the conversation's lock for 5.9 s. The queued message was sent 1.2 s after the Stop. The runtime refused it 409 "Thread lock denied" after the server's own 5 s lock retry. CopilotKit's client (@copilotkit/core 1.88, AgentThreadLockedError) turned the 409 into "Thread is locked", and stoppedReason passed those words straight to the screen.
  • The message had already been added to the transcript before the run, and nothing took it off. The queue also put it back (restoreIfRunFails), still marked Up next, and held the drain until the person started a turn. That is why there were two copies, and why Remove left one looking sent.
  • Neither the refused send nor Remove created anything on the server. The later resend ran normally.

The fix.

  • A refused send waits. A run refused because the conversation still has one going (the 409 shape, AgentThreadLockedError, and the event-stream shape, RUN_ERROR THREAD_ALREADY_RUNNING) shows nothing. Its message comes off the transcript and waits as queued, with Remove. It goes by itself once the conversation is free, with tries backing off from 0.5 s to 4 s. A live send the Bot was too busy for is parked too, not handed back to the box.
  • The server is asked first. After a Stop or a refusal, the queue asks whether a run is still going (the join-token read the app already uses) before it sends. While it waits, the message stays on screen as queued and is never drawn as sent in between.
  • Remove means never sent. A message removed while it waits is gone. Nothing sends it later, and nothing shows it as sent.
  • No ids, no raw upstream words. "Thread … is locked" and "Thread already running" become a plain sentence where a retry can't happen here (a later run of a turn): "The Bot was still finishing its last turn, so this step didn't start. Ask it to carry on." It comes with Carry on. Any upstream sentence that names something by a UUID is replaced with a plain one and sent to the console.
  • Stop reaches the server's stop route. Through the backend's event store, CopilotKit's Stop is stop_run on the socket only. The app now also calls the runtime's stop route, which takes the turn off the server's queue, so a stopped turn is not carried on. Over the plain event stream CopilotKit's Stop already is that route, so nothing is sent twice.

It works the same for built-in Bots and for any Bot connected over AG-UI. It is all on the runtime's own run, stop and join paths, with no private channel.

How the other assistants do it (searched 2026-12-05). Most of them agree: a message sent while a turn is going is queued, drawn as not yet started, sent without another press once the turn ends, and can be taken back so it never sends. None surfaces a busy or locked error.

Where it runs

  • New state that outlives a request? None. The queue, its back-off and the "ask first" flag live in the open conversation in the browser, as the queue always has.
  • What happens on the second replica? The "is a run going" answer comes from the join-token read, which every replica answers from the same store. A send refused by any replica's lock is waited out the same way.
  • Anything serialised? The thread lock does that, as before. This only waits for it.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: resolve, decide, audit, then act.
  • New refusals and new failures each write a row. None added.
  • Nothing new is trusted from the client that the server can resolve itself.

API and database

  • This changes nothing under api/, no app's requests, no database change and no release-policy.json. The Stop now also calls the runtime's existing stop route, which the app already called for a turn the server carries.

Changelog

Conversations.

  • Fixed: a message sent while the Bot is still finishing waits and goes by itself. Sending, or pressing Send now on a queued message, while the conversation is still busy no longer shows "Thread … is locked" or leaves the message looking sent. It waits as queued, with Remove, and goes once the Bot is free. Removed, it never goes.
  • Fixed: Stop stops a turn the server was carrying. Stopping a Bot on OpenBot Cloud's path no longer lets the server carry the stopped turn on in a run of its own.
  • Fixed: no ids in a stopped turn's notice. Words from upstream that name a thread or a run by its id are replaced with a plain sentence.

Proof

Red on main, green here, in Chromium and WebKit (Safari's engine):

  • app/tests/queued-send-locked-browser.test.tsx: the real conversation in Intelligence mode, against a server that answers /run 409 "Thread lock denied" while the thread is held after a Stop sent as stop_run on the socket. Main: the Stop never reaches the stop route (0 calls), and the turn's words are lost. Here: the route is called once, the message waits with nothing said, it goes once, and it is drawn once.
  • app/tests/queued-send-busy-browser.test.tsx: the same over the plain event stream (RUN_ERROR THREAD_ALREADY_RUNNING), light and dark, 1280 px and 390 px. (1) Send now into a run still letting go waits, is refused at least once and never says so, then goes once. (2) Remove on a message waiting for the run to let go means it never runs and its words appear nowhere. Main fails both in both engines; here 16 of 16 pass.
  • app/tests/stopped-turn.test.ts: both shapes of a busy refusal, built from CopilotKit's own AgentThreadLockedError, are known and said in plain words with no id. A UUID in upstream words is never shown.
  • The existing queue, Carry on, failed-send and Stop suites pass (184 tests), with lint, format and typecheck.

Screens (fixed): the waiting message reads "Up next" with Remove under the stopped turn. The answer lands once, with nothing said about the refusal. Removed, the message is gone from the conversation.

… itself

Send now, or any send, into a conversation whose last run still held it on the server
showed "Thread <id> is locked" under the message, kept the message on screen as if
sent, and put a second copy in the queue. Removing that copy left the first one
looking sent, and nothing ran until the person typed it again.

A refused run is now a message that waits: it comes off the screen, waits as queued
with Remove, and goes once the conversation is free, asking the server first after a
Stop and backing off between tries. Removed, it never goes. Words from upstream that
name a thread or a run by its id are never shown; the person reads a plain sentence.

A Stop through the backend's event store now also reaches the server's stop route,
so the server does not carry the stopped turn on in a run of its own.
@davidmckayv
davidmckayv added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit 587f324 Dec 5, 2026
42 checks passed
@davidmckayv
davidmckayv deleted the fix/queued-send-waits branch December 5, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant