feat(admin): add safe processing monitor and operation correlation

This commit is contained in:
cesnimda
2026-10-28 19:31:32 +01:00
parent 1f87301ee9
commit d52403dba8
19 changed files with 1064 additions and 6 deletions
+13
View File
@@ -20,6 +20,7 @@ import torch
import threading
import time
import zipfile
from uuid import UUID
from urllib import request as urllib_request
from urllib.error import URLError, HTTPError
from contextvars import ContextVar
@@ -66,6 +67,16 @@ async def require_service_token(request: Request, call_next):
{"detail": "Invalid or missing service token."},
status_code=401,
)
operation_id = None
supplied_id = request.headers.get("X-Operation-Id", "")
if len(supplied_id) == 36:
try:
parsed_id = UUID(supplied_id)
if parsed_id.int:
operation_id = str(parsed_id)
except ValueError:
pass
request.state.operation_id = operation_id
allowed = (
EXTERNAL_AI_ENABLED
and request.headers.get(EXTERNAL_AI_ALLOWED_HEADER, "").strip().lower() == "true"
@@ -78,6 +89,8 @@ async def require_service_token(request: Request, call_next):
state_token = _route_state.set(state)
try:
response = await call_next(request)
if operation_id:
response.headers["X-Operation-Id"] = operation_id
if request.url.path.startswith("/cv/"):
if state["provider"]:
response.headers["X-Ai-Provider"] = state["provider"]