diff --git a/coworker/server/manager.py b/coworker/server/manager.py index 7eeb1ba8..8d617402 100644 --- a/coworker/server/manager.py +++ b/coworker/server/manager.py @@ -446,6 +446,7 @@ class SessionManager: self._autotitle_sig: dict[str, int] = {} self.workspace_trust = WorkspaceTrustStore() self.secrets = SecretStore() + self._migrate_legacy_ollama_default() # OB-6: record on or off, keep for, and sending recordings to Langfuse or an # OpenTelemetry endpoint. Settings live in the machine's state folder (beside the # secrets), never in a project. Off by default: then no exporter exists at all. @@ -5086,6 +5087,35 @@ class SessionManager: self._save_prefs() return {"ok": True, "dm_session": self.dm_session()} + # The Ollama default before OPE-229 (2026-11-02). The Settings form prefills the + # field and saves every field, so anyone who saved the Ollama card before then + # carries this value without having typed it. + LEGACY_OLLAMA_URL = "http://localhost:11434" + + def _migrate_legacy_ollama_default(self) -> None: + """A saved Ollama `base_url` that is exactly the pre-OPE-229 default becomes the + current one (127.0.0.1), once. On Windows `localhost` tries ::1 first, where Ollama + does not listen, so every new connection waited 0.3-2 s (OPE-250). OPE-229's rule + that a saved address is used as typed stands for anything else: a copy of the old + default is not an address anyone typed, so `localhost:11435` or a path after the + port is left alone.""" + profile = self.secrets.get("provider:ollama") + if not isinstance(profile, dict): + return + saved = str(profile.get("base_url") or "").strip() + bare = saved.rstrip("/") + suffix = "" + if bare.endswith("/v1"): + bare, suffix = bare[: -len("/v1")], "/v1" + if bare.lower() != self.LEGACY_OLLAMA_URL: + return + migrated = dict(profile) + migrated["base_url"] = DEFAULT_OLLAMA_URL + suffix + try: + self.secrets.put("provider:ollama", migrated) + except OSError: + return # a read-only store keeps the slow address; nothing else depends on this + def _ollama_alive(self) -> bool: """Best-effort local-Ollama liveness, cached 30s (get_settings runs on every GUI fetch — no 2s probe inline). Keyless is not the same as PRESENT: `ollama:*` picker diff --git a/tests/test_providers_page_speed.py b/tests/test_providers_page_speed.py index 0be02d67..b0e77577 100644 --- a/tests/test_providers_page_speed.py +++ b/tests/test_providers_page_speed.py @@ -133,6 +133,40 @@ def test_a_server_that_does_not_answer_is_not_asked_for_its_models(tmp_path, mon manager.observability.close() +def test_an_ollama_profile_saved_as_the_old_default_becomes_127_0_0_1(tmp_path, monkeypatch): + """The Settings form saved the prefilled default, so profiles from before OPE-229 carry + `http://localhost:11434` without anyone having typed it. That exact value (a trailing + slash or `/v1` allowed) becomes the current default once; any other address stays as + typed, as OPE-229 decided.""" + from coworker.secrets import SecretStore + + monkeypatch.setenv("COWORKER_STATE_DIR", str(tmp_path / "state")) + store = SecretStore() + + def after(saved: str) -> str: + store.put("provider:ollama", {"base_url": saved, "note": "kept"}) + manager = SessionManager(workspace=tmp_path) + got = manager.secrets.get("provider:ollama") + assert got["note"] == "kept" # the rest of the profile is untouched + if hasattr(manager, "observability"): + manager.observability.close() + return got["base_url"] + + assert after("http://localhost:11434") == "http://127.0.0.1:11434" + assert after("http://localhost:11434/") == "http://127.0.0.1:11434" + assert after("http://LOCALHOST:11434/v1") == "http://127.0.0.1:11434/v1" + # Addresses someone chose are used as typed. + assert after("http://localhost:11435") == "http://localhost:11435" + assert after("http://localhost:11434/ollama") == "http://localhost:11434/ollama" + assert after("http://gpu-box.lan:11434") == "http://gpu-box.lan:11434" + # No profile at all: nothing is written. + store.delete("provider:ollama") + manager = SessionManager(workspace=tmp_path) + assert manager.secrets.get("provider:ollama") is None + if hasattr(manager, "observability"): + manager.observability.close() + + def test_local_server_defaults_name_127_0_0_1_not_localhost(): """`localhost` resolves to ::1 first on Windows, so a probe of a server that is not running waited out two connects; the defaults name the address directly (as OPE-229