react-ag-ui: message queue drains while isSendDisabled is true (expose hold/release or honour isSendDisabled)
Package: @assistant-ui/react-ag-ui (seen on 0.0.58, still present in 0.0.62), @assistant-ui/core 0.3.21
What happens
With unstable_enableMessageQueue: true, useAgUiRuntime dispatches the next queued message as soon as the thread goes idle. It decides this with:
const queueBusy = isRunning || core.getPendingInterrupts() !== null;isSendDisabled is not considered. So when an app blocks sending after a run ends, the queue still sends every queued message. Examples:
- the stream dropped and the app is recovering the lost turn;
- the server refused the request and the app wants the user to resolve it first.
In our case each dispatched message is refused by our transport. It is left in the thread as a failed message. Its failed run then counts as busy→idle, which releases the next queued message, so the whole queue drains into failures.
Why we can't fix it from the app
@assistant-ui/core0.3.21 addedhold()/release()to the controller returned bycreateMessageQueue, which is exactly the pause we need. OnlyLocalThreadRuntimeCorecalls them (for voice).- In
useAgUiRuntimethe controller lives in a private ref. Only itsadapter(items, enqueue, steer, move, edit, remove) is passed to the store. - Switching
unstable_enableMessageQueueoff while blocked callsclear(), which drops the user's queued messages.
Suggested fix (either works)
- In
useAgUiRuntime, callhold()whileoptions.isSendDisabledis true andrelease()when it clears. The pause is separate from the Stop pause and the busy tracking, so it doesn't reset either. - Or expose the controller's
hold/releaseon the returned runtime (e.g.runtime.unstable_holdQueue()), so apps can pause the queue themselves.
Our workaround: a pnpm patch that adds || options.isSendDisabled === true to queueBusy. It has a side effect: notifyBusy() clears the pause that Stop sets, so a Stop-paused queue can drain after an unrelated isSendDisabled blip. That is why option 1 is the better fix.
Source: assistant-ui/assistant-ui