diff --git a/terminal/strata_control/updater.py b/terminal/strata_control/updater.py index 7f2bb2c47f..b09e499446 100644 --- a/terminal/strata_control/updater.py +++ b/terminal/strata_control/updater.py @@ -712,6 +712,15 @@ def _choose_engine(feed: feedmod.Feed, ctx: Context, state: State) -> tuple[dict if report["status"] == "available" and local: report["installed_locally"] = local report["download_bytes"] = 0 + # #6830: the person went back to the engine in use (`strata components rollback`, Settings > Engine): it is pinned and the newer one is in "skipped". + # An explicit update still offers the newer engine (owner, 11-01), but anything that runs by itself (the app's install job: a model's settings, a + # download) must not switch back: SAFETY.md, "an engine is never updated by itself". `person_chose` says so; the app's engine step reads it. + pinned_name = section.get("pinned") + if pinned_name and getattr(installed, "root", None) is not None and installed.root.name == pinned_name \ + and offered.version in (section.get("skipped") or []): + report["person_chose"] = True + report["note"] = (f"you went back to {installed.version} (the newer {offered.version} is installed and left alone); " + "`strata update` or Update engine in Settings switches to it when you ask") if offered.version in (section.get("failed_unproven") or {}) and not ctx.force: # #5400: this engine was used without a test load (memory was short) and could not start the model; switching to it again by itself # would repeat that. The person can ask for it by name. diff --git a/terminal/tests/terminal/test_updater.py b/terminal/tests/terminal/test_updater.py index 698c50e1ff..f50948e933 100644 --- a/terminal/tests/terminal/test_updater.py +++ b/terminal/tests/terminal/test_updater.py @@ -820,6 +820,41 @@ class Cli(UpdaterCase): self.assertIn("Engine moved to the newer version: 0.1.45 -> 0.1.46", text) self.assertNotIn("rolled back", text) + # #6830: after a rollback the newer engine stays installed; the check says the person went back (person_chose) so the app's install job leaves it alone + def test_the_check_says_the_person_went_back_and_a_plain_update_still_switches(self): + self.install_current() + self.publish(("0.1.46", fx.GOOD_ENGINE)) + code, text, _ = self.cli("update", *self.common()) + self.assertEqual(code, 0, text) + self.assertEqual(self.resolved(), "0.1.46") + # nothing chosen yet: a newer engine in the feed is a plain update + code, text, _ = self.cli("components", "rollback", *self.common()) + self.assertEqual(code, 0, text) + self.assertEqual(self.resolved(), "0.1.45") + section = updater.State(self.components).section("engine") + self.assertEqual(section.get("skipped"), ["0.1.46"]) + self.assertTrue(section.get("pinned")) + code, text, _ = self.cli("update", "--check", "--json", *self.common()) + engine = json.loads(text)["engine"] + self.assertEqual(engine["status"], "available", "an explicit update still offers it") + self.assertTrue(engine.get("person_chose"), "but the check says the person went back") + self.assertIn("you went back to 0.1.45", engine["note"]) + self.assertEqual(engine.get("installed_locally") is not None, True) + # the explicit update switches (nothing to download) + code, text, _ = self.cli("update", *self.common()) + self.assertEqual(code, 0, text) + self.assertEqual(self.resolved(), "0.1.46") + code, text, _ = self.cli("update", "--check", "--json", *self.common()) + self.assertFalse(json.loads(text)["engine"].get("person_chose")) + + def test_a_newer_engine_nobody_left_is_not_marked(self): + self.install_current() + self.publish(("0.1.46", fx.GOOD_ENGINE)) + code, text, _ = self.cli("update", "--check", "--json", *self.common()) + engine = json.loads(text)["engine"] + self.assertEqual(engine["status"], "available") + self.assertFalse(engine.get("person_chose")) + def test_a_first_install_does_not_claim_a_previous_engine_is_kept(self): self.publish(("0.1.46", fx.GOOD_ENGINE)) code, text, _ = self.cli("update", *self.common())