fix: no import-time side effects, env-driven paths, shim dead-logic, smoke test

This commit is contained in:
ENI
2026-11-07 14:01:53 +03:00
parent 7cf876a87a
commit 0e68513e1b
6 changed files with 270 additions and 139 deletions
+9 -2
View File
@@ -16,7 +16,7 @@ Env:
MINARA_TOKENS (default /opt/minara-shim/tokens.jsonl)
MINARA_STATE (default /opt/minara-shim/state.json)
"""
import json, os, re, sys, threading, time
import json, os, random, re, sys, threading, time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import requests
@@ -96,10 +96,17 @@ def pick(n=8):
start = RR[0] % len(live)
RR[0] += 1
live = live[start:] + live[:start]
return live[:n]
head = live[:n]
random.shuffle(head) # иначе первые живые токены получают весь трафик
return head
def mark_dead(t, code, body=""):
"""Помечаем токен мёртвым только на реальных отказах доступа.
400/404/422 — это ошибка тела запроса или имени модели, токен тут не виноват:
раньше любой 400 от невалидного запроса выключал живой аккаунт на 30 минут.
"""
with LOCK:
t["fail"] = t.get("fail", 0) + 1
if code in (401, 402, 403) or "insufficient" in (body or "").lower() or "quota" in (body or "").lower():