Recover router availability after failed profile switch
This commit is contained in:
@@ -24,6 +24,7 @@ from router_support import ( # noqa: E402
|
|||||||
load_profile_registry,
|
load_profile_registry,
|
||||||
)
|
)
|
||||||
from ai_profile_router import ( # noqa: E402
|
from ai_profile_router import ( # noqa: E402
|
||||||
|
STATE,
|
||||||
_cap_chat_generation,
|
_cap_chat_generation,
|
||||||
_context_matches,
|
_context_matches,
|
||||||
_inject_global_system_policy,
|
_inject_global_system_policy,
|
||||||
@@ -31,6 +32,7 @@ from ai_profile_router import ( # noqa: E402
|
|||||||
_normalize_chat_images,
|
_normalize_chat_images,
|
||||||
_normalize_llamacpp_reasoning,
|
_normalize_llamacpp_reasoning,
|
||||||
_request_has_image,
|
_request_has_image,
|
||||||
|
switch_profile,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -94,6 +96,16 @@ class ProfileRegistryTests(unittest.TestCase):
|
|||||||
self.assertFalse(_context_matches(80000, 76800))
|
self.assertFalse(_context_matches(80000, 76800))
|
||||||
self.assertFalse(_context_matches(80000, 82000))
|
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):
|
class ChatImageInputTests(unittest.TestCase):
|
||||||
def test_small_png_data_url_is_accepted(self) -> None:
|
def test_small_png_data_url_is_accepted(self) -> None:
|
||||||
|
|||||||
@@ -698,6 +698,11 @@ def switch_profile(profile: str, implicit: bool = False) -> None:
|
|||||||
up = upstream_status()
|
up = upstream_status()
|
||||||
ready = _profile_is_ready(profile, up)
|
ready = _profile_is_ready(profile, up)
|
||||||
if cur == profile and ready:
|
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)
|
log.info("Profil %s ist bereits aktiv", profile)
|
||||||
return
|
return
|
||||||
# Qwen wird neu geladen/gewechselt → für Chats nicht verfügbar.
|
# Qwen wird neu geladen/gewechselt → für Chats nicht verfügbar.
|
||||||
|
|||||||
Reference in New Issue
Block a user