From f49413e78a826a7b78e77cb7fd849273665b6506 Mon Sep 17 00:00:00 2001 From: OoO Date: Wed, 13 May 2026 10:01:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A8=98=E9=8C=84=20EA=20short-circuit=20?= =?UTF-8?q?=E9=81=99=E6=B8=AC=E5=A4=B1=E6=95=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/elephant_alpha_autonomous_engine.py | 6 +++- tests/test_elephant_alpha_engine.py | 32 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/services/elephant_alpha_autonomous_engine.py b/services/elephant_alpha_autonomous_engine.py index f16c842..880752b 100644 --- a/services/elephant_alpha_autonomous_engine.py +++ b/services/elephant_alpha_autonomous_engine.py @@ -569,7 +569,11 @@ class ElephantAlphaAutonomousEngine: ctx.set_tokens(input=0, output=0) # Hermes 已自己記 ctx.status = 'cache_only' # 不算 ok 也不算 error except Exception: - pass # logger 失敗不影響主流程 + self._log.warning( + "EA short-circuit telemetry failed; trigger=%s", + trigger.trigger_type, + exc_info=True, + ) return # Hermes 有實證 threats → 把它存進 trigger.conditions 給 orchestrator 用 diff --git a/tests/test_elephant_alpha_engine.py b/tests/test_elephant_alpha_engine.py index e719a3b..1736251 100644 --- a/tests/test_elephant_alpha_engine.py +++ b/tests/test_elephant_alpha_engine.py @@ -1,4 +1,5 @@ import asyncio +import logging def test_run_with_timeout_supports_sync_function(): @@ -82,3 +83,34 @@ def test_autoheal_derives_python_exception_from_traceback(): svc = AutoHealService() assert svc._derive_error_type({"traceback_str": "Traceback (most recent call last):\nNameError"}) == "python_exception" + + +def test_execute_autonomous_decision_logs_short_circuit_telemetry_failure(monkeypatch, caplog): + from services.elephant_alpha_autonomous_engine import ( + AutonomousTrigger, + ElephantAlphaAutonomousEngine, + ) + import services.ai_call_logger as ai_call_logger + + engine = ElephantAlphaAutonomousEngine() + + async def _no_hermes_threats(top_n=5): + return None + + def _broken_log_ai_call(*args, **kwargs): + raise RuntimeError("ai telemetry unavailable") + + monkeypatch.setattr(engine, "_fetch_hermes_threats_summary", _no_hermes_threats) + monkeypatch.setattr(ai_call_logger, "log_ai_call", _broken_log_ai_call) + caplog.set_level(logging.WARNING, logger="services.elephant_alpha_autonomous_engine") + + trigger = AutonomousTrigger( + trigger_type="price_drop_alert", + conditions={}, + threshold=0.8, + enabled=True, + ) + + asyncio.run(engine._execute_autonomous_decision(trigger)) + + assert "EA short-circuit telemetry failed" in caplog.text