Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(aui): deliver idle-thread messages one microtask later

Steven Enamakel4e36d71fcaee
diff --git a/app/src/features/conversations/aui/queueAdapter.test.tsx b/app/src/features/conversations/aui/queueAdapter.test.tsx
index 31d83be61c..ca8cb86f31 100644
--- a/app/src/features/conversations/aui/queueAdapter.test.tsx
+++ b/app/src/features/conversations/aui/queueAdapter.test.tsx
@@ -57,13 +57,20 @@ describe('buildOpenHumanQueueAdapter', () => {
await waitFor(() => expect(send).toHaveBeenCalledTimes(1));
});
- it('sends an idle-thread message straight through, synchronously (as onNew did)', () => {
- const send = vi.fn().mockResolvedValue(undefined);
- const adapter = buildOpenHumanQueueAdapter({ items: [], send, remove: vi.fn() });
+ it('sends an idle-thread message in the same task, like onNew (no timer)', async () => {
+ vi.useFakeTimers();
+ try {
+ const send = vi.fn().mockResolvedValue(undefined);
+ const adapter = buildOpenHumanQueueAdapter({ items: [], send, remove: vi.fn() });
- adapter.enqueue(append('idle'));
+ adapter.enqueue(append('idle'));
+ await Promise.resolve();
- expect(send).toHaveBeenCalledTimes(1);
+ // Delivered without any timer firing: the caller's `act()` sees it.
+ expect(send).toHaveBeenCalledTimes(1);
+ } finally {
+ vi.useRealTimers();
+ }
});
it('hands a mid-run message to the host after the current task, not synchronously', async () => {
diff --git a/app/src/features/conversations/aui/queueAdapter.ts b/app/src/features/conversations/aui/queueAdapter.ts
index c62f61add9..adc4066387 100644
--- a/app/src/features/conversations/aui/queueAdapter.ts
+++ b/app/src/features/conversations/aui/queueAdapter.ts
@@ -70,8 +70,12 @@ export function buildOpenHumanQueueAdapter({
log('[aui-queue] %s send failed: %s', lane, error instanceof Error ? error.message : error);
});
};
- // Idle thread: the runtime calls `enqueue` exactly where it used to call
- // `onNew`, so deliver synchronously and keep that path unchanged.
+ // Idle thread: the runtime calls `enqueue` where it used to call `onNew`.
+ // Deliver in the same task, one microtask on — which is where `onNew` ran
+ // before (the runtime awaited its tool-invocation cleanup first). That gap
+ // lets the composer clear reach the host draft before a send can fail and
+ // write the draft back; a host follow-up (the Lexical input will not submit
+ // while the runtime is running) always takes this lane.
const enqueue = (message: AppendMessage) => {
log('[aui-queue] enqueue (idle) → host send');
queueMicrotask(() => deliver('enqueue', message));