Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Count only the retry loop's own sleeps in the JSON fallback backoff test (#12189)

Daniel Han9970dccb4770
diff --git a/studio/backend/tests/test_research_json_fallback.py b/studio/backend/tests/test_research_json_fallback.py
index 0444deec371..7fe9f8d4462 100644
--- a/studio/backend/tests/test_research_json_fallback.py
+++ b/studio/backend/tests/test_research_json_fallback.py
@@ -5,6 +5,7 @@
import asyncio
import json
+import threading
from types import SimpleNamespace
import httpx
@@ -514,8 +515,15 @@ def test_json_fallback_does_not_refund_transport_retries(monkeypatch, research_c
sent = []
delays = []
real_sleep = asyncio.sleep
-
- async def sleep(delay):
+ owner = threading.get_ident()
+
+ # `research_runs.asyncio` is the asyncio module, so this patches every event loop in
+ # the process; a TestClient portal another test left running polls with
+ # asyncio.sleep(0.1) from its own thread. Only this thread's sleeps are the retry
+ # loop's (see _capture_backoff in test_research_runs_hardening.py).
+ async def sleep(delay, *args, **kwargs):
+ if threading.get_ident() != owner:
+ return await real_sleep(delay, *args, **kwargs)
delays.append(delay)
await real_sleep(0)