The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway/platforms): bluebubbles.py second pass — walrus guards, fold layouts, compact docs
Teknium100505661975
diff --git a/gateway/platforms/bluebubbles.py b/gateway/platforms/bluebubbles.pyindex b0bfc5f179b..b51b9dd0be2 100644--- a/gateway/platforms/bluebubbles.py+++ b/gateway/platforms/bluebubbles.py@@ -1,8 +1,5 @@-"""BlueBubbles iMessage platform adapter.--Uses the local BlueBubbles macOS server for outbound REST sends and inbound-webhooks: text, media attachments, typing indicators, and read receipts.-"""+"""BlueBubbles iMessage platform adapter: local BlueBubbles macOS server for outbound REST sends and+inbound webhooks (text, media attachments, typing indicators, read receipts)."""import asyncioimport json@@ -28,9 +25,8 @@ from .media_cache import ext_for_mimefrom gateway.platforms.helpers import compile_mention_patterns, strip_markdownfrom utils import TRUTHY_STRINGS-# Historical BlueBubbles mime→ext maps, preserved verbatim as overrides for-# the shared dispatch in gateway.platforms.media_cache. Both maps are-# CLOSED: unlisted mimes fall back to .jpg / .mp3 (never mimetypes).+# Historical BlueBubbles mime→ext maps, preserved verbatim as overrides for the shared dispatch in+# gateway.platforms.media_cache. Both maps are CLOSED: unlisted mimes fall back to .jpg / .mp3._BLUEBUBBLES_IMAGE_EXT_OVERRIDES = {"image/jpeg": ".jpg", "image/png": ".png", "image/gif": ".gif", "image/webp": ".webp","image/heic": ".jpg", "image/heif": ".jpg", "image/tiff": ".jpg", # historical mapping@@ -44,23 +40,20 @@ _BLUEBUBBLES_AUDIO_EXT_OVERRIDES = {logger = logging.getLogger(__name__)DEFAULT_WEBHOOK_HOST = "127.0.0.1"-# Webhook events are small JSON/form payloads; attachments come through the-# REST API. 1 MiB keeps oversized/chunked bodies from buffering unbounded.+# Webhook events are small JSON/form payloads (attachments come through the REST API); 1 MiB keeps+# oversized/chunked bodies from buffering unbounded._WEBHOOK_MAX_BODY_BYTES = 1_048_576DEFAULT_WEBHOOK_PORT = 8645DEFAULT_WEBHOOK_PATH = "/bluebubbles-webhook"MAX_TEXT_LENGTH = 4000-# iMessage has no stable bot mention identity (unlike <@U...>/@botname/MXID),-# so `require_mention: true` without custom aliases uses Hermes wake words.+# iMessage has no stable bot mention identity (unlike <@U...>/@botname/MXID), so+# `require_mention: true` without custom aliases uses Hermes wake words.DEFAULT_MENTION_PATTERNS = [r"(?<![\w@])@?hermes\s+agent\b[,:\-]?", r"(?<![\w@])@?hermes\b[,:\-]?"]-# Tapback associatedMessageType codes: 2000-2005 added, 3000-3005 removed-# (love, like, dislike, laugh, emphasize, question).+# Tapback associatedMessageType codes: 2000-2005 added, 3000-3005 removed (love, like, dislike, ...)._TAPBACK_CODES = {*range(2000, 2006), *range(3000, 3006)}--# Webhook event types that carry user messages-_MESSAGE_EVENTS = {"new-message", "message", "updated-message"}+_MESSAGE_EVENTS = {"new-message", "message", "updated-message"} # webhook event types carrying user messages_PHONE_RE = re.compile(r"\+?\d{7,15}")_EMAIL_RE = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")@@ -86,18 +79,15 @@ def check_bluebubbles_requirements() -> bool:def _normalize_server_url(raw: str) -> str:value = (raw or "").strip()- if not value:- return ""- if not re.match(r"^https?://", value, flags=re.I):+ if value and not re.match(r"^https?://", value, flags=re.I):value = f"http://{value}"return value.rstrip("/")def _closed_ext(mime: str, overrides: Dict[str, str], fallback: str) -> str:"""Historical maps were closed: unlisted mimes fall back without consulting mimetypes."""- return ext_for_mime(- mime, overrides=overrides, use_defaults=False, use_mimetypes=False, fallback=fallback- ) or fallback+ return ext_for_mime(mime, overrides=overrides, use_defaults=False, use_mimetypes=False,+ fallback=fallback) or fallbackdef _setting(extra: Dict[str, Any], key: str, env: str, default: str = "") -> Any:@@ -137,8 +127,7 @@ class BlueBubblesAdapter(BasePlatformAdapter):_require_mention = os.getenv("BLUEBUBBLES_REQUIRE_MENTION")self.require_mention = str(_require_mention).strip().lower() in TRUTHY_STRINGSself._mention_patterns = self._compile_mention_patterns(- extra["mention_patterns"] if "mention_patterns" in extra else os.getenv("BLUEBUBBLES_MENTION_PATTERNS")- )+ extra["mention_patterns"] if "mention_patterns" in extra else os.getenv("BLUEBUBBLES_MENTION_PATTERNS"))self.client: Optional[httpx.AsyncClient] = Noneself._runner = Noneself._private_api_enabled: Optional[bool] = None@@ -153,25 +142,25 @@ class BlueBubblesAdapter(BasePlatformAdapter):@staticmethoddef _compile_mention_patterns(raw: Any) -> List[re.Pattern]:- """Compile group-mention wake words; ``raw`` is a list, a raw env string- (JSON list or comma/newline-separated), or None (Hermes defaults)."""- return compile_mention_patterns(raw, log_prefix="bluebubbles", defaults=DEFAULT_MENTION_PATTERNS, logger_=logger)+ """Compile group-mention wake words; ``raw`` is a list, a raw env string (JSON list or+ comma/newline-separated), or None (Hermes defaults)."""+ return compile_mention_patterns(raw, log_prefix="bluebubbles", defaults=DEFAULT_MENTION_PATTERNS,+ logger_=logger)def _message_matches_mention_patterns(self, text: str) -> bool:return bool(text) and any(pattern.search(text) for pattern in self._mention_patterns)def _clean_mention_text(self, text: str) -> str:- """Strip a leading wake word only — patterns are regexes, so stripping- anywhere later in the prompt could delete ordinary words."""- if not text:- return text+ """Strip a leading wake word only — patterns are regexes, so stripping anywhere later in the+ prompt could delete ordinary words."""+ stripped = (text or "").lstrip()for pattern in self._mention_patterns:- match = pattern.match(text.lstrip())- if match:- return text.lstrip()[match.end():].lstrip(" ,:-") or text+ if match := pattern.match(stripped):+ return stripped[match.end():].lstrip(" ,:-") or textreturn textasync def _api_json(self, method: str, path: str, **kwargs) -> Dict[str, Any]:+ """Authenticated request to the BlueBubbles REST API; raises on HTTP errors, returns decoded JSON."""assert self.client is not Noneres = await getattr(self.client, method)(self._api_url(path), **kwargs)res.raise_for_status()@@ -198,8 +187,7 @@ class BlueBubblesAdapter(BasePlatformAdapter):if not self._private_api_enabled or not self._helper_connected or not self.client:return Falsewith suppress(Exception):- guid = await self._resolve_chat_guid(chat_id)- if guid:+ if guid := await self._resolve_chat_guid(chat_id):url = self._api_url(f"/api/v1/chat/{quote(guid, safe='')}/{action}")await getattr(self.client, method)(url, timeout=5)return True@@ -227,22 +215,21 @@ class BlueBubblesAdapter(BasePlatformAdapter):logger.error("[bluebubbles] cannot reach server at %s: %s", self.server_url, exc)await self._close_client()return False- # client_max_size makes aiohttp enforce the cap on every read path,- # including chunked requests with no Content-Length.+ # client_max_size makes aiohttp enforce the cap on every read path, incl. chunked requests+ # with no Content-Length.app = web.Application(client_max_size=_WEBHOOK_MAX_BODY_BYTES)app.router.add_get("/health", lambda _: web.Response(text="ok"))app.router.add_post(self.webhook_path, self._handle_webhook)- # The webhook auth value rides in the query string (BlueBubbles cannot- # send custom headers) — keep it out of aiohttp access logs.+ # The webhook auth value rides in the query string (BlueBubbles cannot send custom headers)+ # — keep it out of aiohttp access logs.self._runner = web.AppRunner(app, access_log=None)await self._runner.setup()site = web.TCPSite(self._runner, self.webhook_host, self.webhook_port)await site.start()self._mark_connected()- logger.info("[bluebubbles] webhook listening on http://%s:%s%s",- self.webhook_host, self.webhook_port, self.webhook_path)- # The server only sends events to webhooks registered via its API.- await self._register_webhook()+ logger.info("[bluebubbles] webhook listening on http://%s:%s%s", self.webhook_host, self.webhook_port,+ self.webhook_path)+ await self._register_webhook() # the server only sends events to webhooks registered via its API# Plugin-registered native handlers (ctx.register_platform_handler).self._wire_plugin_handlers(None)return True@@ -267,16 +254,13 @@ class BlueBubblesAdapter(BasePlatformAdapter):return f"http://{host}:{self.webhook_port}{self.webhook_path}"def _webhook_register_url_with(self, password_param: str) -> str:- base = self._webhook_url- return f"{base}?password={password_param}" if self.password else base+ return f"{self._webhook_url}?password={password_param}" if self.password else self._webhook_url@propertydef _webhook_register_url(self) -> str:- """Registered webhook URL, password embedded as a query param.-- BlueBubbles posts to the exact registered URL and its registration- API cannot set custom headers, so this is the only way to- authenticate inbound webhooks without disabling auth."""+ """Registered webhook URL with the password as a query param: BlueBubbles posts to the exact+ registered URL and cannot set custom headers, so this is the only way to authenticate inbound+ webhooks without disabling auth."""return self._webhook_register_url_with(quote(self.password, safe=""))@property@@ -292,18 +276,17 @@ class BlueBubblesAdapter(BasePlatformAdapter):return []async def _register_webhook(self) -> bool:- """Register this webhook URL, reusing an existing registration if present- (crash resilience — avoids duplicates after an unclean shutdown)."""+ """Register this webhook URL, reusing an existing registration if present (crash resilience —+ avoids duplicates after an unclean shutdown)."""if not self.client:return False- webhook_url = self._webhook_register_url- log_url = self._webhook_register_url_for_log+ webhook_url, log_url = self._webhook_register_url, self._webhook_register_url_for_logif await self._find_registered_webhooks(webhook_url):logger.info("[bluebubbles] webhook already registered: %s", log_url)return True- payload = {"url": webhook_url, "events": ["new-message", "updated-message"]}try:- res = await self._api_post("/api/v1/webhook", payload)+ res = await self._api_post("/api/v1/webhook",+ {"url": webhook_url, "events": ["new-message", "updated-message"]})status = res.get("status", 0)if 200 <= status < 300:logger.info("[bluebubbles] webhook registered with server: %s", log_url)@@ -321,10 +304,8 @@ class BlueBubblesAdapter(BasePlatformAdapter):removed = Falsetry:for wh in await self._find_registered_webhooks(self._webhook_register_url):- wh_id = wh.get("id")- if wh_id:- res = await self.client.delete(self._api_url(f"/api/v1/webhook/{wh_id}"))- res.raise_for_status()+ if wh_id := wh.get("id"):+ (await self.client.delete(self._api_url(f"/api/v1/webhook/{wh_id}"))).raise_for_status()removed = Trueif removed:logger.info("[bluebubbles] webhook unregistered: %s", self._webhook_register_url_for_log)@@ -335,13 +316,10 @@ class BlueBubblesAdapter(BasePlatformAdapter):# --- Chat GUID resolution ---async def _resolve_chat_guid(self, target: str) -> Optional[str]:- """Resolve an email/phone to a chat GUID (raw ``a;-;b`` GUIDs pass through).-- Matches strictly on ``chatIdentifier`` / ``identifier``. Participant- membership is intentionally NOT a fallback: the same contact appears in- a 1:1 DM and any number of groups, so a participant match could leak a- DM reply into a group thread. Return ``None`` and let the caller create- a fresh DM via ``_create_chat_for_handle``."""+ """Resolve an email/phone to a chat GUID (raw ``a;-;b`` GUIDs pass through). Matches strictly on+ ``chatIdentifier`` / ``identifier``; participant membership is intentionally NOT a fallback —+ the same contact appears in a 1:1 DM and any number of groups, so a participant match could+ leak a DM reply into a group thread. ``None`` lets the caller create a fresh DM."""target = (target or "").strip()if not target:return None@@ -365,8 +343,8 @@ class BlueBubblesAdapter(BasePlatformAdapter):async def _create_chat_for_handle(self, address: str, message: str) -> SendResult:"""Create a new chat by sending the first message to *address*."""- payload = {"addresses": [address], "message": message, "tempGuid": _temp_guid()}- return await self._post_message("/api/v1/chat/new", payload)+ return await self._post_message(+ "/api/v1/chat/new", {"addresses": [address], "message": message, "tempGuid": _temp_guid()})# --- Text sending ---@@ -376,9 +354,8 @@ class BlueBubblesAdapter(BasePlatformAdapter):chunks = BasePlatformAdapter.truncate_message(content, max_length)return [_PAGINATION_SUFFIX_RE.sub("", c) for c in chunks]- async def send(- self, chat_id: str, content: str, reply_to: Optional[str] = None,- metadata: Optional[Dict[str, Any]] = None) -> SendResult:+ async def send(self, chat_id: str, content: str, reply_to: Optional[str] = None,+ metadata: Optional[Dict[str, Any]] = None) -> SendResult:text = self.format_message(content)if not text:return SendResult(success=False, error="BlueBubbles send requires text")@@ -392,8 +369,7 @@ class BlueBubblesAdapter(BasePlatformAdapter):for chunk in chunks:guid = await self._resolve_chat_guid(chat_id)if not guid:- # If the target looks like an address, try creating a new chat- if self._private_api_enabled and ("@" in chat_id or _ADDRESS_RE.match(chat_id)):+ if self._private_api_enabled and ("@" in chat_id or _ADDRESS_RE.match(chat_id)): # address → new chatreturn await self._create_chat_for_handle(chat_id, chunk)return SendResult(success=False, error=f"BlueBubbles chat not found for target: {chat_id}")payload: Dict[str, Any] = {"chatGuid": guid, "tempGuid": _temp_guid(), "message": chunk}@@ -406,9 +382,8 @@ class BlueBubblesAdapter(BasePlatformAdapter):# --- Media sending (outbound) ---- async def _send_attachment(- self, chat_id: str, file_path: str, filename: Optional[str] = None,- caption: Optional[str] = None, is_audio_message: bool = False) -> SendResult:+ async def _send_attachment(self, chat_id: str, file_path: str, filename: Optional[str] = None,+ caption: Optional[str] = None, is_audio_message: bool = False) -> SendResult:"""Send a file attachment via BlueBubbles multipart upload."""if not self.client:return SendResult(success=False, error="Not connected")@@ -419,30 +394,28 @@ class BlueBubblesAdapter(BasePlatformAdapter):return SendResult(success=False, error=f"Chat not found: {chat_id}")fname = filename or os.path.basename(file_path)try:- # httpx's async multipart iterator reads file objects through a sync- # chunk generator — read the bytes off the event-loop thread first.+ # httpx's async multipart iterator reads file objects through a sync chunk generator —+ # read the bytes off the event-loop thread first.payload = await asyncio.to_thread(Path(file_path).read_bytes)- files = {"attachment": (fname, payload, "application/octet-stream")}data: Dict[str, str] = {"chatGuid": guid, "name": fname, "tempGuid": uuid.uuid4().hex}if is_audio_message:data["isAudioMessage"] = "true"- res = await self.client.post(- self._api_url("/api/v1/message/attachment"), files=files, data=data, timeout=120)+ res = await self.client.post(self._api_url("/api/v1/message/attachment"), data=data, timeout=120,+ files={"attachment": (fname, payload, "application/octet-stream")})res.raise_for_status()result = res.json()if caption:await self.send(chat_id, caption)if result.get("status") == 200:rdata = result.get("data") or {}- msg_id = rdata.get("guid") if isinstance(rdata, dict) else None- return SendResult(success=True, message_id=msg_id, raw_response=result)+ return SendResult(success=True, message_id=rdata.get("guid") if isinstance(rdata, dict) else None,+ raw_response=result)return SendResult(success=False, error=result.get("message", "Attachment upload failed"))except Exception as e:return SendResult(success=False, error=str(e))- async def send_image(- self, chat_id: str, image_url: str, caption: Optional[str] = None,- reply_to: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None) -> SendResult:+ async def send_image(self, chat_id: str, image_url: str, caption: Optional[str] = None,+ reply_to: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None) -> SendResult:try:from gateway.platforms.base import cache_image_from_urllocal_path = await cache_image_from_url(image_url)@@ -482,14 +455,12 @@ class BlueBubblesAdapter(BasePlatformAdapter):is_group = ";+;" in (chat_id or "")info: Dict[str, Any] = {"name": chat_id, "type": "group" if is_group else "dm"}with suppress(Exception):- guid = await self._resolve_chat_guid(chat_id)- if guid:+ if guid := await self._resolve_chat_guid(chat_id):res = await self._api_get(f"/api/v1/chat/{quote(guid, safe='')}?with=participants")data = (res or {}).get("data", {})info["name"] = data.get("displayName") or data.get("chatIdentifier") or chat_id- participants = [- addr for p in data.get("participants", []) or [] if (addr := (p.get("address") or "").strip())- ]+ participants = [addr for p in data.get("participants", []) or []+ if (addr := (p.get("address") or "").strip())]if participants:info["participants"] = participantsreturn info@@ -504,9 +475,8 @@ class BlueBubblesAdapter(BasePlatformAdapter):if not self.client:return Nonetry:- resp = await self.client.get(- self._api_url(f"/api/v1/attachment/{quote(att_guid, safe='')}/download"),- timeout=60, follow_redirects=True)+ resp = await self.client.get(self._api_url(f"/api/v1/attachment/{quote(att_guid, safe='')}/download"),+ timeout=60, follow_redirects=True)resp.raise_for_status()data = resp.contentmime = (att_meta.get("mimeType") or "").lower()@@ -515,8 +485,7 @@ class BlueBubblesAdapter(BasePlatformAdapter):if mime.startswith("audio/"):return cache_audio_from_bytes(data, _closed_ext(mime, _BLUEBUBBLES_AUDIO_EXT_OVERRIDES, ".mp3"))# Videos, documents, and everything else- filename = att_meta.get("transferName", "") or f"file_{uuid.uuid4().hex[:8]}"- return cache_document_from_bytes(data, filename)+ return cache_document_from_bytes(data, att_meta.get("transferName", "") or f"file_{uuid.uuid4().hex[:8]}")except Exception as exc:logger.warning("[bluebubbles] failed to download attachment %s: %s", _redact(att_guid), exc)return None@@ -527,10 +496,8 @@ class BlueBubblesAdapter(BasePlatformAdapter):data = payload.get("data")if isinstance(data, dict):return data- if isinstance(data, list):- for item in data:- if isinstance(item, dict):- return item+ if isinstance(data, list) and (first := next((i for i in data if isinstance(i, dict)), None)):+ return firstif isinstance(payload.get("message"), dict):return payload.get("message")return payload if isinstance(payload, dict) else None@@ -557,9 +524,7 @@ class BlueBubblesAdapter(BasePlatformAdapter):msg_type = MessageType.TEXTfor att in record.get("attachments") or []:att_guid = att.get("guid", "")- if not att_guid:- continue- cached = await self._download_attachment(att_guid, att)+ cached = await self._download_attachment(att_guid, att) if att_guid else Noneif not cached:continuemime = (att.get("mimeType") or "").lower()@@ -590,12 +555,8 @@ class BlueBubblesAdapter(BasePlatformAdapter):record.get("chatIdentifier"), record.get("identifier"),payload.get("chatIdentifier"), payload.get("identifier"))handle = record.get("handle")- sender = (- self._value(- handle.get("address") if isinstance(handle, dict) else None,- record.get("sender"), record.get("from"), record.get("address"))- or chat_identifier- or chat_guid)+ sender = (self._value(handle.get("address") if isinstance(handle, dict) else None, record.get("sender"),+ record.get("from"), record.get("address")) or chat_identifier or chat_guid)if not (chat_guid or chat_identifier) and sender:chat_identifier = senderreturn chat_guid, chat_identifier, sender@@ -611,15 +572,13 @@ class BlueBubblesAdapter(BasePlatformAdapter):logger.error("[bluebubbles] webhook parse error: %s", exc)return web.json_response({"error": "invalid payload"}, status=400)event_type = self._value(payload.get("type"), payload.get("event")) or ""- # Only process message events; silently acknowledge everything else- if event_type and event_type not in _MESSAGE_EVENTS:+ if event_type and event_type not in _MESSAGE_EVENTS: # ack non-message events silentlyreturn _ok()record = self._extract_payload_record(payload) or {}if record.get("isFromMe") or record.get("fromMe") or record.get("is_from_me"):return _ok()- # Skip tapback reactions delivered as messagesassoc_type = record.get("associatedMessageType")- if isinstance(assoc_type, int) and assoc_type in _TAPBACK_CODES:+ if isinstance(assoc_type, int) and assoc_type in _TAPBACK_CODES: # tapback reactions delivered as messagesreturn _ok()text = self._value(record.get("text"), record.get("message"), record.get("body")) or ""media_urls, media_types, msg_type = await self._collect_attachments(record)@@ -647,7 +606,6 @@ class BlueBubblesAdapter(BasePlatformAdapter):task = asyncio.create_task(self.handle_message(event))self._background_tasks.add(task)task.add_done_callback(self._background_tasks.discard)- # Fire-and-forget read receipt- if self.send_read_receipts and session_chat_id:+ if self.send_read_receipts and session_chat_id: # fire-and-forget read receiptasyncio.create_task(self.mark_read(session_chat_id))return _ok()diff --git a/gateway/platforms/signal.py b/gateway/platforms/signal.pyindex af0864eef70..5384041ebb7 100644--- a/gateway/platforms/signal.py+++ b/gateway/platforms/signal.py@@ -956,7 +956,8 @@ class SignalAdapter(BasePlatformAdapter):async def send_reaction(self, chat_id: str, emoji: str, target_author: str, target_timestamp: int) -> bool:"""React to the message (author number/UUID, Signal ms timestamp) via signal-cli RPC."""ok = await self._send_reaction_rpc(chat_id, {- "account": self.account, "emoji": emoji, "targetAuthor": target_author, "targetTimestamp": target_timestamp})+ "account": self.account, "emoji": emoji, "targetAuthor": target_author,+ "targetTimestamp": target_timestamp})if not ok:logger.debug("Signal: sendReaction failed (chat=%s, emoji=%s)", chat_id[:20], emoji)return okdiff --git a/gateway/platforms/webhook.py b/gateway/platforms/webhook.pyindex 3635b5340f3..2933cb1709d 100644--- a/gateway/platforms/webhook.py+++ b/gateway/platforms/webhook.py@@ -538,7 +538,8 @@ class WebhookAdapter(BasePlatformAdapter):or payload.get("event_type", "") or payload.get("type", "") or "unknown")allowed_events = route_config.get("events", [])if allowed_events and event_type not in allowed_events:- logger.debug("[webhook] Ignoring event %s for route %s (allowed: %s)", event_type, route_name, allowed_events)+ logger.debug("[webhook] Ignoring event %s for route %s (allowed: %s)", event_type, route_name,+ allowed_events)return web.json_response({"status": "ignored", "event": event_type})if not self._route_processor.route_filters_match(route_config, payload, event_type, request.headers):logger.info("[webhook] filtered event=%s route=%s", event_type, route_name)@@ -550,7 +551,8 @@ class WebhookAdapter(BasePlatformAdapter):if script:# Shells out (up to its timeout) — worker thread so the loop isn't blocked; to_thread# copies contextvars so the profile scope follows.- keep, transformed_payload = await asyncio.to_thread(self._route_processor.run_route_script, script, payload)+ keep, transformed_payload = await asyncio.to_thread(+ self._route_processor.run_route_script, script, payload)if not keep:logger.info("[webhook] script ignored event=%s route=%s", event_type, route_name)return web.json_response({"status": "ignored", "reason": "script", "route": route_name})@@ -658,8 +660,8 @@ class WebhookAdapter(BasePlatformAdapter):logger.warning("[webhook] Route '%s' sent X-Webhook-Signature-V2 with no X-Webhook-Timestamp — ""rejecting rather than falling back to legacy V1", route_name)return False- if not _timestamp_fresh(v2_timestamp, "[webhook] Route '%s' generic HMAC V2 timestamp outside replay window",- route_name):+ if not _timestamp_fresh(+ v2_timestamp, "[webhook] Route '%s' generic HMAC V2 timestamp outside replay window", route_name):return Falsereturn _hmac_str_equal(v2_sig, _hex_hmac(secret, v2_timestamp.encode() + b"." + body))# Generic V1 (legacy, deprecated): body-only HMAC → replays indefinitely.