Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

serve: a request with no free slot gives the control lines back while it waits (long, long, short under parallel: 2 deadlocked: the slot a yielded read held needed the lines); regression test

Niko1221d9621d1e23b5
diff --git a/serve/server.py b/serve/server.py
index 2bb5e8a28..c67d5ef97 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -1231,16 +1231,29 @@ class StrataEngine:
while True:
if slot is None:
# a free slot (they free themselves at BDONE, which needs no control lines): the one that holds
- # the start of this prompt (its conversation's last turn), else the one used longest ago
- with self.slot_cv:
- while True:
+ # the start of this prompt (its conversation's last turn), else the one used longest ago.
+ # With none free the control lines are given back while waiting: a slot can be held by a read
+ # that gave way (BYIELD) and needs them to go on, so waiting with them is a deadlock - long,
+ # long, short at 0.25 s steps under parallel: 2 (ENGINE_REVIEW finding 1, reproduced in 0.1.41).
+ while True:
+ with self.slot_cv:
slot = self.pick_slot(prompt)
if slot is not None:
self.slot_busy[slot] = True
break
- self.slot_cv.wait(timeout=10.0)
- if cancel.is_set():
+ if holding:
+ self.ctl.release()
+ holding = False
+ with self.slot_cv:
+ if self.pick_slot(prompt) is None:
+ self.slot_cv.wait(timeout=1.0)
+ if cancel.is_set():
+ return
+ if not holding:
+ ok = yield from self._take_control(cancel, len(prompt))
+ if not ok:
return
+ holding, born = True, self.gen
if self._yielded is not None: # it gave way: the others waiting then go first
self.slot_held[slot] = list(prompt[:self._yielded[1]])
self._yielded = None
diff --git a/serve/test_parallel.py b/serve/test_parallel.py
index 429e2cf8f..bd834beab 100644
--- a/serve/test_parallel.py
+++ b/serve/test_parallel.py
@@ -387,6 +387,36 @@ class ParallelService(unittest.TestCase):
self.assertEqual(len(self.svc.history), 2)
self.assertFalse(any(self.engine.slot_busy))
+ def test_three_requests_long_long_short_do_not_deadlock(self):
+ """ENGINE_REVIEW finding 1 (0.1.41 check): two long prompts fill both slots, a short one arrives a moment later
+ and wants one of them (the yield path). The reviewer's repro: long, long, short at 0.25 s steps. Every
+ request must be answered; none may wait on the control lock that the yielding read holds."""
+ self.start(2)
+ texts = ["long " * 600, "lung " * 600, "short"]
+ res, errors = {}, []
+
+ def go(t):
+ t0 = time.time()
+ try:
+ r = self.chat(t, max_tokens=64)
+ res[t] = (r["choices"][0]["message"]["content"], time.time() - t0)
+ except Exception as e: # noqa: BLE001 - a timeout is the failure this test looks for
+ errors.append((t[:6], repr(e)))
+ threads = []
+ for t in texts:
+ th = threading.Thread(target=go, args=(t,))
+ th.start()
+ threads.append(th)
+ time.sleep(0.25)
+ for th in threads:
+ th.join(45)
+ self.assertFalse(any(th.is_alive() for th in threads), "a request never finished (deadlock)")
+ self.assertEqual(errors, [])
+ self.assertEqual(sorted(r[0] for r in res.values()), ["ok, done."] * 3)
+ self.assertFalse(any(self.engine.slot_busy))
+ with self.svc.status_lock:
+ self.assertEqual(len(self.svc.history), 3)
+
def test_an_admission_gives_way_too(self):
"""The same while another request decodes in a slot: the long one is being admitted, a short one waits."""
self.start(3)