From b6c2e01589c0d0d2bda3205b2bc7d6e04fc6c832 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 6 Oct 2026 10:36:01 +0200 Subject: [PATCH] serve: a request that meets a restart in progress gets an EngineDied, not an AttributeError (#1012) Found in the live smoke: an old request that learns its engine died while restart() has already taken the process (self.proc is None) failed in death_note() with an AttributeError, and its client got no reply at all. death_note(), alive() and _send() now read the process once and treat None as a dead engine. Test: after close() the death note is a sentence, alive() is False and a send raises EngineDied. --- serve/server.py | 8 +++++--- serve/test_restart_waiters.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/serve/server.py b/serve/server.py index e521432d..d6b1fc37 100644 --- a/serve/server.py +++ b/serve/server.py @@ -721,7 +721,8 @@ class StrataEngine: if "issue #29" in line: return ("The engine stopped itself because it had stopped making progress - a hang it caught. Its log " "line: " + line.strip() + " - please report it at github.com/Niko1221/Strata/issues.") - rc = self.proc.poll() + proc = self.proc # None while a restart has not started the next one yet + rc = proc.poll() if proc is not None else None if rc is not None and rc >= 0 and self.last_err: # its own last words on stdout: they say why return (f"The engine exited (code {rc}) after it reported: {self.last_err} - please report it at " "github.com/Niko1221/Strata/issues with the log.") @@ -734,7 +735,8 @@ class StrataEngine: "smaller model (Q2_0 / IQ2_XS).") def alive(self) -> bool: - return self.proc is not None and not getattr(self, "ended", False) and self.proc.poll() is None + proc = self.proc # read once: restart() / close() may set it to None meanwhile + return proc is not None and not getattr(self, "ended", False) and proc.poll() is None def exit_code(self): if self.proc is None: @@ -894,7 +896,7 @@ class StrataEngine: with self.wlock: self.proc.stdin.write(text + "\n") self.proc.stdin.flush() - except OSError: # the pipe is gone: the engine died (not the client) + except (OSError, AttributeError): # the pipe is gone (or a restart's close() took the process): raise EngineDied(f"the engine stopped unexpectedly (exit code {self.exit_code()})") from None def _control(self, cancel, on_token, stop_when=None): diff --git a/serve/test_restart_waiters.py b/serve/test_restart_waiters.py index 22360d23..9d20e28d 100644 --- a/serve/test_restart_waiters.py +++ b/serve/test_restart_waiters.py @@ -171,6 +171,19 @@ class RestartWaiters(unittest.TestCase): def test_killed_while_reading_with_others_arriving(self): self.killed_mid_read(2, 2) + def test_an_old_request_meets_a_restart_in_progress(self): + """A request that learns its engine died while restart() has already taken the process (self.proc is None): + its death note and its sends answer with EngineDied, not AttributeError (the client got no reply at all).""" + from serve.server import EngineDied + self.start(2) + self.kill() + self.engine.close() # what restart() does first + self.assertIsNone(self.engine.proc) + self.assertTrue(self.engine.death_note()) # a sentence, no AttributeError + self.assertFalse(self.engine.alive()) + with self.assertRaises(EngineDied): + self.engine._send("STOP") + def test_solo_engine_is_unchanged(self): self.start(4, fit=0) # the engine turns batching off self.kill()