diff --git a/omniroute_offload/omniroute_offload/_gw_api.py b/omniroute_offload/omniroute_offload/_gw_api.py index dcc66d8..975b383 100644 --- a/omniroute_offload/omniroute_offload/_gw_api.py +++ b/omniroute_offload/omniroute_offload/_gw_api.py @@ -69,6 +69,9 @@ def alive(cfg: Config) -> bool: return True +EMPTY = "empty completion" # a 200 with no text: a reasoning model out of max_tokens, or a bad answer + + def chat(cfg: Config, key: str, model: str = COMBO, max_tokens: int = 300) -> str: """One real completion through the combo (or one model); its text, or ApiError.""" reply = call( @@ -87,8 +90,7 @@ def chat(cfg: Config, key: str, model: str = COMBO, max_tokens: int = 300) -> st msg = f"unexpected reply: {str(reply)[:200]}" raise ApiError(msg) from err if not text: - msg = "empty completion" - raise ApiError(msg) + raise ApiError(EMPTY) return text diff --git a/omniroute_offload/omniroute_offload/_gw_combo.py b/omniroute_offload/omniroute_offload/_gw_combo.py index 8b134d5..cb79103 100644 --- a/omniroute_offload/omniroute_offload/_gw_combo.py +++ b/omniroute_offload/omniroute_offload/_gw_combo.py @@ -41,7 +41,9 @@ MIN_CONTEXT = 32_000 DEAD = frozenset({"expired", "unauthorized"}) # state_dir file of logins seen dead; one stays out until a real request answers DEAD_FILE = "dead_logins.json" -PROBE_TOKENS = 20 +# Room for a reasoning model's thinking before its text: kilo-auto/free spent all of 20 on reasoning and +# answered no text, so a working login read as still dead (2026-11-29 15:02). +PROBE_TOKENS = 300 def _logged_out(conn: dict[str, Any]) -> bool: @@ -98,6 +100,8 @@ def _answers(cfg: Config, model: str) -> bool: try: api.chat(cfg, health.secret(cfg, "api_key"), model, PROBE_TOKENS) except (api.ApiError, OSError) as err: + if str(err) == api.EMPTY: # it answered 200: the login works, only the text ran out of room + return True print(f"still out: {model}: {err}", file=sys.stderr) return False return True diff --git a/omniroute_offload/omniroute_offload/tests/test_gw_combo.py b/omniroute_offload/omniroute_offload/tests/test_gw_combo.py index a07ad3f..01248c8 100644 --- a/omniroute_offload/omniroute_offload/tests/test_gw_combo.py +++ b/omniroute_offload/omniroute_offload/tests/test_gw_combo.py @@ -298,6 +298,34 @@ def test_keep_live_takes_a_dead_login_back_once_a_real_request_answers( assert combo._remembered(cfg) == {} +def test_keep_live_takes_back_a_login_whose_reasoning_model_answers_no_text( + cfg: gwc.Config, + admins: list[FakeAdmin], + notices: list[str], + monkeypatch: pytest.MonkeyPatch, +) -> None: + """kilo-auto/free spent the probe's tokens on reasoning: a 200 with no text is a working login.""" + _write(cfg, HEADER + "nv/a\tyes\t1.0\t128000\nkilo/auto\tyes\t1.0\t128000\n") + (cfg.conf_dir / "api_key").write_text("k\n") + CONNS.extend([_conn("nv"), _conn("kilo", "expired")]) + CURRENT.extend(["nv/a", "kilo/auto"]) + assert combo.keep_live(cfg) is True + CURRENT[:] = ["nv/a"] + CONNS[1] = _conn("kilo") # kuhy signed it in from the board + asked: list[int] = [] + + def empty(_cfg: gwc.Config, _key: str, _model: str = api.COMBO, max_tokens: int = 0) -> str: + asked.append(max_tokens) + raise api.ApiError(api.EMPTY) + + monkeypatch.setattr(api, "chat", empty) + assert combo.keep_live(cfg) is True + assert admins[-1].upserts == [(api.COMBO, ["nv/a", "kilo/auto"])] + assert combo._remembered(cfg) == {} + assert asked == [combo.PROBE_TOKENS] + assert combo.PROBE_TOKENS >= 200 + + def test_keep_live_does_nothing_while_an_update_holds_the_lock( cfg: gwc.Config, admins: list[FakeAdmin] ) -> None: