From 3e9d53c98c3b6e1391330973b6d0da97e579916f Mon Sep 17 00:00:00 2001 From: OoO Date: Sat, 2 May 2026 13:08:45 +0800 Subject: [PATCH] refactor(telegram): migrate aider_heal_executor sender to EventRouter (ADR-019 Phase 5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit services/aider_heal_executor.py 的 _notify_telegram() 為 ADR-013 AutoHeal 閉環 通知出口(aider 自動修復進度)。原直接 POST sendMessage,timeout=5s(非阻塞)。 改走 services.event_router.dispatch_sync()。 行為變化: - 失敗仍靜默 pass,caller(execute_code_fix 等)行為完全不變 - severity=warning 會被 EventRouter classify 為 L0 或 L1(無 trace 時 L0), 輕量分流不會拖慢自動修復流程 - 享 EventRouter 內建 retry + JSONL queue replay;舊版 timeout=5 失敗即丟訊息 的問題改善(可從 queue 重送) Co-Authored-By: Claude Opus 4.7 (1M context) --- services/aider_heal_executor.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/services/aider_heal_executor.py b/services/aider_heal_executor.py index 566c17d..0e47483 100644 --- a/services/aider_heal_executor.py +++ b/services/aider_heal_executor.py @@ -154,15 +154,26 @@ def _wait_for_health( def _notify_telegram(message_html: str) -> None: - """非阻塞通知,失敗靜默忽略。""" + """ + 非阻塞通知,失敗靜默忽略。 + + ADR-019 Phase 5: 改走 EventRouter 統一入口(event_type=aider_heal_event, + severity=warning,會走 L0/L1 由 EventRouter 內部分流)。失敗仍靜默 pass, + caller 行為不變。 + """ if not TELEGRAM_BOT_TOKEN or not TELEGRAM_CHAT_ID: return try: - requests.post( - f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage", - json={"chat_id": TELEGRAM_CHAT_ID, "text": message_html, "parse_mode": "HTML"}, - timeout=5, - ) + from services.event_router import dispatch_sync + dispatch_sync(event={ + "event_type": "aider_heal_event", + "severity": "warning", + "source": "AiderHealExecutor", + "title": "Aider 自動修復通知", + "summary": message_html[:400], + "status": "heal_notification", + "payload": {"raw_message_html": message_html}, + }, admin_chat_ids=[TELEGRAM_CHAT_ID]) except Exception: pass