Skip to content

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

fix(aui): defer host send by one macrotask to avoid race with composer clear

Steven Enamakel078883e61fd2
diff --git a/app/src/features/conversations/aui/queueAdapter.test.tsx b/app/src/features/conversations/aui/queueAdapter.test.tsx
index 8acdf29477..855ba17a23 100644
--- a/app/src/features/conversations/aui/queueAdapter.test.tsx
+++ b/app/src/features/conversations/aui/queueAdapter.test.tsx
@@ -39,13 +39,14 @@ describe('buildOpenHumanQueueAdapter', () => {
expect(adapter.steerItems).toEqual([]);
});
- it('sends both lanes through the host send path, which owns queue_mode', () => {
+ it('sends both lanes through the host send path, which owns queue_mode', async () => {
const send = vi.fn().mockResolvedValue(undefined);
const adapter = buildOpenHumanQueueAdapter({ items: [], send, remove: vi.fn() });
adapter.enqueue(append('idle send'));
adapter.steer(append('send while running'));
+ await waitFor(() => expect(send).toHaveBeenCalledTimes(2));
expect(send.mock.calls.map(([m]) => (m as AppendMessage).content)).toEqual([
[{ type: 'text', text: 'idle send' }],
[{ type: 'text', text: 'send while running' }],
@@ -57,8 +58,18 @@ describe('buildOpenHumanQueueAdapter', () => {
const adapter = buildOpenHumanQueueAdapter({ items: [], send, remove: vi.fn() });
expect(() => adapter.enqueue(append('x'))).not.toThrow();
+ await waitFor(() => expect(send).toHaveBeenCalledTimes(1));
+ });
+
+ it('hands the message to the host after the current task, not synchronously', async () => {
+ const send = vi.fn().mockResolvedValue(undefined);
+ const adapter = buildOpenHumanQueueAdapter({ items: [], send, remove: vi.fn() });
+
+ adapter.steer(append('x'));
await Promise.resolve();
- expect(send).toHaveBeenCalledTimes(1);
+ expect(send).not.toHaveBeenCalled();
+
+ await waitFor(() => expect(send).toHaveBeenCalledTimes(1));
});
it('forwards removal and ignores move/edit, which the core queue cannot do', () => {
diff --git a/app/src/features/conversations/aui/queueAdapter.ts b/app/src/features/conversations/aui/queueAdapter.ts
index e4fae8c1a0..293f301b0f 100644
--- a/app/src/features/conversations/aui/queueAdapter.ts
+++ b/app/src/features/conversations/aui/queueAdapter.ts
@@ -61,11 +61,17 @@ export function buildOpenHumanQueueAdapter({
}): ExternalThreadQueueAdapter {
const forward = (lane: 'enqueue' | 'steer') => (message: AppendMessage) => {
log('[aui-queue] %s → host send', lane);
- // The host send path reports its own failures (send-error banner); this
- // only keeps a rejection from going unhandled.
- send(message).catch((error: unknown) => {
- log('[aui-queue] %s send failed: %s', lane, error instanceof Error ? error.message : error);
- });
+ // One macrotask later, so the composer clear the runtime made just before
+ // calling us has reached the host draft first. The host restores a failed
+ // send by writing its draft back; a failure that landed before the clear
+ // (a disconnected socket fails at once) would be wiped out by it.
+ setTimeout(() => {
+ // The host reports its own failures (send-error banner); this only keeps
+ // a rejection from going unhandled.
+ send(message).catch((error: unknown) => {
+ log('[aui-queue] %s send failed: %s', lane, error instanceof Error ? error.message : error);
+ });
+ }, 0);
};
return {
items: toQueueItemStates(items),
diff --git a/app/src/pages/dev/assistant-ui-demo/assistantUiMock/mockScript.ts b/app/src/pages/dev/assistant-ui-demo/assistantUiMock/mockScript.ts
index a0225cc71b..72380db4e3 100644
--- a/app/src/pages/dev/assistant-ui-demo/assistantUiMock/mockScript.ts
+++ b/app/src/pages/dev/assistant-ui-demo/assistantUiMock/mockScript.ts
@@ -171,6 +171,33 @@ Both delegations are still working. Nothing about them blocks this turn, so I ca
excerpt: '<MessagePrimitive.GroupedParts groupBy={groupPartByType({ … })}>',
},
},
+ // Exercises the `media_generate_image` toolkit entry
+ // (`elements-image-generation` while running, then the `image` element).
+ {
+ kind: 'tool',
+ toolName: 'media_generate_image',
+ args: { prompt: 'a minimalist line-art fox reading a book' },
+ runMs: 1600,
+ result: {
+ artifacts: [
+ {
+ type: 'image',
+ source_url: 'https://picsum.photos/seed/openhuman-demo/512',
+ artifact_id: 'demo-image-1',
+ },
+ ],
+ },
+ },
+
+ // Exercises the `generate_document` toolkit entry (`elements-artifact-card`).
+ {
+ kind: 'tool',
+ toolName: 'generate_document',
+ args: { title: 'Demo transcript summary', sections: ['Overview', 'Findings'] },
+ runMs: 1200,
+ result: { title: 'Demo transcript summary', path: 'artifacts/demo-transcript-summary.docx' },
+ },
+
{ kind: 'text', text: ANSWER },
];
diff --git a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
index 9fd9103cce..d9b6a086be 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
@@ -306,6 +306,7 @@ async fn web_queue_status_wire_shape_and_clear_cleanup_remain_stable() {
"followups": 0,
"collects": 0,
"total": 0,
+ "items": [],
},
"logs": ["queue status retrieved"],
})
@@ -326,8 +327,80 @@ async fn web_queue_status_wire_shape_and_clear_cleanup_remain_stable() {
"followups": 0,
"collects": 0,
"total": 0,
+ "items": [],
},
"logs": ["no active turn for thread"],
})
);
}
+
+/// `channel.web_queue_remove` retracts exactly the named item, leaving the
+/// rest of the queue untouched, and emits `queue_item_removed`.
+#[tokio::test]
+async fn web_queue_remove_retracts_one_item_and_emits_event() {
+ let _serial = FORCED_ERROR_TEST_LOCK.lock().await;
+ let block = make_block();
+ set_test_run_chat_task_block(Some(block.clone())).await;
+ let thread_id = "queue-remove-one-item";
+ start_parked_turn(thread_id, &block).await;
+
+ assert_eq!(
+ queue_message(thread_id, "keep me", "followup").await["queued"],
+ true
+ );
+ assert_eq!(
+ queue_message(thread_id, "remove me", "steer").await["queued"],
+ true
+ );
+
+ let status = channel_web_queue_status(thread_id)
+ .await
+ .expect("status")
+ .into_cli_compatible_json()
+ .expect("status json");
+ let items = status["result"]["items"].as_array().expect("items");
+ assert_eq!(items.len(), 2);
+ let target_id = items
+ .iter()
+ .find(|item| item["lane"] == "steer")
+ .expect("steer item")["id"]
+ .as_str()
+ .expect("id")
+ .to_string();
+
+ let removed = channel_web_queue_remove("queue-test-client", thread_id, &target_id)
+ .await
+ .expect("remove")
+ .into_cli_compatible_json()
+ .expect("remove json");
+ assert_eq!(
+ removed,
+ json!({
+ "result": {
+ "thread_id": thread_id,
+ "item_id": target_id,
+ "removed": true,
+ },
+ "logs": ["queue item remove processed"],
+ })
+ );
+
+ let status_after = channel_web_queue_status(thread_id)
+ .await
+ .expect("status after remove")
+ .into_cli_compatible_json()
+ .expect("status after remove json");
+ let items_after = status_after["result"]["items"].as_array().expect("items");
+ assert_eq!(items_after.len(), 1);
+ assert_eq!(items_after[0]["lane"], "followup");
+
+ // Removing an id that no longer exists is a no-op, not an error.
+ let removed_again = channel_web_queue_remove("queue-test-client", thread_id, &target_id)
+ .await
+ .expect("remove again")
+ .into_cli_compatible_json()
+ .expect("remove again json");
+ assert_eq!(removed_again["result"]["removed"], false);
+
+ cancel_parked_turn(thread_id, &block).await;
+}