|
29 | 29 | (loop [remaining (- deadline (System/currentTimeMillis))] |
30 | 30 | (when (pos? remaining) |
31 | 31 | (try |
32 | | - (Thread/sleep remaining) |
| 32 | + (Thread/sleep (long remaining)) |
33 | 33 | (catch InterruptedException _)) |
34 | 34 | (recur (- deadline (System/currentTimeMillis))))))) |
35 | 35 |
|
|
258 | 258 | :call-tool-mock |
259 | 259 | ;; Ensure that the tools complete in the 3-2-1 order by adjusting sleep times |
260 | 260 | (fn [name & _others] |
| 261 | + ;; When this is called, we are already in a future. |
261 | 262 | (case name |
262 | 263 |
|
263 | 264 | "ro_tool_1" |
264 | | - (do (deep-sleep 300) |
| 265 | + (do (deep-sleep 900) |
265 | 266 | {:error false |
266 | 267 | :contents [{:type :text :content "RO tool call 1 result"}]}) |
267 | 268 |
|
268 | 269 | "ro_tool_2" |
269 | | - (do (deep-sleep 200) |
| 270 | + (do (deep-sleep 600) |
270 | 271 | {:error false |
271 | 272 | :contents [{:type :text :content "RO tool call 2 result"}]}) |
272 | 273 |
|
|
329 | 330 | {:role :system :content {:type :progress :state :finished}}]} |
330 | 331 | (h/messages)))))) |
331 | 332 |
|
332 | | -(deftest tool-calls-with-prompt-stop |
| 333 | +(deftest tool-calls-with-prompt-stop-test |
333 | 334 | (testing "Three concurrent tool calls. Stopped before they all finished. Tool call 3 finishes. Calls 1,2 reject." |
334 | 335 | (h/reset-components!) |
335 | | - (let [{:keys [chat-id]} |
| 336 | + (let [wait-for-tool3 (promise) |
| 337 | + wait-for-tool2 (promise) |
| 338 | + wait-for-stop (promise) |
| 339 | + {:keys [chat-id]} |
336 | 340 | (complete! |
337 | 341 | {:message "Run 3 read-only tool calls simultaneously."} |
338 | 342 | {:api-mock |
|
344 | 348 | (on-prepare-tool-call {:id "call-1" :name "ro_tool_1" :arguments-text ""}) |
345 | 349 | (on-prepare-tool-call {:id "call-2" :name "ro_tool_2" :arguments-text ""}) |
346 | 350 | (on-prepare-tool-call {:id "call-3" :name "ro_tool_3" :arguments-text ""}) |
347 | | - (future (Thread/sleep 200) |
348 | | - (f.chat/prompt-stop {:chat-id chat-id} (h/db*) (h/messenger) (h/metrics))) |
| 351 | + (future (Thread/sleep 400) |
| 352 | + (when (= :timeout (deref wait-for-tool3 10000 :timeout)) |
| 353 | + (println "tool-calls-with-prompt-stop-test: deref in prompt stop future timed out")) |
| 354 | + (Thread/sleep 50) |
| 355 | + (f.chat/prompt-stop {:chat-id chat-id} (h/db*) (h/messenger) (h/metrics)) |
| 356 | + (deliver wait-for-stop true)) |
349 | 357 | (on-tools-called [{:id "call-1" :name "ro_tool_1" :arguments {}} |
350 | 358 | {:id "call-2" :name "ro_tool_2" :arguments {}} |
351 | 359 | {:id "call-3" :name "ro_tool_3" :arguments {}}]))) |
352 | 360 | :call-tool-mock |
353 | 361 | (fn [name & _others] |
| 362 | + ;; When this is called, we are already in a future |
354 | 363 | (case name |
355 | 364 |
|
356 | 365 | "ro_tool_1" |
357 | | - (do (deep-sleep 350) |
| 366 | + (do (deep-sleep 1000) |
| 367 | + (when (= :timeout (deref wait-for-tool2 10000 :timeout)) |
| 368 | + (println "tool-calls-with-prompt-stop-test: deref in tool 1 timed out")) |
358 | 369 | {:error false |
359 | 370 | :contents [{:type :text :content "RO tool call 1 result"}]}) |
360 | 371 |
|
361 | 372 | "ro_tool_2" |
362 | | - (do (deep-sleep 300) |
| 373 | + (do (deep-sleep 800) |
| 374 | + (when (= :timeout (deref wait-for-stop 10000 :timeout)) |
| 375 | + (println "tool-calls-with-prompt-stop-test: deref in tool 2 timed out")) |
| 376 | + (deliver wait-for-tool2 true) |
363 | 377 | {:error false |
364 | 378 | :contents [{:type :text :content "RO tool call 2 result"}]}) |
365 | 379 |
|
366 | 380 | "ro_tool_3" |
367 | | - (do (deep-sleep 100) |
| 381 | + (do (deep-sleep 200) |
| 382 | + (deliver wait-for-tool3 true) |
368 | 383 | {:error false |
369 | 384 | :contents [{:type :text :content "RO tool call 3 result"}]})))})] |
370 | 385 | (is (match? {chat-id |
|
0 commit comments