feat(ws2): ADR-093 路由統一 — BIGINT + NotificationMatrix + feature flag
## 修復 ### T2.1 BigInteger overflow 修復 - `db/models.py`: telegram_chat_id Integer → BigInteger (原 int32 無法容納群組 ID -1003711974679) ### T2.2 移除 CAST workaround - `approval_db.py:739`: 移除 CAST(:telegram_chat_id AS BIGINT) ORM 已正確使用 BigInteger,workaround 可退役 ### T2.3 Redis key 一致性修復 - `heartbeat_report_service.py:575`: telegram:polling_leader → telegram:polling:leader (telegram_gateway.py 使用冒號分隔,heartbeat 用底線是 bug) ## 新增 ### T2.4 notification_matrix.py - `services/notification_matrix.py`: ADR-093 路由矩陣 - Destination(DM/GROUP/BOTH) + RoutingRule dataclass - NOTIFICATION_ROUTING dict(TYPE-1 ~ TYPE-8M 完整映射) - resolve_chat_ids(type, dm, group, *, tg_group_cutover=False) 灰階切流 API ### T2.5 telegram_gateway.py feature flag 保護 - line 43: 加 notification_matrix import - line 1827-1834: TG_GROUP_CUTOVER=False 時維持舊行為 TG_GROUP_CUTOVER=True 時解除 _interactive_types 黑名單,由矩陣控制 ### T2.6 Migration SQL - `migrations/adr093_notification_routing.sql`: - CREATE TABLE approval_records (telegram_chat_id BIGINT) - CREATE ROLE awoooi_migrator (IF NOT EXISTS) - 含舊環境 ALTER COLUMN int→bigint 保護 ## 測試同步 - `tests/integration/setup_test_schema.sql`: telegram_chat_id BIGINT Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,7 @@ from src.services.security_interceptor import (
|
||||
get_security_interceptor,
|
||||
)
|
||||
from src.services.chat_manager import get_chat_manager
|
||||
from src.services.notification_matrix import resolve_chat_ids # ADR-093 路由矩陣
|
||||
|
||||
# =============================================================================
|
||||
# Snooze/Silence Redis Keys (2026-03-27 P1 優化)
|
||||
@@ -1823,11 +1824,14 @@ class TelegramGateway:
|
||||
# 2026-04-12 ogt: ADR-075 斷點 C 修復 — 含按鈕的互動型通知禁止發群組(nonce 洩漏)
|
||||
# TYPE-1/TYPE-2 → 可發群組(純資訊,無 callback 按鈕)
|
||||
# TYPE-3/TYPE-4/TYPE-4D/TYPE-8M → 僅 DM,不發群組
|
||||
# ADR-093 灰階切流:TG_GROUP_CUTOVER=true 時解除 _interactive_types 黑名單
|
||||
# 改由 notification_matrix.resolve_chat_ids() 控制路由
|
||||
_interactive_types = {"TYPE-3", "TYPE-4", "TYPE-4D", "TYPE-8M"}
|
||||
_is_interactive = notification_type in _interactive_types or (
|
||||
not notification_type and alert_category # 有分類但無明確型別 → 視為互動型
|
||||
)
|
||||
if settings.SRE_GROUP_CHAT_ID and not _is_interactive:
|
||||
_cutover = getattr(settings, "TG_GROUP_CUTOVER", False)
|
||||
if settings.SRE_GROUP_CHAT_ID and (not _is_interactive or _cutover):
|
||||
asyncio.create_task(
|
||||
self._send_approval_card_to_group(
|
||||
approval_id=approval_id,
|
||||
|
||||
Reference in New Issue
Block a user