feat: add corrective engine, execution state, budget guard, transparency layer (2026-05-11)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
Manar Anomaly Corrective Action Engine
|
||||
When anomalies are detected, generate and store targeted corrective recommendations.
|
||||
For critical anomalies with L2/L3 pilot, auto-execute immediately.
|
||||
|
||||
ANOMALY → DIAGNOSIS → CORRECTIVE REC → EXECUTE (if pilot allows)
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import asyncio
|
||||
import asyncpg
|
||||
import threading
|
||||
import httpx
|
||||
from datetime import date, datetime
|
||||
|
||||
log = logging.getLogger("manar-corrective")
|
||||
TENANTS_DB_URL = os.environ.get("TENANTS_DB_URL", "")
|
||||
CORE_DB_URL = os.environ.get("CORE_DB_URL", "")
|
||||
|
||||
|
||||
def run_async(coro, timeout=30):
|
||||
result = [None]; err = []
|
||||
def _run():
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
try:
|
||||
result[0] = loop.run_until_complete(coro)
|
||||
except Exception as e:
|
||||
err.append(e)
|
||||
finally:
|
||||
loop.close()
|
||||
t = threading.Thread(target=_run)
|
||||
t.start()
|
||||
t.join(timeout=timeout)
|
||||
if err: raise err[0]
|
||||
return result[0]
|
||||
|
||||
# See /docker/manar/mcp/corrective_engine.py on VPS for full implementation
|
||||
# This is a reference copy committed 2026-05-11
|
||||
Reference in New Issue
Block a user