mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-30 06:25:34 +01:00
Keep a logged-out provider out of free-best when OmniRoute resets its status
Some checks are pending
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
omniroute_offload pre-commit / pre-commit (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
Some checks are pending
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
omniroute_offload pre-commit / pre-commit (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
OmniRoute set kilo-gateway's testStatus back from 'expired'; the next health tick re-synced it into the combo and its first request answered 401 again (2026-11-29 12:37). A login now also counts as gone while its keys read 'invalid' or its last error is 'unauthorized' and newer than its last success. Bug-class-check: dead-provider check read one field OmniRoute resets; now also the sticky key health and last error (todoImplementer T2629) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4a9c2e03e9
commit
1f52d5f6b3
@ -33,15 +33,40 @@ MIN_TETRIS = 0.85
|
|||||||
# 35k+ tokens and grows, so one 32k member failed every turn with "Input exceeds
|
# 35k+ tokens and grows, so one 32k member failed every turn with "Input exceeds
|
||||||
# context window" (todoImplementer T2628).
|
# context window" (todoImplementer T2628).
|
||||||
MIN_CONTEXT = 100_000
|
MIN_CONTEXT = 100_000
|
||||||
# testStatus of a login that is gone: kuhy reconnects it
|
# testStatus (or lastErrorType) of a login that is gone: kuhy reconnects it
|
||||||
DEAD = frozenset({"expired", "unauthorized"})
|
DEAD = frozenset({"expired", "unauthorized"})
|
||||||
|
|
||||||
|
|
||||||
|
def _logged_out(conn: dict[str, Any]) -> bool:
|
||||||
|
"""Say whether a connection's login is gone, by the marks OmniRoute does not reset.
|
||||||
|
|
||||||
|
OmniRoute sets testStatus back from "expired" now and then; a sync then took the
|
||||||
|
dead kilo-gateway back, and its very next request answered 401 (2026-11-29
|
||||||
|
12:37). Its last error ("unauthorized", newer than its last success) and an
|
||||||
|
"invalid" key stay until kuhy reconnects.
|
||||||
|
"""
|
||||||
|
if conn.get("testStatus") in DEAD:
|
||||||
|
return True
|
||||||
|
data = conn.get("providerSpecificData")
|
||||||
|
keys = data.get("apiKeyHealth") if isinstance(data, dict) else None
|
||||||
|
keys = list(keys.values()) if isinstance(keys, dict) else []
|
||||||
|
success = max(
|
||||||
|
(str(k.get("lastSuccess") or "") for k in keys if isinstance(k, dict)),
|
||||||
|
default="",
|
||||||
|
)
|
||||||
|
if keys and all(isinstance(k, dict) and k.get("status") == "invalid" for k in keys):
|
||||||
|
return True
|
||||||
|
return (
|
||||||
|
conn.get("lastErrorType") in DEAD
|
||||||
|
and str(conn.get("lastErrorAt") or "") > success
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def dead_providers(conns: Iterable[dict[str, Any]]) -> set[str]:
|
def dead_providers(conns: Iterable[dict[str, Any]]) -> set[str]:
|
||||||
"""Return providers with connections but none usable (inactive or logged out)."""
|
"""Return providers with connections but none usable (inactive or logged out)."""
|
||||||
usable: dict[str, bool] = {}
|
usable: dict[str, bool] = {}
|
||||||
for conn in conns:
|
for conn in conns:
|
||||||
live = bool(conn.get("isActive")) and conn.get("testStatus") not in DEAD
|
live = bool(conn.get("isActive")) and not _logged_out(conn)
|
||||||
name = str(conn.get("provider"))
|
name = str(conn.get("provider"))
|
||||||
usable[name] = usable.get(name, False) or live
|
usable[name] = usable.get(name, False) or live
|
||||||
return {name for name, live in usable.items() if not live}
|
return {name for name, live in usable.items() if not live}
|
||||||
|
|||||||
@ -158,6 +158,28 @@ def test_dead_providers_are_those_with_no_usable_connection() -> None:
|
|||||||
assert combo.dead_providers(conns) == {"kilo", "off", "nope"}
|
assert combo.dead_providers(conns) == {"kilo", "off", "nope"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_login_stays_dead_when_omniroute_resets_its_test_status() -> None:
|
||||||
|
"""Live 2026-11-29 12:37: testStatus read active, the next kilo request got 401."""
|
||||||
|
health = {"primary": {"status": "invalid", "lastSuccess": "2026-11-29T11:01"}}
|
||||||
|
invalid = {**_conn("kilo"), "providerSpecificData": {"apiKeyHealth": health}}
|
||||||
|
errored = {
|
||||||
|
**_conn("err"),
|
||||||
|
"lastErrorType": "unauthorized",
|
||||||
|
"lastErrorAt": "2026-11-29T11:37",
|
||||||
|
}
|
||||||
|
ok_key = {"primary": {"status": "active", "lastSuccess": "2026-11-29T12:00"}}
|
||||||
|
fixed = {
|
||||||
|
**errored,
|
||||||
|
"provider": "fixed",
|
||||||
|
"providerSpecificData": {"apiKeyHealth": ok_key},
|
||||||
|
}
|
||||||
|
limited = {**_conn("busy"), "lastErrorType": "rate_limited", "lastErrorAt": "9"}
|
||||||
|
odd = {**_conn("odd"), "providerSpecificData": {"apiKeyHealth": "?"}}
|
||||||
|
conns = [invalid, errored, fixed, limited, odd]
|
||||||
|
# reconnected since its 401, or only rate limited: both stay
|
||||||
|
assert combo.dead_providers(conns) == {"kilo", "err"}
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_leaves_out_a_provider_whose_login_expired(
|
def test_refresh_leaves_out_a_provider_whose_login_expired(
|
||||||
cfg: gwc.Config, admins: list[FakeAdmin], capsys: pytest.CaptureFixture[str]
|
cfg: gwc.Config, admins: list[FakeAdmin], capsys: pytest.CaptureFixture[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user