launch: do not point at an engine log that was never written (#3714)
When the runtime refused the start because another host still owned the profile ('already has a live managed runtime'), no engine existed
and no log was written, but the error ended with 'The engine's log has the reason: <path>' and the screen showed an empty folder. A busy
profile now gets its own sentence (the other server, and strata launch --stop), and a log that is not on disk is no longer named, here or
in the sentence after an engine that stopped while loading.
This commit is contained in:
1 parent
5ef90cb96b
commit
5596cb2c5b
2 files changed
+101
-4
No files matched your search
@@ -1775,7 +1775,7 @@ class Runner:
|
||||
self.emit("start", f"Loading the model… {int(time.monotonic() - t0)} s", None)
|
||||
if "e" in box:
|
||||
self.end_failed_start()
|
||||
raise LaunchError(f"The server could not start: {box['e']}", _log_hint(self.config_path), 6)
|
||||
raise LaunchError(f"The server could not start: {box['e']}", _log_hint(self.config_path, box["e"]), 6)
|
||||
r = box["r"]
|
||||
if not r.get("ok"):
|
||||
text, nxt = explain_engine_exit(r, self.config_path, marks=self._marks, server_log=self.server_log_path())
|
||||
@@ -2390,14 +2390,35 @@ def explain_engine_exit(result: dict, config: Path | None, marks: dict | None =
|
||||
if not text.endswith((".", "!")):
|
||||
text += "."
|
||||
step = HSA_START_NEXT if hsa else next((words for pattern, words in KNOWN_CAUSES if pattern.search(" ".join([cause, str(why or "")]))), "Run it again; if it repeats, report the log.")
|
||||
return text, step + (f" The engine's log: {log}" if log else " The engine's log has the reason (strata logs, or the log named in the run config).")
|
||||
return text, step + _log_sentence(log)
|
||||
|
||||
|
||||
def _log_hint(config: Path | None) -> str:
|
||||
def _log_sentence(log: str | None) -> str:
|
||||
"""The sentence that points at the engine's log. A log that does not exist is not pointed at: a start that stopped before the engine
|
||||
existed (a profile whose runtime is still live, a missing engine package) never wrote one (#3714)."""
|
||||
if log and os.path.isfile(log):
|
||||
return f" The engine's log: {log}"
|
||||
if log:
|
||||
return " The engine did not get as far as writing its log, so the reason is in the lines above (`strata logs` has the server's own)."
|
||||
return " The engine's log has the reason (strata logs, or the log named in the run config)."
|
||||
|
||||
|
||||
#: what the runtime says when another host still owns the profile: the start never began, so there is no engine log to read.
|
||||
PROFILE_BUSY = re.compile(r"already has a live managed runtime", re.I)
|
||||
|
||||
|
||||
def _log_hint(config: Path | None, error: object = None) -> str:
|
||||
if PROFILE_BUSY.search(str(error or "")):
|
||||
return ("Another Strata server for this preset is still running or starting, so this start never began and there is no engine log for it. "
|
||||
"Run the command again; if it repeats, `strata launch --stop` ends the other server first.")
|
||||
log = None
|
||||
if config:
|
||||
try:
|
||||
log = read_config(config).get("log")
|
||||
except (OSError, ValueError):
|
||||
log = None
|
||||
return f"The engine's log has the reason: {log}" if log else "The engine's log has the reason (strata logs, or the log named in the run config)."
|
||||
if log and os.path.isfile(log):
|
||||
return f"The engine's log has the reason: {log}"
|
||||
if log:
|
||||
return "The engine did not get as far as writing its log, so the reason is the message above (`strata logs` has the server's own)."
|
||||
return "The engine's log has the reason (strata logs, or the log named in the run config)."
|
||||
@@ -0,0 +1,76 @@
|
||||
"""#3714: the launch hint named an engine log that was never written (the start stopped before the engine existed). Nothing here starts
|
||||
an engine or reads the real profile."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from strata_cli.launch import runner as R, settings as LS
|
||||
from strata_control.profiles import ProfileError
|
||||
from tests.terminal.launch_support import HW_12, Home, catalog
|
||||
|
||||
|
||||
class LogHint(unittest.TestCase):
|
||||
"""#3714: 'The engine's log has the reason: <path>' for a log that was never written (the start stopped before the engine existed)."""
|
||||
|
||||
def config(self, home: Home, log: Path) -> Path:
|
||||
path = home.base / "run.json"
|
||||
path.write_text('{"exe": "e", "args": [], "log": %s}' % json.dumps(str(log)), encoding="utf-8")
|
||||
return path
|
||||
|
||||
def test_a_busy_profile_gets_its_own_sentence_and_no_log_path(self):
|
||||
with Home() as h:
|
||||
log = h.base / "missing.log"
|
||||
text = R._log_hint(self.config(h, log), ProfileError("this profile already has a live managed runtime", 6))
|
||||
self.assertNotIn(str(log), text)
|
||||
self.assertIn("still running or starting", text)
|
||||
self.assertIn("strata launch --stop", text)
|
||||
|
||||
def test_a_log_that_does_not_exist_is_not_pointed_at(self):
|
||||
with Home() as h:
|
||||
log = h.base / "missing.log"
|
||||
text = R._log_hint(self.config(h, log), RuntimeError("something else"))
|
||||
self.assertNotIn(str(log), text)
|
||||
self.assertIn("did not get as far as writing its log", text)
|
||||
|
||||
def test_a_log_that_exists_is_still_pointed_at(self):
|
||||
with Home() as h:
|
||||
log = h.base / "engine.log"
|
||||
log.write_text("line\n", encoding="utf-8")
|
||||
self.assertEqual(R._log_hint(self.config(h, log), RuntimeError("x")), f"The engine's log has the reason: {log}")
|
||||
|
||||
def test_without_a_config_the_general_sentence_stays(self):
|
||||
self.assertIn("strata logs", R._log_hint(None))
|
||||
|
||||
def test_explain_engine_exit_does_not_name_a_missing_log_either(self):
|
||||
with Home() as h:
|
||||
log = h.base / "missing.log"
|
||||
text, nxt = R.explain_engine_exit({"state": "failed", "error": "server_exited"}, self.config(h, log))
|
||||
self.assertNotIn(str(log), nxt)
|
||||
self.assertIn("did not get as far as writing its log", nxt)
|
||||
log.write_text("[strata] out of memory\n", encoding="utf-8")
|
||||
text, nxt = R.explain_engine_exit({"state": "failed", "error": "server_exited"}, self.config(h, log))
|
||||
self.assertIn(f"The engine's log: {log}", nxt)
|
||||
|
||||
def test_start_reports_a_busy_profile_without_a_log_path(self):
|
||||
with Home() as h:
|
||||
log = h.base / "never-written.log"
|
||||
runner = R.Runner(LS.LaunchSettings(family="qwen", model="IQ3_XXS", context=32768, vision="off"), catalog=catalog(HW_12))
|
||||
runner.config_path = self.config(h, log)
|
||||
busy = ProfileError("this profile already has a live managed runtime", 6)
|
||||
with mock.patch.object(R.Runner, "stop_others"), mock.patch.object(R.Runner, "check_port_free"), \
|
||||
mock.patch.object(R.Runner, "log_marks", return_value={}), mock.patch.object(R.Runner, "end_failed_start"), \
|
||||
mock.patch.object(R.Runner, "start_wait", return_value=5), mock.patch.object(R.Runner, "emit"), \
|
||||
mock.patch("strata_control.runtime.status", return_value={"state": "stopped"}), \
|
||||
mock.patch("strata_control.runtime.start", side_effect=busy):
|
||||
with self.assertRaises(R.LaunchError) as raised:
|
||||
runner.start()
|
||||
self.assertIn("already has a live managed runtime", raised.exception.text)
|
||||
self.assertNotIn(str(log), raised.exception.next)
|
||||
self.assertIn("strata launch --stop", raised.exception.next)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user