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++
Save and launch saves the preset only after the restart question is answered Restart; the question names the running model and port
Niko12213b1ab2848d19
diff --git a/strata_cli/launch/app.py b/strata_cli/launch/app.pyindex 99da45a54..4f1a565f4 100644--- a/strata_cli/launch/app.py+++ b/strata_cli/launch/app.py@@ -45,6 +45,7 @@ class Ctx:move_data: bool = Falseretune: bool = Falserestart: bool = False+ pending_save: str | None = None # the preset name "Save as a preset and launch" saves once nothing blocks the launchnotes: list[str] = field(default_factory=list)start_own_files: bool = Falsepicked_in_list: bool = False@@ -275,7 +276,7 @@ class LaunchApp(App):self.cancel = threading.Event()self.runner = Runner(s, catalog=self.ctx.catalog, emit=self._emit, cancel=self.cancel, feed=self.ctx.feed, confirm=self._ask_from_run,move_data=self.ctx.move_data, retune=self.ctx.retune, restart=self.ctx.restart,- confirm_restart=self._ask_restart)+ confirm_restart=self._ask_restart, after_check=self._save_pending)gb = getattr(self.runner, "download_gb", lambda: 0.0)() if not confirmed else 0.0if gb >= 1.0:free = self.ctx.catalog.disk_free(s.data_dir or self.ctx.catalog.data_dir())@@ -299,6 +300,14 @@ class LaunchApp(App):self.running = Truethreading.Thread(target=self._work, daemon=True).start()+ def _save_pending(self) -> None:+ name, self.ctx.pending_save = self.ctx.pending_save, None+ if name:+ try:+ store.save(self.ctx.settings, name)+ except store.PresetError:+ pass+def _ask_restart(self, title: str, text: str) -> bool:"""Another model is serving other choices: ask once, in the same pop-up, whether to restart it. Cancel leaves it running."""return self._ask_from_run(title, text, [("go", "Restart"), ("no", "Cancel")], default=False)@@ -349,6 +358,7 @@ class LaunchApp(App):self.call_from_thread(screen.on_failure, f"Something unexpected went wrong: {type(e).__name__}: {e}")returnself.running = False+ self._save_pending() # a runner that never asked (nothing was running) still saves what was chosens = self.ctx.settingstry:if s.name and store.load(s.name, missing_ok=True) is not None:diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.pyindex b505e3018..8e6a7dc9f 100644--- a/strata_cli/launch/runner.py+++ b/strata_cli/launch/runner.py@@ -453,8 +453,10 @@ class Runner:cancel: threading.Event | None = None, feed: str | None = None, python: str | None = None,components_dir: str | None = None, hardware: dict | None = None,confirm: Callable[[str, str], bool] | None = None, assume_yes: bool = False, move_data: bool = False,- retune: bool = False, restart: bool = False, confirm_restart: Callable[[str, str], bool] | None = None):+ retune: bool = False, restart: bool = False, confirm_restart: Callable[[str, str], bool] | None = None,+ after_check: Callable[[], None] | None = None):self.s = s+ self.after_check = after_check # called once when nothing blocks the launch (no server, the same one, or "Restart" was answered): the screens save the preset thenself.restart = restart # --restart: a server that serves other choices (or holds this port) is stopped and replaced without askingself.confirm_restart = confirm_restart # the screens: asked (question, detail) once; True = restart. None (no screens) and no --restart: refuse in one lineself._stop_first: list[str] = [] # other launch profiles that hold this port; stopped before the measuring and the start@@ -1322,6 +1324,17 @@ class Runner:out.append({"profile": pid, "name": pid[7:], "port": port, "choices": self._saved_choices(pid)})return out+ def running_phrase(self, row: dict) -> str:+ """`Gyro-S is running on port 8080 with 32K` for the restart question."""+ c = row.get("choices") or {}+ title = None+ try:+ title = next((r.title for r in self.catalog.rows() if r.family == c.get("family") and r.model == c.get("model")), None)+ except Exception: # noqa: BLE001+ title = None+ title = title or ("Your model files" if c.get("model_path") else row["name"])+ return f"{title} is running on port {row['port']}" + (f" with {S.context_label(c['context'])}" if c.get("context") else "")+@staticmethoddef describe_running(row: dict) -> str:c = row.get("choices") or {}@@ -1340,11 +1353,13 @@ class Runner:runs beside the others (the person asked for two), with a warning about graphics memory."""running = self.serving_launches()if not running:+ self.checked()return Noneown = next((r for r in running if r["profile"] == self.profile), None)same_port = [r for r in running if r["profile"] != self.profile and r["port"] == int(self.s.port)]beside = [r for r in running if r["profile"] != self.profile and r["port"] != int(self.s.port)]if own and not self.retune and not same_port and own["choices"] == self.choices() and own["port"] == int(self.s.port):+ self.checked()self.config_path = launch_dir() / f"{self.name}.json"urls = acc.urls_for(self.s, tunnel_url=(acc.tunnel_info(self.profile) or {}).get("url"))self.emit("done", "Already serving these choices; nothing was restarted.", 100, urls=urls)@@ -1354,18 +1369,25 @@ class Runner:"the new one can fail to start. Stop the first with `strata launch --stop` if it does.")blocking = ([own] if own and not self.retune else []) + same_portif not blocking:+ self.checked()return Nonewhat = "; ".join(self.describe_running(r) for r in blocking)if not self.restart:if self.confirm_restart is not None:- if not self.confirm_restart("Restart the model with these settings?", "Answers in progress stop."):+ if not self.confirm_restart(f"{self.running_phrase(blocking[0])}. Restart it with these settings?", "Answers in progress stop."):raise LaunchError("Left as it is: the running model keeps serving.", "", 130)else:raise LaunchError(f"A model is already running: {what}. These choices are different.","Add --restart to stop it and start these, or run `strata launch --stop` first.", 6)self._stop_first = [r["profile"] for r in same_port]+ self.checked()return None+ def checked(self) -> None:+ cb, self.after_check = self.after_check, None+ if cb is not None:+ cb()+def stop_others(self) -> None:"""Stop the other launch servers that hold this port, so the new one gets it (no "port already in use")."""from strata_control import runtimediff --git a/strata_cli/launch/screens.py b/strata_cli/launch/screens.pyindex 8c26b796a..2c95a6ec4 100644--- a/strata_cli/launch/screens.py+++ b/strata_cli/launch/screens.py@@ -1525,10 +1525,15 @@ class SaveScreen(Base):s.name = nameif choice in ("save", "save_launch"):try:- store.save(s, name)+ if choice == "save":+ store.save(s, name)+ else:+ store.check_name(name) # saved by the run once the restart question (if any) is answered "Restart"except store.PresetError as e:self.say(str(e), True)return+ if choice == "save_launch":+ self.ctx.pending_save = nameif choice == "save":self.app.exit(None)self.app.stopped_after_save = True # type: ignore[attr-defined]diff --git a/strata_cli/launch/store.py b/strata_cli/launch/store.pyindex 4176835f3..479693fea 100644--- a/strata_cli/launch/store.py+++ b/strata_cli/launch/store.py@@ -65,6 +65,13 @@ def now_text() -> str:return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now)) + f".{int((now % 1) * 1000000):06d}"+def check_name(name: str) -> None:+ """The error `save` would raise for this name, without writing anything."""+ if not (name or "").strip():+ raise PresetError("A preset needs a name.")+ _path(name.strip())++def save(settings: LaunchSettings, name: str | None = None) -> LaunchSettings:"""Write (or replace) the preset called `name` (default: the settings' own name)."""name = (name or settings.name or "").strip()diff --git a/tests/terminal/test_tui3.py b/tests/terminal/test_tui3.pyindex 4143112dc..c228883b9 100644--- a/tests/terminal/test_tui3.py+++ b/tests/terminal/test_tui3.py@@ -139,5 +139,87 @@ class FolderChangeMovesNothing(unittest.TestCase):self.assertNotIn("are moved into this folder when you start", src)+class SaveWaitsForRestartAnswer(unittest.TestCase):+ """Save as a preset and launch: nothing is saved before the restart question is answered Restart."""++ def _runner(self, **kw):+ s = S.LaunchSettings(family="qwen", model="IQ3_XXS", context=32768, name="gyro")+ return Runner(s, catalog=catalog(), **kw)++ def setUp(self):+ self.home = Home().__enter__()+ self.addCleanup(self.home.__exit__, None, None, None)+ p = mock.patch.object(Catalog, "hardware", lambda self, fresh=False: dict(HW_12, disk_free_gb=500.0))+ p.start()+ self.addCleanup(p.stop)++ def rows(self, r):+ return [{"profile": "launch-gyro", "name": "gyro", "port": 8080,+ "choices": {**r.choices(), "context": 65536, "family": "qwen", "model": "IQ3_XXS"}}]++ def test_cancel_saves_nothing_and_the_question_names_the_running_model(self):+ saved, asked = [], []+ r = self._runner(confirm_restart=lambda q, d: asked.append((q, d)) or False, after_check=lambda: saved.append(1))+ with mock.patch.object(Runner, "serving_launches", lambda self: self.rows_):+ Runner.rows_ = self.rows(r)+ with self.assertRaises(LaunchError):+ r.run()+ self.assertEqual(saved, [])+ self.assertIn("is running on port 8080 with 64K. Restart it with these settings?", asked[0][0])+ self.assertIn("IQ3_XXS", asked[0][0])+ self.assertEqual(asked[0][1], "Answers in progress stop.")++ def test_restart_saves_after_the_answer(self):+ order = []+ r = self._runner(confirm_restart=lambda q, d: order.append("asked") or True, after_check=lambda: order.append("saved"))+ Runner.rows_ = self.rows(r)+ with mock.patch.object(Runner, "serving_launches", lambda self: self.rows_), mock.patch.object(Runner, "ensure_engine", side_effect=RuntimeError("went on")):+ with self.assertRaises(RuntimeError):+ r.run()+ self.assertEqual(order, ["asked", "saved"])++ def test_nothing_running_saves_at_once(self):+ saved = []+ r = self._runner(after_check=lambda: saved.append(1))+ with mock.patch.object(Runner, "serving_launches", lambda self: []), mock.patch.object(Runner, "ensure_engine", side_effect=RuntimeError("went on")):+ with self.assertRaises(RuntimeError):+ r.run()+ self.assertEqual(saved, [1])++ def test_the_save_screen_no_longer_writes_the_preset_itself(self):+ import asyncio+ from strata_cli.launch import store+ from tests.terminal.test_launch_tui import Base, FakeRunner, press, make_ctx+ from strata_cli.launch.app import LaunchApp++ class Case(Base):+ def runTest(self):+ pass++ case = Case()+ case.setUp()+ self.addCleanup(case.tearDown)+ seen = {}++ class Holding(FakeRunner):+ def run(self, start=True):+ seen["presets_during_run"] = [p.name for p in store.list_presets()]+ return super().run(start)++ with mock.patch("strata_cli.launch.app.Runner", Holding):+ async def go():+ app = LaunchApp(make_ctx())+ async with app.run_test(size=(110, 34)) as pilot:+ await pilot.pause(0.2)+ await press(pilot, *("enter",) * 7, "n", "enter")+ self.assertEqual(store.list_presets(), []) # still nothing on the Save screen+ await press(pilot, "enter")+ await pilot.pause(0.8)+ return [p.name for p in store.list_presets()]+ after = asyncio.run(go())+ self.assertEqual(seen["presets_during_run"], []) # not saved before the runner's check+ self.assertEqual(after, ["IQ3_S 32K"]) # saved once the run went on++if __name__ == "__main__":unittest.main()diff --git a/tests/terminal/test_tui_stress_launch.py b/tests/terminal/test_tui_stress_launch.pyindex f64addc0a..3a5a8ec1a 100644--- a/tests/terminal/test_tui_stress_launch.py+++ b/tests/terminal/test_tui_stress_launch.py@@ -69,7 +69,9 @@ class SecondLaunchTests(unittest.TestCase):mock.patch("strata_control.runtime.stop") as stop:with self.assertRaises(LaunchError) as cm:r.run()- self.assertEqual(asked, [("Restart the model with these settings?", "Answers in progress stop.")])+ self.assertEqual(len(asked), 1)+ self.assertIn("Restart it with these settings?", asked[0][0])+ self.assertEqual(asked[0][1], "Answers in progress stop.")self.assertEqual(cm.exception.code, 130)stop.assert_not_called()