修复群总结转图假死:增加阶段进度日志与超时保护

变更项:1) 移除图片渲染前截断,保持完整内容转图。2) 群总结转图增加总超时,超时后快速降级文本,避免任务长期阻塞。3) markdown_to_image 增加每10秒进度心跳日志,定位卡在 markdown_to_html 或 html_to_image。4) 分阶段超时与阶段开始日志完善,解决无错误无进度的问题。
This commit is contained in:
liuwei
2026-04-17 09:16:26 +08:00
parent 6b68de7f4e
commit 55c3b951d5
2 changed files with 78 additions and 6 deletions

View File

@@ -89,6 +89,11 @@ class MessageSummaryPlugin(MessagePluginInterface):
self._connect_timeout_seconds = int(api_config.get("connect_timeout_seconds", 10))
self._request_timeout_seconds = int(api_config.get("request_timeout_seconds", 180))
self._retry_delays_seconds = api_config.get("retry_delays_seconds", [10, 20])
# 输出阶段超时与体积保护:防止 Markdown 转图在异常环境下长时间卡死。
output_config = self._config.get("output", {})
self._image_render_timeout_seconds = int(output_config.get("image_render_timeout_seconds", 90))
# 默认只尝试 1 次,优先保证任务快速返回;需要更高成功率可在配置里提高。
self._image_render_retries = int(output_config.get("image_render_retries", 1))
self.llm_client = UnifiedLLMClient(api_config)
self._api_mode = self.llm_client.mode or self._api_mode
self._response_mode = self.llm_client.response_mode or self._response_mode
@@ -539,7 +544,18 @@ class MessageSummaryPlugin(MessagePluginInterface):
timestamp = int(time.time())
output_path = f"summary_{timestamp}.png"
self.LOG.info(f"开始生成图片: {output_path}")
spath = await convert_md_str_to_image(answer, output_path)
# 额外包一层总超时,确保就算底层依赖异常也不会把整个任务拖住。
total_timeout = max(30, self._image_render_timeout_seconds * self._image_render_retries + 10)
spath = await asyncio.wait_for(
convert_md_str_to_image(
answer,
output_path,
max_retries=self._image_render_retries,
render_timeout_seconds=self._image_render_timeout_seconds,
html_timeout_seconds=min(30, self._image_render_timeout_seconds),
),
timeout=total_timeout,
)
self.LOG.info(f"成功生成图片: {spath}")
except Exception as e:
self.LOG.error(f"生成图片失败: {e}", exc_info=True)