diff --git a/dev/test_router_support.py b/dev/test_router_support.py index 1669a7e..6029576 100644 --- a/dev/test_router_support.py +++ b/dev/test_router_support.py @@ -24,6 +24,7 @@ from router_support import ( # noqa: E402 load_profile_registry, ) from ai_profile_router import ( # noqa: E402 + STATE, _cap_chat_generation, _context_matches, _inject_global_system_policy, @@ -31,6 +32,7 @@ from ai_profile_router import ( # noqa: E402 _normalize_chat_images, _normalize_llamacpp_reasoning, _request_has_image, + switch_profile, ) @@ -94,6 +96,16 @@ class ProfileRegistryTests(unittest.TestCase): self.assertFalse(_context_matches(80000, 76800)) self.assertFalse(_context_matches(80000, 82000)) + def test_ready_profile_clears_stale_unavailable_flag(self) -> None: + with STATE.avail_lock: + STATE.qwen_unavailable = True + status = {"reachable": True, "model": "qwen-medium", "ctx": 160000} + with patch("ai_profile_router.current_profile", return_value="medium"), \ + patch("ai_profile_router.upstream_status", return_value=status): + switch_profile("medium") + with STATE.avail_lock: + self.assertFalse(STATE.qwen_unavailable) + class ChatImageInputTests(unittest.TestCase): def test_small_png_data_url_is_accepted(self) -> None: diff --git a/router/ai_profile_router.py b/router/ai_profile_router.py index b515c34..4c20357 100755 --- a/router/ai_profile_router.py +++ b/router/ai_profile_router.py @@ -698,6 +698,11 @@ def switch_profile(profile: str, implicit: bool = False) -> None: up = upstream_status() ready = _profile_is_ready(profile, up) if cur == profile and ready: + # A previous failed switch can leave the in-memory availability + # flag set even though the controller and llama.cpp have since + # recovered. The semantic readiness check above is authoritative, + # so clear the stale flag before returning. + _set_qwen_unavailable(False) log.info("Profil %s ist bereits aktiv", profile) return # Qwen wird neu geladen/gewechselt → für Chats nicht verfügbar.