From f16c94b2dc0c8fe9f8da06326896373b469c7c59 Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Wed, 15 Apr 2026 19:00:32 +0300 Subject: [PATCH] perf(MAT): fire-and-forget auto-rename + harden memory-extract None response - `_auto_rename_room` now runs as a tracked bg task. Title generation latency no longer affects when the handler returns and frees the room lock, so users can fire the next message sooner. - Memory extraction guards against providers returning `None` for `choices[0].message.content` (observed in logs: AttributeError on .strip). Logs once and returns cleanly instead of raising. Co-Authored-By: Claude Opus 4.6 --- bot.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index b96d3fd..769f1ec 100644 --- a/bot.py +++ b/bot.py @@ -1974,7 +1974,13 @@ class Bot: ], max_tokens=300, ) - raw = resp.choices[0].message.content.strip() + raw_content = resp.choices[0].message.content + if not raw_content: + # Some providers return None content when the model decides to emit nothing + # (e.g. safety filter, empty JSON array would still be a string though). + logger.info("Memory extraction: empty model response, nothing to store") + return + raw = raw_content.strip() logger.info("Memory extraction raw response: %s", raw[:200]) if raw.startswith("```"): @@ -3306,12 +3312,18 @@ class Bot: self._bg_tasks.add(task) task.add_done_callback(self._bg_tasks.discard) - # Auto-rename: only for group rooms with explicit opt-in (not DMs) + # Auto-rename: only for group rooms with explicit opt-in (not DMs). + # Fire-and-forget so the title-generation LLM call doesn't gate + # the turn return path. if room.room_id in self.auto_rename_rooms: last_rename = self.renamed_rooms.get(room.room_id, 0) gap_seconds = time.time() - last_rename if last_rename else float("inf") if gap_seconds > 300: - await self._auto_rename_room(room, user_message, reply) + rename_task = asyncio.create_task( + self._auto_rename_room(room, user_message, reply) + ) + self._bg_tasks.add(rename_task) + rename_task.add_done_callback(self._bg_tasks.discard) return reply except _openai.APIStatusError as e: