fix(m0): retry failed LLM starts and never measure a foreign server
- A Strata install or start that never reached a server is saved as "failed" (not "partial"), so the next run retries the stage. - A launch that exits non-zero is not ready, even if something answers on the port afterwards. - Before the cold start, the stage stops if another program already listens on port 8080 and tells the user to close it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts" / "m0"))
|
||||
|
||||
from m0lib import common # noqa: E402
|
||||
from m0lib import common, llm # noqa: E402
|
||||
from m0lib.llm_client import ChatClient # noqa: E402
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
@@ -100,3 +100,44 @@ def test_chat_client_assembles_streamed_tool_call_and_timings(fake_server):
|
||||
assert a["usage"]["completion_tokens"] == 9
|
||||
# The first sentence ends at "요. ", before the whole answer is done.
|
||||
assert a["first_tool"] <= a["ttft"] <= a["first_sentence"] <= a["total"]
|
||||
|
||||
|
||||
# --- LLM stage: a failed start must not count as measured -------------------
|
||||
|
||||
|
||||
def _run_llm_stage(tmp_path, monkeypatch) -> dict:
|
||||
out = tmp_path / "results" / "llm_fast.json"
|
||||
out.parent.mkdir(parents=True)
|
||||
monkeypatch.setattr(sys, "argv", ["llm.py", "--out", str(out), "--work", str(tmp_path), "--opt", "model=fast"])
|
||||
llm.main()
|
||||
return json.loads(out.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def test_llm_stage_is_failed_when_strata_install_fails(tmp_path, monkeypatch):
|
||||
# A failed stage is retried on the next run; "partial" would be skipped.
|
||||
monkeypatch.setattr(llm.Strata, "install", lambda self: False)
|
||||
assert _run_llm_stage(tmp_path, monkeypatch)["status"] == "failed"
|
||||
|
||||
|
||||
def test_llm_stage_does_not_measure_another_server_on_the_port(tmp_path, monkeypatch, fake_server):
|
||||
port = int(fake_server.rsplit(":", 1)[1].split("/")[0])
|
||||
monkeypatch.setattr(llm, "PORT", port)
|
||||
monkeypatch.setattr(llm.Strata, "install", lambda self: True)
|
||||
monkeypatch.setattr(llm.Strata, "stop", lambda self: None)
|
||||
monkeypatch.setattr(llm.Strata, "plan", lambda self, preset, context: {})
|
||||
monkeypatch.setattr(llm.Strata, "status", lambda self: {})
|
||||
launched = []
|
||||
monkeypatch.setattr(llm.Strata, "launch", lambda self, *a, **k: launched.append(a) or {"ready": True})
|
||||
r = _run_llm_stage(tmp_path, monkeypatch)
|
||||
assert r["status"] == "failed"
|
||||
assert launched == []
|
||||
assert "server" not in r
|
||||
|
||||
|
||||
def test_strata_launch_that_fails_is_not_ready_even_if_a_server_answers(tmp_path, monkeypatch, fake_server):
|
||||
port = int(fake_server.rsplit(":", 1)[1].split("/")[0])
|
||||
monkeypatch.setattr(llm, "PORT", port)
|
||||
monkeypatch.setattr(llm, "run_logged", lambda *a, **k: 1)
|
||||
s = llm.Strata(tmp_path, tmp_path / "strata.log")
|
||||
monkeypatch.setattr(s, "supported_flags", lambda: set())
|
||||
assert s.launch(llm.PRESETS["fast"], 32768, parallel=1)["ready"] is False
|
||||
|
||||
Reference in New Issue
Block a user