From 89fcba69a1add360295192f8051033cef0977cbd Mon Sep 17 00:00:00 2001 From: Phelipe Lorran <112786693+httpsphl@users.noreply.github.com> Date: Fri, 2 Oct 2026 11:24:34 -0300 Subject: [PATCH 1/2] test(rpc): let the daemon read the request before the bot writes in race() On a slow runner the daemon could parse the bot's text before it took the request off the socket, so the text legitimately went out first. Wait 200 ms after sending, well under the 1 s the store is held. --- crates/botloftd/tests/rpc_queue.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/botloftd/tests/rpc_queue.rs b/crates/botloftd/tests/rpc_queue.rs index 906cd58b..74dbbcee 100644 --- a/crates/botloftd/tests/rpc_queue.rs +++ b/crates/botloftd/tests/rpc_queue.rs @@ -31,6 +31,10 @@ async fn race(c: &mut Crew, request: Value) -> Vec<&'static str> { }); is_locked.recv().expect("store held"); c.app.send_raw(&request.to_string()).await; + // Give the daemon time to take the request off the socket, so the text + // comes after it. Nothing shows when it has, but this is far below the + // time the store is held. + tokio::time::sleep(Duration::from_millis(200)).await; // The block that ends sends the text at once, without the timer. let stop = json!({ "type": "stream_event", "event": { "type": "content_block_stop", "index": 0 } }); From 8c811e4f6619c9744b2df5924a71dbae16ed6280 Mon Sep 17 00:00:00 2001 From: Phelipe Lorran <112786693+httpsphl@users.noreply.github.com> Date: Fri, 2 Oct 2026 11:38:40 -0300 Subject: [PATCH 2/2] test(rpc): wait with a thread sleep in race() With the store held, the runtime's timer did not fire until the hold ended, so the 200 ms tokio sleep lasted the whole second and the text then raced the files.list answer (Rust (Ubuntu) on #108). A thread sleep does not depend on that timer. --- crates/botloftd/tests/rpc_queue.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/botloftd/tests/rpc_queue.rs b/crates/botloftd/tests/rpc_queue.rs index 74dbbcee..d3376cbd 100644 --- a/crates/botloftd/tests/rpc_queue.rs +++ b/crates/botloftd/tests/rpc_queue.rs @@ -33,8 +33,9 @@ async fn race(c: &mut Crew, request: Value) -> Vec<&'static str> { c.app.send_raw(&request.to_string()).await; // Give the daemon time to take the request off the socket, so the text // comes after it. Nothing shows when it has, but this is far below the - // time the store is held. - tokio::time::sleep(Duration::from_millis(200)).await; + // time the store is held. A thread sleep, because the runtime's timers + // may not fire while the daemon's tasks wait for the store. + std::thread::sleep(Duration::from_millis(200)); // The block that ends sends the text at once, without the timer. let stop = json!({ "type": "stream_event", "event": { "type": "content_block_stop", "index": 0 } });