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 <noreply@anthropic.com>
This commit is contained in:
18
bot.py
18
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:
|
||||
|
||||
Reference in New Issue
Block a user